From 903213c818aedf9e1cf7be9cab073e7d58f901fc Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 25 Oct 2024 12:45:29 +1000 Subject: [PATCH] Hotkeys: Add hotkey to open cheat settings --- src/core/fullscreen_ui.cpp | 40 ++++++++++++++++++++++++++++---------- src/core/fullscreen_ui.h | 1 + src/core/hotkeys.cpp | 19 +++++++++++------- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index d20e71a69..30ce3ac74 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -285,9 +285,9 @@ static void DoToggleAnalogMode(); static constexpr double INPUT_BINDING_TIMEOUT_SECONDS = 5.0; static void SwitchToSettings(); -static void SwitchToGameSettings(); +static bool SwitchToGameSettings(); static void SwitchToGameSettings(const GameList::Entry* entry); -static void SwitchToGameSettingsForPath(const std::string& path); +static bool SwitchToGameSettingsForPath(const std::string& path); static void SwitchToGameSettingsForSerial(std::string_view serial); static void DrawSettingsWindow(); static void DrawSummarySettingsPage(); @@ -710,6 +710,20 @@ void FullscreenUI::OpenPauseMenu() FixStateIfPaused(); } +void FullscreenUI::OpenCheatsMenu() +{ + if (!System::IsValid()) + return; + + if (!Initialize() || s_current_main_window != MainWindowType::None || !SwitchToGameSettings()) + return; + + s_settings_page = SettingsPage::Cheats; + PauseForMenuOpen(true); + ForceKeyNavEnabled(); + FixStateIfPaused(); +} + void FullscreenUI::FixStateIfPaused() { if (!System::IsValid() || System::IsRunning()) @@ -2715,28 +2729,34 @@ void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial) QueueResetFocus(FocusResetType::ViewChanged); } -void FullscreenUI::SwitchToGameSettings() +bool FullscreenUI::SwitchToGameSettings() { if (System::GetGameSerial().empty()) - return; + return false; auto lock = GameList::GetLock(); const GameList::Entry* entry = GameList::GetEntryForPath(System::GetDiscPath()); if (!entry) { SwitchToGameSettingsForSerial(System::GetGameSerial()); - return; + return true; + } + else + { + SwitchToGameSettings(entry); + return true; } - - SwitchToGameSettings(entry); } -void FullscreenUI::SwitchToGameSettingsForPath(const std::string& path) +bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path) { auto lock = GameList::GetLock(); const GameList::Entry* entry = GameList::GetEntryForPath(path); - if (entry) - SwitchToGameSettings(entry); + if (!entry) + return false; + + SwitchToGameSettings(entry); + return true; } void FullscreenUI::SwitchToGameSettings(const GameList::Entry* entry) diff --git a/src/core/fullscreen_ui.h b/src/core/fullscreen_ui.h index 430382f01..7eb03e334 100644 --- a/src/core/fullscreen_ui.h +++ b/src/core/fullscreen_ui.h @@ -28,6 +28,7 @@ void OnRunningGameChanged(); #ifndef __ANDROID__ void OpenPauseMenu(); +void OpenCheatsMenu(); void OpenAchievementsWindow(); bool IsAchievementsWindowOpen(); void OpenLeaderboardsWindow(); diff --git a/src/core/hotkeys.cpp b/src/core/hotkeys.cpp index 9d1078b9f..6fc333f4d 100644 --- a/src/core/hotkeys.cpp +++ b/src/core/hotkeys.cpp @@ -165,13 +165,6 @@ static bool CanPause() #endif BEGIN_HOTKEY_LIST(g_common_hotkeys) -#ifndef __ANDROID__ -DEFINE_HOTKEY("OpenPauseMenu", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Open Pause Menu"), - [](s32 pressed) { - if (!pressed && CanPause()) - FullscreenUI::OpenPauseMenu(); - }) -#endif DEFINE_HOTKEY("FastForward", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Fast Forward"), [](s32 pressed) { @@ -216,6 +209,18 @@ DEFINE_HOTKEY("PowerOff", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP(" if (!pressed && CanPause()) Host::RequestSystemShutdown(true, g_settings.save_state_on_exit); }) + +DEFINE_HOTKEY("OpenPauseMenu", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Open Pause Menu"), + [](s32 pressed) { + if (!pressed && CanPause()) + FullscreenUI::OpenPauseMenu(); + }) + +DEFINE_HOTKEY("OpenCheatsMenu", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Open Cheat Settings"), + [](s32 pressed) { + if (!pressed && CanPause()) + FullscreenUI::OpenCheatsMenu(); + }) #endif DEFINE_HOTKEY("Screenshot", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Save Screenshot"),