* Fix bug that prevented key up events getting to cgame/ui when not in game

* Use Key_[GS]etCatcher everywhere to set keycatcher
* Clear all key states when the catcher changes
This commit is contained in:
Tim Angus 2007-10-02 14:14:45 +00:00
parent 26641226a4
commit 5692e30fa9
9 changed files with 79 additions and 71 deletions

View file

@ -720,7 +720,7 @@ void Message_Key( int key ) {
if (key == K_ESCAPE) {
cls.keyCatchers &= ~KEYCATCH_MESSAGE;
Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_MESSAGE );
Field_Clear( &chatField );
return;
}
@ -742,7 +742,7 @@ void Message_Key( int key ) {
CL_AddReliableCommand( buffer );
}
cls.keyCatchers &= ~KEYCATCH_MESSAGE;
Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_MESSAGE );
Field_Clear( &chatField );
return;
}
@ -1173,7 +1173,8 @@ void CL_KeyEvent (int key, qboolean down, unsigned time) {
// keys can still be used for bound actions
if ( down && ( key < 128 || key == K_MOUSE1 ) && ( clc.demoplaying || cls.state == CA_CINEMATIC ) && !cls.keyCatchers) {
if ( down && ( key < 128 || key == K_MOUSE1 ) &&
( clc.demoplaying || cls.state == CA_CINEMATIC ) && Key_GetCatcher( ) == 0 ) {
if (Cvar_VariableValue ("com_cameraMode") == 0) {
Cvar_Set ("nextdemo","");
@ -1184,20 +1185,20 @@ void CL_KeyEvent (int key, qboolean down, unsigned time) {
// escape is always handled special
if ( key == K_ESCAPE && down ) {
if ( cls.keyCatchers & KEYCATCH_MESSAGE ) {
if ( Key_GetCatcher( ) & KEYCATCH_MESSAGE ) {
// clear message mode
Message_Key( key );
return;
}
// escape always gets out of CGAME stuff
if (cls.keyCatchers & KEYCATCH_CGAME) {
cls.keyCatchers &= ~KEYCATCH_CGAME;
if (Key_GetCatcher( ) & KEYCATCH_CGAME) {
Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_CGAME );
VM_Call (cgvm, CG_EVENT_HANDLING, CGAME_EVENT_NONE);
return;
}
if ( !( cls.keyCatchers & KEYCATCH_UI ) ) {
if ( !( Key_GetCatcher( ) & KEYCATCH_UI ) ) {
if ( cls.state == CA_ACTIVE && !clc.demoplaying ) {
VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_INGAME );
}
@ -1224,12 +1225,12 @@ void CL_KeyEvent (int key, qboolean down, unsigned time) {
kb = keys[key].binding;
CL_AddKeyUpCommands( key, kb, time );
}
if ( cls.keyCatchers & KEYCATCH_UI && uivm ) {
VM_Call( uivm, UI_KEY_EVENT, key, down );
} else if ( cls.keyCatchers & KEYCATCH_CGAME && cgvm ) {
VM_Call( cgvm, CG_KEY_EVENT, key, down );
}
if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) {
VM_Call( uivm, UI_KEY_EVENT, key, down );
} else if ( Key_GetCatcher( ) & KEYCATCH_CGAME && cgvm ) {
VM_Call( cgvm, CG_KEY_EVENT, key, down );
}
return;
@ -1237,17 +1238,17 @@ void CL_KeyEvent (int key, qboolean down, unsigned time) {
// distribute the key down event to the apropriate handler
if ( cls.keyCatchers & KEYCATCH_CONSOLE ) {
if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) {
Console_Key( key );
} else if ( cls.keyCatchers & KEYCATCH_UI ) {
} else if ( Key_GetCatcher( ) & KEYCATCH_UI ) {
if ( uivm ) {
VM_Call( uivm, UI_KEY_EVENT, key, down );
}
} else if ( cls.keyCatchers & KEYCATCH_CGAME ) {
} else if ( Key_GetCatcher( ) & KEYCATCH_CGAME ) {
if ( cgvm ) {
VM_Call( cgvm, CG_KEY_EVENT, key, down );
}
} else if ( cls.keyCatchers & KEYCATCH_MESSAGE ) {
} else if ( Key_GetCatcher( ) & KEYCATCH_MESSAGE ) {
Message_Key( key );
} else if ( cls.state == CA_DISCONNECTED ) {
Console_Key( key );
@ -1315,15 +1316,15 @@ void CL_CharEvent( int key ) {
}
// distribute the key down event to the apropriate handler
if ( cls.keyCatchers & KEYCATCH_CONSOLE )
if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE )
{
Field_CharEvent( &g_consoleField, key );
}
else if ( cls.keyCatchers & KEYCATCH_UI )
else if ( Key_GetCatcher( ) & KEYCATCH_UI )
{
VM_Call( uivm, UI_KEY_EVENT, key | K_CHAR_FLAG, qtrue );
}
else if ( cls.keyCatchers & KEYCATCH_MESSAGE )
else if ( Key_GetCatcher( ) & KEYCATCH_MESSAGE )
{
Field_CharEvent( &chatField, key );
}
@ -1355,6 +1356,30 @@ void Key_ClearStates (void)
}
}
static int keyCatchers = 0;
/*
====================
Key_GetCatcher
====================
*/
int Key_GetCatcher( void ) {
return keyCatchers;
}
/*
====================
Key_SetCatcher
====================
*/
void Key_SetCatcher( int catcher ) {
// If the catcher state is changing, clear all key states
if( catcher != keyCatchers )
Key_ClearStates( );
keyCatchers = catcher;
}
// This must not exceed MAX_CMD_LINE
#define MAX_CONSOLE_SAVE_BUFFER 1024
#define CONSOLE_HISTORY_FILE "q3history"