#include "menu.hpp" #include #include #include "../delegates.h" #include "../engine.h" #include "../data/dynamic.h" #include "../interfaces/Task.hpp" #include "../files/engine_paths.h" #include "../graphics/ui/elements/Menu.hpp" #include "../graphics/ui/gui_util.hpp" #include "../graphics/ui/GUI.hpp" #include "../logic/scripting/scripting.h" #include "../settings.h" #include "../util/stringutil.h" #include "../window/Window.h" #include "locale/langs.h" #include "UiDocument.h" namespace fs = std::filesystem; using namespace gui; void menus::create_version_label(Engine* engine) { auto gui = engine->getGUI(); auto text = ENGINE_VERSION_STRING+" development build"; gui->add(guiutil::create( "" )); } void menus::create_menus(Engine* engine) { auto menu = engine->getGUI()->getMenu(); menu->setPageLoader([=](auto name) { auto file = engine->getResPaths()->find("layouts/pages/"+name+".xml"); auto fullname = "core:pages/"+name; auto document = UiDocument::read(scripting::get_root_environment(), fullname, file).release(); engine->getAssets()->store(document, fullname); scripting::on_ui_open(document, {}); return document->getRoot(); }); } UiDocument* menus::show(Engine* engine, const std::string& name, std::vector> args) { auto menu = engine->getGUI()->getMenu(); auto file = engine->getResPaths()->find("layouts/"+name+".xml"); auto fullname = "core:layouts/"+name; auto document = UiDocument::read(scripting::get_root_environment(), fullname, file).release(); engine->getAssets()->store(document, fullname); scripting::on_ui_open(document, std::move(args)); menu->addPage(name, document->getRoot()); menu->setPage(name); return document; } void menus::show_process_panel(Engine* engine, std::shared_ptr task, std::wstring text) { using namespace dynamic; uint initialWork = task->getWorkTotal(); auto menu = engine->getGUI()->getMenu(); menu->reset(); std::vector> args; args.emplace_back(Value::of(util::wstr2str_utf8(langs::get(text)))); auto doc = menus::show(engine, "process", std::move(args)); std::dynamic_pointer_cast(doc->getRoot())->listenInterval(0.01f, [=]() { task->update(); uint tasksDone = task->getWorkDone(); scripting::on_ui_progress(doc, tasksDone, initialWork); }); }