mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2024-11-10 23:02:01 +00:00
Allow Cvar_Toggle_f() to iterate through a list of values.
Fixes Bugzilla #3591.
This commit is contained in:
parent
f8604a64f4
commit
aedf24bd72
1 changed files with 30 additions and 7 deletions
|
@ -690,21 +690,44 @@ void Cvar_Print_f(void)
|
||||||
============
|
============
|
||||||
Cvar_Toggle_f
|
Cvar_Toggle_f
|
||||||
|
|
||||||
Toggles a cvar for easy single key binding
|
Toggles a cvar for easy single key binding, optionally through a list of
|
||||||
|
given values
|
||||||
============
|
============
|
||||||
*/
|
*/
|
||||||
void Cvar_Toggle_f( void ) {
|
void Cvar_Toggle_f( void ) {
|
||||||
int v;
|
int i, c = Cmd_Argc();
|
||||||
|
char *curval;
|
||||||
|
|
||||||
if ( Cmd_Argc() != 2 ) {
|
if(c < 2) {
|
||||||
Com_Printf ("usage: toggle <variable>\n");
|
Com_Printf("usage: toggle <variable> [value1, value2, ...]\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
v = Cvar_VariableValue( Cmd_Argv( 1 ) );
|
if(c == 2) {
|
||||||
v = !v;
|
Cvar_Set2(Cmd_Argv(1), va("%d",
|
||||||
|
!Cvar_VariableValue(Cmd_Argv(1))),
|
||||||
|
qfalse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Cvar_Set2 (Cmd_Argv(1), va("%i", v), qfalse);
|
if(c == 3) {
|
||||||
|
Com_Printf("toggle: nothing to toggle to\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
curval = Cvar_VariableString(Cmd_Argv(1));
|
||||||
|
|
||||||
|
// don't bother checking the last arg for a match since the desired
|
||||||
|
// behaviour is the same as no match (set to the first argument)
|
||||||
|
for(i = 2; i + 1 < c; i++) {
|
||||||
|
if(strcmp(curval, Cmd_Argv(i)) == 0) {
|
||||||
|
Cvar_Set2(Cmd_Argv(1), Cmd_Argv(i + 1), qfalse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback
|
||||||
|
Cvar_Set2(Cmd_Argv(1), Cmd_Argv(2), qfalse);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue