CommonHostInterface: Add hotkeys for opening leaderboards/achievements

This commit is contained in:
Connor McLaughlin 2021-06-20 13:33:30 +10:00
parent 1644a0762d
commit a072455903
4 changed files with 73 additions and 18 deletions

View file

@ -1925,6 +1925,7 @@ void CommonHostInterface::SetTurboEnabled(bool enabled)
void CommonHostInterface::RegisterHotkeys() void CommonHostInterface::RegisterHotkeys()
{ {
RegisterGeneralHotkeys(); RegisterGeneralHotkeys();
RegisterSystemHotkeys();
RegisterGraphicsHotkeys(); RegisterGraphicsHotkeys();
RegisterSaveStateHotkeys(); RegisterSaveStateHotkeys();
RegisterAudioHotkeys(); RegisterAudioHotkeys();
@ -2005,19 +2006,50 @@ void CommonHostInterface::RegisterGeneralHotkeys()
#endif #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"), RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Screenshot"),
StaticString(TRANSLATABLE("Hotkeys", "Save Screenshot")), [this](bool pressed) { StaticString(TRANSLATABLE("Hotkeys", "Save Screenshot")), [this](bool pressed) {
if (pressed && System::IsValid()) if (pressed && System::IsValid())
SaveScreenshot(); 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) { StaticString(TRANSLATABLE("Hotkeys", "Change Disc")), [](bool pressed) {
if (pressed && System::IsValid() && System::HasMediaSubImages()) 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) { StaticString(TRANSLATABLE("Hotkeys", "Swap Memory Card Slots")), [this](bool pressed) {
if (pressed && System::IsValid()) if (pressed && System::IsValid())
SwapMemoryCards(); SwapMemoryCards();
}); });
#ifndef __ANDROID__ #ifndef __ANDROID__
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FrameStep"), RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("FrameStep"),
StaticString(TRANSLATABLE("Hotkeys", "Frame Step")), [this](bool pressed) { StaticString(TRANSLATABLE("Hotkeys", "Frame Step")), [this](bool pressed) {
if (pressed && System::IsValid()) 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) { StaticString(TRANSLATABLE("Hotkeys", "Rewind")), [this](bool pressed) {
if (System::IsValid()) 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) { StaticString(TRANSLATABLE("Hotkeys", "Toggle Cheats")), [this](bool pressed) {
if (pressed && System::IsValid()) if (pressed && System::IsValid())
{ {
@ -2075,7 +2107,7 @@ void CommonHostInterface::RegisterGeneralHotkeys()
} }
}); });
#else #else
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("TogglePatchCodes"), RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("TogglePatchCodes"),
StaticString(TRANSLATABLE("Hotkeys", "Toggle Patch Codes")), [this](bool pressed) { StaticString(TRANSLATABLE("Hotkeys", "Toggle Patch Codes")), [this](bool pressed) {
if (pressed && System::IsValid()) if (pressed && System::IsValid())
{ {
@ -2088,7 +2120,7 @@ void CommonHostInterface::RegisterGeneralHotkeys()
#endif #endif
RegisterHotkey( RegisterHotkey(
StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleOverclocking"), StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("ToggleOverclocking"),
StaticString(TRANSLATABLE("Hotkeys", "Toggle Clock Speed Control (Overclocking)")), [this](bool pressed) { StaticString(TRANSLATABLE("Hotkeys", "Toggle Clock Speed Control (Overclocking)")), [this](bool pressed) {
if (pressed && System::IsValid()) if (pressed && System::IsValid())
{ {

View file

@ -488,6 +488,7 @@ private:
void LoadSettings(); void LoadSettings();
void InitializeUserDirectory(); void InitializeUserDirectory();
void RegisterGeneralHotkeys(); void RegisterGeneralHotkeys();
void RegisterSystemHotkeys();
void RegisterGraphicsHotkeys(); void RegisterGraphicsHotkeys();
void RegisterSaveStateHotkeys(); void RegisterSaveStateHotkeys();
void RegisterAudioHotkeys(); void RegisterAudioHotkeys();

View file

@ -299,6 +299,29 @@ void CloseQuickMenu()
ClearImGuiFocus(); 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() void Shutdown()
{ {
if (s_game_list_load_thread.joinable()) if (s_game_list_load_thread.joinable())
@ -2553,14 +2576,11 @@ void DrawQuickMenu(MainWindowType type)
#ifdef WITH_CHEEVOS #ifdef WITH_CHEEVOS
const bool achievements_enabled = Cheevos::HasActiveGame() && (Cheevos::GetAchievementCount() > 0); const bool achievements_enabled = Cheevos::HasActiveGame() && (Cheevos::GetAchievementCount() > 0);
if (ActiveButton(ICON_FA_TROPHY " Achievements", false, achievements_enabled)) 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); const bool leaderboards_enabled = Cheevos::HasActiveGame() && (Cheevos::GetLeaderboardCount() > 0);
if (ActiveButton(ICON_FA_STOPWATCH " Leaderboards", false, leaderboards_enabled)) if (ActiveButton(ICON_FA_STOPWATCH " Leaderboards", false, leaderboards_enabled))
{ OpenLeaderboardsWindow();
s_current_main_window = MainWindowType::Leaderboards;
s_open_leaderboard_id.reset();
}
#else #else
ActiveButton(ICON_FA_TROPHY " Achievements", false, false); ActiveButton(ICON_FA_TROPHY " Achievements", false, false);

View file

@ -49,6 +49,8 @@ void SystemDestroyed();
void SystemPaused(bool paused); void SystemPaused(bool paused);
void OpenQuickMenu(); void OpenQuickMenu();
void CloseQuickMenu(); void CloseQuickMenu();
bool OpenAchievementsWindow();
bool OpenLeaderboardsWindow();
void Shutdown(); void Shutdown();
void Render(); void Render();