@@ -701,6 +701,17 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
701
701
spec.is_exit = true ;
702
702
703
703
GUIButton *e = GUIButton::addButton (Environment, rect, this , spec.fid , spec.flabel .c_str ());
704
+
705
+ auto style = getThemeForElement (type, name);
706
+ if (style.hasProperty (StyleSpec::BGCOLOR)) {
707
+ e->setColor (style.getColor (StyleSpec::BGCOLOR));
708
+ }
709
+ if (style.hasProperty (StyleSpec::TEXTCOLOR)) {
710
+ e->setOverrideColor (style.getColor (StyleSpec::TEXTCOLOR));
711
+ }
712
+
713
+ // e->setSprite();
714
+
704
715
if (spec.fname == data->focused_fieldname ) {
705
716
Environment->setFocus (e);
706
717
}
@@ -1645,7 +1656,7 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen
1645
1656
pos.Y +geom.Y );
1646
1657
1647
1658
gui::IGUITabControl *e = Environment->addTabControl (rect, this ,
1648
- show_background , show_border, spec.fid );
1659
+ false , show_border, spec.fid );
1649
1660
e->setAlignment (irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT,
1650
1661
irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_LOWERRIGHT);
1651
1662
e->setTabHeight (geom.Y );
@@ -1656,9 +1667,17 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen
1656
1667
1657
1668
e->setNotClipped (true );
1658
1669
1670
+ auto style = getThemeForElement (" tabheader" , name);
1671
+
1659
1672
for (const std::string &button : buttons) {
1660
- e->addTab (unescape_translate (unescape_string (
1673
+ auto tab = e->addTab (unescape_translate (unescape_string (
1661
1674
utf8_to_wide (button))).c_str (), -1 );
1675
+ tab->setDrawBackground (false );
1676
+ tab->setBackgroundColor (video::SColor (0xFFFF0000 ));
1677
+ if (style.hasProperty (StyleSpec::BGCOLOR))
1678
+ tab->setBackgroundColor (style.getColor (StyleSpec::BGCOLOR));
1679
+
1680
+ tab->setTextColor (style.getColor (StyleSpec::TEXTCOLOR, video::SColor (0xFFFFFFFF )));
1662
1681
}
1663
1682
1664
1683
if ((tab_index >= 0 ) &&
@@ -2020,6 +2039,45 @@ void GUIFormSpecMenu::parseAnchor(parserData *data, const std::string &element)
2020
2039
<< " '" << std::endl;
2021
2040
}
2022
2041
2042
+ bool GUIFormSpecMenu::parseStyle (parserData *data, const std::string &element, bool style_type)
2043
+ {
2044
+ std::vector<std::string> parts = split (element, ' ;' );
2045
+
2046
+ if (parts.size () != 3 ) {
2047
+ errorstream << " Invalid style element (" << parts.size () << " ): '" << element
2048
+ << " '" << std::endl;
2049
+ return false ;
2050
+ }
2051
+
2052
+ std::string selector = trim (parts[0 ]);
2053
+ std::string propname = trim (parts[1 ]);
2054
+ std::string value = trim (parts[2 ]);
2055
+
2056
+ StyleSpec::Property prop = StyleSpec::GetPropertyByName (propname);
2057
+ if (prop == StyleSpec::NONE) {
2058
+ errorstream << " Invalid style element (Unknown property " << prop << " ): '" << element
2059
+ << " '" << std::endl;
2060
+ return false ;
2061
+ }
2062
+
2063
+ StyleSpec spec;
2064
+ spec.set (prop, value);
2065
+
2066
+ if (selector.empty ()) {
2067
+ errorstream << " Invalid style element (Selector required): '" << element
2068
+ << " '" << std::endl;
2069
+ return false ;
2070
+ }
2071
+
2072
+ if (style_type) {
2073
+ theme_by_type[selector] |= spec;
2074
+ } else {
2075
+ theme_by_name[selector] |= spec;
2076
+ }
2077
+
2078
+ return true ;
2079
+ }
2080
+
2023
2081
void GUIFormSpecMenu::parseElement (parserData* data, const std::string &element)
2024
2082
{
2025
2083
// some prechecks
@@ -2185,6 +2243,16 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
2185
2243
return ;
2186
2244
}
2187
2245
2246
+ if (type == " style" ) {
2247
+ parseStyle (data, description, false );
2248
+ return ;
2249
+ }
2250
+
2251
+ if (type == " style_type" ) {
2252
+ parseStyle (data, description, true );
2253
+ return ;
2254
+ }
2255
+
2188
2256
// Ignore others
2189
2257
infostream << " Unknown DrawSpec: type=" << type << " , data=\" " << description << " \" "
2190
2258
<< std::endl;
@@ -2255,6 +2323,8 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
2255
2323
m_inventory_rings.clear ();
2256
2324
m_static_texts.clear ();
2257
2325
m_dropdowns.clear ();
2326
+ theme_by_name.clear ();
2327
+ theme_by_type.clear ();
2258
2328
2259
2329
m_bgfullscreen = false ;
2260
2330
@@ -4044,3 +4114,19 @@ std::wstring GUIFormSpecMenu::getLabelByID(s32 id)
4044
4114
}
4045
4115
return L" " ;
4046
4116
}
4117
+
4118
+ StyleSpec GUIFormSpecMenu::getThemeForElement (const std::string &type, const std::string &name) {
4119
+ StyleSpec ret;
4120
+
4121
+ auto it = theme_by_type.find (type);
4122
+ if (it != theme_by_type.end ()) {
4123
+ ret |= it->second ;
4124
+ }
4125
+
4126
+ it = theme_by_name.find (name);
4127
+ if (it != theme_by_name.end ()) {
4128
+ ret |= it->second ;
4129
+ }
4130
+
4131
+ return ret;
4132
+ }
0 commit comments