From d901845e03f9306acb32abd2e506ef0f364e4482 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Tue, 14 Sep 2021 02:59:36 +0200 Subject: [PATCH] Close menus --- src/client/game/ui_scripting/lua/engine.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/client/game/ui_scripting/lua/engine.cpp b/src/client/game/ui_scripting/lua/engine.cpp index fe16b457..563b43ef 100644 --- a/src/client/game/ui_scripting/lua/engine.cpp +++ b/src/client/game/ui_scripting/lua/engine.cpp @@ -331,9 +331,28 @@ namespace ui_scripting::lua::engine } } + void close_all_menus() + { + for (auto& menu : menus) + { + if (!is_menu_visible(menu.second)) + { + continue; + } + + event event; + event.element = &menu.second; + event.name = "close"; + notify(event); + + menu.second.close(); + } + } + void clear_menus() { menus.clear(); + for (const auto element : elements) { delete element; @@ -379,6 +398,7 @@ namespace ui_scripting::lua::engine void start() { + close_all_menus(); get_scripts().clear(); clear_menus(); load_scripts(); @@ -386,6 +406,7 @@ namespace ui_scripting::lua::engine void stop() { + close_all_menus(); get_scripts().clear(); clear_menus(); }