From 1ba563d42a52e5a2282e60e34fb0cf52ce0d37d9 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 31 Jan 2024 05:55:01 +0300 Subject: [PATCH] frontend/gui refactor --- src/engine.cpp | 2 +- src/frontend/gui/GUI.cpp | 4 +- src/frontend/gui/GUI.h | 4 +- src/frontend/gui/controls.cpp | 4 +- src/frontend/gui/controls.h | 2 +- src/frontend/gui/gui_util.cpp | 56 ++++++--- src/frontend/gui/gui_util.h | 28 ++++- src/frontend/gui/panels.cpp | 4 - src/frontend/gui/panels.h | 1 - src/frontend/hud.cpp | 14 ++- src/frontend/menu.cpp | 226 +++++++++++++++++++--------------- src/frontend/menu.h | 8 +- src/frontend/screens.cpp | 2 +- 13 files changed, 207 insertions(+), 148 deletions(-) diff --git a/src/engine.cpp b/src/engine.cpp index 0b6e979b..a387cdb2 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -214,7 +214,7 @@ void Engine::setScreen(std::shared_ptr screen) { void Engine::setLanguage(std::string locale) { settings.ui.language = locale; langs::setup(paths->getResources(), locale, contentPacks); - menus::create_menus(this, gui->getMenu()); + menus::create_menus(this); } gui::GUI* Engine::getGUI() { diff --git a/src/frontend/gui/GUI.cpp b/src/frontend/gui/GUI.cpp index 114693d3..2007d5c7 100644 --- a/src/frontend/gui/GUI.cpp +++ b/src/frontend/gui/GUI.cpp @@ -26,7 +26,7 @@ GUI::GUI() { uicamera->perspective = false; uicamera->flipped = true; - menu = new PagesControl(); + menu = std::make_shared(); container->add(menu); container->scrollable(false); } @@ -36,7 +36,7 @@ GUI::~GUI() { delete container; } -PagesControl* GUI::getMenu() { +std::shared_ptr GUI::getMenu() { return menu; } diff --git a/src/frontend/gui/GUI.h b/src/frontend/gui/GUI.h index 6b8876f9..4cd272ef 100644 --- a/src/frontend/gui/GUI.h +++ b/src/frontend/gui/GUI.h @@ -59,13 +59,13 @@ namespace gui { std::unordered_map> storage; Camera* uicamera; - PagesControl* menu; + std::shared_ptr menu; void actMouse(float delta); public: GUI(); ~GUI(); - PagesControl* getMenu(); + std::shared_ptr getMenu(); std::shared_ptr getFocused() const; bool isFocusCaught() const; diff --git a/src/frontend/gui/controls.cpp b/src/frontend/gui/controls.cpp index b5fc5b65..2810cedd 100644 --- a/src/frontend/gui/controls.cpp +++ b/src/frontend/gui/controls.cpp @@ -20,6 +20,7 @@ Label::Label(std::string text, std::string fontName) : UINode(vec2(), vec2(text.length() * 8, 15)), text(util::str2wstr_utf8(text)), fontName_(fontName) { + setInteractive(false); } @@ -27,6 +28,7 @@ Label::Label(std::wstring text, std::string fontName) : UINode(vec2(), vec2(text.length() * 8, 15)), text(text), fontName_(fontName) { + setInteractive(false); } void Label::setText(std::wstring text) { @@ -314,7 +316,7 @@ void TextBox::text(std::wstring value) { InputBindBox::InputBindBox(Binding& binding, vec4 padding) : Panel(vec2(100,32), padding, 0, false), binding(binding) { - label = new Label(L""); + label = std::make_shared