From bc86a3d8da4301ea6ce94c52715bd7cf863b0c37 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 6 Oct 2025 12:46:27 +0300 Subject: [PATCH 1/6] fix incorrect textbox horizontal scroll --- src/graphics/ui/elements/TextBox.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index a05ba5df8..81732348f 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -1211,13 +1211,12 @@ void TextBox::setCaret(size_t position) { } int lcaret = caret - rawTextCache.getTextLineOffset(line); int realoffset = - rawTextCache.metrics.calcWidth(labelText, lcaret) - static_cast(textOffset) + 2; + rawTextCache.metrics.calcWidth(labelText, 0, lcaret) - static_cast(textOffset) + 2; if (realoffset - width > 0) { setTextOffset(textOffset + realoffset - width); } else if (realoffset < 0) { - setTextOffset(std::max(textOffset + realoffset, static_cast(0)) - ); + setTextOffset(std::max(textOffset + realoffset, static_cast(0))); } } From 5626163f17a252212607dc63bfcd726df44bf290 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 6 Oct 2025 19:06:15 +0300 Subject: [PATCH 2/6] fix: wrong environment used in modules imported by require(...) --- res/scripts/stdmin.lua | 11 ++++++++--- src/logic/scripting/lua/lua_engine.cpp | 3 +++ src/logic/scripting/scripting.cpp | 10 ++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/res/scripts/stdmin.lua b/res/scripts/stdmin.lua index bbf3e7e68..f66c66447 100644 --- a/res/scripts/stdmin.lua +++ b/res/scripts/stdmin.lua @@ -558,8 +558,9 @@ local internal_locked = false -- Example `base:scripts/tests.lua` -- -- nocache - ignore cached script, load anyway -function __load_script(path, nocache) +local function __load_script(path, nocache, env) local packname, filename = parse_path(path) + print(packname, filename, env) if internal_locked and (packname == "res" or packname == "core") and filename:starts_with("modules/internal") then @@ -578,6 +579,9 @@ function __load_script(path, nocache) if script == nil then error(err) end + if env then + script = setfenv(script, env) + end local result = script() if not nocache then __cached_scripts[path] = script @@ -593,10 +597,11 @@ end function require(path) if not string.find(path, ':') then local prefix, _ = parse_path(_debug_getinfo(2).source) - return require(prefix..':'..path) + return require(prefix .. ':' .. path) end local prefix, file = parse_path(path) - return __load_script(prefix..":modules/"..file..".lua") + local env = __vc__pack_envs[prefix] + return __load_script(prefix .. ":modules/" .. file .. ".lua", nil, env) end function __scripts_cleanup() diff --git a/src/logic/scripting/lua/lua_engine.cpp b/src/logic/scripting/lua/lua_engine.cpp index 6ffa9057a..875d82eaa 100644 --- a/src/logic/scripting/lua/lua_engine.cpp +++ b/src/logic/scripting/lua/lua_engine.cpp @@ -104,6 +104,9 @@ void lua::init_state(State* L, StateType stateType) { pushnil(L); setglobal(L, "io"); + createtable(L, 0, 0); + setglobal(L, "__vc__pack_envs"); + const char* removed_os[] { "execute", "exit", "remove", "rename", "setlocale", "tmpname", nullptr}; remove_lib_funcs(L, "os", removed_os); diff --git a/src/logic/scripting/scripting.cpp b/src/logic/scripting/scripting.cpp index 57285945e..997b5f82c 100644 --- a/src/logic/scripting/scripting.cpp +++ b/src/logic/scripting/scripting.cpp @@ -181,7 +181,17 @@ std::unique_ptr scripting::start_coroutine(const io::path& script) { lua::setfield(L, "PACK_ENV"); lua::pushstring(L, pack.id); lua::setfield(L, "PACK_ID"); + + lua::dump_stack(L); + if(!lua::getglobal(L, "__vc__pack_envs")) { + lua::createtable(L, 0, 0); + lua::setglobal(L, "__vc__pack_envs"); + lua::pushvalue(L, -1); + } + lua::pushenv(L, id); + lua::setfield(L, pack.id); lua::pop(L); + return std::shared_ptr(new int(id), [=](int* id) { //-V508 lua::remove_environment(L, *id); delete id; From 4fa430b6ba4610f1a43b75e2060b68587e258a56 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 6 Oct 2025 19:30:19 +0300 Subject: [PATCH 3/6] cleanup --- res/scripts/stdmin.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/res/scripts/stdmin.lua b/res/scripts/stdmin.lua index f66c66447..26d5d813c 100644 --- a/res/scripts/stdmin.lua +++ b/res/scripts/stdmin.lua @@ -560,7 +560,6 @@ local internal_locked = false -- nocache - ignore cached script, load anyway local function __load_script(path, nocache, env) local packname, filename = parse_path(path) - print(packname, filename, env) if internal_locked and (packname == "res" or packname == "core") and filename:starts_with("modules/internal") then From 1d314ae3d938112a54d9c8fe8a4061cbd67e8ed5 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 6 Oct 2025 20:42:24 +0300 Subject: [PATCH 4/6] cleanup --- src/logic/scripting/scripting.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/logic/scripting/scripting.cpp b/src/logic/scripting/scripting.cpp index 997b5f82c..4d3672f15 100644 --- a/src/logic/scripting/scripting.cpp +++ b/src/logic/scripting/scripting.cpp @@ -182,7 +182,6 @@ std::unique_ptr scripting::start_coroutine(const io::path& script) { lua::pushstring(L, pack.id); lua::setfield(L, "PACK_ID"); - lua::dump_stack(L); if(!lua::getglobal(L, "__vc__pack_envs")) { lua::createtable(L, 0, 0); lua::setglobal(L, "__vc__pack_envs"); From 8a858beeb421495247a8dfae064672bcf6eb4190 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 6 Oct 2025 20:53:29 +0300 Subject: [PATCH 5/6] fix: some container attributes not available in panel --- res/layouts/pages/worlds.xml | 1 - src/graphics/ui/gui_xml.cpp | 60 +++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/res/layouts/pages/worlds.xml b/res/layouts/pages/worlds.xml index 137659307..a8a536a21 100644 --- a/res/layouts/pages/worlds.xml +++ b/res/layouts/pages/worlds.xml @@ -1,5 +1,4 @@ - diff --git a/src/graphics/ui/gui_xml.cpp b/src/graphics/ui/gui_xml.cpp index 930aef342..18d0fa4b0 100644 --- a/src/graphics/ui/gui_xml.cpp +++ b/src/graphics/ui/gui_xml.cpp @@ -8,19 +8,17 @@ #include "elements/Button.hpp" #include "elements/Canvas.hpp" #include "elements/CheckBox.hpp" -#include "elements/TextBox.hpp" -#include "elements/SplitBox.hpp" -#include "elements/TrackBar.hpp" -#include "elements/SelectBox.hpp" #include "elements/Image.hpp" #include "elements/InlineFrame.hpp" #include "elements/InputBindBox.hpp" #include "elements/InventoryView.hpp" #include "elements/Menu.hpp" +#include "elements/ModelViewer.hpp" #include "elements/Panel.hpp" +#include "elements/SelectBox.hpp" +#include "elements/SplitBox.hpp" #include "elements/TextBox.hpp" #include "elements/TrackBar.hpp" -#include "elements/ModelViewer.hpp" #include "engine/Engine.hpp" #include "frontend/locale.hpp" #include "frontend/menu.hpp" @@ -197,7 +195,10 @@ static void read_uinode( } static void read_container_impl( - UiXmlReader& reader, const xml::xmlelement& element, Container& container + UiXmlReader& reader, + const xml::xmlelement& element, + Container& container, + bool subnodes ) { read_uinode(reader, element, container); @@ -207,6 +208,9 @@ static void read_container_impl( if (element.has("scroll-step")) { container.setScrollStep(element.attr("scroll-step").asInt()); } + if (!subnodes) { + return; + } for (auto& sub : element.getElements()) { if (sub->isText()) continue; auto subnode = reader.readUINode(*sub); @@ -219,7 +223,7 @@ static void read_container_impl( void UiXmlReader::readUINode( UiXmlReader& reader, const xml::xmlelement& element, Container& container ) { - read_container_impl(reader, element, container); + read_container_impl(reader, element, container, true); } void UiXmlReader::readUINode( @@ -229,11 +233,9 @@ void UiXmlReader::readUINode( } static void read_base_panel_impl( - UiXmlReader& reader, - const xml::xmlelement& element, - BasePanel& panel + UiXmlReader& reader, const xml::xmlelement& element, BasePanel& panel ) { - read_uinode(reader, element, panel); + read_container_impl(reader, element, panel, false); if (element.has("padding")) { glm::vec4 padding = element.attr("padding").asVec4(); @@ -244,7 +246,7 @@ static void read_base_panel_impl( )); } if (element.has("orientation")) { - auto &oname = element.attr("orientation").getText(); + auto& oname = element.attr("orientation").getText(); if (oname == "horizontal") { panel.setOrientation(Orientation::horizontal); } @@ -348,7 +350,7 @@ static std::shared_ptr read_container( UiXmlReader& reader, const xml::xmlelement& element ) { auto container = std::make_shared(reader.getGUI(), glm::vec2()); - read_container_impl(reader, element, *container); + read_container_impl(reader, element, *container, true); return container; } @@ -365,8 +367,7 @@ static std::shared_ptr read_split_box( ); read_base_panel_impl(reader, element, *splitBox); for (auto& sub : element.getElements()) { - if (sub->isText()) - continue; + if (sub->isText()) continue; auto subnode = reader.readUINode(*sub); if (subnode) { splitBox->add(subnode); @@ -379,15 +380,15 @@ static std::shared_ptr read_model_viewer( UiXmlReader& reader, const xml::xmlelement& element ) { auto model = element.attr("src", "").getText(); - auto viewer = std::make_shared( - reader.getGUI(), glm::vec2(), model - ); - read_container_impl(reader, element, *viewer); + auto viewer = + std::make_shared(reader.getGUI(), glm::vec2(), model); + read_container_impl(reader, element, *viewer, true); if (element.has("center")) { viewer->setCenter(element.attr("center").asVec3()); } if (element.has("cam-rotation")) { - viewer->setRotation(glm::radians(element.attr("cam-rotation").asVec3())); + viewer->setRotation(glm::radians(element.attr("cam-rotation").asVec3()) + ); } return viewer; } @@ -450,7 +451,8 @@ static std::shared_ptr read_select( } auto value = elem->attr("value").getText(); auto text = parse_inner_text(*elem, reader.getContext()); - options.push_back(SelectBox::Option {std::move(value), std::move(text)}); + options.push_back(SelectBox::Option {std::move(value), std::move(text)} + ); } if (element.has("selected")) { @@ -485,10 +487,9 @@ static std::shared_ptr read_select( element.attr("onselect").getText(), reader.getFilename() ); - selectBox->listenChange( - [callback=std::move(callback)](GUI&, const std::string& value) { - callback(value); - }); + selectBox->listenChange([callback = std::move(callback)]( + GUI&, const std::string& value + ) { callback(value); }); } read_panel_impl(reader, element, *selectBox, false); return selectBox; @@ -539,7 +540,7 @@ static std::shared_ptr read_text_box( ); textbox->setHint(hint); - read_container_impl(reader, element, *textbox); + read_container_impl(reader, element, *textbox, true); if (element.has("padding")) { glm::vec4 padding = element.attr("padding").asVec4(); textbox->setPadding(padding); @@ -839,7 +840,7 @@ static std::shared_ptr read_page_box( auto& gui = reader.getGUI(); auto menu = std::make_shared(gui); menu->setPageLoader(gui.getMenu()->getPageLoader()); - read_container_impl(reader, element, *menu); + read_container_impl(reader, element, *menu, true); return menu; } @@ -849,14 +850,15 @@ static std::shared_ptr read_iframe( ) { auto& gui = reader.getGUI(); auto iframe = std::make_shared(gui); - read_container_impl(reader, element, *iframe); + read_container_impl(reader, element, *iframe, true); std::string src = element.attr("src", "").getText(); iframe->setSrc(src); return iframe; } -UiXmlReader::UiXmlReader(gui::GUI& gui, scriptenv&& env) : gui(gui), env(std::move(env)) { +UiXmlReader::UiXmlReader(gui::GUI& gui, scriptenv&& env) + : gui(gui), env(std::move(env)) { contextStack.emplace(""); add("image", read_image); add("canvas", read_canvas); From b4ba2da95524025991f07be87b61ecc015f12656 Mon Sep 17 00:00:00 2001 From: RomanDonw Date: Fri, 10 Oct 2025 20:59:01 +1000 Subject: [PATCH 6/6] generation.load_fragment fix --- src/logic/scripting/lua/libs/libgeneration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/scripting/lua/libs/libgeneration.cpp b/src/logic/scripting/lua/libs/libgeneration.cpp index ed406bf7b..681977e89 100644 --- a/src/logic/scripting/lua/libs/libgeneration.cpp +++ b/src/logic/scripting/lua/libs/libgeneration.cpp @@ -44,7 +44,7 @@ static int l_create_fragment(lua::State* L) { static int l_load_fragment(lua::State* L) { dv::value map; - if (!lua::isstring(L, 1)) { + if (lua::isstring(L, 1)) { io::path path = lua::require_string(L, 1); if (!io::exists(path)) { throw std::runtime_error("file "+path.string()+" does not exist");