Ticket #2622: gui_mod_fix.patch

File gui_mod_fix.patch, 11.9 KB (added by leper, 10 years ago)

Fixes issues. Refactors some of the code too. One TODO, dunno if that is worth fixing.

  • binaries/data/mods/public/gui/session/minimal.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2
     3<objects>
     4    <object name="unitFormationPanel" size="24 12 100% 100%">
     5        <object size="0 0 100% 100%">
     6            <repeat count="16">
     7                <object name="unitFormationButton[n]" hidden="true" style="iconButton" type="button" size="0 0 36 36" tooltip_style="sessionToolTipBottomBold" z="100">
     8                    <object name="unitFormationIcon[n]" type="image" ghost="true" size="3 3 33 33"/>
     9                    <object name="unitFormationSelection[n]" hidden="true" type="image" ghost="true" size="3 3 33 33" sprite="stretched:session/icons/corners.png"/>
     10                </object>
     11            </repeat>
     12        </object>
     13    </object>
     14</objects>
  • binaries/data/mods/public/gui/session/session.xml

     
    405405    <!-- ================================  ================================ -->
    406406    <!-- Diplomacy Window -->
    407407    <!-- ================================  ================================ -->
    408     <object include="gui/session/diplomacy_window.xml"/>
     408    <include file="gui/session/diplomacy_window.xml"/>
    409409
    410410    <!-- ================================  ================================ -->
    411411    <!-- Trade Window -->
     
    831831    <!-- ================================  ================================ -->
    832832    <object size="50%-304 100%-170 50%-110 100%" name="supplementalSelectionDetails" type="image" sprite="supplementalDetailsPanel" z="20">
    833833
    834         <object name="unitFormationPanel" size="24 12 100% 100%">
    835             <object size="0 0 100% 100%">
    836                 <repeat count="16">
    837                     <object name="unitFormationButton[n]" hidden="true" style="iconButton" type="button" size="0 0 36 36" tooltip_style="sessionToolTipBottomBold" z="100">
    838                         <object name="unitFormationIcon[n]" type="image" ghost="true" size="3 3 33 33"/>
    839                         <object name="unitFormationSelection[n]" hidden="true" type="image" ghost="true" size="3 3 33 33" sprite="stretched:session/icons/corners.png"/>
    840                     </object>
    841                 </repeat>
    842             </object>
    843         </object>
     834        <include file="gui/session/minimal.xml"/>
     835
    844836
    845837        <object name="unitGarrisonPanel" size="24 12 100% 100%">
    846838            <object size="0 0 100% 100%">
  • source/gui/CGUI.cpp

     
    412412            debug_warn(L"CGUI::Destroy error");
    413413            // TODO Gee: Handle
    414414        }
    415        
     415
    416416        delete it->second;
    417417    }
    418418
     
    562562    SGUIText Text; // object we're generating
    563563
    564564    CStrIntern Font(FontW.ToUTF8());
    565    
     565
    566566    if (string.m_Words.size() == 0)
    567567        return Text;
    568568
     
    10671067
    10681068void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, const std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
    10691069{
    1070 
    1071 
    10721070    ENSURE(pParent);
    10731071    int i;
    10741072
     
    11041102    ELMT(translate);
    11051103    ELMT(attribute);
    11061104    ELMT(keep);
     1105    ELMT(include);
    11071106    ATTR(style);
    11081107    ATTR(type);
    11091108    ATTR(name);
     
    11131112    ATTR(file);
    11141113    ATTR(id);
    11151114    ATTR(context);
    1116     ATTR(include);
    11171115
    11181116    //
    11191117    //  Read Style and set defaults
     
    11271125    if (m_Styles.count("default") == 1)
    11281126        object->LoadStyle(*this, "default");
    11291127
    1130     if (! argStyle.empty())
     1128    if (!argStyle.empty())
    11311129    {
    11321130        // additional check
    11331131        if (m_Styles.count(argStyle) == 0)
    1134         {
    11351132            LOGERROR(L"GUI: Trying to use style '%hs' that doesn't exist.", argStyle.c_str());
    1136         }
    1137         else object->LoadStyle(*this, argStyle);
     1133        else
     1134            object->LoadStyle(*this, argStyle);
    11381135    }
    1139    
    11401136
    11411137    //
    11421138    //  Read Attributes
     
    11441140
    11451141    bool NameSet = false;
    11461142    bool ManuallySetZ = false; // if z has been manually set, this turn true
    1147     bool ExternalChildren = false;
    11481143
    11491144    CStrW inclusionPath;
    11501145    CStr hotkeyTag;
     
    11761171            continue;
    11771172        }
    11781173
    1179         if (attr.Name == attr_include)
    1180         {
    1181             ExternalChildren = true;
    1182             inclusionPath = attr.Value.FromUTF8();
    1183             continue;
    1184         }
    1185 
    11861174        // Wire up the hotkey tag, if it has one
    11871175        if (attr.Name == attr_hotkey)
    11881176            hotkeyTag = attr.Value;
     
    12071195    }
    12081196
    12091197    // Attempt to register the hotkey tag, if one was provided
    1210     if (! hotkeyTag.empty())
     1198    if (!hotkeyTag.empty())
    12111199        m_HotkeyObjects[hotkeyTag].push_back(object);
    12121200
    12131201    CStrW caption(Element.GetText().FromUTF8());
     
    12251213    //
    12261214
    12271215    XMBElementList children = Element.GetChildNodes();
    1228     CXeromyces XeroChildren;
    1229     if (ExternalChildren)
    1230     {
    1231         if (children.Count > 0)
    1232             LOGWARNING(L"GUI: Gui XML Object in has child nodes and an 'include' attribute (pointing to '%ls'). The child nodes will be ignored.", inclusionPath.c_str());
    1233 
    1234         if (++nesting_depth > MAX_OBECT_DEPTH)
    1235         {
    1236             LOGERROR(L"GUI: Too many nested GUI includes. Probably caused by a recursive include attribute. Abort rendering '%ls'.", inclusionPath.c_str());
    1237             return;
    1238         }
    1239 
    1240         Paths.insert(inclusionPath);
    1241 
    1242         if (XeroChildren.Load(g_VFS, inclusionPath) == PSRETURN_OK)
    1243         {
    1244             XMBElement node = XeroChildren.GetRoot();
    1245 
    1246             CStr root_name(XeroChildren.GetElementString(node.GetNodeName()));
    1247 
    1248             if (root_name == "objects")
    1249                 children = node.GetChildNodes();
    1250             else
    1251                 LOGERROR(L"GUI: Error reading included XML: '%ls', root element must have the name 'objects'.", inclusionPath.c_str());
    1252         }
    1253         else
    1254             LOGERROR(L"GUI: Error reading included XML: '%ls'", inclusionPath.c_str());
    1255 
    1256         // Set pFile to the new CXeromyces file, as it's only used to handle the children from now on
    1257         pFile = &XeroChildren;
    1258     }
    12591216
    12601217    // Iterate children
    12611218    for (i=0; i<children.Count; ++i)
     
    13171274            }
    13181275
    13191276            CStr action = CStr(child.GetAttributes().GetNamedItem(attr_on));
    1320            
     1277
    13211278            // We need to set the GUI this object belongs to because RegisterScriptHandler requires an associated GUI.
    13221279            object->SetGUI(this);
    13231280            object->RegisterScriptHandler(action.LowerCase(), code, this);
     
    13301287        {
    13311288            // This is an element in the form “<translatableAttribute id="attributeName">attributeValue</translatableAttribute>”.
    13321289            CStr attributeName(child.GetAttributes().GetNamedItem(attr_id)); // Read the attribute name.
    1333             if (!attributeName.empty())
     1290            if (attributeName.empty())
    13341291            {
    1335                 CStr value(child.GetText());
    1336                 if (!value.empty())
    1337                 {
    1338                     CStr context(child.GetAttributes().GetNamedItem(attr_context)); // Read the context if any.
    1339                     if (!context.empty())
    1340                     {
    1341                         CStr translatedValue(L10n::Instance().TranslateWithContext(context, value));
    1342                         object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true);
    1343                     }
    1344                     else
    1345                     {
    1346                         CStr translatedValue(L10n::Instance().Translate(value));
    1347                         object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true);
    1348                     }
    1349                 }
     1292                LOGERROR(L"GUI: ‘translatableAttribute’ XML element with empty ‘id’ XML attribute found. (object: %hs)", object->GetPresentableName().c_str());
     1293                continue;
    13501294            }
    1351             else // Ignore.
     1295
     1296            CStr value(child.GetText());
     1297            if (value.empty())
     1298                continue;
     1299
     1300            CStr context(child.GetAttributes().GetNamedItem(attr_context)); // Read the context if any.
     1301            if (!context.empty())
    13521302            {
    1353                 LOGERROR(L"GUI: ‘attribute’ XML element with empty ‘id’ XML attribute found. (object: %hs)", object->GetPresentableName().c_str());
     1303                CStr translatedValue(L10n::Instance().TranslateWithContext(context, value));
     1304                object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true);
     1305            }
     1306            else
     1307            {
     1308                CStr translatedValue(L10n::Instance().Translate(value));
     1309                object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true);
    13541310            }
    13551311        }
    13561312        else if (element_name == elmt_attribute)
     
    13581314            // This is an element in the form “<attribute id="attributeName"><keep>Don’t translate this part
    13591315            // </keep><translate>but translate this one.</translate></attribute>”.
    13601316            CStr attributeName(child.GetAttributes().GetNamedItem(attr_id)); // Read the attribute name.
    1361             if (!attributeName.empty())
     1317            if (attributeName.empty())
    13621318            {
    1363                 CStr translatedValue;
     1319                LOGERROR(L"GUI: ‘attribute’ XML element with empty ‘id’ XML attribute found. (object: %hs)", object->GetPresentableName().c_str());
     1320                continue;
     1321            }
    13641322
    1365                 XMBElementList grandchildren = child.GetChildNodes();
    1366                 for (int i = 0; i < grandchildren.Count; ++i)
     1323            CStr translatedValue;
     1324
     1325            XMBElementList grandchildren = child.GetChildNodes();
     1326            for (int i = 0; i < grandchildren.Count; ++i)
     1327            {
     1328                XMBElement grandchild = grandchildren.Item(i);
     1329                if (grandchild.GetNodeName() == elmt_translate)
    13671330                {
    1368                     XMBElement grandchild = grandchildren.Item(i);
    1369                     if (grandchild.GetNodeName() == elmt_translate)
    1370                     {
    1371                         translatedValue += L10n::Instance().Translate(grandchild.GetText());
    1372                     }
    1373                     else if (grandchild.GetNodeName() == elmt_keep)
    1374                     {
    1375                         translatedValue += grandchild.GetText();
    1376                     }
     1331                    translatedValue += L10n::Instance().Translate(grandchild.GetText());
     1332                }
     1333                else if (grandchild.GetNodeName() == elmt_keep)
     1334                {
     1335                    translatedValue += grandchild.GetText();
    13771336                }
    1378                 object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true);
    13791337            }
    1380             else // Ignore.
     1338            object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true);
     1339        }
     1340        else if (element_name == elmt_include)
     1341        {
     1342            CStrW filename(child.GetAttributes().GetNamedItem(attr_file).FromUTF8());
     1343            if (filename.empty())
    13811344            {
    1382                 LOGERROR(L"GUI: ‘attribute’ XML element with empty ‘id’ XML attribute found. (object: %hs)", object->GetPresentableName().c_str());
     1345                LOGERROR(L"GUI: 'include' XML element with empty 'file' XML attribute found. (object %hs)", object->GetPresentableName().c_str());
     1346                continue;
     1347            }
     1348            Paths.insert(filename);
     1349
     1350            CXeromyces XeroChildren;
     1351            if (XeroChildren.Load(g_VFS, filename) != PSRETURN_OK)
     1352            {
     1353                LOGERROR(L"GUI: Error reading included XML: '%ls'", filename.c_str());
     1354                continue;
     1355            }
     1356
     1357            XMBElement node = XeroChildren.GetRoot();
     1358            if (node.GetNodeName() != XeroChildren.GetElementID("objects"))
     1359            {
     1360                LOGERROR(L"GUI: Error reading included XML: '%ls', root element must have the name 'objects'.", filename.c_str());
     1361                continue;
     1362            }
     1363
     1364            XMBElementList include_children = node.GetChildNodes();
     1365            // Call this function on the child
     1366            for (int j = 0; j < include_children.Count; ++j)
     1367            {
     1368                // TODO: Handle other objects (repeat, script)
     1369                Xeromyces_ReadObject(include_children.Item(j), &XeroChildren, object, NameSubst, Paths, nesting_depth+1);
    13831370            }
    13841371        }
    13851372        else
     
    17391726    //  Input
    17401727    //
    17411728
    1742     parent.AddImage(Image); 
     1729    parent.AddImage(Image);
    17431730}
    17441731
    17451732void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects)
     
    17741761    // style object we're adding
    17751762    SGUIStyle style;
    17761763    CStr name;
    1777    
     1764
    17781765    //
    17791766    // Read Attributes
    17801767    //
     
    19281915
    19291916        if (attr_name == "name")
    19301917            name = attr_value;
    1931         else
    1932         if (attr_name == "sprite")
     1918        else if (attr_name == "sprite")
    19331919            icon.m_SpriteName = attr_value;
    1934         else
    1935         if (attr_name == "size")
     1920        else if (attr_name == "size")
    19361921        {
    19371922            CSize size;
    19381923            if (!GUI<CSize>::ParseString(attr_value.FromUTF8(), size))
     
    19401925            else
    19411926                icon.m_Size = size;
    19421927        }
    1943         else
    1944         if (attr_name == "cell_id")
     1928        else if (attr_name == "cell_id")
    19451929        {
    19461930            int cell_id;
    19471931            if (!GUI<int>::ParseString(attr_value.FromUTF8(), cell_id))
     
    19721956        CStr attr_value(attr.Value);
    19731957
    19741958        if (attr_name == "name")
    1975         {
    19761959            object->SetName("__tooltip_" + attr_value);
    1977         }
    19781960        else
    1979         {
    19801961            object->SetSetting(attr_name, attr_value.FromUTF8());
    1981         }
    19821962    }
    19831963
    19841964    AddObject(object);