From b83fd1b28f8f498fab819490aba37b96d96ebfef Mon Sep 17 00:00:00 2001 From: Phil Marell Date: Sat, 24 Jul 2021 16:23:58 +1000 Subject: [PATCH] =?UTF-8?q?Move=20=E2=80=9Cend=20game=E2=80=9D=20logic=20i?= =?UTF-8?q?nto=20common=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GpApp/Input.cpp | 63 ++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/GpApp/Input.cpp b/GpApp/Input.cpp index b5e81ce..86fb22d 100644 --- a/GpApp/Input.cpp +++ b/GpApp/Input.cpp @@ -42,6 +42,7 @@ void DoPause (void); void DoTouchScreenMenu (void); void DoBatteryEngaged (gliderPtr); void DoHeliumEngaged (gliderPtr); +void DoEndGame (void); void QuerySaveGame (Boolean &save, Boolean &cancel); @@ -72,27 +73,10 @@ void LogDemoKey (char keyIs) void DoCommandKey (void) { const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); - + if (theKeys->IsSet(PL_KEY_ASCII('Q'))) { - Boolean wantCancel = false; - playing = false; - paused = false; - if ((!twoPlayerGame) && (!demoGoing)) - { - Boolean wantSave = false; - QuerySaveGame(wantSave, wantCancel); - - if (wantSave) - { - // New save game. - if (!SaveGame2()) - wantCancel = true; - } - } - - if (wantCancel) - playing = true; + DoEndGame(); } else if ((theKeys->IsSet(PL_KEY_ASCII('S'))) && (!twoPlayerGame)) { @@ -337,24 +321,7 @@ void DoTouchScreenMenu(void) switch (highlightedItem) { case TouchScreenMenuItems::kQuit: - { - Boolean wantCancel = false; - playing = false; - paused = false; - if ((!twoPlayerGame) && (!demoGoing)) - { - Boolean wantSave = false; - QuerySaveGame(wantSave, wantCancel); - if (wantSave) - { - if (!SaveGame2()) // New save game. - wantCancel = true; - } - } - - if (wantCancel) - playing = true; - } + DoEndGame(); break; case TouchScreenMenuItems::kSave: assert(!twoPlayerGame); @@ -813,6 +780,28 @@ void GetInput (gliderPtr thisGlider) } } +void DoEndGame() { + Boolean wantCancel = false; + playing = false; + paused = false; + quitting = false; + if ((!twoPlayerGame) && (!demoGoing)) + { + Boolean wantSave = false; + QuerySaveGame(wantSave, wantCancel); + if (wantSave) + { + if (!SaveGame2()) // New save game. + wantCancel = true; + } + } + + if (wantCancel) + { + playing = true; + } +} + //-------------------------------------------------------------- QuerySaveGame void QuerySaveGame (Boolean &save, Boolean &cancel)