diff --git a/res/layouts/inventory.xml b/res/layouts/inventory.xml index 00394085..6d2fc761 100644 --- a/res/layouts/inventory.xml +++ b/res/layouts/inventory.xml @@ -1,4 +1,4 @@ - + diff --git a/src/frontend/gui/gui_xml.cpp b/src/frontend/gui/gui_xml.cpp index 13065104..26aaf2e7 100644 --- a/src/frontend/gui/gui_xml.cpp +++ b/src/frontend/gui/gui_xml.cpp @@ -25,8 +25,8 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no if (element->has("id")) { node.setId(element->attr("id").getText()); } - if (element->has("coord")) { - node.setCoord(element->attr("coord").asVec2()); + if (element->has("pos")) { + node.setCoord(element->attr("pos").asVec2()); } if (element->has("size")) { node.setSize(element->attr("size").asVec2()); diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 4326d8cd..49898ecc 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -571,7 +571,7 @@ void Hud::draw(const GfxContext& ctx){ glm::vec2 invSize = inventoryView->getSize(); inventoryView->setCoord(glm::vec2( - glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x), + glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x), height/2-invSize.y/2 )); } diff --git a/src/logic/scripting/lua/libgui.cpp b/src/logic/scripting/lua/libgui.cpp index 083150f7..d8b8f960 100644 --- a/src/logic/scripting/lua/libgui.cpp +++ b/src/logic/scripting/lua/libgui.cpp @@ -71,7 +71,7 @@ int l_gui_getattr(lua_State* L) { if (attr == "color") { return lua::pushcolor_arr(L, node->getColor()); - } else if (attr == "coord") { + } else if (attr == "pos") { return lua::pushvec2_arr(L, node->getCoord()); } else if (attr == "size") { return lua::pushvec2_arr(L, node->getSize()); @@ -96,11 +96,15 @@ int l_gui_setattr(lua_State* L) { const std::string attr = lua_tostring(L, 3); auto node = getDocumentNode(L, docname, element); - - if (setattr(L, dynamic_cast(node), attr)) - return 0; - if (setattr(L, dynamic_cast(node), attr)) - return 0; - + if (attr == "pos") { + node->setCoord(lua::tovec2(L, 1)); + } else if (attr == "size") { + node->setSize(lua::tovec2(L, 1)); + } else { + if (setattr(L, dynamic_cast(node), attr)) + return 0; + if (setattr(L, dynamic_cast(node), attr)) + return 0; + } return 0; } diff --git a/src/logic/scripting/lua/lua_util.h b/src/logic/scripting/lua/lua_util.h index 95761bde..fa750fb9 100644 --- a/src/logic/scripting/lua/lua_util.h +++ b/src/logic/scripting/lua/lua_util.h @@ -85,6 +85,14 @@ namespace lua { lua_rawseti(L, -2, 4); return 1; } + + inline glm::vec2 tovec2(lua_State* L, int idx) { + lua_rawgeti(L, idx, 1); + lua::luanumber x = lua_tonumber(L, -1); lua_pop(L, -1); + lua_rawgeti(L, idx, 1); + lua::luanumber y = lua_tonumber(L, -1); lua_pop(L, -1); + return glm::vec2(x, y); + } } #endif // LOGIC_SCRIPTING_LUA_UTIL_H_