From c5cc94c4b7cb755376081315b6987ef413b90d73 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 30 Mar 2025 14:59:38 +1000 Subject: [PATCH] FullscreenUI: Fix hotkey categories duplicating --- src/core/fullscreen_ui.cpp | 42 ++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index b5b0a5c4c..00d44f858 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -296,6 +296,7 @@ static void DoSetCoverImage(std::string source_path, std::string existing_path, // Settings ////////////////////////////////////////////////////////////////////////// +static void InitializeHotkeyList(); static void SwitchToSettings(); static bool SwitchToGameSettings(); static void SwitchToGameSettings(const GameList::Entry* entry); @@ -744,12 +745,10 @@ bool FullscreenUI::Initialize() } s_state.initialized = true; - s_state.hotkey_list_cache = InputManager::GetHotkeyList(); - - const bool open_main_window = (s_state.current_main_window == MainWindowType::None && !GPUThread::HasGPUBackend() && - !GPUThread::IsGPUBackendRequested()); // in case we open the pause menu while the game is running + const bool open_main_window = (s_state.current_main_window == MainWindowType::None && !GPUThread::HasGPUBackend() && + !GPUThread::IsGPUBackendRequested()); if (GPUThread::HasGPUBackend()) { Host::RunOnCPUThread([]() { @@ -1381,6 +1380,8 @@ bool FullscreenUI::LoadResources() if (!CompileTransitionPipelines()) return false; + InitializeHotkeyList(); + return true; } @@ -3615,6 +3616,39 @@ void FullscreenUI::StartClearBindingsForPort(u32 port) }); } +void FullscreenUI::InitializeHotkeyList() +{ + // sort hotkeys by category so we don't duplicate the groups + const auto hotkeys = InputManager::GetHotkeyList(); + s_state.hotkey_list_cache.reserve(hotkeys.size()); + + // this mess is needed to preserve the category order + for (size_t i = 0; i < hotkeys.size(); i++) + { + const HotkeyInfo* hk = hotkeys[i]; + size_t j; + for (j = 0; j < s_state.hotkey_list_cache.size(); j++) + { + if (std::strcmp(hk->category, s_state.hotkey_list_cache[j]->category) == 0) + break; + } + if (j != s_state.hotkey_list_cache.size()) + { + // already done + continue; + } + + // add all hotkeys with this category + for (const HotkeyInfo* other_hk : hotkeys) + { + if (std::strcmp(hk->category, other_hk->category) != 0) + continue; + + s_state.hotkey_list_cache.push_back(other_hk); + } + } +} + void FullscreenUI::SwitchToSettings() { s_state.game_settings_entry.reset();