From bd90b9d7125d7e41368f59f4f6995fcb245e93f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Dobra?= Date: Wed, 5 Jan 2022 06:25:39 +0100 Subject: [PATCH] Don't resume game when paused manually (#118) You get an annoying behavior when: - press F3 to pause - minimize the window - (keep it in the background, do other stuff) - bring the window back to focus, accidentally (Alt+Tab) - game resumes even if I explicitly paused it with F3 This commit makes F3 (and Pause in the menu) require an explicit resume via F3 (or Pause), other pauses like moving the window still get resumed automatically. --- SpaceCadetPinball/winmain.cpp | 22 +++++++++++++++------- SpaceCadetPinball/winmain.h | 5 +++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 6818b85..a54e666 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -32,6 +32,7 @@ int winmain::no_time_loss; UINT winmain::iFrostUniqueMsg; bool winmain::restart = false; +bool winmain::explicitPaused = false; gdrv_bitmap8 winmain::gfr_display{}; char winmain::DatFileName[300]{}; @@ -522,7 +523,7 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP new_game(); break; case VK_F3: - pause(); + pause(false); break; case VK_F4: options::toggle(0x193u); @@ -602,14 +603,14 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP switch (wParam) { case Menu1_Launch_Ball: - end_pause(); + end_pause(true); pb::launch_ball(); break; case Menu1_Pause_Resume_Game: - pause(); + pause(false); break; case Menu1_Demo: - end_pause(); + end_pause(true); pb::toggle_demo(); break; case Menu1_Select_Table: @@ -844,10 +845,14 @@ int winmain::a_dialog(HINSTANCE hInstance, HWND hWnd) return ShellAboutW(hWnd, appName, szOtherStuff, icon); } -void winmain::end_pause() +void winmain::end_pause(bool explicitResume) { if (single_step) { + if (explicitPaused && !explicitResume) + return; + + explicitPaused = false; if (fullscrn::screen_mode) fullscrn::set_menu_mode(0); pb::pause_continue(); @@ -857,14 +862,17 @@ void winmain::end_pause() void winmain::new_game() { - end_pause(); + end_pause(true); HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT)); pb::replay_level(0); SetCursor(prevCursor); } -void winmain::pause() +void winmain::pause(bool autoResume) { + if (!autoResume) + winmain::explicitPaused = true; + if (fullscrn::screen_mode) { if (single_step) diff --git a/SpaceCadetPinball/winmain.h b/SpaceCadetPinball/winmain.h index bbe5e3c..095b21c 100644 --- a/SpaceCadetPinball/winmain.h +++ b/SpaceCadetPinball/winmain.h @@ -18,9 +18,9 @@ public: static int check_expiration_date(); static HDC _GetDC(HWND hWnd); static int a_dialog(HINSTANCE hInstance, HWND hWnd); - static void end_pause(); + static void end_pause(bool explicitResume = false); static void new_game(); - static void pause(); + static void pause(bool autoResume = true); static void help_introduction(HINSTANCE a1, HWND a2); static void Restart(); private: @@ -30,6 +30,7 @@ private: static gdrv_bitmap8 gfr_display; static HCURSOR mouse_hsave; static bool restart; + static bool explicitPaused; static HDC _BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint); static void ResetTimer()