diff --git a/doc/en/scripting/builtins/libgui.md b/doc/en/scripting/builtins/libgui.md index 53d6e4ad2..a7ddbeaec 100644 --- a/doc/en/scripting/builtins/libgui.md +++ b/doc/en/scripting/builtins/libgui.md @@ -139,7 +139,7 @@ gui.confirm( ## Documents and templates ```lua --- Loads a UI document with its script, returns the name of the document if successfully loaded. +-- Loads a UI document with its script. Returns document environment table gui.load_document( -- Path to the xml file of the page. Example: `core:layouts/pages/main.xml` path: str, @@ -147,7 +147,7 @@ gui.load_document( name: str -- Table of parameters passed to the on_open event args: table -) -> str +) -> table -- Loads and processes layout template from file gui.template( diff --git a/doc/en/xml-ui-layouts.md b/doc/en/xml-ui-layouts.md index 643f2adcb..704a0b786 100644 --- a/doc/en/xml-ui-layouts.md +++ b/doc/en/xml-ui-layouts.md @@ -39,6 +39,8 @@ Examples: - `position-func` - position supplier for an element (two numbers), called on every parent container size update or on element adding on a container. May be called before *on_hud_open* - `size-func` - element size provider (two numbers), called when the size of the container in which the element is located changes, or when an element is added to the container. Can be called before on_hud_open is called. - `onclick` - lua function called when an element is clicked. +- `onrightclick` - lua function called when the right mouse button is pressed on an element. +- `onmiddleclick` - lua function called when the middle mouse button is pressed on an element. - `ondoubleclick` - lua function called when you double click on an element. - `onfocus` - lua function called when focusing on an element. - `ondefocus` - lua function called when the element loses focus. diff --git a/doc/ru/scripting/builtins/libgui.md b/doc/ru/scripting/builtins/libgui.md index 9c2eb7418..ea1221415 100644 --- a/doc/ru/scripting/builtins/libgui.md +++ b/doc/ru/scripting/builtins/libgui.md @@ -140,12 +140,12 @@ gui.confirm( ## Документы и шаблоны ```lua --- Загружает UI документ и его скрипт. Возвращает имя документа. +-- Загружает UI документ и его скрипт. Возвращает пространство имён документа gui.load_document( path: string, -- путь к xml файлу, например: core:layouts/pages/main.xml name: string, -- id документа, например: core:pages/main args: table -- параметры для события on_open -) -> string +) -> table -- Обрабатывает xml шаблон макета из файла gui.template( diff --git a/doc/ru/xml-ui-layouts.md b/doc/ru/xml-ui-layouts.md index 3b40f6c9c..9be788e7f 100644 --- a/doc/ru/xml-ui-layouts.md +++ b/doc/ru/xml-ui-layouts.md @@ -43,6 +43,8 @@ - `position-func` - поставщик позиции элемента (два числа), вызываемый при изменении размера контейнера, в котором находится элемент, либо при добавлении элемента в контейнер. Может быть вызван до вызова on_hud_open. - `size-func` - поставщик размера элемента (два числа), вызываемый при изменении размера контейнера, в котором находится элемент, либо при добавлении элемента в контейнер. Может быть вызван до вызова on_hud_open. - `onclick` - lua функция вызываемая при нажатии на элемент. +- `onrightclick` - lua функция вызываемая при нажатии правой кнопки мыши на элемент. +- `onmiddleclick` - lua функция вызываемая при нажатии средней кнопки мыши на элемент. - `ondoubleclick` - lua функция вызываемая при двойном нажатии на элемент. - `onfocus` - lua функция вызываемая при фокусировке на элемент. - `ondefocus` - lua функция вызываемая при потере фокуса элеметом. diff --git a/res/modules/internal/gui_util.lua b/res/modules/internal/gui_util.lua index 656a0dfc8..971bad39f 100644 --- a/res/modules/internal/gui_util.lua +++ b/res/modules/internal/gui_util.lua @@ -192,13 +192,15 @@ function gui.ask(text, on_yes, on_no, yes_text, no_text) - + - ]], id, string.escape_xml(text)), {on_yes=yes_callback, on_no=no_callback}, - string.escape_xml(yes_text), string.escape_xml(no_text)) + ]], id, + string.escape_xml(text), + string.escape_xml(yes_text), + string.escape_xml(no_text)), {on_yes=yes_callback, on_no=no_callback}) input.add_callback("key:escape", no_callback, gui.root[id]) end diff --git a/src/graphics/ui/elements/ModelViewer.cpp b/src/graphics/ui/elements/ModelViewer.cpp index 727110f8b..748eabae5 100644 --- a/src/graphics/ui/elements/ModelViewer.cpp +++ b/src/graphics/ui/elements/ModelViewer.cpp @@ -13,6 +13,7 @@ #include "window/Window.hpp" #include "../GUI.hpp" +// TODO: remove // TODO: remove #include @@ -24,8 +25,7 @@ ModelViewer::ModelViewer( : Container(gui, size), modelName(modelName), camera(), - batch(std::make_unique(1024)), - fbo(std::make_unique(size.x, size.y)) { + batch(std::make_unique(1024)) { camera.perspective = true; camera.position = glm::vec3(2, 2, 2); } @@ -115,7 +115,13 @@ void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) { return; } auto& prevShader = Shader::getUsed(); - + + if (!fbo) { + if (size.x <= 0 || size.y <= 0) { + return; + } + fbo = std::make_unique(size.x, size.y); + } fbo->resize(size.x, size.y); { glDisable(GL_SCISSOR_TEST); @@ -154,6 +160,13 @@ void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) { Container::draw(pctx, assets); } +void ModelViewer::setVisible(bool flag) { + if (!flag && fbo) { + fbo.reset(); + } + Container::setVisible(flag); +} + void ModelViewer::setCenter(const glm::vec3& center) { this->center = center; } diff --git a/src/graphics/ui/elements/ModelViewer.hpp b/src/graphics/ui/elements/ModelViewer.hpp index 4e841faae..8cf999bb9 100644 --- a/src/graphics/ui/elements/ModelViewer.hpp +++ b/src/graphics/ui/elements/ModelViewer.hpp @@ -23,7 +23,6 @@ namespace gui { bool grabbing = false; public: ModelViewer(GUI& gui, const glm::vec2& size, const std::string& modelName); - ~ModelViewer(); void setModel(const std::string& modelName); @@ -34,6 +33,7 @@ namespace gui { void act(float delta) override; void draw(const DrawContext& pctx, const Assets& assets) override; + void setVisible(bool flag) override; void setRotation(const glm::vec3& euler); void setCenter(const glm::vec3& center); diff --git a/src/graphics/ui/elements/UINode.cpp b/src/graphics/ui/elements/UINode.cpp index 465ff26e4..85347b9a8 100644 --- a/src/graphics/ui/elements/UINode.cpp +++ b/src/graphics/ui/elements/UINode.cpp @@ -79,6 +79,8 @@ void UINode::click(int, int) { void UINode::clicked(Mousecode button) { if (button == Mousecode::BUTTON_2) { actions.notify(UIAction::RIGHT_CLICK, gui); + } else if (button == Mousecode::BUTTON_3) { + actions.notify(UIAction::MIDDLE_CLICK, gui); } } diff --git a/src/graphics/ui/elements/UINode.hpp b/src/graphics/ui/elements/UINode.hpp index fb699a737..a7b18390c 100644 --- a/src/graphics/ui/elements/UINode.hpp +++ b/src/graphics/ui/elements/UINode.hpp @@ -58,6 +58,7 @@ namespace gui { FOCUS, DEFOCUS, RIGHT_CLICK, + MIDDLE_CLICK, MOUSE_OVER, MOUSE_OUT, MOUSE_ENTER, diff --git a/src/graphics/ui/gui_xml.cpp b/src/graphics/ui/gui_xml.cpp index 3026f8215..41a603cea 100644 --- a/src/graphics/ui/gui_xml.cpp +++ b/src/graphics/ui/gui_xml.cpp @@ -181,6 +181,7 @@ static void read_uinode( register_action(node, reader, element, "onclick", UIAction::CLICK); register_action(node, reader, element, "onrightclick", UIAction::RIGHT_CLICK); + register_action(node, reader, element, "onmiddleclick", UIAction::MIDDLE_CLICK); register_action(node, reader, element, "onfocus", UIAction::FOCUS); register_action(node, reader, element, "ondefocus", UIAction::DEFOCUS); register_action(node, reader, element, "ondoubleclick", UIAction::DOUBLE_CLICK); diff --git a/src/logic/scripting/lua/libs/libgui.cpp b/src/logic/scripting/lua/libs/libgui.cpp index 057dc205e..81e5fc4f7 100644 --- a/src/logic/scripting/lua/libs/libgui.cpp +++ b/src/logic/scripting/lua/libs/libgui.cpp @@ -1127,6 +1127,7 @@ static int l_gui_load_document(lua::State* L) { } auto env = scripting::create_doc_environment(parentEnv, alias); + auto envId = *env; // namespace extension if (lua::istable(L, 4)) { if (lua::get_from(L, "table", "extend")) { @@ -1148,7 +1149,7 @@ static int l_gui_load_document(lua::State* L) { engine->requireAssets().store(std::move(documentPtr), alias); scripting::on_ui_open(*document, {args}); - return 0; + return lua::pushenv(L, envId); } static int l_set_syntax_styles(lua::State* L) {