Add togglemenu command

Allow togglemenu to be run in binds while in menu or message mode.
This commit is contained in:
Zack Middleton 2013-01-16 23:03:09 -06:00
parent 4de32b1c1a
commit bf2b04254a
3 changed files with 54 additions and 11 deletions

2
README
View file

@ -281,6 +281,8 @@ New commands
stopvideo - stop video capture stopvideo - stop video capture
stopmusic - stop background music stopmusic - stop background music
minimize - Minimize the game and show desktop minimize - Minimize the game and show desktop
togglemenu - causes escape key event for opening/closing menu, or
going to a pervious menu. works in binds, even in UI
print - print out the contents of a cvar print - print out the contents of a cvar
unset - unset a user created cvar unset - unset a user created cvar

View file

@ -81,6 +81,16 @@ void Con_ToggleConsole_f (void) {
Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_CONSOLE ); Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_CONSOLE );
} }
/*
===================
Con_ToggleMenu_f
===================
*/
void Con_ToggleMenu_f( void ) {
CL_KeyEvent( K_ESCAPE, qtrue, Sys_Milliseconds() );
CL_KeyEvent( K_ESCAPE, qfalse, Sys_Milliseconds() );
}
/* /*
================ ================
Con_MessageMode_f Con_MessageMode_f
@ -332,6 +342,7 @@ void Con_Init (void) {
CL_LoadConsoleHistory( ); CL_LoadConsoleHistory( );
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f); Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f);
Cmd_AddCommand ("togglemenu", Con_ToggleMenu_f);
Cmd_AddCommand ("messagemode", Con_MessageMode_f); Cmd_AddCommand ("messagemode", Con_MessageMode_f);
Cmd_AddCommand ("messagemode2", Con_MessageMode2_f); Cmd_AddCommand ("messagemode2", Con_MessageMode2_f);
Cmd_AddCommand ("messagemode3", Con_MessageMode3_f); Cmd_AddCommand ("messagemode3", Con_MessageMode3_f);
@ -349,6 +360,7 @@ Con_Shutdown
void Con_Shutdown(void) void Con_Shutdown(void)
{ {
Cmd_RemoveCommand("toggleconsole"); Cmd_RemoveCommand("toggleconsole");
Cmd_RemoveCommand("togglemenu");
Cmd_RemoveCommand("messagemode"); Cmd_RemoveCommand("messagemode");
Cmd_RemoveCommand("messagemode2"); Cmd_RemoveCommand("messagemode2");
Cmd_RemoveCommand("messagemode3"); Cmd_RemoveCommand("messagemode3");

View file

@ -1120,6 +1120,23 @@ void CL_InitKeyCommands( void ) {
Cmd_AddCommand ("bindlist",Key_Bindlist_f); Cmd_AddCommand ("bindlist",Key_Bindlist_f);
} }
/*
===================
CL_BindUICommand
Returns qtrue if bind command should be executed while user interface is shown
===================
*/
static qboolean CL_BindUICommand( const char *cmd ) {
if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE )
return qfalse;
if ( !Q_stricmp( cmd, "togglemenu" ) )
return qtrue;
return qfalse;
}
/* /*
=================== ===================
CL_ParseBinding CL_ParseBinding
@ -1130,11 +1147,20 @@ Execute the commands in the bind string
void CL_ParseBinding( int key, qboolean down, unsigned time ) void CL_ParseBinding( int key, qboolean down, unsigned time )
{ {
char buf[ MAX_STRING_CHARS ], *p = buf, *end; char buf[ MAX_STRING_CHARS ], *p = buf, *end;
qboolean allCommands, allowUpCmds;
if( clc.state == CA_DISCONNECTED && Key_GetCatcher( ) == 0 )
return;
if( !keys[key].binding || !keys[key].binding[0] ) if( !keys[key].binding || !keys[key].binding[0] )
return; return;
Q_strncpyz( buf, keys[key].binding, sizeof( buf ) ); Q_strncpyz( buf, keys[key].binding, sizeof( buf ) );
// run all bind commands if console, ui, etc aren't reading keys
allCommands = ( Key_GetCatcher( ) == 0 );
// allow button up commands if in game even if key catcher is set
allowUpCmds = ( clc.state != CA_DISCONNECTED );
while( 1 ) while( 1 )
{ {
while( isspace( *p ) ) while( isspace( *p ) )
@ -1147,17 +1173,21 @@ void CL_ParseBinding( int key, qboolean down, unsigned time )
// button commands add keynum and time as parameters // button commands add keynum and time as parameters
// so that multiple sources can be discriminated and // so that multiple sources can be discriminated and
// subframe corrected // subframe corrected
if ( allCommands || ( allowUpCmds && !down ) ) {
char cmd[1024]; char cmd[1024];
Com_sprintf( cmd, sizeof( cmd ), "%c%s %d %d\n", Com_sprintf( cmd, sizeof( cmd ), "%c%s %d %d\n",
( down ) ? '+' : '-', p + 1, key, time ); ( down ) ? '+' : '-', p + 1, key, time );
Cbuf_AddText( cmd ); Cbuf_AddText( cmd );
} }
}
else if( down ) else if( down )
{ {
// normal commands only execute on key press // normal commands only execute on key press
if ( allCommands || CL_BindUICommand( p ) ) {
Cbuf_AddText( p ); Cbuf_AddText( p );
Cbuf_AddText( "\n" ); Cbuf_AddText( "\n" );
} }
}
if( !end ) if( !end )
break; break;
p = end + 1; p = end + 1;
@ -1250,10 +1280,10 @@ void CL_KeyDownEvent( int key, unsigned time )
Message_Key( key ); Message_Key( key );
} else if ( clc.state == CA_DISCONNECTED ) { } else if ( clc.state == CA_DISCONNECTED ) {
Console_Key( key ); Console_Key( key );
} else { }
// send the bound action // send the bound action
CL_ParseBinding( key, qtrue, time ); CL_ParseBinding( key, qtrue, time );
}
return; return;
} }
@ -1285,7 +1315,6 @@ void CL_KeyUpEvent( int key, unsigned time )
// console mode and menu mode, to keep the character from continuing // console mode and menu mode, to keep the character from continuing
// an action started before a mode switch. // an action started before a mode switch.
// //
if( clc.state != CA_DISCONNECTED )
CL_ParseBinding( key, qfalse, time ); CL_ParseBinding( key, qfalse, time );
if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) { if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) {