diff options
| -rw-r--r-- | code/client/cl_cgame.c | 5 | ||||
| -rw-r--r-- | code/client/cl_console.c | 26 | ||||
| -rw-r--r-- | code/client/cl_input.c | 8 | ||||
| -rw-r--r-- | code/client/cl_keys.c | 63 | ||||
| -rw-r--r-- | code/client/cl_main.c | 13 | ||||
| -rw-r--r-- | code/client/cl_scrn.c | 2 | ||||
| -rw-r--r-- | code/client/cl_ui.c | 26 | ||||
| -rw-r--r-- | code/client/client.h | 3 | ||||
| -rw-r--r-- | code/sdl/sdl_input.c | 4 | 
9 files changed, 79 insertions, 71 deletions
diff --git a/code/client/cl_cgame.c b/code/client/cl_cgame.c index b53e304..b2a3cc4 100644 --- a/code/client/cl_cgame.c +++ b/code/client/cl_cgame.c @@ -387,7 +387,7 @@ CL_ShutdonwCGame  ====================  */  void CL_ShutdownCGame( void ) { -	cls.keyCatchers &= ~KEYCATCH_CGAME; +	Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_CGAME );  	cls.cgameStarted = qfalse;  	if ( !cgvm ) {  		return; @@ -607,7 +607,8 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) {    case CG_KEY_GETCATCHER:  		return Key_GetCatcher();    case CG_KEY_SETCATCHER: -		Key_SetCatcher( args[1] ); +		// Don't allow the cgame module to close the console +		Key_SetCatcher( args[1] | ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) );      return 0;    case CG_KEY_GETKEY:  		return Key_GetKey( VMA(1) ); diff --git a/code/client/cl_console.c b/code/client/cl_console.c index 898fce2..5aad766 100644 --- a/code/client/cl_console.c +++ b/code/client/cl_console.c @@ -72,7 +72,7 @@ Con_ToggleConsole_f  */  void Con_ToggleConsole_f (void) {  	// Can't toggle the console when it's the only thing available -	if ( cls.state == CA_DISCONNECTED && cls.keyCatchers == KEYCATCH_CONSOLE ) { +	if ( cls.state == CA_DISCONNECTED && Key_GetCatcher( ) == KEYCATCH_CONSOLE ) {  		return;  	} @@ -80,7 +80,7 @@ void Con_ToggleConsole_f (void) {  	g_consoleField.widthInChars = g_console_field_width;  	Con_ClearNotify (); -	cls.keyCatchers ^= KEYCATCH_CONSOLE; +	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_CONSOLE );  }  /* @@ -94,7 +94,7 @@ void Con_MessageMode_f (void) {  	Field_Clear( &chatField );  	chatField.widthInChars = 30; -	cls.keyCatchers ^= KEYCATCH_MESSAGE; +	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );  }  /* @@ -107,7 +107,7 @@ void Con_MessageMode2_f (void) {  	chat_team = qtrue;  	Field_Clear( &chatField );  	chatField.widthInChars = 25; -	cls.keyCatchers ^= KEYCATCH_MESSAGE; +	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );  }  /* @@ -124,7 +124,7 @@ void Con_MessageMode3_f (void) {  	chat_team = qfalse;  	Field_Clear( &chatField );  	chatField.widthInChars = 30; -	cls.keyCatchers ^= KEYCATCH_MESSAGE; +	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );  }  /* @@ -141,7 +141,7 @@ void Con_MessageMode4_f (void) {  	chat_team = qfalse;  	Field_Clear( &chatField );  	chatField.widthInChars = 30; -	cls.keyCatchers ^= KEYCATCH_MESSAGE; +	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );  }  /* @@ -477,7 +477,7 @@ Draw the editline after a ] prompt  void Con_DrawInput (void) {  	int		y; -	if ( cls.state != CA_DISCONNECTED && !(cls.keyCatchers & KEYCATCH_CONSOLE ) ) { +	if ( cls.state != CA_DISCONNECTED && !(Key_GetCatcher( ) & KEYCATCH_CONSOLE ) ) {  		return;  	} @@ -524,7 +524,7 @@ void Con_DrawNotify (void)  			continue;  		text = con.text + (i % con.totallines)*con.linewidth; -		if (cl.snap.ps.pm_type != PM_INTERMISSION && cls.keyCatchers & (KEYCATCH_UI | KEYCATCH_CGAME) ) { +		if (cl.snap.ps.pm_type != PM_INTERMISSION && Key_GetCatcher( ) & (KEYCATCH_UI | KEYCATCH_CGAME) ) {  			continue;  		} @@ -544,12 +544,12 @@ void Con_DrawNotify (void)  	re.SetColor( NULL ); -	if (cls.keyCatchers & (KEYCATCH_UI | KEYCATCH_CGAME) ) { +	if (Key_GetCatcher( ) & (KEYCATCH_UI | KEYCATCH_CGAME) ) {  		return;  	}  	// draw the chat line -	if ( cls.keyCatchers & KEYCATCH_MESSAGE ) +	if ( Key_GetCatcher( ) & KEYCATCH_MESSAGE )  	{  		if (chat_team)  		{ @@ -697,7 +697,7 @@ void Con_DrawConsole( void ) {  	// if disconnected, render console full screen  	if ( cls.state == CA_DISCONNECTED ) { -		if ( !( cls.keyCatchers & (KEYCATCH_UI | KEYCATCH_CGAME)) ) { +		if ( !( Key_GetCatcher( ) & (KEYCATCH_UI | KEYCATCH_CGAME)) ) {  			Con_DrawSolidConsole( 1.0 );  			return;  		} @@ -724,7 +724,7 @@ Scroll it up or down  */  void Con_RunConsole (void) {  	// decide on the destination height of the console -	if ( cls.keyCatchers & KEYCATCH_CONSOLE ) +	if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE )  		con.finalFrac = 0.5;		// half screen  	else  		con.finalFrac = 0;				// none visible @@ -779,7 +779,7 @@ void Con_Close( void ) {  	}  	Field_Clear( &g_consoleField );  	Con_ClearNotify (); -	cls.keyCatchers &= ~KEYCATCH_CONSOLE; +	Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_CONSOLE );  	con.finalFrac = 0;				// none visible  	con.displayFrac = 0;  } diff --git a/code/client/cl_input.c b/code/client/cl_input.c index 8609d5a..f7e3920 100644 --- a/code/client/cl_input.c +++ b/code/client/cl_input.c @@ -351,9 +351,9 @@ CL_MouseEvent  =================  */  void CL_MouseEvent( int dx, int dy, int time ) { -	if ( cls.keyCatchers & KEYCATCH_UI ) { +	if ( Key_GetCatcher( ) & KEYCATCH_UI ) {  		VM_Call( uivm, UI_MOUSE_EVENT, dx, dy ); -	} else if (cls.keyCatchers & KEYCATCH_CGAME) { +	} else if (Key_GetCatcher( ) & KEYCATCH_CGAME) {  		VM_Call (cgvm, CG_MOUSE_EVENT, dx, dy);  	} else {  		cl.mouseDx[cl.mouseIndex] += dx; @@ -487,13 +487,13 @@ void CL_CmdButtons( usercmd_t *cmd ) {  		in_buttons[i].wasPressed = qfalse;  	} -	if ( cls.keyCatchers ) { +	if ( Key_GetCatcher( ) ) {  		cmd->buttons |= BUTTON_TALK;  	}  	// allow the game to know if any key at all is  	// currently pressed, even if it isn't bound to anything -	if ( anykeydown && !cls.keyCatchers ) { +	if ( anykeydown && Key_GetCatcher( ) == 0 ) {  		cmd->buttons |= BUTTON_ANY;  	}  } diff --git a/code/client/cl_keys.c b/code/client/cl_keys.c index 8991d0e..0f481a3 100644 --- a/code/client/cl_keys.c +++ b/code/client/cl_keys.c @@ -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" diff --git a/code/client/cl_main.c b/code/client/cl_main.c index 146c234..488c531 100644 --- a/code/client/cl_main.c +++ b/code/client/cl_main.c @@ -652,7 +652,7 @@ Closing the main menu will restart the demo loop  void CL_StartDemoLoop( void ) {  	// start the demo loop again  	Cbuf_AddText ("d1\n"); -	cls.keyCatchers = 0; +	Key_SetCatcher( 0 );  }  /* @@ -751,7 +751,7 @@ memory on the hunk from cgame, ui, and renderer  void CL_MapLoading( void ) {  	if ( com_dedicated->integer ) {  		cls.state = CA_DISCONNECTED; -		cls.keyCatchers = KEYCATCH_CONSOLE; +		Key_SetCatcher( KEYCATCH_CONSOLE );  		return;  	} @@ -760,7 +760,7 @@ void CL_MapLoading( void ) {  	}  	Con_Close(); -	cls.keyCatchers = 0; +	Key_SetCatcher( 0 );  	// if we are already connected to the local host, stay connected  	if ( cls.state >= CA_CONNECTED && !Q_stricmp( cls.servername, "localhost" ) ) { @@ -776,7 +776,7 @@ void CL_MapLoading( void ) {  		CL_Disconnect( qtrue );  		Q_strncpyz( cls.servername, "localhost", sizeof(cls.servername) );  		cls.state = CA_CHALLENGING;		// so the connect screen is drawn -		cls.keyCatchers = 0; +		Key_SetCatcher( 0 );  		SCR_UpdateScreen();  		clc.connectTime = -RETRANSMIT_TIMEOUT;  		NET_StringToAdr( cls.servername, &clc.serverAddress); @@ -1205,7 +1205,7 @@ void CL_Connect_f( void ) {  		cls.state = CA_CONNECTING;  	} -	cls.keyCatchers = 0; +	Key_SetCatcher( 0 );  	clc.connectTime = -99999;	// CL_CheckForResend() will fire immediately  	clc.connectPacketCount = 0; @@ -2228,7 +2228,7 @@ void CL_Frame ( int msec ) {  		// bring up the cd error dialog if needed  		cls.cddialog = qfalse;  		VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_NEED_CD ); -	} else	if ( cls.state == CA_DISCONNECTED && !( cls.keyCatchers & KEYCATCH_UI ) +	} else	if ( cls.state == CA_DISCONNECTED && !( Key_GetCatcher( ) & KEYCATCH_UI )  		&& !com_sv_running->integer ) {  		// if disconnected, bring up the menu  		S_StopAllSounds(); @@ -2857,6 +2857,7 @@ void CL_Shutdown( void ) {  	recursive = qfalse;  	Com_Memset( &cls, 0, sizeof( cls ) ); +	Key_SetCatcher( 0 );  	Com_Printf( "-----------------------\n" ); diff --git a/code/client/cl_scrn.c b/code/client/cl_scrn.c index 86879f1..a24984b 100644 --- a/code/client/cl_scrn.c +++ b/code/client/cl_scrn.c @@ -490,7 +490,7 @@ void SCR_DrawScreenField( stereoFrame_t stereoFrame ) {  	}  	// the menu draws next -	if ( cls.keyCatchers & KEYCATCH_UI && uivm ) { +	if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) {  		VM_Call( uivm, UI_REFRESH, cls.realtime );  	} diff --git a/code/client/cl_ui.c b/code/client/cl_ui.c index ccfc39d..31b938a 100644 --- a/code/client/cl_ui.c +++ b/code/client/cl_ui.c @@ -664,27 +664,6 @@ static void Key_GetBindingBuf( int keynum, char *buf, int buflen ) {  /*  ==================== -Key_GetCatcher -==================== -*/ -int Key_GetCatcher( void ) { -	return cls.keyCatchers; -} - -/* -==================== -Ket_SetCatcher -==================== -*/ -void Key_SetCatcher( int catcher ) { -	// prevent console from being closed -	catcher |= cls.keyCatchers & KEYCATCH_CONSOLE; -	cls.keyCatchers = catcher; -} - - -/* -====================  CLUI_GetCDKey  ====================  */ @@ -932,7 +911,8 @@ intptr_t CL_UISystemCalls( intptr_t *args ) {  		return Key_GetCatcher();  	case UI_KEY_SETCATCHER: -		Key_SetCatcher( args[1] ); +		// Don't allow the ui module to close the console +		Key_SetCatcher( args[1] | ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) );  		return 0;  	case UI_GETCLIPBOARDDATA: @@ -1124,7 +1104,7 @@ CL_ShutdownUI  ====================  */  void CL_ShutdownUI( void ) { -	cls.keyCatchers &= ~KEYCATCH_UI; +	Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_UI );  	cls.uiStarted = qfalse;  	if ( !uivm ) {  		return; diff --git a/code/client/client.h b/code/client/client.h index 936f906..b68b518 100644 --- a/code/client/client.h +++ b/code/client/client.h @@ -270,7 +270,6 @@ typedef struct {  typedef struct {  	connstate_t	state;				// connection status -	int			keyCatchers;		// bit flags  	qboolean	cddialog;			// bring up the cd needed dialog next frame @@ -442,6 +441,8 @@ void CL_VerifyCode( void );  float CL_KeyState (kbutton_t *key);  char *Key_KeynumToString (int keynum); +int Key_GetCatcher( void ); +void Key_SetCatcher( int catcher );  //  // cl_parse.c diff --git a/code/sdl/sdl_input.c b/code/sdl/sdl_input.c index 89b8be6..2e610a8 100644 --- a/code/sdl/sdl_input.c +++ b/code/sdl/sdl_input.c @@ -651,7 +651,7 @@ static void IN_ProcessEvents( void )  	if( !SDL_WasInit( SDL_INIT_VIDEO ) )  			return; -	if( cls.keyCatchers == 0 && keyRepeatEnabled ) +	if( Key_GetCatcher( ) == 0 && keyRepeatEnabled )  	{  		SDL_EnableKeyRepeat( 0, 0 );  		keyRepeatEnabled = qfalse; @@ -730,7 +730,7 @@ void IN_Frame (void)  	IN_JoyMove( );  	// Release the mouse if the console if down and we're windowed -	if( ( cls.keyCatchers & KEYCATCH_CONSOLE ) && !r_fullscreen->integer ) +	if( ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) && !r_fullscreen->integer )  		IN_DeactivateMouse( );  	else  		IN_ActivateMouse( );  | 
