From a401972223a7e1cc547234edde4b96348baae45d Mon Sep 17 00:00:00 2001 From: daobashun <49193927+fangshun2004@users.noreply.github.com> Date: Wed, 17 Dec 2025 22:53:46 +0800 Subject: [PATCH] Fixed hotkey issues (#757) * Fix an issue where some hotkeys reset when loading * Fix the 'Clear' button in the hotkeys not working --- src/core/commands/HotkeySystem.cpp | 14 ++++++++++---- src/core/commands/HotkeySystem.hpp | 2 +- src/game/frontend/submenus/Settings.cpp | 2 ++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/core/commands/HotkeySystem.cpp b/src/core/commands/HotkeySystem.cpp index 082ed8c..2928645 100644 --- a/src/core/commands/HotkeySystem.cpp +++ b/src/core/commands/HotkeySystem.cpp @@ -142,11 +142,17 @@ namespace YimMenu void HotkeySystem::SaveStateImpl(nlohmann::json& state) { - for (auto& hotkey : m_CommandHotkeys) + for (const auto& hotkey : m_CommandHotkeys) { + std::string key = std::to_string(hotkey.first); + if (!hotkey.second.m_Chain.empty()) { - state[std::to_string(hotkey.first).data()] = hotkey.second.m_Chain; + state[key] = hotkey.second.m_Chain; + } + else if (state.contains(key)) + { + state.erase(key); } } } @@ -155,8 +161,8 @@ namespace YimMenu { for (auto& [key, value] : state.items()) { - if (m_CommandHotkeys.contains(std::atoi(key.data()))) - m_CommandHotkeys[std::atoi(key.data())].m_Chain = value.get>(); + if (m_CommandHotkeys.contains(static_cast(std::stoul(key.data())))) + m_CommandHotkeys[static_cast(std::stoul(key.data()))].m_Chain = value.get>(); } } diff --git a/src/core/commands/HotkeySystem.hpp b/src/core/commands/HotkeySystem.hpp index 5236ba6..108f552 100644 --- a/src/core/commands/HotkeySystem.hpp +++ b/src/core/commands/HotkeySystem.hpp @@ -16,7 +16,7 @@ namespace YimMenu public IStateSerializer { std::chrono::system_clock::time_point m_LastHotkeyTriggerTime; - bool m_BeingModified; + bool m_BeingModified = false; public: HotkeySystem(); diff --git a/src/game/frontend/submenus/Settings.cpp b/src/game/frontend/submenus/Settings.cpp index 50b97dd..23c85b1 100644 --- a/src/game/frontend/submenus/Settings.cpp +++ b/src/game/frontend/submenus/Settings.cpp @@ -35,6 +35,8 @@ namespace YimMenu::Submenus for (auto& [name, link] : sortedCommands) { + if (name.empty()) + continue; DrawHotkey(link, name); } };