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 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);
+2 -2
View File
@@ -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;
+44 -20
View File
@@ -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<string, bool> _waitingForKeybind = new();
private readonly Dictionary<string, Keys> _pendingKeybind = new();
private readonly Dictionary<string, Task?> _keybindTask = new();
private readonly ConcurrentQueue<Keys> _keybindResults = new();
private ConfigManager<ConfigData> mainConfig = Program.mainConfig;
private ConfigManager<ColorData> 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.SliderInt("FPS Limit", ref _fpsLimit, 30, 480, "%d"))
if (ImGui.Button(mainConfig.Data.MenuKey.ToString()))
{
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"))
{