diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 139e94ae..3bf7cab2 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -201,6 +201,17 @@ Hud::Hud(Engine& engine, LevelFrontend& frontend, Player& player) "' pos='0' size='256' gravity='top-right' margin='0,20,0,0'/>" ); add(HudElement(hud_element_mode::permanent, nullptr, debugMinimap, true)); + + keepAlive(Events::keyCallbacks[keycode::ESCAPE].add([this]() -> bool { + if (pause) { + setPause(false); + } else if (inventoryOpen) { + closeInventory(); + } else { + setPause(true); + } + return false; + })); } Hud::~Hud() { @@ -223,15 +234,6 @@ void Hud::cleanup() { } void Hud::processInput(bool visible) { - if (Events::jpressed(keycode::ESCAPE)) { - if (pause) { - setPause(false); - } else if (inventoryOpen) { - closeInventory(); - } else { - setPause(true); - } - } if (!Window::isFocused() && !pause && !isInventoryOpen()) { setPause(true); } diff --git a/src/frontend/screens/LevelScreen.cpp b/src/frontend/screens/LevelScreen.cpp index 0c7c8397..f045acee 100644 --- a/src/frontend/screens/LevelScreen.cpp +++ b/src/frontend/screens/LevelScreen.cpp @@ -83,6 +83,7 @@ LevelScreen::LevelScreen(Engine& engine, std::unique_ptr levelPtr) keepAlive(Events::getBinding(BIND_CHUNKS_RELOAD).onactived.add([=](){ player->chunks->saveAndClear(); worldRenderer->clear(); + return false; })); animator = std::make_unique(); diff --git a/src/graphics/ui/elements/Container.hpp b/src/graphics/ui/elements/Container.hpp index f0d37a8d..c51d528a 100644 --- a/src/graphics/ui/elements/Container.hpp +++ b/src/graphics/ui/elements/Container.hpp @@ -2,11 +2,12 @@ #include "UINode.hpp" #include "commons.hpp" +#include "util/ObjectsKeeper.hpp" #include namespace gui { - class Container : public UINode { + class Container : public UINode, public util::ObjectsKeeper { int prevScrollY = -1; protected: std::vector> nodes; diff --git a/src/graphics/ui/elements/Menu.cpp b/src/graphics/ui/elements/Menu.cpp index 99d631bf..49cf1908 100644 --- a/src/graphics/ui/elements/Menu.cpp +++ b/src/graphics/ui/elements/Menu.cpp @@ -13,11 +13,15 @@ bool Menu::has(const std::string& name) { pageSuppliers.find(name) != pageSuppliers.end(); } -void Menu::addPage(const std::string& name, const std::shared_ptr &panel) { - pages[name] = Page{name, panel}; +void Menu::addPage(const std::string& name, const std::shared_ptr& panel) { + pages[name] = Page {name, panel}; } -void Menu::addSupplier(const std::string &name, const supplier> &pageSupplier) { +void Menu::removePage(const std::string& name) { + pages.erase(name); +} + +void Menu::addSupplier(const std::string& name, const supplier>& pageSupplier) { pageSuppliers[name] = pageSupplier; } @@ -89,6 +93,6 @@ void Menu::reset() { clearHistory(); if (current.panel) { Container::remove(current.panel); - current = Page{"", nullptr}; + current = Page {"", nullptr}; } } diff --git a/src/graphics/ui/elements/Menu.hpp b/src/graphics/ui/elements/Menu.hpp index 5a201c01..4d30f373 100644 --- a/src/graphics/ui/elements/Menu.hpp +++ b/src/graphics/ui/elements/Menu.hpp @@ -32,6 +32,7 @@ namespace gui { void setPage(const std::string &name, bool history=true); void setPage(Page page, bool history=true); void addPage(const std::string& name, const std::shared_ptr& panel); + void removePage(const std::string& name); std::shared_ptr fetchPage(const std::string& name); /// @brief Add page supplier used if page is not found diff --git a/src/graphics/ui/gui_util.cpp b/src/graphics/ui/gui_util.cpp index 94ff01d7..84c5934a 100644 --- a/src/graphics/ui/gui_util.cpp +++ b/src/graphics/ui/gui_util.cpp @@ -11,6 +11,9 @@ #include "util/stringutil.hpp" #include "delegates.hpp" +#include "window/Events.hpp" +#include "engine/Engine.hpp" + #include using namespace gui; @@ -50,7 +53,7 @@ void guiutil::alert( } void guiutil::confirm( - const std::shared_ptr& menu, + Engine& engine, const std::wstring& text, const runnable& on_confirm, const runnable& on_deny, @@ -66,19 +69,45 @@ void guiutil::confirm( auto subpanel = std::make_shared(glm::vec2(600, 53)); subpanel->setColor(glm::vec4(0)); - subpanel->add(std::make_shared