From 018f0affaa98bb859b88a969ef4adbdbe0f90e6a Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 17 Feb 2024 00:36:22 +0300 Subject: [PATCH] more docs --- src/frontend/gui/GUI.cpp | 22 +++++++++++--------- src/frontend/gui/GUI.h | 44 +++++++++++++++++++++++++++++++++++----- src/frontend/hud.cpp | 5 +++-- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/src/frontend/gui/GUI.cpp b/src/frontend/gui/GUI.cpp index a2ce3699..9dfa758d 100644 --- a/src/frontend/gui/GUI.cpp +++ b/src/frontend/gui/GUI.cpp @@ -33,6 +33,9 @@ std::shared_ptr GUI::getMenu() { return menu; } +/** Mouse related input and logic handling + * @param delta delta time +*/ void GUI::actMouse(float delta) { auto hover = container->getAt(Events::cursor, nullptr); if (this->hover && this->hover != hover) { @@ -77,6 +80,9 @@ void GUI::actMouse(float delta) { } } +/** Processing user input and UI logic + * @param delta delta time +*/ void GUI::act(float delta) { container->setSize(glm::vec2(Window::width, Window::height)); container->act(delta); @@ -133,23 +139,19 @@ bool GUI::isFocusCaught() const { return focus && focus->isFocuskeeper(); } -void GUI::addBack(std::shared_ptr panel) { - container->addBack(panel); +void GUI::add(std::shared_ptr node) { + container->add(node); } -void GUI::add(std::shared_ptr panel) { - container->add(panel); -} - -void GUI::remove(std::shared_ptr panel) { - container->remove(panel); +void GUI::remove(std::shared_ptr node) noexcept { + container->remove(node); } void GUI::store(std::string name, std::shared_ptr node) { storage[name] = node; } -std::shared_ptr GUI::get(std::string name) { +std::shared_ptr GUI::get(std::string name) noexcept { auto found = storage.find(name); if (found == storage.end()) { return nullptr; @@ -157,7 +159,7 @@ std::shared_ptr GUI::get(std::string name) { return found->second; } -void GUI::remove(std::string name) { +void GUI::remove(std::string name) noexcept { storage.erase(name); } diff --git a/src/frontend/gui/GUI.h b/src/frontend/gui/GUI.h index 6258de66..fa9437ff 100644 --- a/src/frontend/gui/GUI.h +++ b/src/frontend/gui/GUI.h @@ -63,21 +63,55 @@ namespace gui { GUI(); ~GUI(); + /** Get the main menu (PagesControl) node */ std::shared_ptr getMenu(); + /** Get current focused node + * @return focused node or nullptr */ std::shared_ptr getFocused() const; + + /** Check if all user input is caught by some element like TextBox */ bool isFocusCaught() const; + /** Main input handling and logic update method + * @param delta delta time */ void act(float delta); + + /** Draw all visible elements on main container + * @param pctx parent graphics context + * @param assets active assets storage */ void draw(const GfxContext* pctx, Assets* assets); - void addBack(std::shared_ptr panel); - void add(std::shared_ptr panel); - void remove(std::shared_ptr panel); + + /** Add node to the main container */ + void add(std::shared_ptr node); + + /** Remove node from the main container */ + void remove(std::shared_ptr node) noexcept; + + /** Store node in the GUI nodes dictionary + * (does not add node to the main container) + * @param name node key + * @param node target node + */ void store(std::string name, std::shared_ptr node); - std::shared_ptr get(std::string name); - void remove(std::string name); + + /** Get node from the GUI nodes dictionary + * @param name node key + * @return stored node or nullptr + */ + std::shared_ptr get(std::string name) noexcept; + + /** Remove node from the GUI nodes dictionary + * @param name node key + */ + void remove(std::string name) noexcept; + + /** Set node as focused + * @param node new focused node or nullptr to remove focus + */ void setFocus(std::shared_ptr node); + /** Get the main container */ std::shared_ptr getContainer() const; }; } diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 3826f866..afcc9eee 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -294,8 +294,8 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend) debugPanel->setZIndex(2); - gui->addBack(darkOverlay); - gui->addBack(hotbarView); + gui->add(darkOverlay); + gui->add(hotbarView); gui->add(debugPanel); gui->add(contentAccessPanel); gui->add(grabbedItemView); @@ -425,6 +425,7 @@ void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptrinventories->createVirtual(blockUI->getSlotsCount()); } blockUI->bind(blockinv, frontend, interaction.get()); + currentblock = block; add(HudElement(hud_element_mode::inventory_bound, doc, blockUI, false)); }