From dc2adea8ee739cc9277c12760193ce12bf94ee05 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 25 Apr 2020 19:37:33 -0700 Subject: [PATCH] Improve ed_settings Esc press handling This fixes being able to rack up a large amount of stack frames by pressing Esc repeatedly in the editor, which would be a problem if you were to then return to the main menu afterwards. Instead, if Menu::ed_settings is already in the stack, the game will simply return to that menu instead of creating it. Else, it will just create the menu. Also, as extra attention to detail, I made sure that the menu create or return only happens if Esc opens the settings menu, and not when Esc is closes it. --- desktop_version/src/editor.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 59661419..eae32982 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -3719,8 +3719,27 @@ void editorinput() ed.settingsmod=!ed.settingsmod; graphics.backgrounddrawn=false; - game.createmenu(Menu::ed_settings); - map.nexttowercolour(); + if (ed.settingsmod) + { + bool edsettings_in_stack = false; + for (size_t i = 0; i < game.menustack.size(); i++) + { + if (game.menustack[i].name == Menu::ed_settings) + { + edsettings_in_stack = true; + break; + } + } + if (edsettings_in_stack) + { + game.returntomenu(Menu::ed_settings); + } + else + { + game.createmenu(Menu::ed_settings); + } + map.nexttowercolour(); + } } }