mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
xml and lua support
This commit is contained in:
parent
a0e1d4acfe
commit
d04fb4f886
2 changed files with 129 additions and 0 deletions
|
|
@ -15,6 +15,7 @@
|
|||
#include "elements/Menu.hpp"
|
||||
#include "elements/ModelViewer.hpp"
|
||||
#include "elements/Panel.hpp"
|
||||
#include "elements/ProgressBar.hpp"
|
||||
#include "elements/SelectBox.hpp"
|
||||
#include "elements/SplitBox.hpp"
|
||||
#include "elements/TextBox.hpp"
|
||||
|
|
@ -716,6 +717,47 @@ static std::shared_ptr<UINode> read_track_bar(
|
|||
return bar;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> read_progress_bar(
|
||||
const UiXmlReader& reader,
|
||||
const xml::xmlelement& element
|
||||
) {
|
||||
const auto& env = reader.getEnvironment();
|
||||
const auto& file = reader.getFilename();
|
||||
double minv = element.attr("min", "0.0").asFloat();
|
||||
double maxv = element.attr("max", "100.0").asFloat();
|
||||
double def = element.attr("value", "0.0").asFloat();
|
||||
int thickness = element.attr("bar-thickness", "-1").asInt();
|
||||
auto bar = std::make_shared<ProgressBar>(
|
||||
reader.getGUI(), minv, maxv, def, thickness
|
||||
);
|
||||
read_uinode(reader, element, *bar);
|
||||
if (element.has("supplier")) {
|
||||
bar->setSupplier(scripting::create_number_supplier(env, element.attr("supplier").getText(), file));
|
||||
}
|
||||
if (element.has("bar-color")) {
|
||||
bar->setBarColor(element.attr("bar-color").asColor());
|
||||
}
|
||||
if (element.has("bg-color")) {
|
||||
bar->setBgColor(element.attr("bg-color").asColor());
|
||||
}
|
||||
if (element.has("text-format")) {
|
||||
bar->setTextFormat(element.attr("text-format").getText());
|
||||
}
|
||||
if (element.has("text-color")) {
|
||||
bar->setTextColor(element.attr("text-color").asColor());
|
||||
}
|
||||
if (element.has("smooth")) {
|
||||
bar->setSmooth(element.attr("smooth").asBool());
|
||||
}
|
||||
if (element.has("orientation")) {
|
||||
auto& oname = element.attr("orientation").getText();
|
||||
if (oname == "vertical") {
|
||||
bar->setOrientation(Orientation::VERTICAL);
|
||||
}
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> read_input_bind_box(
|
||||
UiXmlReader& reader, const xml::xmlelement& element
|
||||
) {
|
||||
|
|
@ -901,6 +943,7 @@ UiXmlReader::UiXmlReader(gui::GUI& gui, const scriptenv& env)
|
|||
add("select", read_select);
|
||||
add("textbox", read_text_box);
|
||||
add("pagebox", read_page_box);
|
||||
add("progressbar", read_progress_bar);
|
||||
add("splitbox", read_split_box);
|
||||
add("checkbox", read_check_box);
|
||||
add("trackbar", read_track_bar);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "graphics/ui/elements/InventoryView.hpp"
|
||||
#include "graphics/ui/elements/Menu.hpp"
|
||||
#include "graphics/ui/elements/Panel.hpp"
|
||||
#include "graphics/ui/elements/ProgressBar.hpp"
|
||||
#include "graphics/ui/elements/TextBox.hpp"
|
||||
#include "graphics/ui/elements/TrackBar.hpp"
|
||||
#include "graphics/ui/elements/InlineFrame.hpp"
|
||||
|
|
@ -263,15 +264,54 @@ static int p_is_checked(UINode* node, lua::State* L) {
|
|||
static int p_get_value(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getValue());
|
||||
} else if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getValue());
|
||||
} else if (auto box = dynamic_cast<SelectBox*>(node)) {
|
||||
return lua::pushstring(L, box->getSelected().value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_progress(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getProgress());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_bar_color(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
return lua::pushcolor(L, bar->getBarColor());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_bg_color(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
return lua::pushcolor(L, bar->getBgColor());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_text_format(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
return lua::pushstring(L, bar->getTextFormat());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_is_smooth(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
return lua::pushboolean(L, bar->isSmooth());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_min(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getMin());
|
||||
} else if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getMin());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -279,6 +319,8 @@ static int p_get_min(UINode* node, lua::State* L) {
|
|||
static int p_get_max(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getMax());
|
||||
} else if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getMax());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -307,6 +349,8 @@ static int p_get_track_color(UINode* node, lua::State* L) {
|
|||
static int p_get_text_color(UINode* node, lua::State* L) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
return lua::pushcolor(L, box->getTextColor());
|
||||
} else if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
return lua::pushcolor(L, bar->getTextColor());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -676,12 +720,18 @@ static int l_gui_getattr(lua::State* L) {
|
|||
{"src", p_get_src},
|
||||
{"fallback", p_get_fallback},
|
||||
{"value", p_get_value},
|
||||
{"progress", p_get_progress},
|
||||
{"min", p_get_min},
|
||||
{"max", p_get_max},
|
||||
{"step", p_get_step},
|
||||
{"scroll", p_get_scroll},
|
||||
{"trackWidth", p_get_track_width},
|
||||
{"trackColor", p_get_track_color},
|
||||
{"barColor", p_get_bar_color},
|
||||
{"bgColor", p_get_bg_color},
|
||||
{"textColor", p_get_text_color},
|
||||
{"textFormat", p_get_text_format},
|
||||
{"smooth", p_is_smooth},
|
||||
{"textColor", p_get_text_color},
|
||||
{"checked", p_is_checked},
|
||||
{"page", p_get_page},
|
||||
|
|
@ -851,6 +901,8 @@ static void p_set_zindex(UINode* node, lua::State* L, int idx) {
|
|||
static void p_set_value(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setValue(lua::tonumber(L, idx));
|
||||
} else if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
bar->setValue(lua::tonumber(L, idx));
|
||||
} else if (auto selectbox = dynamic_cast<SelectBox*>(node)) {
|
||||
auto value = lua::require_lstring(L, idx);
|
||||
const auto& options = selectbox->getOptions();
|
||||
|
|
@ -867,11 +919,39 @@ static void p_set_value(UINode* node, lua::State* L, int idx) {
|
|||
static void p_set_min(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setMin(lua::tonumber(L, idx));
|
||||
} else if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
bar->setMin(lua::tonumber(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_max(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setMax(lua::tonumber(L, idx));
|
||||
} else if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
bar->setMax(lua::tonumber(L, idx));
|
||||
}
|
||||
}
|
||||
|
||||
static void p_set_bar_color(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
bar->setBarColor(lua::tocolor(L, idx));
|
||||
}
|
||||
}
|
||||
|
||||
static void p_set_bg_color(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
bar->setBgColor(lua::tocolor(L, idx));
|
||||
}
|
||||
}
|
||||
|
||||
static void p_set_text_format(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
bar->setTextFormat(lua::require_string(L, idx));
|
||||
}
|
||||
}
|
||||
|
||||
static void p_set_smooth(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
bar->setSmooth(lua::toboolean(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_step(UINode* node, lua::State* L, int idx) {
|
||||
|
|
@ -892,6 +972,8 @@ static void p_set_track_color(UINode* node, lua::State* L, int idx) {
|
|||
static void p_set_text_color(UINode* node, lua::State* L, int idx) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
box->setTextColor(lua::tocolor(L, idx));
|
||||
} else if (auto bar = dynamic_cast<ProgressBar*>(node)) {
|
||||
bar->setTextColor(lua::tocolor(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_checked(UINode* node, lua::State* L, int idx) {
|
||||
|
|
@ -989,7 +1071,11 @@ static int l_gui_setattr(lua::State* L) {
|
|||
{"scroll", p_set_scroll},
|
||||
{"trackWidth", p_set_track_width},
|
||||
{"trackColor", p_set_track_color},
|
||||
{"barColor", p_set_bar_color},
|
||||
{"bgColor", p_set_bg_color},
|
||||
{"textColor", p_set_text_color},
|
||||
{"textFormat", p_set_text_format},
|
||||
{"smooth", p_set_smooth},
|
||||
{"checked", p_set_checked},
|
||||
{"page", p_set_page},
|
||||
{"inventory", p_set_inventory},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue