private void ExecuteCommand(string rawCmd) { string[] parts = rawCmd.Split(' '); string cvarOrCmd = parts[0].ToLower(); if (Array.IndexOf(CVars.GetNames(), cvarOrCmd) > -1) { string value = rawCmd.Substring(cvarOrCmd.Length).Trim(); if (value.Length > 0) { string oldValue = CVars.RawGet(cvarOrCmd).Serialize(); CVars.RawGet(cvarOrCmd).Deserialize(value); Console.WriteLine("Updated `{0}` from '{1}' to '{2}'.", cvarOrCmd, oldValue, value); } else { CVar <bool> boolCVar = CVars.RawGet(cvarOrCmd) as CVar <bool>; if (boolCVar != null) { bool oldValue = boolCVar.Value; boolCVar.Value = !oldValue; Console.WriteLine("Updated `{0}` from '{1}' to '{2}'.", cvarOrCmd, oldValue, boolCVar.Value); } } } else if (cvarOrCmd == "clear") { _consoleItems.Clear(); } else if (cvarOrCmd == "help") { if (parts.Length > 1) { if (Array.IndexOf(CVars.GetNames(), parts[1].ToLower()) > -1) { ICVar rawCVar = CVars.RawGet(parts[1].ToLower()); Console.WriteLine("`{0}`: {1}", parts[1].ToLower(), rawCVar.GetDescription()); Console.WriteLine("\tDefault value: {0}", rawCVar.SerializeDefault()); Console.WriteLine("\tCurrent value: {0}", rawCVar.Serialize()); } else { Console.WriteLine("`{0}` is not a valid CVar.", parts[1]); } } else { Console.WriteLine("Prints the description of a CVar."); Console.WriteLine("Format: `help <cvar name>`"); } } else { Console.WriteLine("CVar `{0}` not found.", cvarOrCmd); } }
private void DrawCVarWindow() { if (CVars.Get <bool>("debug_show_cvar_viewer")) { ImGui.SetNextWindowSize(new System.Numerics.Vector2(500, 400), ImGuiCond.FirstUseEver); ImGui.Begin("CVar Viewer", ref CVars.Get <bool>("debug_show_cvar_viewer")); if (ImGui.Button("Save##Control")) { CVars.Save(); } ImGui.SameLine(); if (ImGui.Button("Load##Control")) { CVars.SynchronizeFromFile(); } string[] names = CVars.GetNames(); Array.Sort(names); ImGui.Columns(4); ImGui.Text("CVar"); ImGui.NextColumn(); ImGui.Text("Value"); ImGui.NextColumn(); ImGui.Text("Default"); ImGui.NextColumn(); ImGui.Text("Description"); ImGui.NextColumn(); ImGui.Separator(); foreach (string name in names) { if (ImGui.Button(name)) { _cvarEditing = name; } ImGui.NextColumn(); ICVar cvar = CVars.RawGet(name); if (_cvarEditing == name) { switch (cvar) { case CVar <byte> numCVar: { int num = (int)numCVar.Value; ImGui.InputInt("##" + name, ref num); numCVar.Value = (byte)num; } break; case CVar <short> numCVar: { int num = (int)numCVar.Value; ImGui.InputInt("##" + name, ref num); numCVar.Value = (short)num; } break; case CVar <int> numCVar: ImGui.InputInt("##" + name, ref numCVar.Value); break; case CVar <float> numCVar: ImGui.InputFloat("##" + name, ref numCVar.Value); break; case CVar <double> numCVar: ImGui.InputDouble("##" + name, ref numCVar.Value); break; case CVar <bool> boolCVar: ImGui.Checkbox("##" + name, ref boolCVar.Value); break; case CVar <Color> colorCVar: { System.Numerics.Vector3 color = new System.Numerics.Vector3(colorCVar.Value.R / 255.0f, colorCVar.Value.G / 255.0f, colorCVar.Value.B / 255.0f); ImGui.ColorEdit3("##" + name, ref color); colorCVar.Value.R = (byte)(color.X * 255); colorCVar.Value.G = (byte)(color.Y * 255); colorCVar.Value.B = (byte)(color.Z * 255); } break; default: { string strValue = cvar.Serialize(); byte[] buff = new byte[strValue.Length + 500]; Array.Copy(Encoding.UTF8.GetBytes(strValue), buff, strValue.Length); ImGui.InputText("##" + name, buff, (uint)buff.Length); cvar.Deserialize(Encoding.UTF8.GetString(buff, 0, buff.Length)); } break; } } else { ImGui.Text(cvar.Serialize()); } ImGui.NextColumn(); if (ImGui.Button(cvar.SerializeDefault() + "##" + name)) { cvar.Reset(); } ImGui.NextColumn(); ImGui.TextWrapped(cvar.GetDescription()); ImGui.NextColumn(); } ImGui.End(); } }