core.delete_world and pages refreshing
This commit is contained in:
parent
c457bdb293
commit
06efdac106
@ -9,6 +9,13 @@ function on_open()
|
||||
"onclick='core.open_world(\""..name.."\")'"..
|
||||
">"..
|
||||
"<label pos='8,8'>"..name.."</label>"..
|
||||
"<button pos='330,3' "..
|
||||
"color='#00000000' "..
|
||||
"hover-color='#FFFFFF2B' "..
|
||||
"padding='2,2,2,2' "..
|
||||
"onclick='core.delete_world(\""..name.."\")'>"..
|
||||
"<image src='gui/delete_icon' size='32,32' color='#FFFFFF80'/>"..
|
||||
"</button>"..
|
||||
"</container>"
|
||||
)
|
||||
end
|
||||
|
||||
@ -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<ContentPack> scanned;
|
||||
|
||||
@ -267,20 +267,26 @@ void Menu::addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageS
|
||||
pageSuppliers[name] = pageSupplier;
|
||||
}
|
||||
|
||||
void Menu::setPage(std::string name, bool history) {
|
||||
std::shared_ptr<UINode> 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);
|
||||
}
|
||||
|
||||
|
||||
@ -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<UINode> panel);
|
||||
std::shared_ptr<UINode> fetchPage(std::string name);
|
||||
|
||||
/// @brief Add page supplier used if page is not found
|
||||
/// @param name page name
|
||||
|
||||
@ -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<l_get_worlds_list>},
|
||||
{"open_world", lua_wrap_errors<l_open_world>},
|
||||
{"delete_world", lua_wrap_errors<l_delete_world>},
|
||||
{"quit", lua_wrap_errors<l_quit>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user