menu page queries
This commit is contained in:
parent
7f8a86b740
commit
4dc2c4701d
@ -1,4 +1,7 @@
|
|||||||
function on_open()
|
function on_open(params)
|
||||||
|
if params then
|
||||||
|
mode = params.mode
|
||||||
|
end
|
||||||
refresh()
|
refresh()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -6,7 +9,8 @@ add_packs = {}
|
|||||||
rem_packs = {}
|
rem_packs = {}
|
||||||
|
|
||||||
function apply()
|
function apply()
|
||||||
if not core.reconfig_packs(add_packs, rem_packs) then
|
core.reconfig_packs(add_packs, rem_packs)
|
||||||
|
if mode ~= "world" then
|
||||||
menu:back()
|
menu:back()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<panel size='400' color='0' interval='1' context='menu'>
|
<panel size='400' color='0' interval='1' context='menu'>
|
||||||
<button onclick='menu:reset()'>@Continue</button>
|
<button onclick='menu:reset()'>@Continue</button>
|
||||||
<button onclick='menu.page="content"'>@Content</button>
|
<button onclick='menu.page="content?mode=world"'>@Content</button>
|
||||||
<button onclick='menu.page="settings"'>@Settings</button>
|
<button onclick='menu.page="settings"'>@Settings</button>
|
||||||
<button onclick='core.close_world(true)'>
|
<button onclick='core.close_world(true)'>
|
||||||
@Save and Quit to Menu
|
@Save and Quit to Menu
|
||||||
|
|||||||
@ -164,6 +164,14 @@ char BasicParser::peek() {
|
|||||||
return source[pos];
|
return source[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string BasicParser::readUntil(char c) {
|
||||||
|
int start = pos;
|
||||||
|
while (hasNext() && source[pos] != c) {
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
return source.substr(start, pos-start);
|
||||||
|
}
|
||||||
|
|
||||||
std::string BasicParser::parseName() {
|
std::string BasicParser::parseName() {
|
||||||
char c = peek();
|
char c = peek();
|
||||||
if (!is_identifier_start(c)) {
|
if (!is_identifier_start(c)) {
|
||||||
|
|||||||
@ -82,20 +82,23 @@ protected:
|
|||||||
bool skipTo(const std::string& substring);
|
bool skipTo(const std::string& substring);
|
||||||
void expect(char expected);
|
void expect(char expected);
|
||||||
void expect(const std::string& substring);
|
void expect(const std::string& substring);
|
||||||
char peek();
|
|
||||||
char nextChar();
|
|
||||||
bool hasNext();
|
|
||||||
bool isNext(const std::string& substring);
|
bool isNext(const std::string& substring);
|
||||||
void expectNewLine();
|
void expectNewLine();
|
||||||
void goBack();
|
void goBack();
|
||||||
|
|
||||||
std::string parseName();
|
|
||||||
int64_t parseSimpleInt(int base);
|
int64_t parseSimpleInt(int base);
|
||||||
bool parseNumber(int sign, number_u& out);
|
bool parseNumber(int sign, number_u& out);
|
||||||
std::string parseString(char chr, bool closeRequired=true);
|
std::string parseString(char chr, bool closeRequired=true);
|
||||||
|
|
||||||
parsing_error error(std::string message);
|
parsing_error error(std::string message);
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string readUntil(char c);
|
||||||
|
std::string parseName();
|
||||||
|
bool hasNext();
|
||||||
|
char peek();
|
||||||
|
char nextChar();
|
||||||
|
|
||||||
BasicParser(const std::string& file, const std::string& source);
|
BasicParser(const std::string& file, const std::string& source);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -386,3 +386,7 @@ std::unique_ptr<Value> Value::of(number_u value) {
|
|||||||
std::unique_ptr<Value> Value::of(const std::string& value) {
|
std::unique_ptr<Value> Value::of(const std::string& value) {
|
||||||
return std::make_unique<Value>(valtype::string, value);
|
return std::make_unique<Value>(valtype::string, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Value> Value::of(std::unique_ptr<Map> value) {
|
||||||
|
return std::make_unique<Value>(valtype::map, value.release());
|
||||||
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ namespace dynamic {
|
|||||||
static std::unique_ptr<Value> boolean(bool value);
|
static std::unique_ptr<Value> boolean(bool value);
|
||||||
static std::unique_ptr<Value> of(number_u value);
|
static std::unique_ptr<Value> of(number_u value);
|
||||||
static std::unique_ptr<Value> of(const std::string& value);
|
static std::unique_ptr<Value> of(const std::string& value);
|
||||||
|
static std::unique_ptr<Value> of(std::unique_ptr<Map> value);
|
||||||
};
|
};
|
||||||
|
|
||||||
class List {
|
class List {
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include "../graphics/ui/GUI.hpp"
|
#include "../graphics/ui/GUI.hpp"
|
||||||
#include "../logic/scripting/scripting.h"
|
#include "../logic/scripting/scripting.h"
|
||||||
#include "../settings.h"
|
#include "../settings.h"
|
||||||
|
#include "../coders/commons.h"
|
||||||
#include "../util/stringutil.h"
|
#include "../util/stringutil.h"
|
||||||
#include "../window/Window.hpp"
|
#include "../window/Window.hpp"
|
||||||
#include "locale/langs.h"
|
#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) {
|
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 file = engine->getResPaths()->find("layouts/pages/"+name+".xml");
|
||||||
auto fullname = "core:pages/"+name;
|
auto fullname = "core:pages/"+name;
|
||||||
|
|
||||||
auto document = UiDocument::read(scripting::get_root_environment(), fullname, file).release();
|
auto document = UiDocument::read(scripting::get_root_environment(), fullname, file).release();
|
||||||
engine->getAssets()->store(document, fullname);
|
engine->getAssets()->store(document, fullname);
|
||||||
scripting::on_ui_open(document, {});
|
|
||||||
|
scripting::on_ui_open(document, std::move(args));
|
||||||
return document->getRoot();
|
return document->getRoot();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,8 +91,7 @@ static int l_reconfig_packs(lua_State* L) {
|
|||||||
}
|
}
|
||||||
auto controller = scripting::engine->getController();
|
auto controller = scripting::engine->getController();
|
||||||
controller->reconfigPacks(scripting::controller, addPacks, remPacks);
|
controller->reconfigPacks(scripting::controller, addPacks, remPacks);
|
||||||
lua_pushboolean(L, scripting::controller != nullptr);
|
return 0;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_get_bindings(lua_State* L) {
|
static int l_get_bindings(lua_State* L) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user