From f39fed9f802790e3031eb9aa3e25d37b803116c1 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 20 Apr 2006 23:54:12 +0000 Subject: [PATCH] added keyup function for menu qc at Black's request git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6323 d7cf8633-e32d-0410-b094-e92efae38249 --- keys.c | 38 ++++++++++++++++++++------------------ menu.c | 22 +++++++++++++++------- menu.h | 6 +++--- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/keys.c b/keys.c index 340a3c31..8bdc4e1d 100644 --- a/keys.c +++ b/keys.c @@ -861,7 +861,13 @@ Key_Event (int key, char ascii, qboolean down) } } - if (!down) + if (down) + { + // increment key repeat count each time a down is received so that things + // which want to ignore key repeat can ignore it + keydown[key] = min(keydown[key] + 1, 2); + } + else { // clear repeat count now that the key is released keydown[key] = 0; @@ -872,15 +878,8 @@ Key_Event (int key, char ascii, qboolean down) // downs can be matched with ups if (bind && bind[0] == '+') Cbuf_AddText(va("-%s %i\n", bind + 1, key)); - return; } - // from here on we know this is a down event - - // increment key repeat count each time a down is received so that things - // which want to ignore key repeat can ignore it - keydown[key] = min(keydown[key] + 1, 2); - // key_consoleactive is a flag not a key_dest because the console is a // high priority overlay ontop of the normal screen (designed as a safety // feature so that developers and users can rescue themselves from a bad @@ -903,7 +902,7 @@ Key_Event (int key, char ascii, qboolean down) // key_menu - go to parent menu (or key_game) // key_game - open menu // in all modes shift-escape toggles console - if ((key_consoleactive & KEY_CONSOLEACTIVE_USER) || keydown[K_SHIFT]) + if (((key_consoleactive & KEY_CONSOLEACTIVE_USER) || keydown[K_SHIFT]) && down) { Con_ToggleConsole_f (); return; @@ -911,13 +910,15 @@ Key_Event (int key, char ascii, qboolean down) switch (key_dest) { case key_message: - Key_Message (key, ascii); + if (down) + Key_Message (key, ascii); break; case key_menu: - MR_Keydown (key, ascii); + MR_KeyEvent (key, ascii, down); break; case key_game: - MR_ToggleMenu_f (); + if (down) + MR_ToggleMenu_f (); break; default: Con_Printf ("Key_Event: Bad key_dest\n"); @@ -926,7 +927,7 @@ Key_Event (int key, char ascii, qboolean down) } // send function keydowns to interpreter no matter what mode is - if (key >= K_F1 && key <= K_F12) + if (key >= K_F1 && key <= K_F12 && down) { // ignore key repeats on F1-F12 binds if (keydown[key] > 1) @@ -947,11 +948,11 @@ Key_Event (int key, char ascii, qboolean down) #if 1 // ignore binds (other than the above escape/F1-F12 keys) while in console - if (key_consoleactive) + if (key_consoleactive && down) #else // respond to toggleconsole binds while in console unless the pressed key // happens to be the color prefix character (such as on German keyboards) - if (key_consoleactive && (strncmp(bind, "toggleconsole", strlen("toggleconsole")) || ascii == STRING_COLOR_TAG)) + if (key_consoleactive && down && (strncmp(bind, "toggleconsole", strlen("toggleconsole")) || ascii == STRING_COLOR_TAG)) #endif { Key_Console (key, ascii); @@ -962,14 +963,15 @@ Key_Event (int key, char ascii, qboolean down) switch (key_dest) { case key_message: - Key_Message (key, ascii); + if (down) + Key_Message (key, ascii); break; case key_menu: - MR_Keydown (key, ascii); + MR_KeyEvent (key, ascii, down); break; case key_game: // ignore key repeats on binds - if (bind && keydown[key] == 1) + if (bind && keydown[key] == 1 && down) { // button commands add keynum as a parm if (bind[0] == '+') diff --git a/menu.c b/menu.c index f3e3378e..25e2ab55 100644 --- a/menu.c +++ b/menu.c @@ -4410,7 +4410,7 @@ static void M_ServerList_Key(int k, char ascii) //============================================================================= /* Menu Subsystem */ -static void M_Keydown(int key, char ascii); +static void M_KeyEvent(int key, char ascii, qboolean downevent); static void M_Draw(void); void M_ToggleMenu_f(void); static void M_Shutdown(void); @@ -4642,8 +4642,10 @@ void M_Draw (void) } -void M_Keydown (int key, char ascii) +void M_KeyEvent (int key, char ascii, qboolean downevent) { + if (!downevent) + return; switch (m_state) { case m_none: @@ -4756,6 +4758,7 @@ mfunction_t *PRVM_ED_FindFunction(const char *); #define M_F_INIT "m_init" #define M_F_KEYDOWN "m_keydown" +#define M_F_KEYUP "m_keyup" #define M_F_DRAW "m_draw" // normal menu names (rest) #define M_F_TOGGLE "m_toggle" @@ -4776,6 +4779,7 @@ static qboolean m_displayed; static int m_numrequiredfunc = sizeof(m_required_func) / sizeof(char*); static func_t m_draw, m_keydown; +static mfunction_t *m_keyup; void MR_SetRouting (qboolean forceold); @@ -4811,7 +4815,7 @@ void MP_Error(const char *format, ...) Host_AbortCurrentFrame(); } -void MP_Keydown (int key, char ascii) +void MP_KeyEvent (int key, char ascii, qboolean downevent) { PRVM_Begin; PRVM_SetProg(PRVM_MENUPROG); @@ -4822,7 +4826,10 @@ void MP_Keydown (int key, char ascii) // pass key prog->globals.generic[OFS_PARM0] = (float) key; prog->globals.generic[OFS_PARM1] = (float) ascii; - PRVM_ExecuteProgram(m_keydown, M_F_KEYDOWN"(float key, float ascii) required\n"); + if (downevent) + PRVM_ExecuteProgram(m_keydown, M_F_KEYDOWN"(float key, float ascii) required\n"); + else if (m_keyup) + PRVM_ExecuteProgram((func_t)(m_keyup - prog->functions), M_F_KEYUP"(float key, float ascii) required\n"); PRVM_End; } @@ -4915,6 +4922,7 @@ void MP_Init (void) // set m_draw and m_keydown m_draw = (func_t) (PRVM_ED_FindFunction(M_F_DRAW) - prog->functions); m_keydown = (func_t) (PRVM_ED_FindFunction(M_F_KEYDOWN) - prog->functions); + m_keyup = PRVM_ED_FindFunction(M_F_KEYUP); #ifdef NG_MENU m_displayed = false; @@ -4939,7 +4947,7 @@ void MP_Restart(void) static cvar_t forceqmenu = { 0, "forceqmenu", "0", "enables the quake menu instead of the quakec menu.dat (if present)" }; -void (*MR_Keydown) (int key, char ascii); +void (*MR_KeyEvent) (int key, char ascii, qboolean downevent); void (*MR_Draw) (void); void (*MR_ToggleMenu_f) (void); void (*MR_Shutdown) (void); @@ -4952,7 +4960,7 @@ void MR_SetRouting(qboolean forceold) if(!FS_FileExists(M_PROG_FILENAME) || forceqmenu.integer || forceold) { // set menu router function pointers - MR_Keydown = M_Keydown; + MR_KeyEvent = M_KeyEvent; MR_Draw = M_Draw; MR_ToggleMenu_f = M_ToggleMenu_f; MR_Shutdown = M_Shutdown; @@ -4969,7 +4977,7 @@ void MR_SetRouting(qboolean forceold) else { // set menu router function pointers - MR_Keydown = MP_Keydown; + MR_KeyEvent = MP_KeyEvent; MR_Draw = MP_Draw; MR_ToggleMenu_f = MP_ToggleMenu_f; MR_Shutdown = MP_Shutdown; diff --git a/menu.h b/menu.h index 73adb738..d2666824 100644 --- a/menu.h +++ b/menu.h @@ -59,7 +59,7 @@ void M_Update_Return_Reason(char *s); // hard-coded menus // void M_Init (void); -void M_Keydown (int key); +void M_KeyEvent (int key); void M_Draw (void); void M_ToggleMenu_f (void); @@ -67,7 +67,7 @@ void M_ToggleMenu_f (void); // menu prog menu // void MP_Init (void); -void MP_Keydown (int key); +void MP_KeyEvent (int key); void MP_Draw (void); void MP_ToggleMenu_f (void); void MP_Shutdown (void);*/ @@ -78,7 +78,7 @@ void MP_Shutdown (void);*/ void MR_Init_Commands (void); void MR_Init (void); void MR_Restart (void); -extern void (*MR_Keydown) (int key, char ascii); +extern void (*MR_KeyEvent) (int key, char ascii, qboolean downevent); extern void (*MR_Draw) (void); extern void (*MR_ToggleMenu_f) (void); extern void (*MR_Shutdown) (void); -- 2.39.2