]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/gui/guiFormSpecMenu.cpp
Formspecs: Introduce formspec_version to mods
[dragonfireclient.git] / src / gui / guiFormSpecMenu.cpp
index c9ae7675051e1c08ed6b302e0014e9b6405da8d8..f291b4e877b09747bf4d9632ba4c958638799274 100644 (file)
@@ -1403,7 +1403,8 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
                std::vector<std::string> lines = split(text, '\n');
 
                for (unsigned int i = 0; i != lines.size(); i++) {
-                       std::wstring wlabel = utf8_to_wide(unescape_string(lines[i]));
+                       std::wstring wlabel = unescape_translate(unescape_string(
+                               utf8_to_wide(lines[i])));
 
                        core::rect<s32> rect;
 
@@ -1458,11 +1459,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
 
                        auto style = getStyleForElement("label", spec.fname);
                        e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
-                       e->setDrawBorder(style.getBool(StyleSpec::BORDER, false));
                        e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
-                       if (style.isNotDefault(StyleSpec::BGCOLOR)) {
-                               e->setBackgroundColor(style.getColor(StyleSpec::BGCOLOR));
-                       }
 
                        m_fields.push_back(spec);
                }
@@ -1538,11 +1535,7 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen
 
                auto style = getStyleForElement("vertlabel", spec.fname, "label");
                e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
-               e->setDrawBorder(style.getBool(StyleSpec::BORDER, false));
                e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
-               if (style.isNotDefault(StyleSpec::BGCOLOR)) {
-                       e->setBackgroundColor(style.getColor(StyleSpec::BGCOLOR));
-               }
 
                m_fields.push_back(spec);
                return;
@@ -2174,6 +2167,9 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
        if (element.empty())
                return;
 
+       if (parseVersionDirect(element))
+               return;
+
        std::vector<std::string> parts = split(element,'[');
 
        // ugly workaround to keep compatibility
@@ -2510,7 +2506,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
        }
 
        /* Copy of the "real_coordinates" element for after the form size. */
-       mydata.real_coordinates = false;
+       mydata.real_coordinates = m_formspec_version >= 2;
        for (; i < elements.size(); i++) {
                std::vector<std::string> parts = split(elements[i], '[');
                std::string name = trim(parts[0]);
@@ -2655,10 +2651,14 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
        if (enable_prepends) {
                // Backup the coordinates so that prepends can use the coordinates of choice.
                bool rc_backup = mydata.real_coordinates;
+               bool version_backup = m_formspec_version;
                mydata.real_coordinates = false; // Old coordinates by default.
+
                std::vector<std::string> prepend_elements = split(m_formspec_prepend, ']');
                for (const auto &element : prepend_elements)
                        parseElement(&mydata, element);
+
+               m_formspec_version = version_backup;
                mydata.real_coordinates = rc_backup; // Restore coordinates
        }
 
@@ -2852,37 +2852,23 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int layer,
                }
 
                if (layer == 1) {
-                       // Draw item stack
                        if (selected)
                                item.takeItem(m_selected_amount);
 
                        if (!item.empty()) {
+                               // Draw item stack
                                drawItemStack(driver, m_font, item,
                                        rect, &AbsoluteClippingRect, m_client,
                                        rotation_kind);
-                       }
-
-                       // Draw tooltip
-                       std::wstring tooltip_text;
-                       if (hovering && !m_selected_item) {
-                               const std::string &desc = item.metadata.getString("description");
-                               if (desc.empty())
-                                       tooltip_text =
-                                               utf8_to_wide(item.getDefinition(m_client->idef()).description);
-                               else
-                                       tooltip_text = utf8_to_wide(desc);
-
-                               if (!item.name.empty()) {
-                                       if (tooltip_text.empty())
-                                               tooltip_text = utf8_to_wide(item.name);
-                                       else if (m_tooltip_append_itemname)
-                                               tooltip_text += utf8_to_wide("\n[" + item.name + "]");
+                               // Draw tooltip
+                               if (hovering && !m_selected_item) {
+                                       std::string tooltip = item.getDescription(m_client->idef());
+                                       if (m_tooltip_append_itemname)
+                                               tooltip += "\n[" + item.name + "]";
+                                       showTooltip(utf8_to_wide(tooltip), m_default_tooltip_color,
+                                                       m_default_tooltip_bgcolor);
                                }
                        }
-                       if (!tooltip_text.empty()) {
-                               showTooltip(tooltip_text, m_default_tooltip_color,
-                                       m_default_tooltip_bgcolor);
-                       }
                }
        }
 }