test worlds panel with XML + lua
This commit is contained in:
@@ -58,13 +58,13 @@ void UiDocument::collect(uinodes_map& map, std::shared_ptr<gui::UINode> node) {
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<UiDocument> UiDocument::read(int penv, std::string namesp, fs::path file) {
|
||||
std::unique_ptr<UiDocument> UiDocument::read(int penv, std::string name, fs::path file) {
|
||||
const std::string text = files::read_string(file);
|
||||
auto xmldoc = xml::parse(file.u8string(), text);
|
||||
|
||||
auto env = penv == -1
|
||||
? std::make_unique<scripting::Environment>(0)
|
||||
: scripting::create_doc_environment(penv, namesp);
|
||||
: scripting::create_doc_environment(penv, name);
|
||||
|
||||
gui::UiXmlReader reader(*env);
|
||||
InventoryView::createReaders(reader);
|
||||
@@ -75,9 +75,9 @@ std::unique_ptr<UiDocument> UiDocument::read(int penv, std::string namesp, fs::p
|
||||
uidocscript script {};
|
||||
auto scriptFile = fs::path(file.u8string()+".lua");
|
||||
if (fs::is_regular_file(scriptFile)) {
|
||||
scripting::load_layout_script(env->getId(), namesp, scriptFile, script);
|
||||
scripting::load_layout_script(env->getId(), name, scriptFile, script);
|
||||
}
|
||||
return std::make_unique<UiDocument>(namesp, script, view, std::move(env));
|
||||
return std::make_unique<UiDocument>(name, script, view, std::move(env));
|
||||
}
|
||||
|
||||
std::shared_ptr<gui::UINode> UiDocument::readElement(fs::path file) {
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
/* Collect map of all uinodes having identifiers */
|
||||
static void collect(uinodes_map& map, std::shared_ptr<gui::UINode> node);
|
||||
|
||||
static std::unique_ptr<UiDocument> read(int env, std::string namesp, fs::path file);
|
||||
static std::unique_ptr<UiDocument> read(int env, std::string name, fs::path file);
|
||||
static std::shared_ptr<gui::UINode> readElement(fs::path file);
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "../../graphics/ui/elements/controls.h"
|
||||
#include "../screens.h"
|
||||
#include "../UiDocument.h"
|
||||
#include "../../logic/scripting/scripting.h"
|
||||
|
||||
#include "../../coders/png.h"
|
||||
#include "../../util/stringutil.h"
|
||||
@@ -289,19 +290,33 @@ void create_main_menu_panel(Engine* engine) {
|
||||
));
|
||||
}
|
||||
|
||||
static void add_page_loader(Engine* engine, const std::string& name) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
auto file = engine->getResPaths()->find("layouts/pages/"+name+".xml");
|
||||
auto fullname = "core:pages/"+name;
|
||||
menu->addSupplier(name, [=]() {
|
||||
auto document = UiDocument::read(0, fullname, file).release();
|
||||
engine->getAssets()->store(document, fullname);
|
||||
scripting::on_ui_open(document, nullptr, glm::ivec3());
|
||||
return document->getRoot();
|
||||
});
|
||||
}
|
||||
|
||||
void menus::create_menus(Engine* engine) {
|
||||
menus::generatorID = WorldGenerators::getDefaultGeneratorID();
|
||||
create_new_world_panel(engine);
|
||||
create_settings_panel(engine);
|
||||
create_languages_panel(engine);
|
||||
create_main_menu_panel(engine);
|
||||
//create_main_menu_panel(engine);
|
||||
create_world_generators_panel(engine);
|
||||
add_page_loader(engine, "main");
|
||||
load_page(engine, "404");
|
||||
}
|
||||
|
||||
void menus::refresh_menus(Engine* engine) {
|
||||
create_main_menu_panel(engine);
|
||||
//create_main_menu_panel(engine);
|
||||
create_new_world_panel(engine);
|
||||
create_world_generators_panel(engine);
|
||||
add_page_loader(engine, "main");
|
||||
load_page(engine, "404");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user