diff --git a/res/layouts/pages/main.xml.lua b/res/layouts/pages/main.xml.lua
new file mode 100644
index 00000000..f6ec94f6
--- /dev/null
+++ b/res/layouts/pages/main.xml.lua
@@ -0,0 +1,15 @@
+function on_open()
+ local worlds = core.get_worlds_list()
+ for _, name in ipairs(worlds) do
+ document.worlds:add(
+ ""..
+ ""..
+ ""
+ )
+ end
+end
diff --git a/src/frontend/UiDocument.cpp b/src/frontend/UiDocument.cpp
index 0d78e64a..d68ff06c 100644
--- a/src/frontend/UiDocument.cpp
+++ b/src/frontend/UiDocument.cpp
@@ -58,13 +58,13 @@ void UiDocument::collect(uinodes_map& map, std::shared_ptr node) {
}
}
-std::unique_ptr UiDocument::read(int penv, std::string namesp, fs::path file) {
+std::unique_ptr 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(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::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(namesp, script, view, std::move(env));
+ return std::make_unique(name, script, view, std::move(env));
}
std::shared_ptr UiDocument::readElement(fs::path file) {
diff --git a/src/frontend/UiDocument.h b/src/frontend/UiDocument.h
index 943008cf..8583f34d 100644
--- a/src/frontend/UiDocument.h
+++ b/src/frontend/UiDocument.h
@@ -47,7 +47,7 @@ public:
/* Collect map of all uinodes having identifiers */
static void collect(uinodes_map& map, std::shared_ptr node);
- static std::unique_ptr read(int env, std::string namesp, fs::path file);
+ static std::unique_ptr read(int env, std::string name, fs::path file);
static std::shared_ptr readElement(fs::path file);
};
diff --git a/src/frontend/menu/menu.cpp b/src/frontend/menu/menu.cpp
index a4e86034..9ad58c13 100644
--- a/src/frontend/menu/menu.cpp
+++ b/src/frontend/menu/menu.cpp
@@ -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");
}
diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp
index 7bb4c75c..1e09c817 100644
--- a/src/graphics/ui/GUI.cpp
+++ b/src/graphics/ui/GUI.cpp
@@ -81,6 +81,28 @@ void GUI::actMouse(float delta) {
}
}
+void GUI::actFocused() {
+ if (Events::jpressed(keycode::ESCAPE)) {
+ focus->defocus();
+ focus = nullptr;
+ return;
+ }
+ for (auto codepoint : Events::codepoints) {
+ focus->typed(codepoint);
+ }
+ for (auto key : Events::pressedKeys) {
+ focus->keyPressed(key);
+ }
+
+ if (!Events::_cursor_locked) {
+ if (Events::clicked(mousecode::BUTTON_1) &&
+ (Events::jclicked(mousecode::BUTTON_1) || Events::delta.x || Events::delta.y))
+ {
+ focus->mouseMove(this, Events::cursor.x, Events::cursor.y);
+ }
+ }
+}
+
/// @brief Processing user input and UI logic
/// @param delta delta time
void GUI::act(float delta) {
@@ -99,27 +121,7 @@ void GUI::act(float delta) {
}
if (focus) {
- if (Events::jpressed(keycode::ESCAPE)) {
- focus->defocus();
- focus = nullptr;
- } else {
- for (auto codepoint : Events::codepoints) {
- focus->typed(codepoint);
- }
- for (auto key : Events::pressedKeys) {
- focus->keyPressed(key);
- }
-
- if (!Events::_cursor_locked) {
- if (Events::clicked(mousecode::BUTTON_1)) {
- if (Events::jclicked(mousecode::BUTTON_1) ||
- Events::delta.x || Events::delta.y)
- {
- focus->mouseMove(this, Events::cursor.x, Events::cursor.y);
- }
- }
- }
- }
+ actFocused();
}
if (focus && !focus->isFocused()) {
focus = nullptr;
diff --git a/src/graphics/ui/GUI.h b/src/graphics/ui/GUI.h
index 9aeda7c6..2bfd9e6a 100644
--- a/src/graphics/ui/GUI.h
+++ b/src/graphics/ui/GUI.h
@@ -63,6 +63,7 @@ namespace gui {
std::shared_ptr