menu page queries
This commit is contained in:
+27
-2
@@ -13,6 +13,7 @@
|
||||
#include "../graphics/ui/GUI.hpp"
|
||||
#include "../logic/scripting/scripting.h"
|
||||
#include "../settings.h"
|
||||
#include "../coders/commons.h"
|
||||
#include "../util/stringutil.h"
|
||||
#include "../window/Window.hpp"
|
||||
#include "locale/langs.h"
|
||||
@@ -32,13 +33,37 @@ void menus::create_version_label(Engine* engine) {
|
||||
}
|
||||
|
||||
gui::page_loader_func menus::create_page_loader(Engine* engine) {
|
||||
return [=](auto name) {
|
||||
return [=](const std::string& query) {
|
||||
using namespace dynamic;
|
||||
|
||||
std::vector<std::unique_ptr<Value>> args;
|
||||
|
||||
std::string name;
|
||||
size_t index = query.find('?');
|
||||
if (index != std::string::npos) {
|
||||
auto argstr = query.substr(index+1);
|
||||
name = query.substr(0, index);
|
||||
|
||||
auto map = std::make_unique<Map>();
|
||||
BasicParser parser("query for "+name, argstr);
|
||||
while (parser.hasNext()) {
|
||||
auto key = parser.readUntil('=');
|
||||
parser.nextChar();
|
||||
auto value = parser.readUntil('&');
|
||||
map->put(key, value);
|
||||
}
|
||||
args.push_back(Value::of(std::move(map)));
|
||||
} else {
|
||||
name = query;
|
||||
}
|
||||
|
||||
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, {});
|
||||
|
||||
scripting::on_ui_open(document, std::move(args));
|
||||
return document->getRoot();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user