diff --git a/res/layouts/pages/main.xml.lua b/res/layouts/pages/main.xml.lua index f6ec94f6..43436e95 100644 --- a/res/layouts/pages/main.xml.lua +++ b/res/layouts/pages/main.xml.lua @@ -9,6 +9,13 @@ function on_open() "onclick='core.open_world(\""..name.."\")'".. ">".. "".. + "".. "" ) end diff --git a/src/frontend/menu/menu_pause.cpp b/src/frontend/menu/menu_pause.cpp index d0b958fc..3cfd4137 100644 --- a/src/frontend/menu/menu_pause.cpp +++ b/src/frontend/menu/menu_pause.cpp @@ -106,7 +106,6 @@ static void reopen_world(Engine* engine, World* world) { // FIXME static bool try_add_dependency(Engine* engine, World* world, const ContentPack& pack, std::string& missing) { auto paths = engine->getPaths(); - auto gui = engine->getGUI(); for (const auto& dependency : pack.dependencies) { fs::path folder = ContentPack::findPack( paths, @@ -128,7 +127,6 @@ static bool try_add_dependency(Engine* engine, World* world, const ContentPack& void create_content_panel(Engine* engine, LevelController* controller) { auto level = controller->getLevel(); auto menu = engine->getGUI()->getMenu(); - auto paths = engine->getPaths(); auto mainPanel = menus::create_page(engine, "content", 550, 0.0f, 5); std::vector scanned; diff --git a/src/graphics/ui/elements/containers.cpp b/src/graphics/ui/elements/containers.cpp index 0c31cb84..74d60aa8 100644 --- a/src/graphics/ui/elements/containers.cpp +++ b/src/graphics/ui/elements/containers.cpp @@ -267,20 +267,26 @@ void Menu::addSupplier(std::string name, supplier> pageS pageSuppliers[name] = pageSupplier; } -void Menu::setPage(std::string name, bool history) { +std::shared_ptr Menu::fetchPage(std::string name) { auto found = pages.find(name); - Page page {name, nullptr}; if (found == pages.end()) { auto supplier = pageSuppliers.find(name); if (supplier == pageSuppliers.end()) { - throw std::runtime_error("no page found"); + return nullptr; } else { - page.panel = supplier->second(); - // pages[name] = page; + return supplier->second(); // supplied pages caching is not implemented } } else { - page = found->second; + return found->second.panel; + } +} + + +void Menu::setPage(std::string name, bool history) { + Page page {name, fetchPage(name)}; + if (page.panel == nullptr) { + throw std::runtime_error("no page found"); } setPage(page, history); } @@ -302,6 +308,12 @@ void Menu::back() { return; Page page = pageStack.top(); pageStack.pop(); + + auto updated = fetchPage(page.name); + if (updated) { + page.panel = updated; + } + setPage(page, false); } diff --git a/src/graphics/ui/elements/containers.h b/src/graphics/ui/elements/containers.h index cb332cf6..b70f96a1 100644 --- a/src/graphics/ui/elements/containers.h +++ b/src/graphics/ui/elements/containers.h @@ -113,6 +113,7 @@ namespace gui { void setPage(std::string name, bool history=true); void setPage(Page page, bool history=true); void addPage(std::string name, std::shared_ptr panel); + std::shared_ptr fetchPage(std::string name); /// @brief Add page supplier used if page is not found /// @param name page name diff --git a/src/logic/scripting/lua/libcore.cpp b/src/logic/scripting/lua/libcore.cpp index e9d33662..d9383a71 100644 --- a/src/logic/scripting/lua/libcore.cpp +++ b/src/logic/scripting/lua/libcore.cpp @@ -28,6 +28,12 @@ static int l_open_world(lua_State* L) { return 0; } +static int l_delete_world(lua_State* L) { + auto name = lua_tostring(L, 1); + menus::delete_world(name, scripting::engine); + return 0; +} + static int l_quit(lua_State* L) { Window::setShouldClose(true); return 0; @@ -36,6 +42,7 @@ static int l_quit(lua_State* L) { const luaL_Reg corelib [] = { {"get_worlds_list", lua_wrap_errors}, {"open_world", lua_wrap_errors}, + {"delete_world", lua_wrap_errors}, {"quit", lua_wrap_errors}, {NULL, NULL} };