Hotkeys: Add hotkey to open cheat settings

This commit is contained in:
Stenzek 2024-10-25 12:45:29 +10:00
parent 7d2216c289
commit 903213c818
No known key found for this signature in database
3 changed files with 43 additions and 17 deletions

View File

@ -285,9 +285,9 @@ static void DoToggleAnalogMode();
static constexpr double INPUT_BINDING_TIMEOUT_SECONDS = 5.0; static constexpr double INPUT_BINDING_TIMEOUT_SECONDS = 5.0;
static void SwitchToSettings(); static void SwitchToSettings();
static void SwitchToGameSettings(); static bool SwitchToGameSettings();
static void SwitchToGameSettings(const GameList::Entry* entry); 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 SwitchToGameSettingsForSerial(std::string_view serial);
static void DrawSettingsWindow(); static void DrawSettingsWindow();
static void DrawSummarySettingsPage(); static void DrawSummarySettingsPage();
@ -710,6 +710,20 @@ void FullscreenUI::OpenPauseMenu()
FixStateIfPaused(); 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() void FullscreenUI::FixStateIfPaused()
{ {
if (!System::IsValid() || System::IsRunning()) if (!System::IsValid() || System::IsRunning())
@ -2715,28 +2729,34 @@ void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial)
QueueResetFocus(FocusResetType::ViewChanged); QueueResetFocus(FocusResetType::ViewChanged);
} }
void FullscreenUI::SwitchToGameSettings() bool FullscreenUI::SwitchToGameSettings()
{ {
if (System::GetGameSerial().empty()) if (System::GetGameSerial().empty())
return; return false;
auto lock = GameList::GetLock(); auto lock = GameList::GetLock();
const GameList::Entry* entry = GameList::GetEntryForPath(System::GetDiscPath()); const GameList::Entry* entry = GameList::GetEntryForPath(System::GetDiscPath());
if (!entry) if (!entry)
{ {
SwitchToGameSettingsForSerial(System::GetGameSerial()); 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(); auto lock = GameList::GetLock();
const GameList::Entry* entry = GameList::GetEntryForPath(path); const GameList::Entry* entry = GameList::GetEntryForPath(path);
if (entry) if (!entry)
SwitchToGameSettings(entry); return false;
SwitchToGameSettings(entry);
return true;
} }
void FullscreenUI::SwitchToGameSettings(const GameList::Entry* entry) void FullscreenUI::SwitchToGameSettings(const GameList::Entry* entry)

View File

@ -28,6 +28,7 @@ void OnRunningGameChanged();
#ifndef __ANDROID__ #ifndef __ANDROID__
void OpenPauseMenu(); void OpenPauseMenu();
void OpenCheatsMenu();
void OpenAchievementsWindow(); void OpenAchievementsWindow();
bool IsAchievementsWindowOpen(); bool IsAchievementsWindowOpen();
void OpenLeaderboardsWindow(); void OpenLeaderboardsWindow();

View File

@ -165,13 +165,6 @@ static bool CanPause()
#endif #endif
BEGIN_HOTKEY_LIST(g_common_hotkeys) 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"), DEFINE_HOTKEY("FastForward", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Fast Forward"),
[](s32 pressed) { [](s32 pressed) {
@ -216,6 +209,18 @@ DEFINE_HOTKEY("PowerOff", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("
if (!pressed && CanPause()) if (!pressed && CanPause())
Host::RequestSystemShutdown(true, g_settings.save_state_on_exit); 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 #endif
DEFINE_HOTKEY("Screenshot", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Save Screenshot"), DEFINE_HOTKEY("Screenshot", TRANSLATE_NOOP("Hotkeys", "General"), TRANSLATE_NOOP("Hotkeys", "Save Screenshot"),