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>
This commit is contained in:
Darío 2025-02-06 19:21:18 -03:00 committed by GitHub
parent e7cc5a858e
commit 266d436c28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 45 additions and 15 deletions

View file

@ -6973,14 +6973,14 @@ PPC_FUNC(sub_82E328D8)
class SDLEventListenerForPSOCaching : public SDLEventListener class SDLEventListenerForPSOCaching : public SDLEventListener
{ {
public: public:
void OnSDLEvent(SDL_Event* event) override bool OnSDLEvent(SDL_Event* event) override
{ {
if (event->type != SDL_QUIT) if (event->type != SDL_QUIT)
return; return false;
std::lock_guard lock(g_pipelineCacheMutex); std::lock_guard lock(g_pipelineCacheMutex);
if (g_pipelineStatesToCache.empty()) if (g_pipelineStatesToCache.empty())
return; return false;
FILE* f = fopen("send_this_file_to_skyth.txt", "ab"); FILE* f = fopen("send_this_file_to_skyth.txt", "ab");
if (f != nullptr) if (f != nullptr)
@ -7095,6 +7095,8 @@ public:
fclose(f); fclose(f);
} }
return false;
} }
}; };
SDLEventListenerForPSOCaching g_sdlEventListenerForPSOCaching; SDLEventListenerForPSOCaching g_sdlEventListenerForPSOCaching;

View file

@ -9,10 +9,10 @@ static class FrontendListener : public SDLEventListener
bool m_isF8KeyDown = false; bool m_isF8KeyDown = false;
public: public:
void OnSDLEvent(SDL_Event* event) override bool OnSDLEvent(SDL_Event* event) override
{ {
if (!Config::HUDToggleHotkey || OptionsMenu::s_isVisible) if (!Config::HUDToggleHotkey || OptionsMenu::s_isVisible)
return; return false;
switch (event->type) switch (event->type)
{ {
@ -34,6 +34,8 @@ public:
m_isF8KeyDown = event->key.keysym.sym != SDLK_F8; m_isF8KeyDown = event->key.keysym.sym != SDLK_F8;
break; break;
} }
return false;
} }
} }
g_frontendListener; g_frontendListener;

View file

@ -121,10 +121,10 @@ public:
} }
} }
void OnSDLEvent(SDL_Event* event) override bool OnSDLEvent(SDL_Event* event) override
{ {
if (!hid::IsInputAllowed()) if (!hid::IsInputAllowed())
return; return false;
switch (event->type) switch (event->type)
{ {
@ -202,6 +202,8 @@ public:
ms_touchpadFingerCount--; ms_touchpadFingerCount--;
break; break;
} }
return false;
} }
} }
g_sdlEventListenerForInputPatches; g_sdlEventListenerForInputPatches;

View file

@ -4,7 +4,7 @@ class ISDLEventListener
{ {
public: public:
virtual ~ISDLEventListener() = default; virtual ~ISDLEventListener() = default;
virtual void OnSDLEvent(SDL_Event* event) = 0; virtual bool OnSDLEvent(SDL_Event* event) = 0;
}; };
extern std::vector<ISDLEventListener*>& GetEventListeners(); extern std::vector<ISDLEventListener*>& GetEventListeners();
@ -17,5 +17,5 @@ public:
GetEventListeners().emplace_back(this); GetEventListeners().emplace_back(this);
} }
void OnSDLEvent(SDL_Event* event) override {} bool OnSDLEvent(SDL_Event* event) override { return false; }
}; };

View file

@ -24,7 +24,12 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
ImGui_ImplSDL2_ProcessEvent(event); ImGui_ImplSDL2_ProcessEvent(event);
for (auto listener : GetEventListeners()) for (auto listener : GetEventListeners())
listener->OnSDLEvent(event); {
if (listener->OnSDLEvent(event))
{
return 0;
}
}
switch (event->type) switch (event->type)
{ {

View file

@ -170,10 +170,25 @@ static std::string g_creditsStr;
class SDLEventListenerForInstaller : public SDLEventListener class SDLEventListenerForInstaller : public SDLEventListener
{ {
public: public:
void OnSDLEvent(SDL_Event *event) override bool OnSDLEvent(SDL_Event *event) override
{ {
if (!InstallerWizard::s_isVisible || !g_currentMessagePrompt.empty() || g_currentPickerVisible || !hid::IsInputAllowed()) if (!InstallerWizard::s_isVisible)
return; 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 AxisValueRange = 32767.0f;
constexpr float AxisTapRange = 0.5f; constexpr float AxisTapRange = 0.5f;
@ -326,6 +341,8 @@ public:
g_currentCursorIndex = newCursorIndex; g_currentCursorIndex = newCursorIndex;
} }
return false;
} }
} }
g_sdlEventListenerForInstaller; g_sdlEventListenerForInstaller;

View file

@ -48,10 +48,10 @@ int g_cancelButtonIndex;
class SDLEventListenerForMessageWindow : public SDLEventListener class SDLEventListenerForMessageWindow : public SDLEventListener
{ {
public: public:
void OnSDLEvent(SDL_Event* event) override bool OnSDLEvent(SDL_Event* event) override
{ {
if (App::s_isInit || !MessageWindow::s_isVisible || !hid::IsInputAllowed()) if (App::s_isInit || !MessageWindow::s_isVisible || !hid::IsInputAllowed())
return; return false;
constexpr float axisValueRange = 32767.0f; constexpr float axisValueRange = 32767.0f;
constexpr float axisTapRange = 0.5f; constexpr float axisTapRange = 0.5f;
@ -142,6 +142,8 @@ public:
break; break;
} }
} }
return false;
} }
} }
g_sdlEventListenerForMessageWindow; g_sdlEventListenerForMessageWindow;