From dd119f597131479e08657cd731571c0ab384ac52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 17 Feb 2025 15:54:01 -0600 Subject: [PATCH] Merge the two ConfirmExit paths --- UI/PauseScreen.cpp | 18 +++++++++++++----- UI/PauseScreen.h | 2 ++ Windows/MainWindow.cpp | 34 ++++++++++++++-------------------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index 03a71f6afe..4230b8bf29 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -587,7 +587,8 @@ int GetUnsavedProgressSeconds() { return (int)std::min(timeSinceSaveState, timeSinceGameSave); } -UI::EventReturn GamePauseScreen::OnExit(UI::EventParams &e) { +// If empty, no confirmation dialog should be shown. +std::string GetConfirmExitMessage() { std::string confirmMessage; int unsavedSeconds = GetUnsavedProgressSeconds(); @@ -606,13 +607,20 @@ UI::EventReturn GamePauseScreen::OnExit(UI::EventParams &e) { } else if (g_Config.iAskForExitConfirmationAfterSeconds > 0 && unsavedSeconds > g_Config.iAskForExitConfirmationAfterSeconds) { auto di = GetI18NCategory(I18NCat::DIALOG); confirmMessage = ApplySafeSubstitutions(di->T("You haven't saved your progress for %1."), NiceTimeFormat((int)unsavedSeconds)); + confirmMessage += '\n'; } - if (!confirmMessage.empty()) { + return confirmMessage; +} + +UI::EventReturn GamePauseScreen::OnExit(UI::EventParams &e) { + std::string confirmExitMessage = GetConfirmExitMessage(); + + if (!confirmExitMessage.empty()) { auto di = GetI18NCategory(I18NCat::DIALOG); - confirmMessage += '\n'; - confirmMessage += di->T("Are you sure you want to exit?"); - screenManager()->push(new PromptScreen(gamePath_, confirmMessage, di->T("Yes"), di->T("No"), [=](bool result) { + confirmExitMessage += '\n'; + confirmExitMessage += di->T("Are you sure you want to exit?"); + screenManager()->push(new PromptScreen(gamePath_, confirmExitMessage, di->T("Yes"), di->T("No"), [=](bool result) { if (result) { if (g_Config.bPauseMenuExitsEmulator) { System_ExitApp(); diff --git a/UI/PauseScreen.h b/UI/PauseScreen.h index 99dbc47d36..b225e28e4a 100644 --- a/UI/PauseScreen.h +++ b/UI/PauseScreen.h @@ -72,3 +72,5 @@ private: bool lastAdhocServerConnected_ = false; bool lastDNSConfigLoaded_ = false; }; + +std::string GetConfirmExitMessage(); diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index afef226700..72eb6f4ddb 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -86,8 +86,8 @@ #include "GPU/GPUCommon.h" #include "UI/OnScreenDisplay.h" #include "UI/GameSettingsScreen.h" +#include "UI/PauseScreen.h" #include "Core/SaveState.h" -#include "Core/Dialog/PSPSaveDialog.h" #define MOUSEEVENTF_FROMTOUCH_NOPEN 0xFF515780 //http://msdn.microsoft.com/en-us/library/windows/desktop/ms703320(v=vs.85).aspx #define MOUSEEVENTF_MASK_PLUS_PENTOUCH 0xFFFFFF80 @@ -817,26 +817,20 @@ namespace MainWindow } bool ConfirmExit(HWND hWnd) { - GlobalUIState state = GetUIState(); - if (state != UISTATE_MENU && state != UISTATE_EXIT && g_Config.iAskForExitConfirmationAfterSeconds > 0) { - const double timeSinceSaveState = SaveState::SecondsSinceLastSavestate(); - const double timeSinceGameSave = SecondsSinceLastGameSave(); - - const double minTime = std::min(timeSinceSaveState, timeSinceGameSave); - if (minTime > g_Config.iAskForExitConfirmationAfterSeconds) { - auto di = GetI18NCategory(I18NCat::DIALOG); - auto mm = GetI18NCategory(I18NCat::MAINMENU); - std::string dlgMsg = ApplySafeSubstitutions(di->T("You haven't saved your progress for %1."), NiceTimeFormat((int)minTime)); - dlgMsg += '\n'; - dlgMsg += '\n'; - dlgMsg += di->T("Are you sure you want to exit? All unsaved progress will be lost."); - - if (IDNO == MessageBox(hWnd, ConvertUTF8ToWString(dlgMsg).c_str(), ConvertUTF8ToWString(mm->T("Exit")).c_str(), MB_YESNO | MB_ICONQUESTION)) { - return false; - } - } + const GlobalUIState state = GetUIState(); + if (state == UISTATE_MENU || state == UISTATE_EXIT) { + return false; } - return true; + + std::string confirmExitMessage = GetConfirmExitMessage(); + if (confirmExitMessage.empty()) { + return false; + } + auto di = GetI18NCategory(I18NCat::DIALOG); + auto mm = GetI18NCategory(I18NCat::MAINMENU); + confirmExitMessage += '\n'; + confirmExitMessage += di->T("Are you sure you want to exit?"); + return IDYES == MessageBox(hWnd, ConvertUTF8ToWString(confirmExitMessage).c_str(), ConvertUTF8ToWString(mm->T("Exit")).c_str(), MB_YESNO | MB_ICONQUESTION); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {