diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 4443eed3..7d551a4a 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -441,7 +441,9 @@ function __vc_on_hud_open() end) input.add_callback("key:escape", function() if menu.page ~= "" then - menu:reset() + if not menu:back() then + menu:reset() + end elseif hud.is_inventory_open() then hud.close_inventory() else diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index a977f354..3053b613 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -26,6 +26,7 @@ #include "graphics/core/ImageData.hpp" #include "graphics/core/Shader.hpp" #include "graphics/ui/GUI.hpp" +#include "graphics/ui/elements/Menu.hpp" #include "objects/rigging.hpp" #include "logic/EngineController.hpp" #include "logic/CommandsInterpreter.hpp" @@ -154,6 +155,14 @@ void Engine::initializeClient() { }, true )); + + keepAlive(this->input->addKeyCallback(Keycode::ESCAPE, [this]() { + auto& menu = *gui->getMenu(); + if (menu.hasOpenPage() && menu.back()) { + return true; + } + return false; + })); } void Engine::initialize(CoreParameters coreParameters) { diff --git a/src/frontend/debug_panel.cpp b/src/frontend/debug_panel.cpp index 10c6b85c..c42b2930 100644 --- a/src/frontend/debug_panel.cpp +++ b/src/frontend/debug_panel.cpp @@ -9,6 +9,7 @@ #include "graphics/ui/elements/TextBox.hpp" #include "graphics/ui/elements/TrackBar.hpp" #include "graphics/ui/elements/InputBindBox.hpp" +#include "graphics/ui/GUI.hpp" #include "graphics/render/WorldRenderer.hpp" #include "graphics/render/ParticlesRenderer.hpp" #include "graphics/render/ChunksRenderer.hpp" @@ -43,10 +44,15 @@ static std::shared_ptr