ui: more xml support + hud.close function
This commit is contained in:
parent
e58624d3e8
commit
d8b3920d65
@ -40,6 +40,12 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
|||||||
if (element->has("z-index")) {
|
if (element->has("z-index")) {
|
||||||
node.setZIndex(element->attr("z-index").asInt());
|
node.setZIndex(element->attr("z-index").asInt());
|
||||||
}
|
}
|
||||||
|
if (element->has("interactive")) {
|
||||||
|
node.setInteractive(element->attr("interactive").asBool());
|
||||||
|
}
|
||||||
|
if (element->has("visible")) {
|
||||||
|
node.setVisible(element->attr("visible").asBool());
|
||||||
|
}
|
||||||
if (element->has("position-func")) {
|
if (element->has("position-func")) {
|
||||||
auto supplier = scripting::create_vec2_supplier(
|
auto supplier = scripting::create_vec2_supplier(
|
||||||
reader.getEnvironment().getId(),
|
reader.getEnvironment().getId(),
|
||||||
@ -202,6 +208,14 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
|
|||||||
);
|
);
|
||||||
bar->setConsumer(consumer);
|
bar->setConsumer(consumer);
|
||||||
}
|
}
|
||||||
|
if (element->has("supplier")) {
|
||||||
|
auto supplier = scripting::create_number_supplier(
|
||||||
|
reader.getEnvironment().getId(),
|
||||||
|
element->attr("supplier").getText(),
|
||||||
|
reader.getFilename()+".lua"
|
||||||
|
);
|
||||||
|
bar->setSupplier(supplier);
|
||||||
|
}
|
||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
#include "../../../logic/BlocksController.h"
|
#include "../../../logic/BlocksController.h"
|
||||||
#include "../../../items/Inventories.h"
|
#include "../../../items/Inventories.h"
|
||||||
#include "../../../engine.h"
|
#include "../../../engine.h"
|
||||||
|
#include "../../../frontend/UiDocument.h"
|
||||||
|
|
||||||
namespace scripting {
|
namespace scripting {
|
||||||
extern Hud* hud;
|
extern Hud* hud;
|
||||||
@ -64,13 +65,23 @@ int l_hud_open_block(lua_State* L) {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int l_hud_open_permanent(lua_State* L) {
|
UiDocument* require_layout(lua_State* L, const char* name) {
|
||||||
auto assets = scripting::engine->getAssets();
|
auto assets = scripting::engine->getAssets();
|
||||||
auto name = lua_tostring(L, 1);
|
|
||||||
auto layout = assets->getLayout(name);
|
auto layout = assets->getLayout(name);
|
||||||
if (layout == nullptr) {
|
if (layout == nullptr) {
|
||||||
luaL_error(L, "layout '%s' is not found", name);
|
luaL_error(L, "layout '%s' is not found", name);
|
||||||
}
|
}
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_hud_open_permanent(lua_State* L) {
|
||||||
|
auto layout = require_layout(L, lua_tostring(L, 1));
|
||||||
scripting::hud->openPermanent(layout);
|
scripting::hud->openPermanent(layout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_hud_close(lua_State* L) {
|
||||||
|
auto layout = require_layout(L, lua_tostring(L, 1));
|
||||||
|
scripting::hud->remove(layout->getRoot());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@ -7,12 +7,14 @@ extern int l_hud_open_inventory(lua_State* L);
|
|||||||
extern int l_hud_close_inventory(lua_State* L);
|
extern int l_hud_close_inventory(lua_State* L);
|
||||||
extern int l_hud_open_block(lua_State* L);
|
extern int l_hud_open_block(lua_State* L);
|
||||||
extern int l_hud_open_permanent(lua_State* L);
|
extern int l_hud_open_permanent(lua_State* L);
|
||||||
|
extern int l_hud_close(lua_State* L);
|
||||||
|
|
||||||
static const luaL_Reg hudlib [] = {
|
static const luaL_Reg hudlib [] = {
|
||||||
{"open_inventory", l_hud_open_inventory},
|
{"open_inventory", l_hud_open_inventory},
|
||||||
{"close_inventory", l_hud_close_inventory},
|
{"close_inventory", l_hud_close_inventory},
|
||||||
{"open_block", l_hud_open_block},
|
{"open_block", l_hud_open_block},
|
||||||
{"open_permanent", l_hud_open_permanent},
|
{"open_permanent", l_hud_open_permanent},
|
||||||
|
{"close", l_hud_close},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -60,6 +60,21 @@ doubleconsumer scripting::create_number_consumer(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doublesupplier scripting::create_number_supplier(
|
||||||
|
int env,
|
||||||
|
const std::string& src,
|
||||||
|
const std::string& file
|
||||||
|
) {
|
||||||
|
return [=](){
|
||||||
|
if (processCallback(env, src, file)) {
|
||||||
|
state->callNoThrow(0);
|
||||||
|
lua::luanumber x = state->tonumber(-1); state->pop();
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
return 0.0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
int_array_consumer scripting::create_int_array_consumer(
|
int_array_consumer scripting::create_int_array_consumer(
|
||||||
int env,
|
int env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
|
|||||||
@ -24,6 +24,12 @@ namespace scripting {
|
|||||||
const std::string& file="<string>"
|
const std::string& file="<string>"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
doublesupplier create_number_supplier(
|
||||||
|
int env,
|
||||||
|
const std::string& src,
|
||||||
|
const std::string& file="<string>"
|
||||||
|
);
|
||||||
|
|
||||||
int_array_consumer create_int_array_consumer(
|
int_array_consumer create_int_array_consumer(
|
||||||
int env,
|
int env,
|
||||||
const std::string& src,
|
const std::string& src,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user