diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 4750f808..4326d8cd 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -441,7 +441,16 @@ void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptrgetRoot()); + auto root = doc->getRoot(); + remove(root); + + auto invview = std::dynamic_pointer_cast(root); + if (invview) { + auto level = frontend->getLevel(); + auto player = level->player; + auto inventory = player->getInventory(); + invview->bind(inventory, frontend, interaction.get()); + } add(HudElement(hud_element_mode::permanent, doc, doc->getRoot(), false)); } diff --git a/src/logic/scripting/lua/libhud.cpp b/src/logic/scripting/lua/libhud.cpp index 773a96f6..f709ed90 100644 --- a/src/logic/scripting/lua/libhud.cpp +++ b/src/logic/scripting/lua/libhud.cpp @@ -23,12 +23,16 @@ namespace scripting { } int l_hud_open_inventory(lua_State* L) { - scripting::hud->openInventory(); + if (!scripting::hud->isInventoryOpen()) { + scripting::hud->openInventory(); + } return 0; } int l_hud_close_inventory(lua_State* L) { - scripting::hud->closeInventory(); + if (scripting::hud->isInventoryOpen()) { + scripting::hud->closeInventory(); + } return 0; } @@ -77,10 +81,6 @@ UiDocument* require_layout(lua_State* L, const char* name) { int l_hud_open_permanent(lua_State* L) { auto layout = require_layout(L, lua_tostring(L, 1)); - auto invview = std::dynamic_pointer_cast(layout->getRoot()); - if (invview) { - luaL_error(L, "layout must not contain 'inventory' element"); - } scripting::hud->openPermanent(layout); return 0; }