From a07245590380f1ef87273248bcff6ab59aa3852b Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 20 Jun 2021 13:33:30 +1000 Subject: [PATCH] CommonHostInterface: Add hotkeys for opening leaderboards/achievements --- src/frontend-common/common_host_interface.cpp | 58 ++++++++++++++----- src/frontend-common/common_host_interface.h | 1 + src/frontend-common/fullscreen_ui.cpp | 30 ++++++++-- src/frontend-common/fullscreen_ui.h | 2 + 4 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index fddcec324..2ab47ccac 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1925,6 +1925,7 @@ void CommonHostInterface::SetTurboEnabled(bool enabled) void CommonHostInterface::RegisterHotkeys() { RegisterGeneralHotkeys(); + RegisterSystemHotkeys(); RegisterGraphicsHotkeys(); RegisterSaveStateHotkeys(); RegisterAudioHotkeys(); @@ -2005,19 +2006,50 @@ void CommonHostInterface::RegisterGeneralHotkeys() #endif - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Reset"), - StaticString(TRANSLATABLE("Hotkeys", "Reset System")), [this](bool pressed) { - if (pressed && System::IsValid()) - ResetSystem(); - }); - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Screenshot"), StaticString(TRANSLATABLE("Hotkeys", "Save Screenshot")), [this](bool pressed) { if (pressed && System::IsValid()) SaveScreenshot(); }); - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ChangeDisc"), +#ifdef WITH_CHEEVOS + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("OpenAchievements"), + StaticString(TRANSLATABLE("Hotkeys", "Open Achievement List")), [this](bool pressed) { + if (pressed && System::IsValid()) + { + if (!m_fullscreen_ui_enabled || !FullscreenUI::OpenAchievementsWindow()) + { + AddOSDMessage( + TranslateStdString("OSDMessage", "Achievements are disabled or unavailable for this game."), + 10.0f); + } + } + }); + + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("OpenLeaderboards"), + StaticString(TRANSLATABLE("Hotkeys", "Open Leaderboard List")), [this](bool pressed) { + if (pressed && System::IsValid()) + { + if (!m_fullscreen_ui_enabled || !FullscreenUI::OpenLeaderboardsWindow()) + { + AddOSDMessage( + TranslateStdString("OSDMessage", "Leaderboards are disabled or unavailable for this game."), + 10.0f); + } + } + }); +#endif +} + +void CommonHostInterface::RegisterSystemHotkeys() +{ + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("Reset"), + StaticString(TRANSLATABLE("Hotkeys", "Reset System")), [this](bool pressed) { + if (pressed && System::IsValid()) + ResetSystem(); + }); + + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("ChangeDisc"), StaticString(TRANSLATABLE("Hotkeys", "Change Disc")), [](bool pressed) { if (pressed && System::IsValid() && System::HasMediaSubImages()) { @@ -2028,14 +2060,14 @@ void CommonHostInterface::RegisterGeneralHotkeys() } }); - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("SwapMemoryCards"), + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("SwapMemoryCards"), StaticString(TRANSLATABLE("Hotkeys", "Swap Memory Card Slots")), [this](bool pressed) { if (pressed && System::IsValid()) SwapMemoryCards(); }); #ifndef __ANDROID__ - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FrameStep"), + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("FrameStep"), StaticString(TRANSLATABLE("Hotkeys", "Frame Step")), [this](bool pressed) { if (pressed && System::IsValid()) { @@ -2046,7 +2078,7 @@ void CommonHostInterface::RegisterGeneralHotkeys() } }); - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Rewind"), + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("Rewind"), StaticString(TRANSLATABLE("Hotkeys", "Rewind")), [this](bool pressed) { if (System::IsValid()) { @@ -2064,7 +2096,7 @@ void CommonHostInterface::RegisterGeneralHotkeys() } }); - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleCheats"), + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("ToggleCheats"), StaticString(TRANSLATABLE("Hotkeys", "Toggle Cheats")), [this](bool pressed) { if (pressed && System::IsValid()) { @@ -2075,7 +2107,7 @@ void CommonHostInterface::RegisterGeneralHotkeys() } }); #else - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("TogglePatchCodes"), + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("TogglePatchCodes"), StaticString(TRANSLATABLE("Hotkeys", "Toggle Patch Codes")), [this](bool pressed) { if (pressed && System::IsValid()) { @@ -2088,7 +2120,7 @@ void CommonHostInterface::RegisterGeneralHotkeys() #endif RegisterHotkey( - StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleOverclocking"), + StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("ToggleOverclocking"), StaticString(TRANSLATABLE("Hotkeys", "Toggle Clock Speed Control (Overclocking)")), [this](bool pressed) { if (pressed && System::IsValid()) { diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index e85d6df05..a7fc6c21d 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -488,6 +488,7 @@ private: void LoadSettings(); void InitializeUserDirectory(); void RegisterGeneralHotkeys(); + void RegisterSystemHotkeys(); void RegisterGraphicsHotkeys(); void RegisterSaveStateHotkeys(); void RegisterAudioHotkeys(); diff --git a/src/frontend-common/fullscreen_ui.cpp b/src/frontend-common/fullscreen_ui.cpp index a506f7b39..bd6f7095e 100644 --- a/src/frontend-common/fullscreen_ui.cpp +++ b/src/frontend-common/fullscreen_ui.cpp @@ -299,6 +299,29 @@ void CloseQuickMenu() ClearImGuiFocus(); } +bool OpenAchievementsWindow() +{ + const bool achievements_enabled = Cheevos::HasActiveGame() && (Cheevos::GetAchievementCount() > 0); + if (!achievements_enabled) + return false; + + s_current_main_window = MainWindowType::Achievements; + s_quick_menu_was_open = false; + return true; +} + +bool OpenLeaderboardsWindow() +{ + const bool leaderboards_enabled = Cheevos::HasActiveGame() && (Cheevos::GetLeaderboardCount() > 0); + if (!leaderboards_enabled) + return false; + + s_current_main_window = MainWindowType::Leaderboards; + s_open_leaderboard_id.reset(); + s_quick_menu_was_open = false; + return true; +} + void Shutdown() { if (s_game_list_load_thread.joinable()) @@ -2553,14 +2576,11 @@ void DrawQuickMenu(MainWindowType type) #ifdef WITH_CHEEVOS const bool achievements_enabled = Cheevos::HasActiveGame() && (Cheevos::GetAchievementCount() > 0); if (ActiveButton(ICON_FA_TROPHY " Achievements", false, achievements_enabled)) - s_current_main_window = MainWindowType::Achievements; + OpenAchievementsWindow(); const bool leaderboards_enabled = Cheevos::HasActiveGame() && (Cheevos::GetLeaderboardCount() > 0); if (ActiveButton(ICON_FA_STOPWATCH " Leaderboards", false, leaderboards_enabled)) - { - s_current_main_window = MainWindowType::Leaderboards; - s_open_leaderboard_id.reset(); - } + OpenLeaderboardsWindow(); #else ActiveButton(ICON_FA_TROPHY " Achievements", false, false); diff --git a/src/frontend-common/fullscreen_ui.h b/src/frontend-common/fullscreen_ui.h index 430be1d76..66dd78d6d 100644 --- a/src/frontend-common/fullscreen_ui.h +++ b/src/frontend-common/fullscreen_ui.h @@ -49,6 +49,8 @@ void SystemDestroyed(); void SystemPaused(bool paused); void OpenQuickMenu(); void CloseQuickMenu(); +bool OpenAchievementsWindow(); +bool OpenLeaderboardsWindow(); void Shutdown(); void Render();