Ticket #2622: gui_mod_fix.patch
File gui_mod_fix.patch, 11.9 KB (added by , 10 years ago) |
---|
-
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
405 405 <!-- ================================ ================================ --> 406 406 <!-- Diplomacy Window --> 407 407 <!-- ================================ ================================ --> 408 < object include="gui/session/diplomacy_window.xml"/>408 <include file="gui/session/diplomacy_window.xml"/> 409 409 410 410 <!-- ================================ ================================ --> 411 411 <!-- Trade Window --> … … 831 831 <!-- ================================ ================================ --> 832 832 <object size="50%-304 100%-170 50%-110 100%" name="supplementalSelectionDetails" type="image" sprite="supplementalDetailsPanel" z="20"> 833 833 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 844 836 845 837 <object name="unitGarrisonPanel" size="24 12 100% 100%"> 846 838 <object size="0 0 100% 100%"> -
source/gui/CGUI.cpp
412 412 debug_warn(L"CGUI::Destroy error"); 413 413 // TODO Gee: Handle 414 414 } 415 415 416 416 delete it->second; 417 417 } 418 418 … … 562 562 SGUIText Text; // object we're generating 563 563 564 564 CStrIntern Font(FontW.ToUTF8()); 565 565 566 566 if (string.m_Words.size() == 0) 567 567 return Text; 568 568 … … 1067 1067 1068 1068 void 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) 1069 1069 { 1070 1071 1072 1070 ENSURE(pParent); 1073 1071 int i; 1074 1072 … … 1104 1102 ELMT(translate); 1105 1103 ELMT(attribute); 1106 1104 ELMT(keep); 1105 ELMT(include); 1107 1106 ATTR(style); 1108 1107 ATTR(type); 1109 1108 ATTR(name); … … 1113 1112 ATTR(file); 1114 1113 ATTR(id); 1115 1114 ATTR(context); 1116 ATTR(include);1117 1115 1118 1116 // 1119 1117 // Read Style and set defaults … … 1127 1125 if (m_Styles.count("default") == 1) 1128 1126 object->LoadStyle(*this, "default"); 1129 1127 1130 if (! 1128 if (!argStyle.empty()) 1131 1129 { 1132 1130 // additional check 1133 1131 if (m_Styles.count(argStyle) == 0) 1134 {1135 1132 LOGERROR(L"GUI: Trying to use style '%hs' that doesn't exist.", argStyle.c_str()); 1136 }1137 elseobject->LoadStyle(*this, argStyle);1133 else 1134 object->LoadStyle(*this, argStyle); 1138 1135 } 1139 1140 1136 1141 1137 // 1142 1138 // Read Attributes … … 1144 1140 1145 1141 bool NameSet = false; 1146 1142 bool ManuallySetZ = false; // if z has been manually set, this turn true 1147 bool ExternalChildren = false;1148 1143 1149 1144 CStrW inclusionPath; 1150 1145 CStr hotkeyTag; … … 1176 1171 continue; 1177 1172 } 1178 1173 1179 if (attr.Name == attr_include)1180 {1181 ExternalChildren = true;1182 inclusionPath = attr.Value.FromUTF8();1183 continue;1184 }1185 1186 1174 // Wire up the hotkey tag, if it has one 1187 1175 if (attr.Name == attr_hotkey) 1188 1176 hotkeyTag = attr.Value; … … 1207 1195 } 1208 1196 1209 1197 // Attempt to register the hotkey tag, if one was provided 1210 if (! 1198 if (!hotkeyTag.empty()) 1211 1199 m_HotkeyObjects[hotkeyTag].push_back(object); 1212 1200 1213 1201 CStrW caption(Element.GetText().FromUTF8()); … … 1225 1213 // 1226 1214 1227 1215 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 else1251 LOGERROR(L"GUI: Error reading included XML: '%ls', root element must have the name 'objects'.", inclusionPath.c_str());1252 }1253 else1254 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 on1257 pFile = &XeroChildren;1258 }1259 1216 1260 1217 // Iterate children 1261 1218 for (i=0; i<children.Count; ++i) … … 1317 1274 } 1318 1275 1319 1276 CStr action = CStr(child.GetAttributes().GetNamedItem(attr_on)); 1320 1277 1321 1278 // We need to set the GUI this object belongs to because RegisterScriptHandler requires an associated GUI. 1322 1279 object->SetGUI(this); 1323 1280 object->RegisterScriptHandler(action.LowerCase(), code, this); … … 1330 1287 { 1331 1288 // This is an element in the form “<translatableAttribute id="attributeName">attributeValue</translatableAttribute>”. 1332 1289 CStr attributeName(child.GetAttributes().GetNamedItem(attr_id)); // Read the attribute name. 1333 if ( !attributeName.empty())1290 if (attributeName.empty()) 1334 1291 { 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; 1350 1294 } 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()) 1352 1302 { 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); 1354 1310 } 1355 1311 } 1356 1312 else if (element_name == elmt_attribute) … … 1358 1314 // This is an element in the form “<attribute id="attributeName"><keep>Don’t translate this part 1359 1315 // </keep><translate>but translate this one.</translate></attribute>”. 1360 1316 CStr attributeName(child.GetAttributes().GetNamedItem(attr_id)); // Read the attribute name. 1361 if ( !attributeName.empty())1317 if (attributeName.empty()) 1362 1318 { 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 } 1364 1322 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) 1367 1330 { 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(); 1377 1336 } 1378 object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true);1379 1337 } 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()) 1381 1344 { 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); 1383 1370 } 1384 1371 } 1385 1372 else … … 1739 1726 // Input 1740 1727 // 1741 1728 1742 parent.AddImage(Image); 1729 parent.AddImage(Image); 1743 1730 } 1744 1731 1745 1732 void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects) … … 1774 1761 // style object we're adding 1775 1762 SGUIStyle style; 1776 1763 CStr name; 1777 1764 1778 1765 // 1779 1766 // Read Attributes 1780 1767 // … … 1928 1915 1929 1916 if (attr_name == "name") 1930 1917 name = attr_value; 1931 else 1932 if (attr_name == "sprite") 1918 else if (attr_name == "sprite") 1933 1919 icon.m_SpriteName = attr_value; 1934 else 1935 if (attr_name == "size") 1920 else if (attr_name == "size") 1936 1921 { 1937 1922 CSize size; 1938 1923 if (!GUI<CSize>::ParseString(attr_value.FromUTF8(), size)) … … 1940 1925 else 1941 1926 icon.m_Size = size; 1942 1927 } 1943 else 1944 if (attr_name == "cell_id") 1928 else if (attr_name == "cell_id") 1945 1929 { 1946 1930 int cell_id; 1947 1931 if (!GUI<int>::ParseString(attr_value.FromUTF8(), cell_id)) … … 1972 1956 CStr attr_value(attr.Value); 1973 1957 1974 1958 if (attr_name == "name") 1975 {1976 1959 object->SetName("__tooltip_" + attr_value); 1977 }1978 1960 else 1979 {1980 1961 object->SetSetting(attr_name, attr_value.FromUTF8()); 1981 }1982 1962 } 1983 1963 1984 1964 AddObject(object);