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
stopmusic - stop background music
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
unset - unset a user created cvar

View file

@ -81,6 +81,16 @@ void Con_ToggleConsole_f (void) {
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
@ -332,6 +342,7 @@ void Con_Init (void) {
CL_LoadConsoleHistory( );
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f);
Cmd_AddCommand ("togglemenu", Con_ToggleMenu_f);
Cmd_AddCommand ("messagemode", Con_MessageMode_f);
Cmd_AddCommand ("messagemode2", Con_MessageMode2_f);
Cmd_AddCommand ("messagemode3", Con_MessageMode3_f);
@ -349,6 +360,7 @@ Con_Shutdown
void Con_Shutdown(void)
{
Cmd_RemoveCommand("toggleconsole");
Cmd_RemoveCommand("togglemenu");
Cmd_RemoveCommand("messagemode");
Cmd_RemoveCommand("messagemode2");
Cmd_RemoveCommand("messagemode3");

View file

@ -1120,6 +1120,23 @@ void CL_InitKeyCommands( void ) {
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
@ -1130,11 +1147,20 @@ Execute the commands in the bind string
void CL_ParseBinding( int key, qboolean down, unsigned time )
{
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] )
return;
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( isspace( *p ) )
@ -1147,17 +1173,21 @@ void CL_ParseBinding( int key, qboolean down, unsigned time )
// button commands add keynum and time as parameters
// so that multiple sources can be discriminated and
// subframe corrected
if ( allCommands || ( allowUpCmds && !down ) ) {
char cmd[1024];
Com_sprintf( cmd, sizeof( cmd ), "%c%s %d %d\n",
( down ) ? '+' : '-', p + 1, key, time );
Cbuf_AddText( cmd );
}
}
else if( down )
{
// normal commands only execute on key press
if ( allCommands || CL_BindUICommand( p ) ) {
Cbuf_AddText( p );
Cbuf_AddText( "\n" );
}
}
if( !end )
break;
p = end + 1;
@ -1250,10 +1280,10 @@ void CL_KeyDownEvent( int key, unsigned time )
Message_Key( key );
} else if ( clc.state == CA_DISCONNECTED ) {
Console_Key( key );
} else {
}
// send the bound action
CL_ParseBinding( key, qtrue, time );
}
return;
}
@ -1285,7 +1315,6 @@ void CL_KeyUpEvent( int key, unsigned time )
// console mode and menu mode, to keep the character from continuing
// an action started before a mode switch.
//
if( clc.state != CA_DISCONNECTED )
CL_ParseBinding( key, qfalse, time );
if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) {