diff options
author | Andrey Nazarov <skuller@skuller.net> | 2011-02-23 16:13:23 +0300 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2011-02-23 16:13:23 +0300 |
commit | 356f70c3d55c4e21d61a30ab24cb6b0ba46861d6 (patch) | |
tree | e65f7b5c36feb294ebf79250d27ffc6508e4f25b | |
parent | d1a4276a7d1f9497b573c65a701c9ba79ac54f8e (diff) |
Allow F1-12 keys to be rebound from menu.
-rw-r--r-- | src/cl_keys.c | 38 | ||||
-rw-r--r-- | src/key_public.h | 4 | ||||
-rw-r--r-- | src/ui_atoms.c | 50 | ||||
-rw-r--r-- | src/ui_local.h | 1 | ||||
-rw-r--r-- | src/ui_menu.c | 63 |
5 files changed, 89 insertions, 67 deletions
diff --git a/src/cl_keys.c b/src/cl_keys.c index b481d85..e5c8522 100644 --- a/src/cl_keys.c +++ b/src/cl_keys.c @@ -27,13 +27,15 @@ key up events are sent even if in console mode static int anykeydown; -//static int key_waiting; +static keywaitcb_t key_wait_cb; +static void *key_wait_arg; + static char *keybindings[256]; -// if true, can't be rebound while in console +// if false, passed to interpreter while in console static qboolean consolekeys[256]; -// if true, can't be rebound while in menu +// if true, passed to interpreter while in menu static qboolean menubound[256]; #if !USE_CHAR_EVENTS @@ -623,14 +625,10 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) { Com_DDPrintf( "%u: %c%s\n", time, down ? '+' : '-', Key_KeynumToString( key ) ); -#if 0 - // hack for modal presses - if( key_waiting == -1 ) { - if( down ) - key_waiting = key; + // hack for menu key binding + if( key_wait_cb && down && !key_wait_cb( key_wait_arg, key ) ) { return; } -#endif // update auto-repeat status if( down ) { @@ -740,6 +738,11 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) { if( anykeydown < 0 ) anykeydown = 0; } + + // hack for demo freelook in windowed mode + if( cls.key_dest == KEY_GAME && cls.demo.playback && key == K_SHIFT ) { + IN_Activate(); + } // // if not a consolekey, send to the interpreter no matter what mode is @@ -748,11 +751,6 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) { ( ( cls.key_dest & KEY_CONSOLE ) && !consolekeys[key] ) || ( ( cls.key_dest & KEY_MENU ) && menubound[key] ) ) { - - // hack for demo freelook in windowed mode - if( cls.demo.playback && key == K_SHIFT ) { - IN_Activate(); - } // // Key up events only generate commands if the game key binding is // a button command (leading + sign). @@ -942,7 +940,13 @@ void Key_ClearStates( void ) { anykeydown = 0; } - - - +/* +=================== +Key_WaitKey +=================== +*/ +void Key_WaitKey( keywaitcb_t wait, void *arg ) { + key_wait_cb = wait; + key_wait_arg = arg; +} diff --git a/src/key_public.h b/src/key_public.h index f8f6ef3..227ce91 100644 --- a/src/key_public.h +++ b/src/key_public.h @@ -116,6 +116,8 @@ typedef enum keydest_e { KEY_MENU = ( 1 << 2 ) } keydest_t; +typedef qboolean (*keywaitcb_t)( void *arg, int key ); + qboolean Key_GetOverstrikeMode( void ); void Key_SetOverstrikeMode( qboolean overstrike ); keydest_t Key_GetDest( void ); @@ -131,3 +133,5 @@ void Key_SetBinding( int keynum, const char *binding ); char *Key_GetBinding( const char *binding ); int Key_EnumBindings( int key, const char *binding ); +void Key_WaitKey( keywaitcb_t wait, void *arg ); + diff --git a/src/ui_atoms.c b/src/ui_atoms.c index f7ae7b4..729d322 100644 --- a/src/ui_atoms.c +++ b/src/ui_atoms.c @@ -492,20 +492,7 @@ void UI_Draw( int realtime ) { R_SetColor( DRAW_COLOR_CLEAR, NULL ); } -/* -================= -UI_Keydown -================= -*/ -void UI_Keydown( int key ) { - menuSound_t sound; - - if( !uis.activeMenu ) { - return; - } - - sound = Menu_Keydown( uis.activeMenu, key ); - +void UI_StartSound( menuSound_t sound ) { switch( sound ) { case QMS_IN: S_StartLocalSound( "misc/menu1.wav" ); @@ -522,7 +509,23 @@ void UI_Keydown( int key ) { default: break; } +} + +/* +================= +UI_Keydown +================= +*/ +void UI_Keydown( int key ) { + menuSound_t sound; + + if( !uis.activeMenu ) { + return; + } + + sound = Menu_Keydown( uis.activeMenu, key ); + UI_StartSound( sound ); } /* @@ -544,24 +547,7 @@ void UI_CharEvent( int key ) { return; } - switch( sound ) { - case QMS_IN: - S_StartLocalSound( "misc/menu1.wav" ); - break; - case QMS_MOVE: - S_StartLocalSound( "misc/menu2.wav" ); - break; - case QMS_OUT: - S_StartLocalSound( "misc/menu3.wav" ); - break; - case QMS_BEEP: - S_StartLocalSound( "misc/talk1.wav" ); - break; - case QMS_NOTHANDLED: - default: - break; - } - + UI_StartSound( sound ); } static void UI_Menu_g( genctx_t *ctx ) { diff --git a/src/ui_local.h b/src/ui_local.h index 0f3e79c..dc76bd1 100644 --- a/src/ui_local.h +++ b/src/ui_local.h @@ -306,6 +306,7 @@ extern cvar_t *ui_debug; void UI_PushMenu( menuFrameWork_t *menu ); void UI_ForceMenuOff( void ); void UI_PopMenu( void ); +void UI_StartSound( menuSound_t sound ); qboolean UI_DoHitTest( void ); qboolean UI_CursorInRect( vrect_t *rect ); void *UI_FormatColumns( int extrasize, ... ) q_sentinel; diff --git a/src/ui_menu.c b/src/ui_menu.c index 7ad0b2b..c6a6ab1 100644 --- a/src/ui_menu.c +++ b/src/ui_menu.c @@ -226,14 +226,6 @@ static void Keybind_Draw( menuKeybind_t *k ) { k->generic.uiFlags | UI_LEFT, string ); } -static menuSound_t Keybind_DoEnter( menuKeybind_t *k ) { - menuFrameWork_t *menu = k->generic.parent; - - menu->keywait = qtrue; - menu->status = "Press the desired key, Escape to cancel"; - return QMS_IN; -} - static void Keybind_Push( menuKeybind_t *k ) { int key = Key_EnumBindings( 0, k->cmd ); k->altbinding[0] = 0; @@ -248,6 +240,10 @@ static void Keybind_Push( menuKeybind_t *k ) { } } +static void Keybind_Pop( menuKeybind_t *k ) { + Key_WaitKey( NULL, NULL ); +} + static void Keybind_Update( menuFrameWork_t *menu ) { menuKeybind_t *k; int i; @@ -272,20 +268,48 @@ static void Keybind_Remove( const char *cmd ) { } } +static qboolean keybind_cb( void *arg, int key ) { + menuKeybind_t *k = arg; + menuFrameWork_t *menu = k->generic.parent; + + // console key is hardcoded + if( key == '`' ) { + UI_StartSound( QMS_BEEP ); + return qfalse; + } + + // menu key is hardcoded + if( key != K_ESCAPE ) { + if( k->altbinding[0] ) { + Keybind_Remove( k->cmd ); + } + Key_SetBinding( key, k->cmd ); + } + + Keybind_Update( menu ); + + menu->keywait = qfalse; + menu->status = "Press Enter to change, Backspace to clear"; + Key_WaitKey( NULL, NULL ); + + UI_StartSound( QMS_OUT ); + return qfalse; +} + +static menuSound_t Keybind_DoEnter( menuKeybind_t *k ) { + menuFrameWork_t *menu = k->generic.parent; + + menu->keywait = qtrue; + menu->status = "Press the desired key, Escape to cancel"; + Key_WaitKey( keybind_cb, k ); + return QMS_IN; +} + static menuSound_t Keybind_Key( menuKeybind_t *k, int key ) { menuFrameWork_t *menu = k->generic.parent; if( menu->keywait ) { - if( key != K_ESCAPE ) { - if( k->altbinding[0] ) { - Keybind_Remove( k->cmd ); - } - Key_SetBinding( key, k->cmd ); - } - Keybind_Update( menu ); - menu->keywait = qfalse; - menu->status = "Press Enter to change, Backspace to clear"; - return QMS_OUT; + return QMS_OUT; // never gets there } if( key == K_BACKSPACE || key == K_DEL ) { @@ -1943,6 +1967,9 @@ void Menu_Pop( menuFrameWork_t *menu ) { case MTYPE_TOGGLE: SpinControl_Pop( item ); break; + case MTYPE_KEYBIND: + Keybind_Pop( item ); + break; case MTYPE_FIELD: Field_Pop( item ); break; |