FullscreenUI: Add fade transition to most screen changes

This commit is contained in:
Stenzek 2025-03-30 14:40:52 +10:00
parent e6e6313219
commit 64513395f3
No known key found for this signature in database
2 changed files with 235 additions and 195 deletions

View File

@ -3515,7 +3515,7 @@ void Achievements::DrawLeaderboardsWindow()
} }
if (close_leaderboard_on_exit) if (close_leaderboard_on_exit)
CloseLeaderboard(); FullscreenUI::BeginTransition(&CloseLeaderboard);
} }
void Achievements::DrawLeaderboardEntry(const rc_client_leaderboard_entry_t& entry, bool is_self, void Achievements::DrawLeaderboardEntry(const rc_client_leaderboard_entry_t& entry, bool is_self,
@ -3631,7 +3631,7 @@ void Achievements::DrawLeaderboardListEntry(const rc_client_leaderboard_t* lboar
} }
if (pressed) if (pressed)
OpenLeaderboard(lboard); FullscreenUI::BeginTransition([id = lboard->id]() { OpenLeaderboardById(id); });
} }
#endif // __ANDROID__ #endif // __ANDROID__

View File

@ -227,7 +227,8 @@ struct PostProcessingStageInfo
static void PauseForMenuOpen(bool set_pause_menu_open); static void PauseForMenuOpen(bool set_pause_menu_open);
static bool AreAnyDialogsOpen(); static bool AreAnyDialogsOpen();
static void ClosePauseMenu(); static void ClosePauseMenu();
static void OpenPauseSubMenu(PauseSubMenu submenu); static void ClosePauseMenuImmediately();
static void SwitchToMainWindow(MainWindowType type);
static void DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size); static void DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size);
static void DrawLandingWindow(); static void DrawLandingWindow();
static void DrawStartGameWindow(); static void DrawStartGameWindow();
@ -270,7 +271,6 @@ static bool UserThemeableHorizontalButton(const std::string_view png_name, const
// Landing // Landing
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
static bool ShouldOpenToGameList(); static bool ShouldOpenToGameList();
static void SwitchToLanding();
static ImGuiFullscreen::FileSelectorFilters GetDiscImageFilters(); static ImGuiFullscreen::FileSelectorFilters GetDiscImageFilters();
static ImGuiFullscreen::FileSelectorFilters GetImageFilters(); static ImGuiFullscreen::FileSelectorFilters GetImageFilters();
static void DoStartPath(std::string path, std::string state = std::string(), static void DoStartPath(std::string path, std::string state = std::string(),
@ -462,6 +462,8 @@ static GPUTexture* GetGameListCover(const GameList::Entry* entry, bool fallback_
bool fallback_to_icon); bool fallback_to_icon);
static GPUTexture* GetGameListCoverTrophy(const GameList::Entry* entry, const ImVec2& image_size); static GPUTexture* GetGameListCoverTrophy(const GameList::Entry* entry, const ImVec2& image_size);
static GPUTexture* GetCoverForCurrentGame(); static GPUTexture* GetCoverForCurrentGame();
static void SwitchToAchievements();
static void SwitchToLeaderboards();
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Constants // Constants
@ -1004,7 +1006,7 @@ void FullscreenUI::OnSystemResumed()
// get rid of pause menu if we unpaused another way // get rid of pause menu if we unpaused another way
if (s_state.current_main_window == MainWindowType::PauseMenu) if (s_state.current_main_window == MainWindowType::PauseMenu)
ClosePauseMenu(); ClosePauseMenuImmediately();
UpdateRunIdleState(); UpdateRunIdleState();
}); });
@ -1064,13 +1066,13 @@ void FullscreenUI::OpenPauseMenu()
return; return;
PauseForMenuOpen(true); PauseForMenuOpen(true);
Achievements::UpdateRecentUnlockAndAlmostThere();
s_state.current_main_window = MainWindowType::PauseMenu;
s_state.current_pause_submenu = PauseSubMenu::None;
QueueResetFocus(FocusResetType::ViewChanged);
ForceKeyNavEnabled(); ForceKeyNavEnabled();
UpdateRunIdleState();
FixStateIfPaused(); Achievements::UpdateRecentUnlockAndAlmostThere();
BeginTransition(SHORT_TRANSITION_TIME, []() {
s_state.current_pause_submenu = PauseSubMenu::None;
SwitchToMainWindow(MainWindowType::PauseMenu);
});
}); });
} }
@ -1080,16 +1082,22 @@ void FullscreenUI::OpenCheatsMenu()
return; return;
GPUThread::RunOnThread([]() { GPUThread::RunOnThread([]() {
if (!Initialize() || s_state.current_main_window != MainWindowType::None || !SwitchToGameSettings()) if (!Initialize() || s_state.current_main_window != MainWindowType::None)
return; return;
PauseForMenuOpen(false); PauseForMenuOpen(false);
s_state.current_main_window = MainWindowType::Settings;
s_state.settings_page = SettingsPage::Cheats;
QueueResetFocus(FocusResetType::ViewChanged);
ForceKeyNavEnabled(); ForceKeyNavEnabled();
UpdateRunIdleState();
FixStateIfPaused(); BeginTransition(SHORT_TRANSITION_TIME, []() {
if (!SwitchToGameSettings())
{
ClosePauseMenuImmediately();
return;
}
SwitchToMainWindow(MainWindowType::Settings);
s_state.settings_page = SettingsPage::Cheats;
});
}); });
} }
@ -1119,24 +1127,78 @@ void FullscreenUI::ClosePauseMenu()
if (GPUThread::IsSystemPaused() && !s_state.was_paused_on_quick_menu_open) if (GPUThread::IsSystemPaused() && !s_state.was_paused_on_quick_menu_open)
Host::RunOnCPUThread([]() { System::PauseSystem(false); }); Host::RunOnCPUThread([]() { System::PauseSystem(false); });
s_state.current_main_window = MainWindowType::None; BeginTransition(SHORT_TRANSITION_TIME, []() {
s_state.current_pause_submenu = PauseSubMenu::None;
s_state.pause_menu_was_open = false;
SwitchToMainWindow(MainWindowType::None);
});
}
void FullscreenUI::ClosePauseMenuImmediately()
{
if (!GPUThread::HasGPUBackend())
return;
CancelTransition();
if (GPUThread::IsSystemPaused() && !s_state.was_paused_on_quick_menu_open)
Host::RunOnCPUThread([]() { System::PauseSystem(false); });
s_state.current_pause_submenu = PauseSubMenu::None; s_state.current_pause_submenu = PauseSubMenu::None;
s_state.pause_menu_was_open = false; s_state.pause_menu_was_open = false;
ImGui::SetWindowFocus(nullptr); SwitchToMainWindow(MainWindowType::None);
QueueResetFocus(FocusResetType::ViewChanged);
UpdateRunIdleState();
FixStateIfPaused();
// Present frame with menu closed. We have to defer this for a frame so imgui loses keyboard focus. // Present frame with menu closed. We have to defer this for a frame so imgui loses keyboard focus.
if (GPUThread::IsSystemPaused()) if (GPUThread::IsSystemPaused())
GPUThread::PresentCurrentFrame(); GPUThread::PresentCurrentFrame();
} }
void FullscreenUI::OpenPauseSubMenu(PauseSubMenu submenu) void FullscreenUI::SwitchToMainWindow(MainWindowType type)
{ {
s_state.current_main_window = MainWindowType::PauseMenu; if (s_state.current_main_window == type)
s_state.current_pause_submenu = submenu; return;
s_state.current_main_window = type;
ImGui::SetWindowFocus(nullptr);
QueueResetFocus(FocusResetType::ViewChanged); QueueResetFocus(FocusResetType::ViewChanged);
UpdateRunIdleState();
FixStateIfPaused();
}
void FullscreenUI::ReturnToPreviousWindow()
{
if (GPUThread::HasGPUBackend() && s_state.pause_menu_was_open)
{
BeginTransition([]() { SwitchToMainWindow(MainWindowType::PauseMenu); });
}
else
{
ReturnToMainWindow();
}
}
void FullscreenUI::ReturnToMainWindow()
{
if (GPUThread::IsSystemPaused() && !s_state.was_paused_on_quick_menu_open)
Host::RunOnCPUThread([]() { System::PauseSystem(false); });
const float transition_time = GPUThread::HasGPUBackend() ? SHORT_TRANSITION_TIME : DEFAULT_TRANSITION_TIME;
BeginTransition(transition_time, []() {
s_state.current_pause_submenu = PauseSubMenu::None;
s_state.pause_menu_was_open = false;
if (GPUThread::HasGPUBackend())
{
SwitchToMainWindow(MainWindowType::None);
}
else
{
if (ShouldOpenToGameList())
SwitchToGameList();
else
SwitchToMainWindow(MainWindowType::Landing);
}
});
} }
void FullscreenUI::Shutdown(bool clear_state) void FullscreenUI::Shutdown(bool clear_state)
@ -1308,43 +1370,6 @@ void FullscreenUI::InvalidateCoverCache()
}); });
} }
void FullscreenUI::ReturnToPreviousWindow()
{
if (GPUThread::HasGPUBackend() && s_state.pause_menu_was_open)
{
s_state.current_main_window = MainWindowType::PauseMenu;
QueueResetFocus(FocusResetType::ViewChanged);
}
else
{
ReturnToMainWindow();
}
}
void FullscreenUI::ReturnToMainWindow()
{
ClosePauseMenu();
if (GPUThread::HasGPUBackend())
{
s_state.current_main_window = MainWindowType::None;
ImGui::SetWindowFocus(nullptr);
}
else if (ShouldOpenToGameList())
{
SwitchToGameList();
ForceKeyNavEnabled();
}
else
{
s_state.current_main_window = MainWindowType::Landing;
ForceKeyNavEnabled();
}
UpdateRunIdleState();
FixStateIfPaused();
}
bool FullscreenUI::LoadResources() bool FullscreenUI::LoadResources()
{ {
s_state.app_icon_texture = LoadTexture("images/duck.png"); s_state.app_icon_texture = LoadTexture("images/duck.png");
@ -1568,25 +1593,25 @@ void FullscreenUI::ConfirmIfSavingMemoryCards(std::string action, std::function<
void FullscreenUI::RequestShutdown(bool save_state) void FullscreenUI::RequestShutdown(bool save_state)
{ {
s_state.current_main_window = MainWindowType::None; SwitchToMainWindow(MainWindowType::None);
ConfirmIfSavingMemoryCards(FSUI_STR("shut down"), [save_state](bool result) { ConfirmIfSavingMemoryCards(FSUI_STR("shut down"), [save_state](bool result) {
if (result) if (result)
Host::RunOnCPUThread([save_state]() { Host::RequestSystemShutdown(false, save_state); }); Host::RunOnCPUThread([save_state]() { Host::RequestSystemShutdown(false, save_state); });
else else
ClosePauseMenu(); ClosePauseMenuImmediately();
}); });
} }
void FullscreenUI::RequestReset() void FullscreenUI::RequestReset()
{ {
s_state.current_main_window = MainWindowType::None; SwitchToMainWindow(MainWindowType::None);
ConfirmIfSavingMemoryCards(FSUI_STR("reset"), [](bool result) { ConfirmIfSavingMemoryCards(FSUI_STR("reset"), [](bool result) {
if (result) if (result)
Host::RunOnCPUThread(System::ResetSystem); Host::RunOnCPUThread(System::ResetSystem);
ClosePauseMenu(); ClosePauseMenuImmediately();
}); });
} }
@ -2062,12 +2087,6 @@ bool FullscreenUI::ShouldOpenToGameList()
return Host::GetBaseBoolSettingValue("Main", "FullscreenUIOpenToGameList", false); return Host::GetBaseBoolSettingValue("Main", "FullscreenUIOpenToGameList", false);
} }
void FullscreenUI::SwitchToLanding()
{
s_state.current_main_window = MainWindowType::Landing;
QueueResetFocus(FocusResetType::ViewChanged);
}
void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size) void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size)
{ {
const ImGuiIO& io = ImGui::GetIO(); const ImGuiIO& io = ImGui::GetIO();
@ -2158,7 +2177,7 @@ void FullscreenUI::DrawLandingWindow()
FSUI_CSTR("Game List"), FSUI_CSTR("Game List"),
FSUI_CSTR("Launch a game from images scanned from your game directories."))) FSUI_CSTR("Launch a game from images scanned from your game directories.")))
{ {
SwitchToGameList(); BeginTransition(&SwitchToGameList);
} }
ImGui::SetItemDefaultFocus(); ImGui::SetItemDefaultFocus();
@ -2167,22 +2186,20 @@ void FullscreenUI::DrawLandingWindow()
"fullscreenui/cdrom.png", "fullscreenui/start-disc.svg", FSUI_CSTR("Start Game"), "fullscreenui/cdrom.png", "fullscreenui/start-disc.svg", FSUI_CSTR("Start Game"),
FSUI_CSTR("Launch a game from a file, disc, or starts the console without any disc inserted."))) FSUI_CSTR("Launch a game from a file, disc, or starts the console without any disc inserted.")))
{ {
s_state.current_main_window = MainWindowType::StartGame; BeginTransition([]() { SwitchToMainWindow(MainWindowType::StartGame); });
QueueResetFocus(FocusResetType::ViewChanged);
} }
if (UserThemeableHorizontalButton("fullscreenui/settings.png", "fullscreenui/settings.svg", FSUI_CSTR("Settings"), if (UserThemeableHorizontalButton("fullscreenui/settings.png", "fullscreenui/settings.svg", FSUI_CSTR("Settings"),
FSUI_CSTR("Changes settings for the application."))) FSUI_CSTR("Changes settings for the application.")))
{ {
SwitchToSettings(); BeginTransition(&SwitchToSettings);
} }
if (UserThemeableHorizontalButton("fullscreenui/exit.png", "fullscreenui/exit.svg", FSUI_CSTR("Exit"), if (UserThemeableHorizontalButton("fullscreenui/exit.png", "fullscreenui/exit.svg", FSUI_CSTR("Exit"),
FSUI_CSTR("Return to desktop mode, or exit the application.")) || FSUI_CSTR("Return to desktop mode, or exit the application.")) ||
(!AreAnyDialogsOpen() && WantsToCloseMenu())) (!AreAnyDialogsOpen() && WantsToCloseMenu()))
{ {
s_state.current_main_window = MainWindowType::Exit; BeginTransition([]() { SwitchToMainWindow(MainWindowType::Exit); });
QueueResetFocus(FocusResetType::ViewChanged);
} }
} }
EndHorizontalMenu(); EndHorizontalMenu();
@ -2255,8 +2272,7 @@ void FullscreenUI::DrawStartGameWindow()
FSUI_CSTR("Back"), FSUI_CSTR("Return to the previous menu.")) || FSUI_CSTR("Back"), FSUI_CSTR("Return to the previous menu.")) ||
(!AreAnyDialogsOpen() && WantsToCloseMenu())) (!AreAnyDialogsOpen() && WantsToCloseMenu()))
{ {
s_state.current_main_window = MainWindowType::Landing; BeginTransition([]() { SwitchToMainWindow(MainWindowType::Landing); });
QueueResetFocus(FocusResetType::ViewChanged);
} }
} }
EndHorizontalMenu(); EndHorizontalMenu();
@ -2303,8 +2319,7 @@ void FullscreenUI::DrawExitWindow()
FSUI_CSTR("Back"), FSUI_CSTR("Return to the previous menu.")) || FSUI_CSTR("Back"), FSUI_CSTR("Return to the previous menu.")) ||
WantsToCloseMenu()) WantsToCloseMenu())
{ {
s_state.current_main_window = MainWindowType::Landing; BeginTransition([]() { SwitchToMainWindow(MainWindowType::Landing); });
QueueResetFocus(FocusResetType::ViewChanged);
} }
if (HorizontalMenuItem(GetUserThemeableTexture("fullscreenui/exit.png", "fullscreenui/exit.svg"), if (HorizontalMenuItem(GetUserThemeableTexture("fullscreenui/exit.png", "fullscreenui/exit.svg"),
@ -3622,7 +3637,7 @@ void FullscreenUI::SwitchToSettings()
PopulateGameListDirectoryCache(Host::Internal::GetBaseSettingsLayer()); PopulateGameListDirectoryCache(Host::Internal::GetBaseSettingsLayer());
} }
s_state.current_main_window = MainWindowType::Settings; SwitchToMainWindow(MainWindowType::Settings);
s_state.settings_page = SettingsPage::Interface; s_state.settings_page = SettingsPage::Interface;
s_state.settings_last_bg_alpha = GetBackgroundAlpha(); s_state.settings_last_bg_alpha = GetBackgroundAlpha();
} }
@ -3636,9 +3651,8 @@ void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial, GameHa
s_state.game_settings_interface = s_state.game_settings_interface =
System::GetGameSettingsInterface(s_state.game_settings_db_entry, serial, true, false); System::GetGameSettingsInterface(s_state.game_settings_db_entry, serial, true, false);
PopulatePatchesAndCheatsList(); PopulatePatchesAndCheatsList();
s_state.current_main_window = MainWindowType::Settings;
s_state.settings_page = SettingsPage::Summary; s_state.settings_page = SettingsPage::Summary;
QueueResetFocus(FocusResetType::ViewChanged); SwitchToMainWindow(MainWindowType::Settings);
} }
bool FullscreenUI::SwitchToGameSettings() bool FullscreenUI::SwitchToGameSettings()
@ -3823,17 +3837,19 @@ void FullscreenUI::DrawSettingsWindow()
if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadLeft, true) || if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadLeft, true) ||
ImGui::IsKeyPressed(ImGuiKey_NavGamepadTweakSlow, true) || ImGui::IsKeyPressed(ImGuiKey_LeftArrow, true)) ImGui::IsKeyPressed(ImGuiKey_NavGamepadTweakSlow, true) || ImGui::IsKeyPressed(ImGuiKey_LeftArrow, true))
{ {
index = (index == 0) ? (count - 1) : (index - 1); BeginTransition([page = pages[(index == 0) ? (count - 1) : (index - 1)]]() {
s_state.settings_page = pages[index]; s_state.settings_page = page;
QueueResetFocus(FocusResetType::Other); QueueResetFocus(FocusResetType::Other);
});
} }
else if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadRight, true) || else if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadRight, true) ||
ImGui::IsKeyPressed(ImGuiKey_NavGamepadTweakFast, true) || ImGui::IsKeyPressed(ImGuiKey_NavGamepadTweakFast, true) ||
ImGui::IsKeyPressed(ImGuiKey_RightArrow, true)) ImGui::IsKeyPressed(ImGuiKey_RightArrow, true))
{ {
index = (index + 1) % count; BeginTransition([page = pages[(index + 1) % count]]() {
s_state.settings_page = pages[index]; s_state.settings_page = page;
QueueResetFocus(FocusResetType::Other); QueueResetFocus(FocusResetType::Other);
});
} }
} }
@ -3852,8 +3868,10 @@ void FullscreenUI::DrawSettingsWindow()
if (NavButton(titles[static_cast<u32>(pages[i])].second, i == index, true, ITEM_WIDTH, if (NavButton(titles[static_cast<u32>(pages[i])].second, i == index, true, ITEM_WIDTH,
LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY))
{ {
s_state.settings_page = pages[i]; BeginTransition([page = pages[i]]() {
QueueResetFocus(FocusResetType::Other); s_state.settings_page = page;
QueueResetFocus(FocusResetType::Other);
});
} }
} }
@ -6708,6 +6726,11 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats)
void FullscreenUI::DrawPauseMenu() void FullscreenUI::DrawPauseMenu()
{ {
static constexpr auto switch_submenu = [](PauseSubMenu submenu) {
s_state.current_pause_submenu = submenu;
QueueResetFocus(FocusResetType::ViewChanged);
};
static constexpr float top_bar_height = 90.0f; static constexpr float top_bar_height = 90.0f;
static constexpr float top_bar_padding = 10.0f; static constexpr float top_bar_padding = 10.0f;
@ -6836,10 +6859,16 @@ void FullscreenUI::DrawPauseMenu()
} }
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_UNDO, "Load State"), has_game)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_UNDO, "Load State"), has_game))
OpenSaveStateSelector(s_state.current_game_serial, s_state.current_game_path, true); {
BeginTransition(
[]() { OpenSaveStateSelector(s_state.current_game_serial, s_state.current_game_path, true); });
}
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_DOWNLOAD, "Save State"), has_game)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_DOWNLOAD, "Save State"), has_game))
OpenSaveStateSelector(s_state.current_game_serial, s_state.current_game_path, false); {
BeginTransition(
[]() { OpenSaveStateSelector(s_state.current_game_serial, s_state.current_game_path, false); });
}
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_GAMEPAD, "Toggle Analog"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_GAMEPAD, "Toggle Analog")))
{ {
@ -6848,18 +6877,16 @@ void FullscreenUI::DrawPauseMenu()
} }
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_WRENCH, "Game Properties"), has_game)) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_WRENCH, "Game Properties"), has_game))
{ BeginTransition([]() { SwitchToGameSettings(); });
SwitchToGameSettings();
}
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_TROPHY, "Achievements"), if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_TROPHY, "Achievements"),
Achievements::HasAchievementsOrLeaderboards())) Achievements::HasAchievementsOrLeaderboards()))
{ {
// skip second menu and go straight to cheevos if there's no lbs // skip second menu and go straight to cheevos if there's no lbs
if (!Achievements::HasLeaderboards()) if (!Achievements::HasLeaderboards())
OpenAchievementsWindow(); BeginTransition(&SwitchToAchievements);
else else
OpenPauseSubMenu(PauseSubMenu::Achievements); BeginTransition([]() { switch_submenu(PauseSubMenu::Achievements); });
} }
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_CAMERA, "Save Screenshot"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_CAMERA, "Save Screenshot")))
@ -6870,20 +6897,20 @@ void FullscreenUI::DrawPauseMenu()
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Change Disc"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Change Disc")))
{ {
s_state.current_main_window = MainWindowType::None; BeginTransition(SHORT_TRANSITION_TIME, []() { s_state.current_main_window = MainWindowType::None; });
Host::RunOnCPUThread([]() { BeginChangeDiscOnCPUThread(false); }); Host::RunOnCPUThread([]() { BeginChangeDiscOnCPUThread(false); });
} }
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_SLIDERS_H, "Settings"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_SLIDERS_H, "Settings")))
SwitchToSettings(); BeginTransition(&SwitchToSettings);
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_POWER_OFF, "Close Game"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_POWER_OFF, "Close Game")))
{ {
// skip submenu when we can't save anyway // skip submenu when we can't save anyway
if (!has_game) if (!has_game)
RequestShutdown(false); BeginTransition([]() { RequestShutdown(false); });
else else
OpenPauseSubMenu(PauseSubMenu::Exit); BeginTransition([]() { switch_submenu(PauseSubMenu::Exit); });
} }
} }
break; break;
@ -6891,33 +6918,33 @@ void FullscreenUI::DrawPauseMenu()
case PauseSubMenu::Exit: case PauseSubMenu::Exit:
{ {
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_PF_NAVIGATION_BACK, "Back To Pause Menu")) || WantsToCloseMenu()) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_PF_NAVIGATION_BACK, "Back To Pause Menu")) || WantsToCloseMenu())
OpenPauseSubMenu(PauseSubMenu::None); BeginTransition([]() { switch_submenu(PauseSubMenu::None); });
else else
ImGui::SetItemDefaultFocus(); ImGui::SetItemDefaultFocus();
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_SYNC, "Reset System"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_SYNC, "Reset System")))
RequestReset(); BeginTransition([]() { RequestReset(); });
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_SAVE, "Exit And Save State"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_SAVE, "Exit And Save State")))
RequestShutdown(true); BeginTransition([]() { RequestShutdown(true); });
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_POWER_OFF, "Exit Without Saving"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_POWER_OFF, "Exit Without Saving")))
RequestShutdown(false); BeginTransition([]() { RequestShutdown(false); });
} }
break; break;
case PauseSubMenu::Achievements: case PauseSubMenu::Achievements:
{ {
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_PF_NAVIGATION_BACK, "Back To Pause Menu")) || WantsToCloseMenu()) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_PF_NAVIGATION_BACK, "Back To Pause Menu")) || WantsToCloseMenu())
OpenPauseSubMenu(PauseSubMenu::None); BeginTransition([]() { switch_submenu(PauseSubMenu::None); });
else else
ImGui::SetItemDefaultFocus(); ImGui::SetItemDefaultFocus();
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_TROPHY, "Achievements"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_TROPHY, "Achievements")))
OpenAchievementsWindow(); BeginTransition(&SwitchToAchievements);
if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_STOPWATCH, "Leaderboards"))) if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_STOPWATCH, "Leaderboards")))
OpenLeaderboardsWindow(); BeginTransition(&SwitchToLeaderboards);
} }
break; break;
} }
@ -7057,8 +7084,7 @@ void FullscreenUI::OpenSaveStateSelector(const std::string& serial, const std::s
if (PopulateSaveStateListEntries(serial, std::move(undo_state), is_loading) > 0) if (PopulateSaveStateListEntries(serial, std::move(undo_state), is_loading) > 0)
{ {
s_state.save_state_selector_loading = is_loading; s_state.save_state_selector_loading = is_loading;
s_state.current_main_window = MainWindowType::SaveStateSelector; SwitchToMainWindow(MainWindowType::SaveStateSelector);
QueueResetFocus(FocusResetType::ViewChanged);
} }
else else
{ {
@ -7072,8 +7098,7 @@ void FullscreenUI::OpenSaveStateSelector(const std::string& serial, const std::s
if (PopulateSaveStateListEntries(serial, std::nullopt, is_loading) > 0) if (PopulateSaveStateListEntries(serial, std::nullopt, is_loading) > 0)
{ {
s_state.save_state_selector_loading = is_loading; s_state.save_state_selector_loading = is_loading;
s_state.current_main_window = MainWindowType::SaveStateSelector; SwitchToMainWindow(MainWindowType::SaveStateSelector);
QueueResetFocus(FocusResetType::ViewChanged);
} }
else else
{ {
@ -7613,7 +7638,7 @@ void FullscreenUI::DrawGameListWindow()
BeginNavBar(); BeginNavBar();
if (NavButton(ICON_PF_NAVIGATION_BACK, true, true)) if (NavButton(ICON_PF_NAVIGATION_BACK, true, true))
SwitchToLanding(); BeginTransition([]() { SwitchToMainWindow(MainWindowType::Landing); });
NavTitle(Host::TranslateToCString(TR_CONTEXT, titles[static_cast<u32>(s_state.game_list_view)])); NavTitle(Host::TranslateToCString(TR_CONTEXT, titles[static_cast<u32>(s_state.game_list_view)]));
RightAlignNavButtons(count, ITEM_WIDTH, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); RightAlignNavButtons(count, ITEM_WIDTH, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
@ -7648,11 +7673,20 @@ void FullscreenUI::DrawGameListWindow()
if (!AreAnyDialogsOpen()) if (!AreAnyDialogsOpen())
{ {
if (ImGui::IsKeyPressed(ImGuiKey_NavGamepadMenu, false) || ImGui::IsKeyPressed(ImGuiKey_F4, false)) if (ImGui::IsKeyPressed(ImGuiKey_NavGamepadMenu, false) || ImGui::IsKeyPressed(ImGuiKey_F4, false))
s_state.game_list_view = (s_state.game_list_view == GameListView::Grid) ? GameListView::List : GameListView::Grid; {
BeginTransition([]() {
s_state.game_list_view =
(s_state.game_list_view == GameListView::Grid) ? GameListView::List : GameListView::Grid;
});
}
else if (ImGui::IsKeyPressed(ImGuiKey_GamepadBack, false) || ImGui::IsKeyPressed(ImGuiKey_F2, false)) else if (ImGui::IsKeyPressed(ImGuiKey_GamepadBack, false) || ImGui::IsKeyPressed(ImGuiKey_F2, false))
SwitchToSettings(); {
BeginTransition(&SwitchToSettings);
}
else if (ImGui::IsKeyPressed(ImGuiKey_GamepadStart, false) || ImGui::IsKeyPressed(ImGuiKey_F3, false)) else if (ImGui::IsKeyPressed(ImGuiKey_GamepadStart, false) || ImGui::IsKeyPressed(ImGuiKey_F3, false))
{
DoResume(); DoResume();
}
} }
if (IsGamepadInputSource()) if (IsGamepadInputSource())
@ -7694,7 +7728,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
} }
if (!AreAnyDialogsOpen() && WantsToCloseMenu()) if (!AreAnyDialogsOpen() && WantsToCloseMenu())
SwitchToLanding(); BeginTransition([]() { SwitchToMainWindow(MainWindowType::Landing); });
auto game_list_lock = GameList::GetLock(); auto game_list_lock = GameList::GetLock();
const GameList::Entry* selected_entry = nullptr; const GameList::Entry* selected_entry = nullptr;
@ -7991,7 +8025,7 @@ void FullscreenUI::DrawGameGrid(const ImVec2& heading_size)
} }
if (ImGui::IsWindowFocused() && WantsToCloseMenu()) if (ImGui::IsWindowFocused() && WantsToCloseMenu())
SwitchToLanding(); BeginTransition([]() { SwitchToMainWindow(MainWindowType::Landing); });
ResetFocusHere(); ResetFocusHere();
BeginMenuButtons(); BeginMenuButtons();
@ -8132,42 +8166,45 @@ void FullscreenUI::HandleGameListOptions(const GameList::Entry* entry)
{FSUI_ICONSTR(ICON_FA_FOLDER_MINUS, "Reset Play Time"), false}, {FSUI_ICONSTR(ICON_FA_FOLDER_MINUS, "Reset Play Time"), false},
}; };
OpenChoiceDialog(entry->title.c_str(), false, std::move(options), OpenChoiceDialog(
[entry_path = entry->path, entry_serial = entry->serial](s32 index, const std::string& title, entry->title.c_str(), false, std::move(options),
bool checked) mutable { [entry_path = entry->path, entry_serial = entry->serial](s32 index, const std::string& title,
switch (index) bool checked) mutable {
{ switch (index)
case 0: // Open Game Properties {
SwitchToGameSettingsForPath(entry_path); case 0: // Open Game Properties
break; BeginTransition([entry_path = std::move(entry_path)]() { SwitchToGameSettingsForPath(entry_path); });
case 1: // Open Containing Directory break;
ExitFullscreenAndOpenURL(Path::CreateFileURL(Path::GetDirectory(entry_path))); case 1: // Open Containing Directory
break; ExitFullscreenAndOpenURL(Path::CreateFileURL(Path::GetDirectory(entry_path)));
case 2: // Set Cover Image break;
DoSetCoverImage(std::move(entry_path)); case 2: // Set Cover Image
break; DoSetCoverImage(std::move(entry_path));
case 3: // Resume Game break;
DoStartPath(entry_path, System::GetGameSaveStateFileName(entry_serial, -1)); case 3: // Resume Game
break; DoStartPath(entry_path, System::GetGameSaveStateFileName(entry_serial, -1));
case 4: // Load State break;
OpenSaveStateSelector(entry_serial, entry_path, true); case 4: // Load State
break; BeginTransition([entry_serial = std::move(entry_serial), entry_path = std::move(entry_path)]() {
case 5: // Default Boot OpenSaveStateSelector(entry_serial, entry_path, true);
DoStartPath(entry_path); });
break; break;
case 6: // Fast Boot case 5: // Default Boot
DoStartPath(entry_path, {}, true); DoStartPath(entry_path);
break; break;
case 7: // Slow Boot case 6: // Fast Boot
DoStartPath(entry_path, {}, false); DoStartPath(entry_path, {}, true);
break; break;
case 8: // Reset Play Time case 7: // Slow Boot
GameList::ClearPlayedTimeForSerial(entry_serial); DoStartPath(entry_path, {}, false);
break; break;
default: case 8: // Reset Play Time
break; GameList::ClearPlayedTimeForSerial(entry_serial);
} break;
}); default:
break;
}
});
} }
else else
{ {
@ -8188,7 +8225,8 @@ void FullscreenUI::HandleGameListOptions(const GameList::Entry* entry)
switch (index) switch (index)
{ {
case 0: // Open Game Properties case 0: // Open Game Properties
SwitchToGameSettingsForPath(entry_path); BeginTransition(
[entry_path = std::move(entry_path)]() { SwitchToGameSettingsForPath(entry_path); });
break; break;
case 1: // Set Cover Image case 1: // Set Cover Image
DoSetCoverImage(std::move(disc_set_name)); DoSetCoverImage(std::move(disc_set_name));
@ -8386,7 +8424,6 @@ void FullscreenUI::DrawGameListSettingsPage()
void FullscreenUI::SwitchToGameList() void FullscreenUI::SwitchToGameList()
{ {
s_state.current_main_window = MainWindowType::GameList;
s_state.game_list_view = s_state.game_list_view =
static_cast<GameListView>(Host::GetBaseIntSettingValue("Main", "DefaultFullscreenUIGameView", 0)); static_cast<GameListView>(Host::GetBaseIntSettingValue("Main", "DefaultFullscreenUIGameView", 0));
s_state.game_list_show_trophy_icons = Host::GetBaseBoolSettingValue("Main", "FullscreenUIShowTrophyIcons", true); s_state.game_list_show_trophy_icons = Host::GetBaseBoolSettingValue("Main", "FullscreenUIShowTrophyIcons", true);
@ -8399,7 +8436,7 @@ void FullscreenUI::SwitchToGameList()
} }
s_state.icon_image_map.clear(); s_state.icon_image_map.clear();
QueueResetFocus(FocusResetType::ViewChanged); SwitchToMainWindow(MainWindowType::GameList);
} }
GPUTexture* FullscreenUI::GetGameListCover(const GameList::Entry* entry, bool fallback_to_achievements_icon, GPUTexture* FullscreenUI::GetGameListCover(const GameList::Entry* entry, bool fallback_to_achievements_icon,
@ -8549,72 +8586,75 @@ void FullscreenUI::DrawAboutWindow()
void FullscreenUI::OpenAchievementsWindow() void FullscreenUI::OpenAchievementsWindow()
{ {
// NOTE: Called from CPU thread.
if (!System::IsValid()) if (!System::IsValid())
return; return;
if (!Achievements::IsActive()) const auto lock = Achievements::GetLock();
if (!Achievements::IsActive() || !Achievements::HasAchievements())
{ {
Host::AddKeyedOSDMessage("achievements_disabled", FSUI_STR("Achievements are not enabled."), ShowToast(std::string(), Achievements::IsActive() ? FSUI_STR("This game has no achievements.") :
Host::OSD_INFO_DURATION); FSUI_STR("Achievements are not enabled."));
return;
}
else if (!Achievements::HasAchievements())
{
ShowToast(std::string(), FSUI_STR("This game has no achievements."));
return; return;
} }
GPUThread::RunOnThread([]() { GPUThread::RunOnThread([]() {
if (!Initialize() || !Achievements::PrepareAchievementsWindow()) if (!Initialize())
return; return;
if (s_state.current_main_window != MainWindowType::PauseMenu) PauseForMenuOpen(false);
{ ForceKeyNavEnabled();
PauseForMenuOpen(false);
ForceKeyNavEnabled();
}
s_state.current_main_window = MainWindowType::Achievements; BeginTransition(SHORT_TRANSITION_TIME, &SwitchToAchievements);
QueueResetFocus(FocusResetType::ViewChanged);
UpdateRunIdleState();
FixStateIfPaused();
}); });
} }
void FullscreenUI::SwitchToAchievements()
{
if (!Achievements::PrepareAchievementsWindow())
{
ClosePauseMenuImmediately();
return;
}
SwitchToMainWindow(MainWindowType::Achievements);
}
void FullscreenUI::OpenLeaderboardsWindow() void FullscreenUI::OpenLeaderboardsWindow()
{ {
if (!System::IsValid()) if (!System::IsValid())
return; return;
if (!Achievements::IsActive()) const auto lock = Achievements::GetLock();
if (!Achievements::IsActive() || !Achievements::HasLeaderboards())
{ {
Host::AddKeyedOSDMessage("achievements_disabled", FSUI_STR("Leaderboards are not enabled."), ShowToast(std::string(), Achievements::IsActive() ? FSUI_STR("This game has no leaderboards.") :
Host::OSD_INFO_DURATION); FSUI_STR("Achievements are not enabled."));
return;
}
else if (!Achievements::HasLeaderboards())
{
ShowToast(std::string(), FSUI_STR("This game has no leaderboards."));
return; return;
} }
GPUThread::RunOnThread([]() { GPUThread::RunOnThread([]() {
if (!Initialize() || !Achievements::PrepareLeaderboardsWindow()) if (!Initialize())
return; return;
if (s_state.current_main_window != MainWindowType::PauseMenu) PauseForMenuOpen(false);
{ ForceKeyNavEnabled();
PauseForMenuOpen(false);
ForceKeyNavEnabled();
}
s_state.current_main_window = MainWindowType::Leaderboards; BeginTransition(SHORT_TRANSITION_TIME, &SwitchToLeaderboards);
QueueResetFocus(FocusResetType::ViewChanged);
UpdateRunIdleState();
FixStateIfPaused();
}); });
} }
void FullscreenUI::SwitchToLeaderboards()
{
if (!Achievements::PrepareLeaderboardsWindow())
{
ClosePauseMenuImmediately();
return;
}
SwitchToMainWindow(MainWindowType::Leaderboards);
}
FullscreenUI::BackgroundProgressCallback::BackgroundProgressCallback(std::string name) FullscreenUI::BackgroundProgressCallback::BackgroundProgressCallback(std::string name)
: ProgressCallback(), m_name(std::move(name)) : ProgressCallback(), m_name(std::move(name))
{ {