From e5d929d8145aafe3e21f7427c422a2db2eff2af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 21 May 2025 21:39:22 +0200 Subject: [PATCH] Cancel all popups when loading a new game during gameplay --- Common/UI/Screen.cpp | 26 ++++++++++++++++++++++++++ Common/UI/Screen.h | 4 ++++ UI/EmuScreen.cpp | 20 ++++++++++++++++---- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Common/UI/Screen.cpp b/Common/UI/Screen.cpp index 1c6ade3e9d..b2f14ea8a0 100644 --- a/Common/UI/Screen.cpp +++ b/Common/UI/Screen.cpp @@ -75,12 +75,38 @@ void ScreenManager::switchScreen(Screen *screen) { } } +void ScreenManager::cancelScreensAbove(Screen *screen) { + bool found = false; + for (int i = 0; i < stack_.size(); i++) { + if (stack_[i].screen == screen) { + found = true; + } + } + + if (found) { + cancelScreensAbove_ = screen; + } +} + void ScreenManager::update() { std::lock_guard guard(inputLock_); if (!nextStack_.empty()) { switchToNext(); } + if (cancelScreensAbove_) { + bool found = false; + for (int i = stack_.size() - 1; i >= 0; i--) { + if (stack_[i].screen == cancelScreensAbove_) { + break; + } + Layer temp = stack_.back(); + stack_.pop_back(); + delete temp.screen; + } + cancelScreensAbove_ = nullptr; + } + if (overlayScreen_) { // NOTE: This is not a full UIScreen update, to avoid double global event processing. overlayScreen_->update(); diff --git a/Common/UI/Screen.h b/Common/UI/Screen.h index cd8fd09031..447e86ac1a 100644 --- a/Common/UI/Screen.h +++ b/Common/UI/Screen.h @@ -177,6 +177,8 @@ public: return stack_.empty() ? nullptr : stack_.back().screen; } + void cancelScreensAbove(Screen *screen); + void getFocusPosition(float &x, float &y, float &z); // Will delete any existing overlay screen. @@ -201,6 +203,8 @@ private: Screen *backgroundScreen_ = nullptr; Screen *overlayScreen_ = nullptr; + Screen *cancelScreensAbove_ = nullptr; + struct Layer { Screen *screen; int flags; // From LAYER_ enum above diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 8d9517644a..1f0b25631f 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -551,6 +551,8 @@ void EmuScreen::sendMessage(UIMessage message, const char *value) { return; } } else if (message == UIMessage::REQUEST_GAME_BOOT) { + INFO_LOG(Log::Loader, "EmuScreen received REQUEST_GAME_BOOT: %s", value); + if (bootPending_) { ERROR_LOG(Log::Loader, "Can't boot a new game during a pending boot"); return; @@ -560,17 +562,27 @@ void EmuScreen::sendMessage(UIMessage message, const char *value) { WARN_LOG(Log::Loader, "Game already running, ignoring"); return; } - const char *ext = strrchr(value, '.'); - if (ext != nullptr && !strcmp(ext, ".ppst")) { - SaveState::Load(Path(value), -1, [](SaveState::Status status, std::string_view message) { + + // TODO: Create a path first and + Path newGamePath(value); + + if (newGamePath.GetFileExtension() == ".ppst") { + // TODO: Should verify that it's for the correct game.... + INFO_LOG(Log::Loader, "New game is a save state - just load it."); + SaveState::Load(newGamePath, -1, [](SaveState::Status status, std::string_view message) { Core_Resume(); System_Notify(SystemNotification::DISASSEMBLY); }); } else { PSP_Shutdown(true); Achievements::UnloadGame(); + + // OK, now pop any open settings screens and stuff that are running above us. + // Otherwise, we can get strange results with game-specific settings. + screenManager()->cancelScreensAbove(this); + bootPending_ = true; - gamePath_ = Path(value); + gamePath_ = newGamePath; } } else if (message == UIMessage::CONFIG_LOADED) { // In case we need to position touch controls differently.