From bf4427c75a930bb070de306193a91b9aa356b0e7 Mon Sep 17 00:00:00 2001 From: Misa Date: Thu, 16 Apr 2020 19:16:40 -0700 Subject: [PATCH] Add function Game::returnmenu() It simply goes to the previous menu stack frame. --- desktop_version/src/Game.cpp | 24 ++++++++++++++++++++++++ desktop_version/src/Game.h | 1 + 2 files changed, 25 insertions(+) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 87c21260..6495e751 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -6552,6 +6552,30 @@ std::string Game::timetstring( int t ) return tempstring; } +void Game::returnmenu() +{ + if (menustack.empty()) + { + puts("Error: returning to previous menu frame on empty stack!"); + return; + } + + MenuStackFrame& frame = menustack[menustack.size()-1]; + + //Store this in case createmenu() removes the stack frame + int previousoption = frame.option; + + createmenu(frame.name, true); + currentmenuoption = previousoption; + + //Remove the stackframe now, but createmenu() might have already gotten to it + //if we were returning to the main menu + if (!menustack.empty()) + { + menustack.pop_back(); + } +} + void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) { if (t == Menu::mainmenu) diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 7a604339..dd06d97b 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -115,6 +115,7 @@ public: std::string timetstring(int t); + void returnmenu(); void createmenu(enum Menu::MenuName t, bool samemenu = false); void lifesequence();