diff --git a/Spectrum/Config.cs b/Spectrum/Config.cs index a6f2344..a9d288a 100644 --- a/Spectrum/Config.cs +++ b/Spectrum/Config.cs @@ -121,6 +121,7 @@ namespace Spectrum public bool DrawDetections { get; set; } = true; public Vector4 DetectionColor { get; set; } = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); public bool ShowMenu { get; set; } = true; + public Keys MenuKey { get; set; } = Keys.Insert; public bool DrawFOV { get; set; } = false; public Vector4 FOVColor { get; set; } = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); diff --git a/Spectrum/Program.cs b/Spectrum/Program.cs index edd6e01..6170e80 100644 --- a/Spectrum/Program.cs +++ b/Spectrum/Program.cs @@ -173,10 +173,10 @@ namespace Spectrum mat.Dispose(); drawing.Dispose(); } - else if (SystemHelper.GetAsyncKeyState(0x2D) < 0) + else if (SystemHelper.GetAsyncKeyState((int)mainConfig.Data.MenuKey) < 0) { var now = DateTime.Now; - if ((now - lastMenuToggle).TotalMilliseconds > 200) + if ((now - lastMenuToggle).TotalMilliseconds > 175) { mainConfig.Data.ShowMenu = !mainConfig.Data.ShowMenu; lastMenuToggle = now; diff --git a/Spectrum/Renderer.cs b/Spectrum/Renderer.cs index fb5abc9..e7a4efd 100644 --- a/Spectrum/Renderer.cs +++ b/Spectrum/Renderer.cs @@ -16,9 +16,9 @@ namespace Spectrum private bool _vsync = true; private int _fpsLimit = 240; - private Keys _pendingKeybind = Keys.None; - private bool _waitingForKeybind = false; - private Task? _keybindTask = null; + private readonly Dictionary _waitingForKeybind = new(); + private readonly Dictionary _pendingKeybind = new(); + private readonly Dictionary _keybindTask = new(); private readonly ConcurrentQueue _keybindResults = new(); private ConfigManager mainConfig = Program.mainConfig; private ConfigManager colorConfig = Program.colorConfig; @@ -67,27 +67,27 @@ namespace Spectrum } ImGui.SameLine(); - if (!_waitingForKeybind) + if (!_waitingForKeybind.GetValueOrDefault("Aiming", false)) { if (ImGui.Button(mainConfig.Data.Keybind.ToString())) { - _waitingForKeybind = true; - _pendingKeybind = Keys.None; - _keybindTask = Task.Run(async () => + _waitingForKeybind["Aiming"] = true; + _pendingKeybind["Aiming"] = Keys.None; + _keybindTask["Aiming"] = Task.Run(async () => { var key = await InputManager.ListenForNextKeyOrMouseAsync(); - _pendingKeybind = key; + _pendingKeybind["Aiming"] = key; }); } } else { ImGui.Button("Listening..."); - if (_pendingKeybind != Keys.None) + if (_pendingKeybind.GetValueOrDefault("Aiming", Keys.None) != Keys.None) { - mainConfig.Data.Keybind = _pendingKeybind; - _pendingKeybind = Keys.None; - _waitingForKeybind = false; + mainConfig.Data.Keybind = _pendingKeybind["Aiming"]; + _pendingKeybind["Aiming"] = Keys.None; + _waitingForKeybind["Aiming"] = false; } } ImGui.SameLine(); @@ -277,7 +277,7 @@ namespace Spectrum ImGui.EndTabItem(); } - if (ImGui.BeginTabItem("Misc.")) + if (ImGui.BeginTabItem("Settings")) { bool ShowDetectionWindow = mainConfig.Data.ShowDetectionWindow; if (ImGui.Checkbox("Show Detection Window", ref ShowDetectionWindow)) @@ -300,6 +300,15 @@ namespace Spectrum mainConfig.Data.AutoLabel = AutoLabel; } + if (ImGui.Checkbox("VSync", ref _vsync)) + { + VSync = _vsync; + } + + if (ImGui.SliderInt("FPS Limit", ref _fpsLimit, 30, 480, "%d")) + { + FPSLimit = _fpsLimit; + } int BackgroundImageInterval = mainConfig.Data.BackgroundImageInterval; if (ImGui.InputInt("Background Image Interval", ref BackgroundImageInterval, 1, 500)) { @@ -311,16 +320,31 @@ namespace Spectrum mainConfig.Data.BackgroundImageInterval = BackgroundImageInterval; } - - if (ImGui.Checkbox("VSync", ref _vsync)) + if (!_waitingForKeybind.GetValueOrDefault("Menu Key", false)) { - VSync = _vsync; + if (ImGui.Button(mainConfig.Data.MenuKey.ToString())) + { + _waitingForKeybind["Menu Key"] = true; + _pendingKeybind["Menu Key"] = Keys.None; + _keybindTask["Menu Key"] = Task.Run(async () => + { + var key = await InputManager.ListenForNextKeyOrMouseAsync(); + _pendingKeybind["Menu Key"] = key; + }); + } } - - if (ImGui.SliderInt("FPS Limit", ref _fpsLimit, 30, 480, "%d")) + else { - FPSLimit = _fpsLimit; + ImGui.Button("Listening..."); + if (_pendingKeybind.GetValueOrDefault("Menu Key", Keys.None) != Keys.None) + { + mainConfig.Data.MenuKey = _pendingKeybind["Menu Key"]; + _pendingKeybind["Menu Key"] = Keys.None; + _waitingForKeybind["Menu Key"] = false; + } } + ImGui.SameLine(); + ImGui.Text("Menu Keybind"); if (ImGui.Button("Save Configs")) {