1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-22 08:50:18 +01:00

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.
This commit is contained in:
Gábor Dobra 2022-01-05 06:25:39 +01:00 committed by GitHub
parent ed0ef9044d
commit bd90b9d712
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View file

@ -32,6 +32,7 @@ int winmain::no_time_loss;
UINT winmain::iFrostUniqueMsg; UINT winmain::iFrostUniqueMsg;
bool winmain::restart = false; bool winmain::restart = false;
bool winmain::explicitPaused = false;
gdrv_bitmap8 winmain::gfr_display{}; gdrv_bitmap8 winmain::gfr_display{};
char winmain::DatFileName[300]{}; char winmain::DatFileName[300]{};
@ -522,7 +523,7 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
new_game(); new_game();
break; break;
case VK_F3: case VK_F3:
pause(); pause(false);
break; break;
case VK_F4: case VK_F4:
options::toggle(0x193u); options::toggle(0x193u);
@ -602,14 +603,14 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
switch (wParam) switch (wParam)
{ {
case Menu1_Launch_Ball: case Menu1_Launch_Ball:
end_pause(); end_pause(true);
pb::launch_ball(); pb::launch_ball();
break; break;
case Menu1_Pause_Resume_Game: case Menu1_Pause_Resume_Game:
pause(); pause(false);
break; break;
case Menu1_Demo: case Menu1_Demo:
end_pause(); end_pause(true);
pb::toggle_demo(); pb::toggle_demo();
break; break;
case Menu1_Select_Table: case Menu1_Select_Table:
@ -844,10 +845,14 @@ int winmain::a_dialog(HINSTANCE hInstance, HWND hWnd)
return ShellAboutW(hWnd, appName, szOtherStuff, icon); return ShellAboutW(hWnd, appName, szOtherStuff, icon);
} }
void winmain::end_pause() void winmain::end_pause(bool explicitResume)
{ {
if (single_step) if (single_step)
{ {
if (explicitPaused && !explicitResume)
return;
explicitPaused = false;
if (fullscrn::screen_mode) if (fullscrn::screen_mode)
fullscrn::set_menu_mode(0); fullscrn::set_menu_mode(0);
pb::pause_continue(); pb::pause_continue();
@ -857,14 +862,17 @@ void winmain::end_pause()
void winmain::new_game() void winmain::new_game()
{ {
end_pause(); end_pause(true);
HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT)); HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT));
pb::replay_level(0); pb::replay_level(0);
SetCursor(prevCursor); SetCursor(prevCursor);
} }
void winmain::pause() void winmain::pause(bool autoResume)
{ {
if (!autoResume)
winmain::explicitPaused = true;
if (fullscrn::screen_mode) if (fullscrn::screen_mode)
{ {
if (single_step) if (single_step)

View file

@ -18,9 +18,9 @@ public:
static int check_expiration_date(); static int check_expiration_date();
static HDC _GetDC(HWND hWnd); static HDC _GetDC(HWND hWnd);
static int a_dialog(HINSTANCE hInstance, 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 new_game();
static void pause(); static void pause(bool autoResume = true);
static void help_introduction(HINSTANCE a1, HWND a2); static void help_introduction(HINSTANCE a1, HWND a2);
static void Restart(); static void Restart();
private: private:
@ -30,6 +30,7 @@ private:
static gdrv_bitmap8 gfr_display; static gdrv_bitmap8 gfr_display;
static HCURSOR mouse_hsave; static HCURSOR mouse_hsave;
static bool restart; static bool restart;
static bool explicitPaused;
static HDC _BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint); static HDC _BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);
static void ResetTimer() static void ResetTimer()