diff options
author | icculus <icculus@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2009-09-15 05:43:53 +0000 |
---|---|---|
committer | icculus <icculus@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2009-09-15 05:43:53 +0000 |
commit | 5a2e1890226bfa015f2825ddfb81d23cc2d6bd88 (patch) | |
tree | db41a679ffaccfffcb6fbdf1d158ffe4bec5063c | |
parent | da827dbb091b0cba604e408854fa7d89f83c5b65 (diff) | |
download | ioquake3-aero-5a2e1890226bfa015f2825ddfb81d23cc2d6bd88.tar.gz ioquake3-aero-5a2e1890226bfa015f2825ddfb81d23cc2d6bd88.zip |
Allow Cvar_Toggle_f() to iterate through a list of values.
Fixes Bugzilla #3591.
git-svn-id: svn://svn.icculus.org/quake3/trunk@1617 edf5b092-35ff-0310-97b2-ce42778d08ea
-rw-r--r-- | code/qcommon/cvar.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/code/qcommon/cvar.c b/code/qcommon/cvar.c index 278b990..d4809ae 100644 --- a/code/qcommon/cvar.c +++ b/code/qcommon/cvar.c @@ -690,21 +690,44 @@ void Cvar_Print_f(void) ============ 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 ) { - int v; + int i, c = Cmd_Argc(); + char *curval; - if ( Cmd_Argc() != 2 ) { - Com_Printf ("usage: toggle <variable>\n"); + if(c < 2) { + Com_Printf("usage: toggle <variable> [value1, value2, ...]\n"); + return; + } + + if(c == 2) { + Cvar_Set2(Cmd_Argv(1), va("%d", + !Cvar_VariableValue(Cmd_Argv(1))), + qfalse); + return; + } + + if(c == 3) { + Com_Printf("toggle: nothing to toggle to\n"); return; } - v = Cvar_VariableValue( Cmd_Argv( 1 ) ); - v = !v; + 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; + } + } - Cvar_Set2 (Cmd_Argv(1), va("%i", v), qfalse); + // fallback + Cvar_Set2(Cmd_Argv(1), Cmd_Argv(2), qfalse); } /* |