mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 15:01:49 +00:00
add 'fallback' property to xml and scripting
This commit is contained in:
parent
18e7fb55a6
commit
6aac90094e
5 changed files with 19 additions and 4 deletions
|
|
@ -11,5 +11,5 @@
|
||||||
<label ifnot='%{error}' pos='80,28' size='355,50' multiline='true' color='#FFFFFFB2'>
|
<label ifnot='%{error}' pos='80,28' size='355,50' multiline='true' color='#FFFFFFB2'>
|
||||||
%{description}
|
%{description}
|
||||||
</label>
|
</label>
|
||||||
<image pos='8,8' src='%{icon}' size='64'/>
|
<image pos='8,8' src='%{icon}' fallback='gui/no_icon' size='64'/>
|
||||||
</container>
|
</container>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
hover-color='#162B3399'
|
hover-color='#162B3399'
|
||||||
onclick='app.open_world("%{name}")'
|
onclick='app.open_world("%{name}")'
|
||||||
>
|
>
|
||||||
<image pos='1' src='%{icon}' size='96,64'></image>
|
<image pos='1' src='%{icon}' fallback='gui/no_world_icon' size='96,64'></image>
|
||||||
<label pos='104,8'>%{name}</label>
|
<label pos='104,8'>%{name}</label>
|
||||||
<button margin='4'
|
<button margin='4'
|
||||||
gravity='center-right'
|
gravity='center-right'
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ namespace gui {
|
||||||
std::string fallback;
|
std::string fallback;
|
||||||
UVRegion region {};
|
UVRegion region {};
|
||||||
bool autoresize = false;
|
bool autoresize = false;
|
||||||
bool isFallback = false;
|
|
||||||
|
|
||||||
util::TextureRegion refreshTexture(const Assets& assets);
|
util::TextureRegion refreshTexture(const Assets& assets);
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -632,8 +632,10 @@ static std::shared_ptr<UINode> read_image(
|
||||||
const UiXmlReader& reader, const xml::xmlelement& element
|
const UiXmlReader& reader, const xml::xmlelement& element
|
||||||
) {
|
) {
|
||||||
std::string src = element.attr("src", "").getText();
|
std::string src = element.attr("src", "").getText();
|
||||||
auto image = std::make_shared<Image>(reader.getGUI(), src);
|
std::string fallback = element.attr("fallback", "").getText();
|
||||||
|
auto image = std::make_shared<Image>(reader.getGUI(), std::move(src));
|
||||||
read_uinode(reader, element, *image);
|
read_uinode(reader, element, *image);
|
||||||
|
image->setFallback(std::move(fallback));
|
||||||
|
|
||||||
if (element.has("region")) {
|
if (element.has("region")) {
|
||||||
auto vec = element.attr("region").asVec4();
|
auto vec = element.attr("region").asVec4();
|
||||||
|
|
|
||||||
|
|
@ -397,6 +397,13 @@ static int p_get_src(UINode* node, lua::State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int p_get_fallback(UINode* node, lua::State* L) {
|
||||||
|
if (auto image = dynamic_cast<Image*>(node)) {
|
||||||
|
return lua::pushstring(L, image->getFallback());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int p_get_region(UINode* node, lua::State* L) {
|
static int p_get_region(UINode* node, lua::State* L) {
|
||||||
if (auto image = dynamic_cast<Image*>(node)) {
|
if (auto image = dynamic_cast<Image*>(node)) {
|
||||||
const auto& region = image->getRegion();
|
const auto& region = image->getRegion();
|
||||||
|
|
@ -663,6 +670,7 @@ static int l_gui_getattr(lua::State* L) {
|
||||||
{"syntax", p_get_syntax},
|
{"syntax", p_get_syntax},
|
||||||
{"markup", p_get_markup},
|
{"markup", p_get_markup},
|
||||||
{"src", p_get_src},
|
{"src", p_get_src},
|
||||||
|
{"fallback", p_get_fallback},
|
||||||
{"value", p_get_value},
|
{"value", p_get_value},
|
||||||
{"min", p_get_min},
|
{"min", p_get_min},
|
||||||
{"max", p_get_max},
|
{"max", p_get_max},
|
||||||
|
|
@ -790,6 +798,11 @@ static void p_set_src(UINode* node, lua::State* L, int idx) {
|
||||||
modelviewer->setModel(lua::require_string(L, idx));
|
modelviewer->setModel(lua::require_string(L, idx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void p_set_fallback(UINode* node, lua::State* L, int idx) {
|
||||||
|
if (auto image = dynamic_cast<Image*>(node)) {
|
||||||
|
image->setFallback(lua::require_string(L, idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
static void p_set_region(UINode* node, lua::State* L, int idx) {
|
static void p_set_region(UINode* node, lua::State* L, int idx) {
|
||||||
if (auto image = dynamic_cast<Image*>(node)) {
|
if (auto image = dynamic_cast<Image*>(node)) {
|
||||||
auto vec = lua::tovec4(L, idx);
|
auto vec = lua::tovec4(L, idx);
|
||||||
|
|
@ -962,6 +975,7 @@ static int l_gui_setattr(lua::State* L) {
|
||||||
{"syntax", p_set_syntax},
|
{"syntax", p_set_syntax},
|
||||||
{"markup", p_set_markup},
|
{"markup", p_set_markup},
|
||||||
{"src", p_set_src},
|
{"src", p_set_src},
|
||||||
|
{"fallback", p_set_fallback},
|
||||||
{"caret", p_set_caret},
|
{"caret", p_set_caret},
|
||||||
{"value", p_set_value},
|
{"value", p_set_value},
|
||||||
{"min", p_set_min},
|
{"min", p_set_min},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue