page 404 moved to xml document

This commit is contained in:
MihailRis 2024-03-20 11:41:02 +03:00
parent 8b8447e6e0
commit b836ec514a
4 changed files with 17 additions and 10 deletions

4
res/layouts/404.xml Normal file
View File

@ -0,0 +1,4 @@
<panel size='400' padding='8' interval='8' color='0'>
<label context='menu'>@Page does not exists</label>
<button padding='10' onclick='menu:back()'>@Back</button>
</panel>

View File

@ -62,8 +62,9 @@ std::unique_ptr<UiDocument> UiDocument::read(int penv, std::string namesp, fs::p
const std::string text = files::read_string(file);
auto xmldoc = xml::parse(file.u8string(), text);
auto env = scripting::create_doc_environment(penv, namesp);
gui::UiXmlReader reader(*env);
auto env = penv == -1 ? nullptr : scripting::create_doc_environment(penv, namesp);
scripting::Environment envview {penv == -1 ? 0 : env->getId()};
gui::UiXmlReader reader(envview);
InventoryView::createReaders(reader);
auto view = reader.readXML(
file.u8string(), xmldoc->getRoot()
@ -72,7 +73,12 @@ 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(envview.getId(), namesp, scriptFile, script);
}
return std::make_unique<UiDocument>(namesp, script, view, std::move(env));
return std::make_unique<UiDocument>(namesp, script, view, penv == -1 ? nullptr : std::move(env));
}
std::shared_ptr<gui::UINode> UiDocument::readElement(fs::path file) {
auto document = read(-1, file.filename().u8string(), file);
return document->getRoot();
}

View File

@ -48,6 +48,7 @@ public:
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::shared_ptr<gui::UINode> readElement(fs::path file);
};
#endif // FRONTEND_UI_DOCUMENT_H_

View File

@ -13,6 +13,7 @@
#include "../../graphics/ui/elements/containers.h"
#include "../../graphics/ui/elements/controls.h"
#include "../screens.h"
#include "../UiDocument.h"
#include "../../coders/png.h"
#include "../../util/stringutil.h"
@ -281,12 +282,7 @@ void create_main_menu_panel(Engine* engine) {
void create_404_page(Engine* engine) {
auto menu = engine->getGUI()->getMenu();
menu->addPage("404", guiutil::create(
"<panel size='400' padding='8' interval='8' color='0'>"
"<label context='menu'>@Page does not exists</label>"
"<button padding='10' onclick='menu:back()'>@Back</button>"
"</panel>"
));
menu->addPage("404", UiDocument::readElement(engine->getResPaths()->find("layouts/404.xml")));
}
void menus::create_menus(Engine* engine) {