summaryrefslogtreecommitdiff
path: root/src/gui/guiFormSpecMenu.cpp
diff options
context:
space:
mode:
authorv-rob <robinsonvincent89@gmail.com>2020-03-16 14:56:48 -0700
committerGitHub <noreply@github.com>2020-03-16 22:56:48 +0100
commit13ad8e2a090eec97f31a1c62e2052a51dcff4434 (patch)
treef13d97357516f5ed427143a045f5daf14876a8be /src/gui/guiFormSpecMenu.cpp
parent1441281809d9961ff7498df86601db151956b030 (diff)
downloadminetest-13ad8e2a090eec97f31a1c62e2052a51dcff4434.tar.gz
minetest-13ad8e2a090eec97f31a1c62e2052a51dcff4434.tar.bz2
minetest-13ad8e2a090eec97f31a1c62e2052a51dcff4434.zip
Formspecs: Add starting frame to `animated_image` (#9411)
Diffstat (limited to 'src/gui/guiFormSpecMenu.cpp')
-rw-r--r--src/gui/guiFormSpecMenu.cpp83
1 files changed, 48 insertions, 35 deletions
diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp
index b96f53664..9f20877a9 100644
--- a/src/gui/guiFormSpecMenu.cpp
+++ b/src/gui/guiFormSpecMenu.cpp
@@ -784,16 +784,19 @@ void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &el
{
std::vector<std::string> parts = split(element, ';');
- if (parts.size() != 3 &&
- !(parts.size() > 3 && m_formspec_version > FORMSPEC_API_VERSION)) {
- errorstream << "Invalid animated image element(" << parts.size()
- << "): '" << element << "'" << std::endl;
+ if (parts.size() != 6 && parts.size() != 7 &&
+ !(parts.size() > 7 && m_formspec_version > FORMSPEC_API_VERSION)) {
+ errorstream << "Invalid animated_image element(" << parts.size()
+ << "): '" << element << "'" << std::endl;
return;
}
- std::vector<std::string> v_pos = split(parts[0], ',');
- std::vector<std::string> v_geom = split(parts[1], ',');
- std::string name = unescape_string(parts[2]);
+ std::vector<std::string> v_pos = split(parts[0], ',');
+ std::vector<std::string> v_geom = split(parts[1], ',');
+ std::string name = parts[2];
+ std::string texture_name = unescape_string(parts[3]);
+ s32 frame_count = stoi(parts[4]);
+ s32 frame_duration = stoi(parts[5]);
MY_CHECKPOS("animated_image", 0);
MY_CHECKGEOM("animated_image", 1);
@@ -811,21 +814,26 @@ void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &el
}
if (!data->explicit_size)
- warningstream << "invalid use of animated_image without a size[] element" << std::endl;
+ warningstream << "Invalid use of animated_image without a size[] element" << std::endl;
FieldSpec spec(
- "",
- L"",
- L"",
- 258 + m_fields.size()
+ name,
+ L"",
+ L"",
+ 258 + m_fields.size()
);
+ spec.ftype = f_AnimatedImage;
+ spec.send = true;
core::rect<s32> rect = core::rect<s32>(pos, pos + geom);
- gui::IGUIElement *e = new GUIAnimatedImage(Environment, this, spec.fid,
- rect, name, m_tsrc);
+ GUIAnimatedImage *e = new GUIAnimatedImage(Environment, this, spec.fid,
+ rect, texture_name, frame_count, frame_duration, m_tsrc);
+
+ if (parts.size() >= 7)
+ e->setFrameIndex(stoi(parts[6]) - 1);
- auto style = getStyleForElement("animated_image", spec.fname);
+ auto style = getStyleForElement("animated_image", spec.fname, "image");
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
e->drop();
@@ -3499,7 +3507,7 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
}
for (const GUIFormSpecMenu::FieldSpec &s : m_fields) {
- if(s.send) {
+ if (s.send) {
std::string name = s.fname;
if (s.ftype == f_Button) {
fields[name] = wide_to_utf8(s.flabel);
@@ -3508,14 +3516,13 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
if (table) {
fields[name] = table->checkEvent();
}
- }
- else if(s.ftype == f_DropDown) {
- // no dynamic cast possible due to some distributions shipped
- // without rtti support in irrlicht
+ } else if (s.ftype == f_DropDown) {
+ // No dynamic cast possible due to some distributions shipped
+ // without rtti support in Irrlicht
IGUIElement *element = getElementFromId(s.fid, true);
gui::IGUIComboBox *e = NULL;
if ((element) && (element->getType() == gui::EGUIET_COMBO_BOX)) {
- e = static_cast<gui::IGUIComboBox*>(element);
+ e = static_cast<gui::IGUIComboBox *>(element);
} else {
warningstream << "GUIFormSpecMenu::acceptInput: dropdown "
<< "field without dropdown element" << std::endl;
@@ -3529,10 +3536,9 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
fields[name] = (*dropdown_values)[selected];
}
}
- }
- else if (s.ftype == f_TabHeader) {
- // no dynamic cast possible due to some distributions shipped
- // without rttzi support in irrlicht
+ } else if (s.ftype == f_TabHeader) {
+ // No dynamic cast possible due to some distributions shipped
+ // without rtti support in Irrlicht
IGUIElement *element = getElementFromId(s.fid, true);
gui::IGUITabControl *e = nullptr;
if ((element) && (element->getType() == gui::EGUIET_TAB_CONTROL)) {
@@ -3544,10 +3550,9 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
ss << (e->getActiveTab() +1);
fields[name] = ss.str();
}
- }
- else if (s.ftype == f_CheckBox) {
- // no dynamic cast possible due to some distributions shipped
- // without rtti support in irrlicht
+ } else if (s.ftype == f_CheckBox) {
+ // No dynamic cast possible due to some distributions shipped
+ // without rtti support in Irrlicht
IGUIElement *element = getElementFromId(s.fid, true);
gui::IGUICheckBox *e = nullptr;
if ((element) && (element->getType() == gui::EGUIET_CHECK_BOX)) {
@@ -3560,10 +3565,9 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
else
fields[name] = "false";
}
- }
- else if (s.ftype == f_ScrollBar) {
- // no dynamic cast possible due to some distributions shipped
- // without rtti support in irrlicht
+ } else if (s.ftype == f_ScrollBar) {
+ // No dynamic cast possible due to some distributions shipped
+ // without rtti support in Irrlicht
IGUIElement *element = getElementFromId(s.fid, true);
GUIScrollBar *e = nullptr;
if (element && element->getType() == gui::EGUIET_ELEMENT)
@@ -3577,8 +3581,17 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
else
fields[name] = "VAL:" + os.str();
}
- }
- else {
+ } else if (s.ftype == f_AnimatedImage) {
+ // No dynamic cast possible due to some distributions shipped
+ // without rtti support in Irrlicht
+ IGUIElement *element = getElementFromId(s.fid, true);
+ GUIAnimatedImage *e = nullptr;
+ if (element && element->getType() == gui::EGUIET_ELEMENT)
+ e = static_cast<GUIAnimatedImage *>(element);
+
+ if (e)
+ fields[name] = std::to_string(e->getFrameIndex() + 1);
+ } else {
IGUIElement *e = getElementFromId(s.fid, true);
if (e)
fields[name] = wide_to_utf8(e->getText());