feat(config): add MenuKey for dynamic menu toggling

- Introduced `MenuKey` property in `Config.cs` for user-defined menu toggling.
- Updated key state checks in `Program.cs` to utilize `MenuKey`.
- Refactored keybind handling in `Renderer.cs` to use dictionaries for "Aiming" and "Menu Key".
- Enhanced UI to allow dynamic keybind setting and listening.
- Changed tab item name from "Misc." to "Settings".
This commit is contained in:
whoswhip
2025-07-17 20:00:44 -04:00
parent f89fd135b4
commit dce1f835f0
3 changed files with 46 additions and 21 deletions
+1
View File
@@ -121,6 +121,7 @@ namespace Spectrum
public bool DrawDetections { get; set; } = true; public bool DrawDetections { get; set; } = true;
public Vector4 DetectionColor { get; set; } = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); public Vector4 DetectionColor { get; set; } = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
public bool ShowMenu { get; set; } = true; public bool ShowMenu { get; set; } = true;
public Keys MenuKey { get; set; } = Keys.Insert;
public bool DrawFOV { get; set; } = false; public bool DrawFOV { get; set; } = false;
public Vector4 FOVColor { get; set; } = new Vector4(0.0f, 1.0f, 0.0f, 1.0f); public Vector4 FOVColor { get; set; } = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
+2 -2
View File
@@ -173,10 +173,10 @@ namespace Spectrum
mat.Dispose(); mat.Dispose();
drawing.Dispose(); drawing.Dispose();
} }
else if (SystemHelper.GetAsyncKeyState(0x2D) < 0) else if (SystemHelper.GetAsyncKeyState((int)mainConfig.Data.MenuKey) < 0)
{ {
var now = DateTime.Now; var now = DateTime.Now;
if ((now - lastMenuToggle).TotalMilliseconds > 200) if ((now - lastMenuToggle).TotalMilliseconds > 175)
{ {
mainConfig.Data.ShowMenu = !mainConfig.Data.ShowMenu; mainConfig.Data.ShowMenu = !mainConfig.Data.ShowMenu;
lastMenuToggle = now; lastMenuToggle = now;
+44 -20
View File
@@ -16,9 +16,9 @@ namespace Spectrum
private bool _vsync = true; private bool _vsync = true;
private int _fpsLimit = 240; private int _fpsLimit = 240;
private Keys _pendingKeybind = Keys.None; private readonly Dictionary<string, bool> _waitingForKeybind = new();
private bool _waitingForKeybind = false; private readonly Dictionary<string, Keys> _pendingKeybind = new();
private Task? _keybindTask = null; private readonly Dictionary<string, Task?> _keybindTask = new();
private readonly ConcurrentQueue<Keys> _keybindResults = new(); private readonly ConcurrentQueue<Keys> _keybindResults = new();
private ConfigManager<ConfigData> mainConfig = Program.mainConfig; private ConfigManager<ConfigData> mainConfig = Program.mainConfig;
private ConfigManager<ColorData> colorConfig = Program.colorConfig; private ConfigManager<ColorData> colorConfig = Program.colorConfig;
@@ -67,27 +67,27 @@ namespace Spectrum
} }
ImGui.SameLine(); ImGui.SameLine();
if (!_waitingForKeybind) if (!_waitingForKeybind.GetValueOrDefault("Aiming", false))
{ {
if (ImGui.Button(mainConfig.Data.Keybind.ToString())) if (ImGui.Button(mainConfig.Data.Keybind.ToString()))
{ {
_waitingForKeybind = true; _waitingForKeybind["Aiming"] = true;
_pendingKeybind = Keys.None; _pendingKeybind["Aiming"] = Keys.None;
_keybindTask = Task.Run(async () => _keybindTask["Aiming"] = Task.Run(async () =>
{ {
var key = await InputManager.ListenForNextKeyOrMouseAsync(); var key = await InputManager.ListenForNextKeyOrMouseAsync();
_pendingKeybind = key; _pendingKeybind["Aiming"] = key;
}); });
} }
} }
else else
{ {
ImGui.Button("Listening..."); ImGui.Button("Listening...");
if (_pendingKeybind != Keys.None) if (_pendingKeybind.GetValueOrDefault("Aiming", Keys.None) != Keys.None)
{ {
mainConfig.Data.Keybind = _pendingKeybind; mainConfig.Data.Keybind = _pendingKeybind["Aiming"];
_pendingKeybind = Keys.None; _pendingKeybind["Aiming"] = Keys.None;
_waitingForKeybind = false; _waitingForKeybind["Aiming"] = false;
} }
} }
ImGui.SameLine(); ImGui.SameLine();
@@ -277,7 +277,7 @@ namespace Spectrum
ImGui.EndTabItem(); ImGui.EndTabItem();
} }
if (ImGui.BeginTabItem("Misc.")) if (ImGui.BeginTabItem("Settings"))
{ {
bool ShowDetectionWindow = mainConfig.Data.ShowDetectionWindow; bool ShowDetectionWindow = mainConfig.Data.ShowDetectionWindow;
if (ImGui.Checkbox("Show Detection Window", ref ShowDetectionWindow)) if (ImGui.Checkbox("Show Detection Window", ref ShowDetectionWindow))
@@ -300,6 +300,15 @@ namespace Spectrum
mainConfig.Data.AutoLabel = AutoLabel; 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; int BackgroundImageInterval = mainConfig.Data.BackgroundImageInterval;
if (ImGui.InputInt("Background Image Interval", ref BackgroundImageInterval, 1, 500)) if (ImGui.InputInt("Background Image Interval", ref BackgroundImageInterval, 1, 500))
{ {
@@ -311,16 +320,31 @@ namespace Spectrum
mainConfig.Data.BackgroundImageInterval = BackgroundImageInterval; mainConfig.Data.BackgroundImageInterval = BackgroundImageInterval;
} }
if (!_waitingForKeybind.GetValueOrDefault("Menu Key", false))
if (ImGui.Checkbox("VSync", ref _vsync))
{ {
VSync = _vsync; if (ImGui.Button(mainConfig.Data.MenuKey.ToString()))
}
if (ImGui.SliderInt("FPS Limit", ref _fpsLimit, 30, 480, "%d"))
{ {
FPSLimit = _fpsLimit; _waitingForKeybind["Menu Key"] = true;
_pendingKeybind["Menu Key"] = Keys.None;
_keybindTask["Menu Key"] = Task.Run(async () =>
{
var key = await InputManager.ListenForNextKeyOrMouseAsync();
_pendingKeybind["Menu Key"] = key;
});
} }
}
else
{
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")) if (ImGui.Button("Save Configs"))
{ {