ui scripting related fixes
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
using runnable = std::function<void()>;
|
using runnable = std::function<void()>;
|
||||||
using stringconsumer = std::function<void(const std::string&)>;
|
using stringconsumer = std::function<void(const std::string&)>;
|
||||||
|
using wstringsupplier = std::function<std::wstring()>;
|
||||||
using wstringconsumer = std::function<void(const std::wstring&)>;
|
using wstringconsumer = std::function<void(const std::wstring&)>;
|
||||||
|
|
||||||
#endif // DELEGATES_H_
|
#endif // DELEGATES_H_
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ std::unique_ptr<UiDocument> UiDocument::read(AssetsLoader& loader, int penv, std
|
|||||||
const std::string text = files::read_string(file);
|
const std::string text = files::read_string(file);
|
||||||
auto xmldoc = xml::parse(file.u8string(), text);
|
auto xmldoc = xml::parse(file.u8string(), text);
|
||||||
|
|
||||||
auto env = scripting::create_environment(penv);
|
auto env = scripting::create_doc_environment(penv, namesp);
|
||||||
gui::UiXmlReader reader(*env, loader);
|
gui::UiXmlReader reader(*env, loader);
|
||||||
InventoryView::createReaders(reader);
|
InventoryView::createReaders(reader);
|
||||||
auto view = reader.readXML(
|
auto view = reader.readXML(
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ class Batch2D;
|
|||||||
class Assets;
|
class Assets;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
using wstringsupplier = std::function<std::wstring()>;
|
|
||||||
using wstringconsumer = std::function<void(std::wstring)>;
|
|
||||||
|
|
||||||
using doublesupplier = std::function<double()>;
|
using doublesupplier = std::function<double()>;
|
||||||
using doubleconsumer = std::function<void(double)>;
|
using doubleconsumer = std::function<void(double)>;
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ static std::shared_ptr<UINode> readButton(UiXmlReader& reader, xml::xmlelement e
|
|||||||
auto callback = scripting::create_runnable(
|
auto callback = scripting::create_runnable(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment().getId(),
|
||||||
element->attr("onclick").getText(),
|
element->attr("onclick").getText(),
|
||||||
"<onclick>"
|
reader.getFilename()+".lua"
|
||||||
);
|
);
|
||||||
button->listenAction([callback](GUI*) {
|
button->listenAction([callback](GUI*) {
|
||||||
callback();
|
callback();
|
||||||
@@ -156,7 +156,7 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
|
|||||||
auto consumer = scripting::create_wstring_consumer(
|
auto consumer = scripting::create_wstring_consumer(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment().getId(),
|
||||||
element->attr("consumer").getText(),
|
element->attr("consumer").getText(),
|
||||||
reader.getFilename()
|
reader.getFilename()+"lua"
|
||||||
);
|
);
|
||||||
textbox->textConsumer(consumer);
|
textbox->textConsumer(consumer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include "LevelFrontend.h"
|
#include "LevelFrontend.h"
|
||||||
#include "UiDocument.h"
|
#include "UiDocument.h"
|
||||||
#include "../engine.h"
|
#include "../engine.h"
|
||||||
|
#include "../delegates.h"
|
||||||
#include "../core_defs.h"
|
#include "../core_defs.h"
|
||||||
#include "../items/ItemDef.h"
|
#include "../items/ItemDef.h"
|
||||||
#include "../items/Inventory.h"
|
#include "../items/Inventory.h"
|
||||||
@@ -53,7 +54,7 @@ using glm::vec3;
|
|||||||
using glm::vec4;
|
using glm::vec4;
|
||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
static std::shared_ptr<Label> create_label(gui::wstringsupplier supplier) {
|
static std::shared_ptr<Label> create_label(wstringsupplier supplier) {
|
||||||
auto label = std::make_shared<Label>(L"-");
|
auto label = std::make_shared<Label>(L"-");
|
||||||
label->textSupplier(supplier);
|
label->textSupplier(supplier);
|
||||||
return label;
|
return label;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "../window/Window.h"
|
#include "../window/Window.h"
|
||||||
#include "../engine.h"
|
#include "../engine.h"
|
||||||
#include "../settings.h"
|
#include "../settings.h"
|
||||||
|
#include "../delegates.h"
|
||||||
#include "../content/Content.h"
|
#include "../content/Content.h"
|
||||||
#include "../content/ContentLUT.h"
|
#include "../content/ContentLUT.h"
|
||||||
#include "../content/ContentPack.h"
|
#include "../content/ContentPack.h"
|
||||||
@@ -46,7 +47,7 @@ inline uint64_t randU64() {
|
|||||||
((uint64_t)rand() << 56);
|
((uint64_t)rand() << 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::shared_ptr<Label> create_label(gui::wstringsupplier supplier) {
|
static std::shared_ptr<Label> create_label(wstringsupplier supplier) {
|
||||||
auto label = std::make_shared<Label>(L"-");
|
auto label = std::make_shared<Label>(L"-");
|
||||||
label->textSupplier(supplier);
|
label->textSupplier(supplier);
|
||||||
return label;
|
return label;
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ wstringconsumer scripting::create_wstring_consumer(
|
|||||||
const std::string& src,
|
const std::string& src,
|
||||||
const std::string& file
|
const std::string& file
|
||||||
) {
|
) {
|
||||||
auto funcName = state->storeAnonymous();
|
|
||||||
return [=](const std::wstring& x){
|
return [=](const std::wstring& x){
|
||||||
try {
|
try {
|
||||||
if (state->eval(env, src, file) == 0)
|
if (state->eval(env, src, file) == 0)
|
||||||
@@ -119,6 +118,18 @@ std::unique_ptr<Environment> scripting::create_pack_environment(const ContentPac
|
|||||||
state->setfield("PACK_ENV");
|
state->setfield("PACK_ENV");
|
||||||
state->pushstring(pack.id);
|
state->pushstring(pack.id);
|
||||||
state->setfield("PACK_ID");
|
state->setfield("PACK_ID");
|
||||||
|
state->pop();
|
||||||
|
return std::make_unique<Environment>(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Environment> scripting::create_doc_environment(int parent, const std::string& name) {
|
||||||
|
int id = state->createEnvironment(parent);
|
||||||
|
state->pushenv(id);
|
||||||
|
state->pushvalue(-1);
|
||||||
|
state->setfield("DOC_ENV");
|
||||||
|
state->pushstring(name.c_str());
|
||||||
|
state->setfield("DOC_NAME");
|
||||||
|
state->pop();
|
||||||
return std::make_unique<Environment>(id);
|
return std::make_unique<Environment>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace scripting {
|
|||||||
|
|
||||||
std::unique_ptr<Environment> create_environment(int parent=0);
|
std::unique_ptr<Environment> create_environment(int parent=0);
|
||||||
std::unique_ptr<Environment> create_pack_environment(const ContentPack& pack);
|
std::unique_ptr<Environment> create_pack_environment(const ContentPack& pack);
|
||||||
|
std::unique_ptr<Environment> create_doc_environment(int parent, const std::string& name);
|
||||||
|
|
||||||
void on_world_load(Level* level, BlocksController* blocks);
|
void on_world_load(Level* level, BlocksController* blocks);
|
||||||
void on_world_save();
|
void on_world_save();
|
||||||
|
|||||||
Reference in New Issue
Block a user