Browse Source

Added new LoadChildXML() method to UIElement and exposed it to Script. Changed Editor app to call LoadChildXML() instead of LoadXML() to prevent child XML-chunk from accidentally modifying the parent element's tyle. Note: child XML-chunk does not require nested element tag anymore.

Wei Tjong Yao 12 years ago
parent
commit
1b2497dc10

+ 12 - 24
Bin/Data/Scripts/Editor/EditorActions.as

@@ -487,11 +487,7 @@ class CreateUIElementAction : EditAction
         parentID = GetUIElementID(element.parent);
         elementData = XMLFile();
         XMLElement rootElem = elementData.CreateRoot("element");
-        // No style processing for the root element
-        rootElem.SetAttribute("style", "none");
-        // Need another nested element tag otherwise the LoadXML() does not work as expected
-        XMLElement childElem = rootElem.CreateChild("element");
-        element.SaveXML(childElem);
+        element.SaveXML(rootElem);
         styleFile = element.defaultStyle;
     }
 
@@ -514,7 +510,7 @@ class CreateUIElementAction : EditAction
             // Have to update manually because the element ID var is not set yet when the E_ELEMENTADDED event is sent
             suppressUIElementChanges = true;
 
-            if (parent.LoadXML(elementData.root, styleFile))
+            if (parent.LoadChildXML(elementData.root, styleFile))
             {
                 UIElement@ element = parent.children[parent.numChildren - 1];
                 UpdateHierarchyItem(element);
@@ -540,13 +536,9 @@ class DeleteUIElementAction : EditAction
         parentID = GetUIElementID(element.parent);
         elementData = XMLFile();
         XMLElement rootElem = elementData.CreateRoot("element");
-        // No style processing for the root element
-        rootElem.SetAttribute("style", "none");
-        // Need another nested element tag otherwise the LoadXML() does not work as expected
-        XMLElement childElem = rootElem.CreateChild("element");
-        element.SaveXML(childElem);
-        childElem.SetUInt("index", element.parent.FindChild(element));
-        childElem.SetUInt("listItemIndex", GetListIndex(element));
+        element.SaveXML(rootElem);
+        rootElem.SetUInt("index", element.parent.FindChild(element));
+        rootElem.SetUInt("listItemIndex", GetListIndex(element));
         styleFile = element.defaultStyle;
     }
 
@@ -558,11 +550,11 @@ class DeleteUIElementAction : EditAction
             // Have to update manually because the element ID var is not set yet when the E_ELEMENTADDED event is sent
             suppressUIElementChanges = true;
 
-            if (parent.LoadXML(elementData.root, styleFile))
+            if (parent.LoadChildXML(elementData.root, styleFile))
             {
-                XMLElement childElem = elementData.root.GetChild("element");
-                uint index = childElem.GetUInt("index");
-                uint listItemIndex = childElem.GetUInt("listItemIndex");
+                XMLElement rootElem = elementData.root;
+                uint index = rootElem.GetUInt("index");
+                uint listItemIndex = rootElem.GetUInt("listItemIndex");
                 UIElement@ element = parent.children[index];
                 UIElement@ parentItem = hierarchyList.items[GetListIndex(parent)];
                 UpdateHierarchyItem(listItemIndex, element, parentItem);
@@ -631,12 +623,8 @@ class ApplyUIElementStyleAction : EditAction
         parentID = GetUIElementID(element.parent);
         elementData = XMLFile();
         XMLElement rootElem = elementData.CreateRoot("element");
-        // No style processing for the root element
-        rootElem.SetAttribute("style", "none");
-        // Need another nested element tag otherwise the LoadXML() does not work as expected
-        XMLElement childElem = rootElem.CreateChild("element");
-        element.SaveXML(childElem);
-        childElem.SetUInt("index", element.parent.FindChild(element));
+        element.SaveXML(rootElem);
+        rootElem.SetUInt("index", element.parent.FindChild(element));
         styleFile = element.defaultStyle;
         style = newStyle;
     }
@@ -651,7 +639,7 @@ class ApplyUIElementStyleAction : EditAction
             suppressUIElementChanges = true;
 
             parent.RemoveChild(element);
-            parent.LoadXML(elementData.root, styleFile);
+            parent.LoadChildXML(elementData.root, styleFile);
 
             suppressUIElementChanges = false;
 

+ 6 - 6
Bin/Data/Scripts/Editor/EditorNodeWindow.as

@@ -51,9 +51,9 @@ UIElement@ GetNodeContainer()
         return GetContainer(nodeContainerIndex);
 
     nodeContainerIndex = parentContainer.numChildren;
-    parentContainer.LoadXML(xmlResources[ATTRIBUTE_RES], uiStyle);
+    parentContainer.LoadChildXML(xmlResources[ATTRIBUTE_RES], uiStyle);
     UIElement@ container = GetContainer(nodeContainerIndex);
-    container.LoadXML(xmlResources[VARIABLE_RES], uiStyle);
+    container.LoadChildXML(xmlResources[VARIABLE_RES], uiStyle);
     SubscribeToEvent(container.GetChild("ResetToDefault", true), "Released", "HandleResetToDefault");
     SubscribeToEvent(container.GetChild("NewVarDropDown", true), "ItemSelected", "CreateNodeVariable");
     SubscribeToEvent(container.GetChild("DeleteVarButton", true), "Released", "DeleteNodeVariable");
@@ -64,7 +64,7 @@ UIElement@ GetNodeContainer()
 UIElement@ GetComponentContainer(uint index)
 {
     for (uint i = parentContainer.numChildren - componentContainerStartIndex; i <= index; ++i)
-        parentContainer.LoadXML(xmlResources[ATTRIBUTE_RES], uiStyle);
+        parentContainer.LoadChildXML(xmlResources[ATTRIBUTE_RES], uiStyle);
     UIElement@ container = parentContainer.children[componentContainerStartIndex + index];
     SubscribeToEvent(container.GetChild("ResetToDefault", true), "Released", "HandleResetToDefault");
     return container;
@@ -76,10 +76,10 @@ UIElement@ GetUIElementContainer()
         return GetContainer(elementContainerIndex);
 
     elementContainerIndex = parentContainer.numChildren;
-    parentContainer.LoadXML(xmlResources[ATTRIBUTE_RES], uiStyle);
+    parentContainer.LoadChildXML(xmlResources[ATTRIBUTE_RES], uiStyle);
     UIElement@ container = GetContainer(elementContainerIndex);
-    container.LoadXML(xmlResources[VARIABLE_RES], uiStyle);
-    container.LoadXML(xmlResources[STYLE_RES], uiStyle);
+    container.LoadChildXML(xmlResources[VARIABLE_RES], uiStyle);
+    container.LoadChildXML(xmlResources[STYLE_RES], uiStyle);
     DropDownList@ styleList = container.GetChild("StyleDropDown", true);
     styleList.placeholderText = STRIKED_OUT;
     styleList.parent.GetChild("StyleDropDownLabel").SetFixedWidth(LABEL_WIDTH);

+ 5 - 13
Bin/Data/Scripts/Editor/EditorUIElement.as

@@ -259,7 +259,7 @@ void LoadChildUIElement(const String&in fileName)
 
     suppressUIElementChanges = true;
 
-    if (editUIElement.LoadXML(xmlFile, uiElementDefaultStyle !is null ? uiElementDefaultStyle : uiStyle))
+    if (editUIElement.LoadChildXML(xmlFile, uiElementDefaultStyle !is null ? uiElementDefaultStyle : uiStyle))
     {
         UIElement@ element = editUIElement.children[editUIElement.numChildren - 1];
         ResetSortChildren(element);
@@ -290,14 +290,10 @@ bool SaveChildUIElement(const String&in fileName)
 
     XMLFile@ elementData = XMLFile();
     XMLElement rootElem = elementData.CreateRoot("element");
-    // No style processing for the root element
-    rootElem.SetAttribute("style", "none");
-    // Need another nested element tag otherwise the LoadXML() does not work as expected
-    XMLElement childElem = rootElem.CreateChild("element");
-    bool success = editUIElement.SaveXML(childElem);
+    bool success = editUIElement.SaveXML(rootElem);
     if (success)
     {
-        FilterInternalVars(childElem);
+        FilterInternalVars(rootElem);
         success = elementData.Save(file);
     }
 
@@ -431,11 +427,7 @@ bool UIElementCopy()
     {
         XMLFile@ xml = XMLFile();
         XMLElement rootElem = xml.CreateRoot("element");
-        // No style processing for the root element
-        rootElem.SetAttribute("style", "none");
-        // Need another nested element tag otherwise the LoadXML() does not work as expected
-        XMLElement childElem = rootElem.CreateChild("element");
-        selectedUIElements[i].SaveXML(childElem);
+        selectedUIElements[i].SaveXML(rootElem);
         uiElementCopyBuffer.Push(xml);
     }
 
@@ -466,7 +458,7 @@ bool UIElementPaste()
     for (uint i = 0; i < uiElementCopyBuffer.length; ++i)
     {
         XMLElement rootElem = uiElementCopyBuffer[i].root;
-        if (editUIElement.LoadXML(rootElem))
+        if (editUIElement.LoadChildXML(rootElem, null))
         {
             UIElement@ element = editUIElement.children[editUIElement.numChildren - 1];
             ResetDuplicateID(element);

+ 23 - 25
Bin/Data/UI/EditorInspector_Attribute.xml

@@ -1,33 +1,31 @@
 <element>
-    <element>
-        <attribute name="Name" value="AttributeContainer" />
-        <attribute name="Layout Mode" value="Vertical" />
-        <attribute name="Layout Spacing" value="4" />
-        <element type="BorderImage" style="EditorDivider" />
-        <element type="Text">
-            <attribute name="Name" value="TitleText" />
+    <attribute name="Name" value="AttributeContainer" />
+    <attribute name="Layout Mode" value="Vertical" />
+    <attribute name="Layout Spacing" value="4" />
+    <element type="BorderImage" style="EditorDivider" />
+    <element type="Text">
+        <attribute name="Name" value="TitleText" />
+        <element>
+            <attribute name="Name" value="IconsPanel" />
+            <attribute name="Layout Mode" value="Horizontal" />
+            <attribute name="Layout Spacing" value="2" />
             <element>
-                <attribute name="Name" value="IconsPanel" />
+                <attribute name="Name" value="Spacer" />
+            </element>
+            <element type="Button">
+                <attribute name="Name" value="ResetToDefault" />
+                <attribute name="Min Size" value="16 16" />
+                <attribute name="Max Size" value="16 16" />
                 <attribute name="Layout Mode" value="Horizontal" />
-                <attribute name="Layout Spacing" value="2" />
-                <element>
-                    <attribute name="Name" value="Spacer" />
-                </element>
-                <element type="Button">
-                    <attribute name="Name" value="ResetToDefault" />
-                    <attribute name="Min Size" value="16 16" />
-                    <attribute name="Max Size" value="16 16" />
-                    <attribute name="Layout Mode" value="Horizontal" />
-                    <element type="BorderImage">
-                        <attribute name="Texture" value="Texture2D;Textures/UI.png" />
-                        <attribute name="Image Rect" value="128 32 144 48" />
-                    </element>
+                <element type="BorderImage">
+                    <attribute name="Texture" value="Texture2D;Textures/UI.png" />
+                    <attribute name="Image Rect" value="128 32 144 48" />
                 </element>
             </element>
         </element>
-        <element type="ListView">
-            <attribute name="Name" value="AttributeList" />
-            <attribute name="Clip Children" value="false" />
-        </element>
+    </element>
+    <element type="ListView">
+        <attribute name="Name" value="AttributeList" />
+        <attribute name="Clip Children" value="false" />
     </element>
 </element>

+ 23 - 25
Bin/Data/UI/EditorInspector_Style.xml

@@ -1,29 +1,27 @@
-<element>
-    <element index="2">
-        <attribute name="Name" value="StyleContainer" />
-        <attribute name="Max Size" value="2147483647 17" />
-        <attribute name="Layout Mode" value="Horizontal" />
-        <attribute name="Layout Spacing" value="4" />
-        <element type="Text" style="EditorAttributeText">
-            <attribute name="Name" value="StyleDropDownLabel" />
-            <attribute name="Text" value="Style" />
-        </element>
-        <element type="DropDownList">
-            <attribute name="Name" value="StyleDropDown" />
-            <attribute name="Resize Popup" value="true" />
-            <!-- Skip style processing as the purpose of below tags is to populate the content element -->
-            <element type="Window" internal="true" popup="true" style="none">
-                <element type="ListView" internal="true" style="none">
-                    <element type="BorderImage" internal="true" style="none">
-                        <element internal="true" style="none">
-                            <element type="Text" style="EditorEnumAttributeText">
-                                <attribute name="Text" value="auto" />
-                            </element>
-                            <element type="Text" style="EditorEnumAttributeText">
-                                <attribute name="Text" value="none" />
-                            </element>
-                            <element type="BorderImage" style="EditorDivider" />
+<element index="2">
+    <attribute name="Name" value="StyleContainer" />
+    <attribute name="Max Size" value="2147483647 17" />
+    <attribute name="Layout Mode" value="Horizontal" />
+    <attribute name="Layout Spacing" value="4" />
+    <element type="Text" style="EditorAttributeText">
+        <attribute name="Name" value="StyleDropDownLabel" />
+        <attribute name="Text" value="Style" />
+    </element>
+    <element type="DropDownList">
+        <attribute name="Name" value="StyleDropDown" />
+        <attribute name="Resize Popup" value="true" />
+        <!-- Skip style processing as the purpose of below tags is to populate the content element -->
+        <element type="Window" internal="true" popup="true" style="none">
+            <element type="ListView" internal="true" style="none">
+                <element type="BorderImage" internal="true" style="none">
+                    <element internal="true" style="none">
+                        <element type="Text" style="EditorEnumAttributeText">
+                            <attribute name="Text" value="auto" />
+                        </element>
+                        <element type="Text" style="EditorEnumAttributeText">
+                            <attribute name="Text" value="none" />
                         </element>
+                        <element type="BorderImage" style="EditorDivider" />
                     </element>
                 </element>
             </element>

+ 50 - 52
Bin/Data/UI/EditorInspector_Variable.xml

@@ -1,62 +1,60 @@
 <element>
-    <element>
-        <attribute name="Name" value="VariableContainer" />
-        <attribute name="Max Size" value="2147483647 17" />
-        <attribute name="Layout Mode" value="Horizontal" />
-        <attribute name="Layout Spacing" value="4" />
-        <element type="LineEdit">
-            <attribute name="Name" value="VarNameEdit" />
+    <attribute name="Name" value="VariableContainer" />
+    <attribute name="Max Size" value="2147483647 17" />
+    <attribute name="Layout Mode" value="Horizontal" />
+    <attribute name="Layout Spacing" value="4" />
+    <element type="LineEdit">
+        <attribute name="Name" value="VarNameEdit" />
+    </element>
+    <element type="DropDownList">
+        <attribute name="Name" value="NewVarDropDown" />
+        <attribute name="Min Size" value="50 17" />
+        <attribute name="Max Size" value="50 17" />
+        <attribute name="Resize Popup" value="true" />
+        <element internal="true">
+            <attribute name="Is Visible" value="false" />
         </element>
-        <element type="DropDownList">
-            <attribute name="Name" value="NewVarDropDown" />
-            <attribute name="Min Size" value="50 17" />
-            <attribute name="Max Size" value="50 17" />
-            <attribute name="Resize Popup" value="true" />
-            <element internal="true">
-                <attribute name="Is Visible" value="false" />
-            </element>
-            <element type="Text">
-                <attribute name="Text" value="New" />
-                <attribute name="Text Alignment" value="Center" />
-            </element>
-            <!-- Skip style processing as the purpose of below tags is to populate the content element -->
-            <element type="Window" internal="true" popup="true" style="none">
-                <element type="ListView" internal="true" style="none">
-                    <element type="BorderImage" internal="true" style="none">
-                        <element internal="true" style="none">
-                            <element type="Text" style="EditorEnumAttributeText">
-                                <attribute name="Text" value="Int" />
-                            </element>
-                            <element type="Text" style="EditorEnumAttributeText">
-                                <attribute name="Text" value="Bool" />
-                            </element>
-                            <element type="Text" style="EditorEnumAttributeText">
-                                <attribute name="Text" value="Float" />
-                            </element>
-                            <element type="Text" style="EditorEnumAttributeText">
-                                <attribute name="Text" value="String" />
-                            </element>
-                            <element type="Text" style="EditorEnumAttributeText">
-                                <attribute name="Text" value="Vector3" />
-                            </element>
-                            <element type="Text" style="EditorEnumAttributeText">
-                                <attribute name="Text" value="Color" />
-                            </element>
+        <element type="Text">
+            <attribute name="Text" value="New" />
+            <attribute name="Text Alignment" value="Center" />
+        </element>
+        <!-- Skip style processing as the purpose of below tags is to populate the content element -->
+        <element type="Window" internal="true" popup="true" style="none">
+            <element type="ListView" internal="true" style="none">
+                <element type="BorderImage" internal="true" style="none">
+                    <element internal="true" style="none">
+                        <element type="Text" style="EditorEnumAttributeText">
+                            <attribute name="Text" value="Int" />
+                        </element>
+                        <element type="Text" style="EditorEnumAttributeText">
+                            <attribute name="Text" value="Bool" />
+                        </element>
+                        <element type="Text" style="EditorEnumAttributeText">
+                            <attribute name="Text" value="Float" />
+                        </element>
+                        <element type="Text" style="EditorEnumAttributeText">
+                            <attribute name="Text" value="String" />
+                        </element>
+                        <element type="Text" style="EditorEnumAttributeText">
+                            <attribute name="Text" value="Vector3" />
+                        </element>
+                        <element type="Text" style="EditorEnumAttributeText">
+                            <attribute name="Text" value="Color" />
                         </element>
                     </element>
                 </element>
             </element>
         </element>
-        <element type="Button">
-            <attribute name="Name" value="DeleteVarButton" />
-            <attribute name="Min Size" value="50 17" />
-            <attribute name="Max Size" value="50 17" />
-            <attribute name="Layout Mode" value="Vertical" />
-            <attribute name="Layout Border" value="1 1 1 1" />
-            <element type="Text">
-                <attribute name="Text" value="Del" />
-                <attribute name="Text Alignment" value="Center" />
-            </element>
+    </element>
+    <element type="Button">
+        <attribute name="Name" value="DeleteVarButton" />
+        <attribute name="Min Size" value="50 17" />
+        <attribute name="Max Size" value="50 17" />
+        <attribute name="Layout Mode" value="Vertical" />
+        <attribute name="Layout Border" value="1 1 1 1" />
+        <element type="Text">
+            <attribute name="Text" value="Del" />
+            <attribute name="Text Alignment" value="Center" />
         </element>
     </element>
 </element>

+ 30 - 0
Docs/ScriptAPI.dox

@@ -3270,6 +3270,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -3390,6 +3392,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -3518,6 +3522,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -3612,6 +3618,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -3747,6 +3755,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -3878,6 +3888,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -4008,6 +4020,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -4142,6 +4156,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -4274,6 +4290,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -4404,6 +4422,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -4563,6 +4583,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -4764,6 +4786,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -4903,6 +4927,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -5045,6 +5071,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
@@ -5199,6 +5227,8 @@ Methods:<br>
 - bool LoadXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadXML(File@)
 - bool LoadXML(XMLFile@, XMLFile@)
+- bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
+- bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)

+ 13 - 0
Engine/Engine/APITemplates.h

@@ -758,6 +758,17 @@ static bool UIElementLoadXML(XMLFile* file, XMLFile* styleFile, UIElement* ptr)
         return false;
 }
 
+static bool UIElementLoadChildXML(XMLFile* file, XMLFile* styleFile, UIElement* ptr)
+{
+    if (file)
+    {
+        XMLElement rootElem = file->GetRoot("element");
+        return rootElem && ptr->LoadChildXML(rootElem, styleFile);
+    }
+    else
+        return false;
+}
+
 static bool UIElementSaveXML(File* file, UIElement* ptr)
 {
     return file && ptr->SaveXML(*file);
@@ -819,6 +830,8 @@ template <class T> void RegisterUIElement(asIScriptEngine* engine, const char* c
     engine->RegisterObjectMethod(className, "bool LoadXML(const XMLElement&in, XMLFile@+, bool arg2 = false)", asMETHODPR(T, LoadXML, (const XMLElement&, XMLFile*, bool), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool LoadXML(File@+)", asFUNCTIONPR(UIElementLoadXML, (File*, UIElement*), bool), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool LoadXML(XMLFile@+, XMLFile@+)", asFUNCTIONPR(UIElementLoadXML, (XMLFile*, XMLFile*, UIElement*), bool), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod(className, "bool LoadChildXML(const XMLElement&in, XMLFile@+, bool arg2 = false)", asMETHOD(T, LoadChildXML), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "bool LoadChildXML(XMLFile@+, XMLFile@+)", asFUNCTION(UIElementLoadChildXML), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool SaveXML(File@+)", asFUNCTION(UIElementSaveXML), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "void SetStyle(const XMLElement&in)", asMETHODPR(T, SetStyle, (const XMLElement&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetStyle(XMLFile@+, const String&in)", asMETHODPR(T, SetStyle, (XMLFile*, const String&), void), asCALL_THISCALL);

+ 1 - 4
Engine/UI/Menu.cpp

@@ -129,10 +129,7 @@ bool Menu::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setInstanc
         if (styleName.Empty())
             styleName = GetTypeName();
 
-        if (styleName.ToLower() == "none")
-            appliedStyle_ = styleName;
-        else
-            SetStyle(styleFile, styleName);
+        SetStyle(styleFile, styleName);
     }
     // The 'style' attribute value in the style file cannot be equals to original's applied style to prevent infinite loop
     else if (!styleName.Empty() && styleName != appliedStyle_)

+ 26 - 0
Engine/UI/UIElement.cpp

@@ -294,6 +294,32 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setIn
     return true;
 }
 
+bool UIElement::LoadChildXML(const XMLElement& childElem, XMLFile* styleFile, bool setInstanceDefault)
+{
+    bool internalElem = childElem.GetBool("internal");
+    if (internalElem)
+    {
+        LOGERROR("Loading internal child element is not supported");
+        return false;
+    }
+
+    String typeName = childElem.GetAttribute("type");
+    if (typeName.Empty())
+        typeName = "UIElement";
+    unsigned index = childElem.HasAttribute("index") ? childElem.GetUInt("index") : M_MAX_UNSIGNED;
+    UIElement* child = CreateChild(typeName, String::EMPTY, index);
+
+    if (child)
+    {
+        if (!styleFile)
+            styleFile = GetDefaultStyle();
+        if (!child->LoadXML(childElem, styleFile, setInstanceDefault))
+            return false;
+    }
+
+    return true;
+}
+
 bool UIElement::SaveXML(XMLElement& dest) const
 {
     // Write type

+ 2 - 0
Engine/UI/UIElement.h

@@ -129,6 +129,8 @@ public:
     virtual bool LoadXML(const XMLElement& source, bool setInstanceDefault = false);
     /// Load from XML data with style. Return true if successful.
     virtual bool LoadXML(const XMLElement& source, XMLFile* styleFile, bool setInstanceDefault = false);
+    /// Create a child by Loading from XML data with style. Return true if successful.
+    virtual bool LoadChildXML(const XMLElement& childElem, XMLFile* styleFile, bool setInstanceDefault = false);
     /// Save as XML data. Return true if successful.
     virtual bool SaveXML(XMLElement& dest) const;