From 266d436c283118a3c28e63c9b8fda08d550bbcdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo?= Date: Thu, 6 Feb 2025 19:21:18 -0300 Subject: [PATCH] Block exit button from terminating the installer while it's in progress. (#300) * Block exit button from terminating the installer while it's in progress. * Fix quit prompt not appearing when closing the game from the taskbar. --------- Co-authored-by: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> --- UnleashedRecomp/gpu/video.cpp | 8 ++++--- UnleashedRecomp/patches/frontend_listener.cpp | 6 +++-- UnleashedRecomp/patches/input_patches.cpp | 6 +++-- UnleashedRecomp/sdl_listener.h | 4 ++-- UnleashedRecomp/ui/game_window.cpp | 7 +++++- UnleashedRecomp/ui/installer_wizard.cpp | 23 ++++++++++++++++--- UnleashedRecomp/ui/message_window.cpp | 6 +++-- 7 files changed, 45 insertions(+), 15 deletions(-) diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index c54f6c1..447ace8 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -6973,14 +6973,14 @@ PPC_FUNC(sub_82E328D8) class SDLEventListenerForPSOCaching : public SDLEventListener { public: - void OnSDLEvent(SDL_Event* event) override + bool OnSDLEvent(SDL_Event* event) override { if (event->type != SDL_QUIT) - return; + return false; std::lock_guard lock(g_pipelineCacheMutex); if (g_pipelineStatesToCache.empty()) - return; + return false; FILE* f = fopen("send_this_file_to_skyth.txt", "ab"); if (f != nullptr) @@ -7095,6 +7095,8 @@ public: fclose(f); } + + return false; } }; SDLEventListenerForPSOCaching g_sdlEventListenerForPSOCaching; diff --git a/UnleashedRecomp/patches/frontend_listener.cpp b/UnleashedRecomp/patches/frontend_listener.cpp index c66224a..249c8e5 100644 --- a/UnleashedRecomp/patches/frontend_listener.cpp +++ b/UnleashedRecomp/patches/frontend_listener.cpp @@ -9,10 +9,10 @@ static class FrontendListener : public SDLEventListener bool m_isF8KeyDown = false; public: - void OnSDLEvent(SDL_Event* event) override + bool OnSDLEvent(SDL_Event* event) override { if (!Config::HUDToggleHotkey || OptionsMenu::s_isVisible) - return; + return false; switch (event->type) { @@ -34,6 +34,8 @@ public: m_isF8KeyDown = event->key.keysym.sym != SDLK_F8; break; } + + return false; } } g_frontendListener; diff --git a/UnleashedRecomp/patches/input_patches.cpp b/UnleashedRecomp/patches/input_patches.cpp index e4cac4c..6c5c981 100644 --- a/UnleashedRecomp/patches/input_patches.cpp +++ b/UnleashedRecomp/patches/input_patches.cpp @@ -121,10 +121,10 @@ public: } } - void OnSDLEvent(SDL_Event* event) override + bool OnSDLEvent(SDL_Event* event) override { if (!hid::IsInputAllowed()) - return; + return false; switch (event->type) { @@ -202,6 +202,8 @@ public: ms_touchpadFingerCount--; break; } + + return false; } } g_sdlEventListenerForInputPatches; diff --git a/UnleashedRecomp/sdl_listener.h b/UnleashedRecomp/sdl_listener.h index 27eed82..f4f6bed 100644 --- a/UnleashedRecomp/sdl_listener.h +++ b/UnleashedRecomp/sdl_listener.h @@ -4,7 +4,7 @@ class ISDLEventListener { public: virtual ~ISDLEventListener() = default; - virtual void OnSDLEvent(SDL_Event* event) = 0; + virtual bool OnSDLEvent(SDL_Event* event) = 0; }; extern std::vector& GetEventListeners(); @@ -17,5 +17,5 @@ public: GetEventListeners().emplace_back(this); } - void OnSDLEvent(SDL_Event* event) override {} + bool OnSDLEvent(SDL_Event* event) override { return false; } }; diff --git a/UnleashedRecomp/ui/game_window.cpp b/UnleashedRecomp/ui/game_window.cpp index 81fb201..cd6fac9 100644 --- a/UnleashedRecomp/ui/game_window.cpp +++ b/UnleashedRecomp/ui/game_window.cpp @@ -24,7 +24,12 @@ int Window_OnSDLEvent(void*, SDL_Event* event) ImGui_ImplSDL2_ProcessEvent(event); for (auto listener : GetEventListeners()) - listener->OnSDLEvent(event); + { + if (listener->OnSDLEvent(event)) + { + return 0; + } + } switch (event->type) { diff --git a/UnleashedRecomp/ui/installer_wizard.cpp b/UnleashedRecomp/ui/installer_wizard.cpp index 4d4c0f8..6ccfacd 100644 --- a/UnleashedRecomp/ui/installer_wizard.cpp +++ b/UnleashedRecomp/ui/installer_wizard.cpp @@ -170,10 +170,25 @@ static std::string g_creditsStr; class SDLEventListenerForInstaller : public SDLEventListener { public: - void OnSDLEvent(SDL_Event *event) override + bool OnSDLEvent(SDL_Event *event) override { - if (!InstallerWizard::s_isVisible || !g_currentMessagePrompt.empty() || g_currentPickerVisible || !hid::IsInputAllowed()) - return; + if (!InstallerWizard::s_isVisible) + return false; + + bool noModals = g_currentMessagePrompt.empty() && !g_currentPickerVisible; + if (event->type == SDL_QUIT && g_currentPage == WizardPage::Installing) + { + // Pretend the back button was pressed if the user tried quitting during installation. + // This condition is above the rest of the event processing as we want to block the exit + // button while there's confirmation message is open as well. + if (noModals) + g_currentCursorBack = true; + + return true; + } + + if (!noModals || !hid::IsInputAllowed()) + return false; constexpr float AxisValueRange = 32767.0f; constexpr float AxisTapRange = 0.5f; @@ -326,6 +341,8 @@ public: g_currentCursorIndex = newCursorIndex; } + + return false; } } g_sdlEventListenerForInstaller; diff --git a/UnleashedRecomp/ui/message_window.cpp b/UnleashedRecomp/ui/message_window.cpp index de57d4a..7249178 100644 --- a/UnleashedRecomp/ui/message_window.cpp +++ b/UnleashedRecomp/ui/message_window.cpp @@ -48,10 +48,10 @@ int g_cancelButtonIndex; class SDLEventListenerForMessageWindow : public SDLEventListener { public: - void OnSDLEvent(SDL_Event* event) override + bool OnSDLEvent(SDL_Event* event) override { if (App::s_isInit || !MessageWindow::s_isVisible || !hid::IsInputAllowed()) - return; + return false; constexpr float axisValueRange = 32767.0f; constexpr float axisTapRange = 0.5f; @@ -142,6 +142,8 @@ public: break; } } + + return false; } } g_sdlEventListenerForMessageWindow;