From 9dafba109226d8d039cc164e2cf1a7cfddfce8ee Mon Sep 17 00:00:00 2001 From: elasota Date: Thu, 12 Nov 2020 19:16:47 -0500 Subject: [PATCH] Add cancel option to save game prompt --- ApplicationResourcePatches/DITL/1041.json | 45 +++++++++++++++++++++ ApplicationResourcePatches/manifest.json | 1 + GpApp/GliderProtos.h | 2 +- GpApp/Input.cpp | 48 +++++++++++++++++------ GpApp/SavedGames.cpp | 10 +++-- 5 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 ApplicationResourcePatches/DITL/1041.json diff --git a/ApplicationResourcePatches/DITL/1041.json b/ApplicationResourcePatches/DITL/1041.json new file mode 100644 index 0000000..74f643e --- /dev/null +++ b/ApplicationResourcePatches/DITL/1041.json @@ -0,0 +1,45 @@ +{ + "items" : + [ + { + "name" : "Save First", + "itemType" : "Button", + "pos" : [ 174, 48 ], + "size" : [ 80, 20 ], + "id" : 0, + "enabled" : true + }, + { + "name" : "Don't Save", + "itemType" : "Button", + "pos" : [ 82, 48 ], + "size" : [ 80, 20 ], + "id" : 0, + "enabled" : true + }, + { + "name" : "Cancel", + "itemType" : "Button", + "pos" : [ 20, 48 ], + "size" : [ 50, 20 ], + "id" : 0, + "enabled" : true + }, + { + "name" : "Do you want to save the state of the game before quitting?", + "itemType" : "Label", + "pos" : [ 8, 8 ], + "size" : [ 201, 32 ], + "id" : 0, + "enabled" : false + }, + { + "name" : "", + "itemType" : "Icon", + "pos" : [ 222, 8 ], + "size" : [ 32, 32 ], + "id" : 1072, + "enabled" : false + } + ] +} \ No newline at end of file diff --git a/ApplicationResourcePatches/manifest.json b/ApplicationResourcePatches/manifest.json index 2bf078e..145c787 100644 --- a/ApplicationResourcePatches/manifest.json +++ b/ApplicationResourcePatches/manifest.json @@ -2,6 +2,7 @@ "add" : { "DITL/1017.json" : "ApplicationResourcePatches/DITL/1017.json", + "DITL/1041.json" : "ApplicationResourcePatches/DITL/1041.json", "DITL/2000.json" : "ApplicationResourcePatches/DITL/2000.json", "DITL/2001.json" : "ApplicationResourcePatches/DITL/2001.json", "DITL/2002.json" : "ApplicationResourcePatches/DITL/2002.json", diff --git a/GpApp/GliderProtos.h b/GpApp/GliderProtos.h index 382a0e5..b4a93e8 100644 --- a/GpApp/GliderProtos.h +++ b/GpApp/GliderProtos.h @@ -425,7 +425,7 @@ void HandleBands (void); // --- RubberBands.c Boolean AddBand (gliderPtr, SInt16, SInt16, Boolean); void KillAllBands (void); -void SaveGame2 (void); // --- SavedGames.c +Boolean SaveGame2 (void); // --- SavedGames.c Boolean OpenSavedGame (void); //void SaveGame (Boolean); diff --git a/GpApp/Input.cpp b/GpApp/Input.cpp index a7fa33f..447b158 100644 --- a/GpApp/Input.cpp +++ b/GpApp/Input.cpp @@ -42,7 +42,7 @@ void DoPause (void); void DoTouchScreenMenu (void); void DoBatteryEngaged (gliderPtr); void DoHeliumEngaged (gliderPtr); -Boolean QuerySaveGame (void); +void QuerySaveGame (Boolean &save, Boolean &cancel); demoPtr demoData; @@ -75,13 +75,24 @@ void DoCommandKey (void) if (theKeys->IsSet(PL_KEY_ASCII('Q'))) { + Boolean wantCancel = false; playing = false; paused = false; if ((!twoPlayerGame) && (!demoGoing)) { - if (QuerySaveGame()) - SaveGame2(); // New save game. + Boolean wantSave = false; + QuerySaveGame(wantSave, wantCancel); + + if (wantSave) + { + // New save game. + if (!SaveGame2()) + wantCancel = true; + } } + + if (wantCancel) + playing = true; } else if ((theKeys->IsSet(PL_KEY_ASCII('S'))) && (!twoPlayerGame)) { @@ -326,12 +337,23 @@ void DoTouchScreenMenu(void) switch (highlightedItem) { case TouchScreenMenuItems::kQuit: - playing = false; - paused = false; - if ((!twoPlayerGame) && (!demoGoing)) { - if (QuerySaveGame()) - SaveGame2(); // New save game. + 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; } break; case TouchScreenMenuItems::kSave: @@ -793,19 +815,19 @@ void GetInput (gliderPtr thisGlider) //-------------------------------------------------------------- QuerySaveGame -Boolean QuerySaveGame (void) +void QuerySaveGame (Boolean &save, Boolean &cancel) { #define kSaveGameAlert 1041 #define kYesSaveGameButton 1 + #define kNoButton 2 + #define kCancelButton 3 short hitWhat; InitCursor(); FlushEvents(); // CenterAlert(kSaveGameAlert); hitWhat = PortabilityLayer::DialogManager::GetInstance()->DisplayAlert(kSaveGameAlert, nullptr); - if (hitWhat == kYesSaveGameButton) - return (true); - else - return (false); + save = (hitWhat == kYesSaveGameButton); + cancel = (hitWhat == kCancelButton); } diff --git a/GpApp/SavedGames.cpp b/GpApp/SavedGames.cpp index 040932c..a1ddb33 100644 --- a/GpApp/SavedGames.cpp +++ b/GpApp/SavedGames.cpp @@ -116,7 +116,7 @@ static PortabilityLayer::FileBrowserUI_DetailsCallbackAPI GetSavedGameDetailsAPI //-------------------------------------------------------------- SaveGame2 -void SaveGame2 (void) +Boolean SaveGame2 (void) { // Bringing up the save file UI can cause key/mouse events to be missed, resulting in state being stuck when this comes back. // To avoid that, clear all state here. @@ -146,7 +146,7 @@ void SaveGame2 (void) if (savedGame == nil) { YellowAlert(kYellowFailedSaveGame, PLErrors::kOutOfMemory); - return; + return false; } memset(savedGame, 0, byteCount); @@ -166,7 +166,7 @@ void SaveGame2 (void) if (!fm->PromptSaveFile(spec.m_dir, 'gliG', savePath, savePathLength, sizeof(spec.m_name), PLPasStr(gameNameStr), PSTR("Save Game"), GetSavedGameDetailsAPI())) { mm->Release(savedGame); - return; + return false; } assert(savePathLength < sizeof(spec.m_name) - 1); @@ -179,7 +179,7 @@ void SaveGame2 (void) if (!fm->DeleteFile(spec.m_dir, spec.m_name)) { CheckFileError(PLErrors::kAccessDenied, PSTR("Saved Game")); - return; + return false; } } @@ -233,6 +233,8 @@ void SaveGame2 (void) } mm->Release(savedGame); + + return true; } //-------------------------------------------------------------- SavedGameMismatchError