Răsfoiți Sursa

UIElement serialization / deserialization.
Fixed XML serialization of IntVector2.

Lasse Öörni 13 ani în urmă
părinte
comite
0a16099532

+ 168 - 0
Docs/ScriptAPI.dox

@@ -2739,6 +2739,15 @@ Properties:<br>
 UIElement
 UIElement
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -2771,6 +2780,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -2820,6 +2832,15 @@ Properties:<br>
 BorderImage
 BorderImage
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -2854,6 +2875,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -2907,6 +2931,15 @@ Properties:<br>
 Button
 Button
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -2944,6 +2977,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3001,6 +3037,15 @@ Properties:<br>
 CheckBox
 CheckBox
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3036,6 +3081,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3091,6 +3139,15 @@ Properties:<br>
 Cursor
 Cursor
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3126,6 +3183,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3180,6 +3240,15 @@ Properties:<br>
 Slider
 Slider
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3215,6 +3284,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3272,6 +3344,15 @@ Properties:<br>
 ScrollBar
 ScrollBar
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3307,6 +3388,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3365,6 +3449,15 @@ Properties:<br>
 ScrollView
 ScrollView
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3399,6 +3492,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3455,6 +3551,15 @@ Properties:<br>
 ListView
 ListView
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3505,6 +3610,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3572,6 +3680,15 @@ Properties:<br>
 Text
 Text
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3608,6 +3725,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3669,6 +3789,15 @@ Properties:<br>
 LineEdit
 LineEdit
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3703,6 +3832,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3766,6 +3898,15 @@ Properties:<br>
 Menu
 Menu
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3805,6 +3946,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3867,6 +4011,15 @@ Properties:<br>
 DropDownList
 DropDownList
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -3912,6 +4065,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position
@@ -3979,6 +4135,15 @@ Properties:<br>
 Window
 Window
 
 
 Methods:<br>
 Methods:<br>
+- bool Load(File@)
+- bool Save(File@)
+- bool LoadXML(const XMLElement&)
+- bool SaveXML(XMLElement&)
+- void ApplyAttributes()
+- bool SetAttribute(const String&, const Variant&)
+- Variant GetAttribute(const String&)
+- bool LoadXML(File@)
+- bool SaveXML(File@)
 - void SetStyle(const XMLElement&)
 - void SetStyle(const XMLElement&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyle(XMLFile@, const String&)
 - void SetStyleAuto(XMLFile@)
 - void SetStyleAuto(XMLFile@)
@@ -4013,6 +4178,9 @@ Methods:<br>
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - String typeName (readonly)
+- uint numAttributes (readonly)
+- Variant[] attributes
+- AttributeInfo[] attributeInfos (readonly)
 - XMLFile@ style (writeonly)
 - XMLFile@ style (writeonly)
 - String name
 - String name
 - IntVector2 position
 - IntVector2 position

+ 1 - 1
Engine/Core/Variant.cpp

@@ -346,7 +346,7 @@ String Variant::ToString() const
         return (reinterpret_cast<const IntRect*>(&value_))->ToString();
         return (reinterpret_cast<const IntRect*>(&value_))->ToString();
         
         
     case VAR_INTVECTOR2:
     case VAR_INTVECTOR2:
-        return (reinterpret_cast<const IntRect*>(&value_))->ToString();
+        return (reinterpret_cast<const IntVector2*>(&value_))->ToString();
         
         
     default:
     default:
         return String();
         return String();

+ 19 - 1
Engine/Engine/APITemplates.h

@@ -343,7 +343,7 @@ template <class T> void RegisterSerializable(asIScriptEngine* engine, const char
     engine->RegisterObjectMethod(className, "bool SetAttribute(const String&in, const Variant&in)", asMETHODPR(T, SetAttribute, (const String&, const Variant&), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool SetAttribute(const String&in, const Variant&in)", asMETHODPR(T, SetAttribute, (const String&, const Variant&), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Variant GetAttribute(const String&in)", asMETHODPR(T, GetAttribute, (const String&), Variant), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Variant GetAttribute(const String&in)", asMETHODPR(T, GetAttribute, (const String&), Variant), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "uint get_numAttributes() const", asMETHODPR(T, GetNumAttributes, () const, unsigned), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "uint get_numAttributes() const", asMETHODPR(T, GetNumAttributes, () const, unsigned), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_attributes(uint, const Variant&in) const", asMETHODPR(T, SetAttribute, (unsigned, const Variant&), bool), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "bool set_attributes(uint, const Variant&in) const", asMETHODPR(T, SetAttribute, (unsigned, const Variant&), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Variant get_attributes(uint) const", asMETHODPR(T, GetAttribute, (unsigned), Variant), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Variant get_attributes(uint) const", asMETHODPR(T, GetAttribute, (unsigned), Variant), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "const AttributeInfo& get_attributeInfos(uint) const", asFUNCTION(SerializableGetAttributeInfo), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "const AttributeInfo& get_attributeInfos(uint) const", asFUNCTION(SerializableGetAttributeInfo), asCALL_CDECL_OBJLAST);
     RegisterSubclass<Object, T>(engine, "Serializable", className);
     RegisterSubclass<Object, T>(engine, "Serializable", className);
@@ -690,6 +690,22 @@ template <class T> void RegisterTexture(asIScriptEngine* engine, const char* cla
     engine->RegisterObjectMethod(className, "bool get_dataLost() const", asMETHODPR(T, IsDataLost, () const, bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool get_dataLost() const", asMETHODPR(T, IsDataLost, () const, bool), asCALL_THISCALL);
 }
 }
 
 
+static bool UIElementLoadXML(File* file, UIElement* ptr)
+{
+    if (file)
+        return ptr->LoadXML(*file);
+    else
+        return false;
+}
+
+static bool UIElementSaveXML(File* file, UIElement* ptr)
+{
+    if (file)
+        return ptr->SaveXML(*file);
+    else
+        return false;
+}
+
 static UIElement* UIElementCreateChild(const String& typeName, const String& name, UIElement* ptr)
 static UIElement* UIElementCreateChild(const String& typeName, const String& name, UIElement* ptr)
 {
 {
     return ptr->CreateChild(ShortStringHash(typeName), name);
     return ptr->CreateChild(ShortStringHash(typeName), name);
@@ -724,6 +740,8 @@ template <class T> void RegisterUIElement(asIScriptEngine* engine, const char* c
     RegisterObjectConstructor<T>(engine, className);
     RegisterObjectConstructor<T>(engine, className);
     RegisterNamedObjectConstructor<T>(engine, className);
     RegisterNamedObjectConstructor<T>(engine, className);
     RegisterSubclass<UIElement, T>(engine, "UIElement", className);
     RegisterSubclass<UIElement, T>(engine, "UIElement", className);
+    engine->RegisterObjectMethod(className, "bool LoadXML(File@+)", asFUNCTION(UIElementLoadXML), 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(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);
     engine->RegisterObjectMethod(className, "void SetStyle(XMLFile@+, const String&in)", asMETHODPR(T, SetStyle, (XMLFile*, const String&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetStyleAuto(XMLFile@+)", asMETHODPR(T, SetStyleAuto, (XMLFile*), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetStyleAuto(XMLFile@+)", asMETHODPR(T, SetStyleAuto, (XMLFile*), void), asCALL_THISCALL);

+ 2 - 0
Engine/UI/Text.cpp

@@ -85,6 +85,8 @@ void Text::RegisterObject(Context* context)
 
 
 void Text::ApplyAttributes()
 void Text::ApplyAttributes()
 {
 {
+    UIElement::ApplyAttributes();
+    
     fontSize_ = Max(fontSize_, 1);
     fontSize_ = Max(fontSize_, 1);
     ValidateSelection();
     ValidateSelection();
     UpdateText();
     UpdateText();

+ 98 - 0
Engine/UI/UIElement.cpp

@@ -202,6 +202,84 @@ void UIElement::ApplyAttributes()
     }
     }
 }
 }
 
 
+bool UIElement::LoadXML(const XMLElement& source)
+{
+    if (!Serializable::LoadXML(source))
+        return false;
+    
+    // Attributes can be applied immediately, as there are no element reference attributes
+    ApplyAttributes();
+    
+    unsigned nextInternalChild = 0;
+    
+    // Load child elements. Internal elements are not to be created as they already exist
+    XMLElement childElem = source.GetChild("node");
+    while (childElem)
+    {
+        bool internalElem = childElem.GetBool("internal");
+        String typeName = childElem.GetAttribute("type");
+        UIElement* child = 0;
+        
+        if (!internalElem)
+        {
+            child = CreateChild(ShortStringHash(typeName));
+            if (!child)
+                return false;
+        }
+        else
+        {
+            for (unsigned i = nextInternalChild; i < children_.Size(); ++i)
+            {
+                if (children_[i]->IsInternal() && children_[i]->GetTypeName() == typeName)
+                {
+                    child = children_[i];
+                    nextInternalChild = i + 1;
+                    break;
+                }
+            }
+        }
+        
+        if (child)
+        {
+            if (!child->LoadXML(childElem))
+                return false;
+        }
+        else
+            LOGWARNING("Could not find matching internal child element of type " + typeName);
+        
+        childElem = childElem.GetNext();
+    }
+    
+    return true;
+}
+
+bool UIElement::SaveXML(XMLElement& dest)
+{
+    // Write type and internal flag
+    if (!dest.SetString("type", GetTypeName()))
+        return false;
+    if (internal_)
+    {
+        if (!dest.SetBool("internal", internal_))
+            return false;
+    }
+    
+    // Write attributes
+    if (!Serializable::SaveXML(dest))
+        return false;
+    
+    // Write child elements
+    for (unsigned i = 0; i < children_.Size(); ++i)
+    {
+        UIElement* element = children_[i];
+        XMLElement childElem = dest.CreateChild("element");
+        if (!element->SaveXML(childElem))
+            return false;
+    }
+    
+    return true;
+}
+
 void UIElement::SetStyle(const XMLElement& element)
 void UIElement::SetStyle(const XMLElement& element)
 {
 {
     if (element.HasAttribute("name"))
     if (element.HasAttribute("name"))
@@ -374,6 +452,26 @@ void UIElement::OnResize()
 {
 {
 }
 }
 
 
+
+bool UIElement::LoadXML(Deserializer& source)
+{
+    SharedPtr<XMLFile> xml(new XMLFile(context_));
+    if (!xml->Load(source))
+        return false;
+    
+    return LoadXML(xml->GetRoot());
+}
+
+bool UIElement::SaveXML(Serializer& dest)
+{
+    SharedPtr<XMLFile> xml(new XMLFile(context_));
+    XMLElement rootElem = xml->CreateRoot("element");
+    if (!SaveXML(rootElem))
+        return false;
+    
+    return xml->Save(dest);
+}
+
 void UIElement::SetName(const String& name)
 void UIElement::SetName(const String& name)
 {
 {
     name_ = name;
     name_ = name;

+ 9 - 0
Engine/UI/UIElement.h

@@ -115,6 +115,10 @@ public:
     
     
     /// Apply attribute changes that can not be applied immediately.
     /// Apply attribute changes that can not be applied immediately.
     virtual void ApplyAttributes();
     virtual void ApplyAttributes();
+    /// Load from XML data. Return true if successful.
+    virtual bool LoadXML(const XMLElement& source);
+    /// Save as XML data. Return true if successful.
+    virtual bool SaveXML(XMLElement& dest);
     /// Set UI element style from XML data.
     /// Set UI element style from XML data.
     virtual void SetStyle(const XMLElement& element);
     virtual void SetStyle(const XMLElement& element);
     /// Perform UI element update.
     /// Perform UI element update.
@@ -145,6 +149,11 @@ public:
     /// React to resize.
     /// React to resize.
     virtual void OnResize();
     virtual void OnResize();
     
     
+    /// Load from an XML file. Return true if successful.
+    bool LoadXML(Deserializer& source);
+    /// Save to an XML file. Return true if successful.
+    bool SaveXML(Serializer& dest);
+    
     /// Set name.
     /// Set name.
     void SetName(const String& name);
     void SetName(const String& name);
     /// Set position.
     /// Set position.