예제 #1
0
        /// <summary>
        /// Called by the command system when a command is unrecognized.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool Command(idCmdArgs args)
        {
            idInternalCvar intern = FindInternal(args.Get(0));

            if (intern == null)
            {
                return(false);
            }

            if (args.Length == 1)
            {
                // print the variable
                idConsole.WriteLine("\"{0}\" is: \"{1}\" {2} default: \"{3}\"", intern.Name, intern.ToString(), idColorString.White, intern.ResetString);

                if (intern.Description.Length > 0)
                {
                    idConsole.WriteLine("{0}{1}", idColorString.White, intern.Description);
                }
            }
            else
            {
                // set the value
                intern.Set(args.ToString(), false, false);
            }

            return(true);
        }
예제 #2
0
        private void Cmd_Restart(object sender, CommandEventArgs e)
        {
            List <string> toRemove = new List <string>();

            foreach (KeyValuePair <string, idInternalCvar> kvp in _cvarList)
            {
                idInternalCvar cvar = kvp.Value;

                // don't mess with rom values
                if ((cvar.Flags & (CvarFlags.ReadOnly | CvarFlags.Init)) != 0)
                {
                    continue;
                }

                // throw out any variables the user created
                if ((cvar.Flags & CvarFlags.Static) == 0)
                {
                    toRemove.Add(cvar.Name);
                }
                else
                {
                    cvar.Reset();
                }
            }

            foreach (string name in toRemove)
            {
                _cvarList.Remove(name);
            }
        }
예제 #3
0
        public void ClearModified(string name)
        {
            idInternalCvar intern = FindInternal(name);

            if (intern != null)
            {
                intern.IsModified = false;
            }
        }
예제 #4
0
        public bool IsModified(string name)
        {
            idInternalCvar intern = FindInternal(name);

            if (intern != null)
            {
                return(intern.IsModified);
            }

            return(false);
        }
예제 #5
0
        public float GetFloat(string name)
        {
            idInternalCvar intern = FindInternal(name);

            if (intern != null)
            {
                return(intern.ToFloat());
            }

            return(0);
        }
예제 #6
0
        public int GetInteger(string name)
        {
            idInternalCvar intern = FindInternal(name);

            if (intern != null)
            {
                return(intern.ToInt());
            }

            return(0);
        }
예제 #7
0
        public bool GetBool(string name)
        {
            idInternalCvar intern = FindInternal(name);

            if (intern != null)
            {
                return(intern.ToBool());
            }

            return(false);
        }
예제 #8
0
        public string GetString(string name)
        {
            idInternalCvar intern = FindInternal(name);

            if (intern != null)
            {
                return(intern.ToString());
            }

            return(string.Empty);
        }
예제 #9
0
        private void Cmd_SetA(object sender, CommandEventArgs e)
        {
            Cmd_Set(sender, e);

            idInternalCvar cvar = FindInternal(e.Args.Get(1));

            if (cvar != null)
            {
                cvar.Flags |= CvarFlags.Archive;
            }
        }
예제 #10
0
        public string[] ArgCompletion(string name, string argText)
        {
            idCmdArgs      args    = new idCmdArgs(argText, true);
            idInternalCvar intern  = FindInternal(name);
            List <string>  matches = new List <string>();

            if ((intern != null) && (intern.ValueCompletion != null))
            {
                matches.AddRange(intern.ValueCompletion.Complete(args));
            }

            return(matches.ToArray());
        }
예제 #11
0
        private void Cmd_Reset(object sender, CommandEventArgs e)
        {
            if (e.Args.Length != 2)
            {
                idConsole.WriteLine("usage: reset <variable>");
            }
            else
            {
                idInternalCvar cvar = FindInternal(e.Args.Get(1));

                if (cvar != null)
                {
                    cvar.Reset();
                }
            }
        }
예제 #12
0
        private void SetInternal(string name, string value, CvarFlags flags)
        {
            idInternalCvar intern = FindInternal(name);

            if (intern != null)
            {
                intern.SetStringInternal(value);
                intern.Flags |= flags & ~CvarFlags.Static;
                intern.UpdateCheat();
            }
            else
            {
                idConsole.Warning("Tried to set unknown cvar '{0}'", name);

                intern = new idInternalCvar(name, value, flags);

                _cvarList.Add(intern.Name, intern);
            }
        }
예제 #13
0
        public void Register(idCvar var)
        {
            var.Internal = var;

            idInternalCvar intern = FindInternal(var.Name, true);

            if (intern != null)
            {
                intern.Update(var);
            }
            else
            {
                intern = new idInternalCvar(var);

                _cvarList.Add(intern.Name, intern);
            }

            var.Internal = intern;
        }
예제 #14
0
		public void Register(idCvar var)
		{
			var.Internal = var;

			idInternalCvar intern = FindInternal(var.Name, true);

			if(intern != null)
			{
				intern.Update(var);
			}
			else
			{
				intern = new idInternalCvar(var);

				_cvarList.Add(intern.Name, intern);
			}

			var.Internal = intern;
		}
예제 #15
0
        private void ListByFlags(idCmdArgs args, CvarFlags flags)
        {
            int           argNum = 1;
            string        match;
            ShowMode      show = ShowMode.Value;
            List <idCvar> list = new List <idCvar>();

            if ((StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum), "-") == 0) || (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum), "/") == 0))
            {
                if ((StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "help") == 0) || (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "?") == 0))
                {
                    argNum = 3;
                    show   = ShowMode.Description;
                }
                else if ((StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "type") == 0) || (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "range") == 0))
                {
                    argNum = 3;
                    show   = ShowMode.Type;
                }
                else if (StringComparer.InvariantCultureIgnoreCase.Compare(args.Get(argNum + 1), "flags") == 0)
                {
                    argNum = 3;
                    show   = ShowMode.Flags;
                }
            }

            if (args.Length > argNum)
            {
                match = args.Get(argNum, -1);
                match = match.Replace(" ", "");
            }
            else
            {
                match = "";
            }

            foreach (KeyValuePair <string, idInternalCvar> kvp in _cvarList)
            {
                idInternalCvar cvar = kvp.Value;

                if ((cvar.Flags & flags) == 0)
                {
                    continue;
                }

                if ((match.Length > 0) && (cvar.Name.ToLower().Contains(match.ToLower()) == false))
                {
                    continue;
                }

                list.Add(cvar);
            }

            list.OrderBy(a => a.Name);

            switch (show)
            {
            case ShowMode.Value:
                foreach (idCvar cvar in list)
                {
                    idConsole.WriteLine("{0}{1}\"{2}\"", cvar.Name.PadRight(32), idColorString.White, cvar.ToString());
                }
                break;

            case ShowMode.Description:
                foreach (idCvar cvar in list)
                {
                    idConsole.WriteLine("{0}{1}{2}", cvar.Name.PadRight(32), idColorString.White, idHelper.WrapText(cvar.Description, 77 - 33, 33));
                }
                break;

            case ShowMode.Type:
                foreach (idCvar cvar in list)
                {
                    if ((cvar.Flags & CvarFlags.Bool) == CvarFlags.Bool)
                    {
                        idConsole.WriteLine("{0}{1}bool", cvar.Name.PadRight(32), idColorString.Cyan);
                    }
                    else if ((cvar.Flags & CvarFlags.Integer) == CvarFlags.Integer)
                    {
                        if (cvar.MinValue < cvar.MaxValue)
                        {
                            idConsole.WriteLine("{0}{1}int {2}[{3}, {4}]", cvar.Name.PadRight(32), idColorString.Green, idColorString.White, cvar.MinValue, cvar.MaxValue);
                        }
                        else
                        {
                            idConsole.WriteLine("{0}{1}int", cvar.Name.PadRight(32), idColorString.Green);
                        }
                    }
                    else if ((cvar.Flags & CvarFlags.Float) == CvarFlags.Float)
                    {
                        if (cvar.MinValue < cvar.MaxValue)
                        {
                            idConsole.WriteLine("{0}{1}float {2}[{3}, {4}]", cvar.Name.PadRight(32), idColorString.Red, idColorString.White, cvar.MinValue, cvar.MaxValue);
                        }
                        else
                        {
                            idConsole.WriteLine("{0}{1}float", cvar.Name.PadRight(32), idColorString.Red);
                        }
                    }
                    else if (cvar.ValueStrings != null)
                    {
                        idConsole.Write("{0}{1}string {2}[", cvar.Name.PadRight(32), idColorString.White, idColorString.White);

                        int count = cvar.ValueStrings.Length;

                        for (int j = 0; j < count; j++)
                        {
                            if (j > 0)
                            {
                                idConsole.Write("{0}, {1}", idColorString.White, cvar.ValueStrings[j]);
                            }
                            else
                            {
                                idConsole.Write("{0}{1}", idColorString.White, cvar.ValueStrings[j]);
                            }
                        }

                        idConsole.WriteLine("{0}]", idColorString.White);
                    }
                    else
                    {
                        idConsole.WriteLine("{0}{1}string", cvar.Name.PadRight(32), idColorString.White);
                    }
                }
                break;

            case ShowMode.Flags:
                foreach (idCvar cvar in list)
                {
                    idConsole.Write(cvar.Name.PadRight(32));

                    string str = string.Empty;

                    if ((cvar.Flags & CvarFlags.Bool) == CvarFlags.Bool)
                    {
                        str += string.Format("{0}B ", idColorString.Cyan);
                    }
                    else if ((cvar.Flags & CvarFlags.Integer) == CvarFlags.Integer)
                    {
                        str += string.Format("{0}U ", idColorString.Green);
                    }
                    else if ((cvar.Flags & CvarFlags.Float) == CvarFlags.Float)
                    {
                        str += string.Format("{0}F ", idColorString.Red);
                    }
                    else
                    {
                        str += string.Format("{0}S ", idColorString.White);
                    }

                    if ((cvar.Flags & CvarFlags.System) == CvarFlags.System)
                    {
                        str += string.Format("{0}SYS  ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Renderer) == CvarFlags.Renderer)
                    {
                        str += string.Format("{0}RNDR ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Sound) == CvarFlags.Sound)
                    {
                        str += string.Format("{0}SND  ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Gui) == CvarFlags.Gui)
                    {
                        str += string.Format("{0}GUI  ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Game) == CvarFlags.Game)
                    {
                        str += string.Format("{0}GAME ", idColorString.White);
                    }
                    else if ((cvar.Flags & CvarFlags.Tool) == CvarFlags.Tool)
                    {
                        str += string.Format("{0}TOOL ", idColorString.White);
                    }
                    else
                    {
                        str += string.Format("{0}     ", idColorString.White);
                    }

                    str += ((cvar.Flags & CvarFlags.UserInfo) == CvarFlags.UserInfo) ? "UI " : "   ";
                    str += ((cvar.Flags & CvarFlags.ServerInfo) == CvarFlags.ServerInfo) ? "SI " : "   ";
                    str += ((cvar.Flags & CvarFlags.Static) == CvarFlags.Static) ? "ST " : "   ";
                    str += ((cvar.Flags & CvarFlags.Cheat) == CvarFlags.Cheat) ? "CH " : "   ";
                    str += ((cvar.Flags & CvarFlags.Init) == CvarFlags.Init) ? "IN " : "   ";
                    str += ((cvar.Flags & CvarFlags.ReadOnly) == CvarFlags.ReadOnly) ? "RO " : "   ";
                    str += ((cvar.Flags & CvarFlags.Archive) == CvarFlags.Archive) ? "AR " : "   ";
                    str += ((cvar.Flags & CvarFlags.Modified) == CvarFlags.Modified) ? "MO " : "   ";

                    idConsole.WriteLine(str);
                }
                break;
            }

            idConsole.WriteLine("\n{0} cvars listed\n", list.Count);
            idConsole.WriteLine("listCvar [search string]          = list cvar values");
            idConsole.WriteLine("listCvar -help [search string]    = list cvar descriptions");
            idConsole.WriteLine("listCvar -type [search string]    = list cvar types");
            idConsole.WriteLine("listCvar -flags [search string]   = list cvar flags");
        }
예제 #16
0
		private void SetInternal(string name, string value, CvarFlags flags)
		{
			idInternalCvar intern = FindInternal(name);

			if(intern != null)
			{
				intern.SetStringInternal(value);
				intern.Flags |= flags & ~CvarFlags.Static;
				intern.UpdateCheat();
			}
			else
			{
				idConsole.Warning("Tried to set unknown cvar '{0}'", name);

				intern = new idInternalCvar(name, value, flags);

				_cvarList.Add(intern.Name, intern);
			}
		}
예제 #17
0
        private void Cmd_Toggle(object sender, CommandEventArgs e)
        {
            int argCount = e.Args.Length;

            if (argCount < 2)
            {
                idConsole.WriteLine("usage:");
                idConsole.WriteLine("    toggle <variable> - toggles between 0 and 1");
                idConsole.WriteLine("    toggle <variable> <value> - toggles between 0 and <value>");
                idConsole.WriteLine("    toggle <variable [string 1] [string 2]...[string n] - cycles through all strings");
            }
            else
            {
                idInternalCvar cvar = idE.CvarSystem.FindInternal(e.Args.Get(1));

                if (cvar == null)
                {
                    idConsole.WriteLine("toggle: cvar \"{0}\" not found", e.Args.Get(1));
                }
                else if (argCount > 3)
                {
                    // cycle through multiple values
                    string text = cvar.ToString();
                    int    i    = 0;


                    for (i = 2; i < argCount; i++)
                    {
                        if (StringComparer.CurrentCultureIgnoreCase.Compare(text, e.Args.Get(i)) == 0)
                        {
                            i++;
                            break;
                        }
                    }

                    if (i >= argCount)
                    {
                        i = 2;
                    }

                    idConsole.WriteLine("set {0} = {1}", e.Args.Get(1), e.Args.Get(i));
                    cvar.Set(e.Args.Get(i), false, false);
                }
                else
                {
                    // toggle between 0 and 1
                    float current = cvar.ToFloat();
                    float set     = 0;

                    if (e.Args.Length == 3)
                    {
                        float.TryParse(e.Args.Get(2), out set);
                    }
                    else
                    {
                        set = 1.0f;
                    }

                    if (current == 0.0f)
                    {
                        current = set;
                    }
                    else
                    {
                        current = 0.0f;
                    }

                    idConsole.WriteLine("set {0} = {1}", e.Args.Get(1), current);
                    cvar.Set(current.ToString(), false, false);
                }
            }
        }