============ idCVarSystemLocal::Toggle_f ============ */
| 901 | ============ |
| 902 | */ |
| 903 | void idCVarSystemLocal::Toggle_f( const idCmdArgs &args ) { |
| 904 | int argc, i; |
| 905 | float current, set; |
| 906 | const char *text; |
| 907 | |
| 908 | argc = args.Argc(); |
| 909 | if ( argc < 2 ) { |
| 910 | common->Printf ("usage:\n" |
| 911 | " toggle <variable> - toggles between 0 and 1\n" |
| 912 | " toggle <variable> <value> - toggles between 0 and <value>\n" |
| 913 | " toggle <variable> [string 1] [string 2]...[string n] - cycles through all strings\n"); |
| 914 | return; |
| 915 | } |
| 916 | |
| 917 | idInternalCVar *cvar = localCVarSystem.FindInternal( args.Argv( 1 ) ); |
| 918 | |
| 919 | if ( cvar == NULL ) { |
| 920 | common->Warning( "Toggle_f: cvar \"%s\" not found", args.Argv( 1 ) ); |
| 921 | return; |
| 922 | } |
| 923 | |
| 924 | if ( argc > 3 ) { |
| 925 | // cycle through multiple values |
| 926 | text = cvar->GetString(); |
| 927 | for( i = 2; i < argc; i++ ) { |
| 928 | if ( !idStr::Icmp( text, args.Argv( i ) ) ) { |
| 929 | // point to next value |
| 930 | i++; |
| 931 | break; |
| 932 | } |
| 933 | } |
| 934 | if ( i >= argc ) { |
| 935 | i = 2; |
| 936 | } |
| 937 | |
| 938 | common->Printf( "set %s = %s\n", args.Argv(1), args.Argv( i ) ); |
| 939 | cvar->Set( va("%s", args.Argv( i ) ), false, false ); |
| 940 | } else { |
| 941 | // toggle between 0 and 1 |
| 942 | current = cvar->GetFloat(); |
| 943 | if ( argc == 3 ) { |
| 944 | set = atof( args.Argv( 2 ) ); |
| 945 | } else { |
| 946 | set = 1.0f; |
| 947 | } |
| 948 | if ( current == 0.0f ) { |
| 949 | current = set; |
| 950 | } else { |
| 951 | current = 0.0f; |
| 952 | } |
| 953 | common->Printf( "set %s = %f\n", args.Argv(1), current ); |
| 954 | cvar->Set( idStr( current ), false, false ); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | /* |
| 959 | ============ |