From 536184f3948953590bc58db1f09b4f060e5d8be8 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 25 Apr 2020 17:36:36 -0700 Subject: [PATCH] Add function Game::returntomenu() When exiting from a game-gamestate which may have been entered through a varying amount of menus, the solution is to not use Game::returnmenu(), and to instead have a way to go back to a certain given menu. --- desktop_version/src/Game.cpp | 26 ++++++++++++++++++++++++++ desktop_version/src/Game.h | 1 + 2 files changed, 27 insertions(+) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 99b3b445..0053a2a5 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -6588,6 +6588,32 @@ void Game::returnmenu() } } +void Game::returntomenu(enum Menu::MenuName t) +{ + if (currentmenuname == t) + { + //Why are you calling this function then? + return; + } + + //Unwind the menu stack until we reach our desired menu + int i = menustack.size() - 1; + while (i >= 0) + { + //If we pop it off we can't reference it anymore, so check for it now + bool is_the_menu_we_want = menustack[i].name == t; + + returnmenu(); + + if (is_the_menu_we_want) + { + break; + } + + i--; + } +} + 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 f16ea6db..1dbe1582 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -106,6 +106,7 @@ public: std::string timetstring(int t); void returnmenu(); + void returntomenu(enum Menu::MenuName t); void createmenu(enum Menu::MenuName t, bool samemenu = false); void lifesequence();