Forráskód Böngészése

Added checked attribute to CheckBox.
Perform re-parenting hacks during Menu & DropDownList serialization to allow reloading the popup content.

Lasse Öörni 13 éve
szülő
commit
85c14f96f9

+ 1 - 0
Engine/UI/CheckBox.cpp

@@ -50,6 +50,7 @@ void CheckBox::RegisterObject(Context* context)
 {
 {
     context->RegisterFactory<CheckBox>();
     context->RegisterFactory<CheckBox>();
     
     
+    ACCESSOR_ATTRIBUTE(CheckBox, VAR_BOOL,"Checked", IsChecked, SetChecked, bool, true, AM_FILE);
     REF_ACCESSOR_ATTRIBUTE(CheckBox, VAR_INTVECTOR2,"Checked Image Offset", GetCheckedOffset, SetCheckedOffset, IntVector2, IntVector2::ZERO, AM_FILE);
     REF_ACCESSOR_ATTRIBUTE(CheckBox, VAR_INTVECTOR2,"Checked Image Offset", GetCheckedOffset, SetCheckedOffset, IntVector2, IntVector2::ZERO, AM_FILE);
     COPY_BASE_ATTRIBUTES(CheckBox, BorderImage);
     COPY_BASE_ATTRIBUTES(CheckBox, BorderImage);
 }
 }

+ 24 - 2
Engine/UI/DropDownList.cpp

@@ -43,7 +43,7 @@ DropDownList::DropDownList(Context* context) :
     window->SetInternal(true);
     window->SetInternal(true);
     SetPopup(window);
     SetPopup(window);
     
     
-    // Hack: parent the popup to the dropdownlist until first shown to allow loading style from XML
+    // Hack: parent the popup until first shown to allow loading style from XML
     AddChild(window);
     AddChild(window);
     window->SetVisible(false);
     window->SetVisible(false);
     
     
@@ -71,10 +71,32 @@ void DropDownList::RegisterObject(Context* context)
     ACCESSOR_ATTRIBUTE(DropDownList, VAR_BOOL, "Resize Popup", GetResizePopup, SetResizePopup, bool, false, AM_FILE);
     ACCESSOR_ATTRIBUTE(DropDownList, VAR_BOOL, "Resize Popup", GetResizePopup, SetResizePopup, bool, false, AM_FILE);
 }
 }
 
 
+bool DropDownList::SaveXML(XMLElement& dest)
+{
+    // Hack: parent the popup and the list items during serialization
+    bool popupShown = popup_ && popup_->IsVisible();
+    if (popup_)
+    {
+        InsertChild(0, popup_);
+        popup_->SetVisible(false);
+    }
+    
+    while (listView_->GetNumItems())
+        placeholder_->AddChild(listView_->GetItem(0));
+    
+    bool success = UIElement::SaveXML(dest);
+    
+    while (placeholder_->GetNumChildren())
+        listView_->AddItem(placeholder_->GetChild(0));
+    
+    ShowPopup(popupShown);
+    
+    return success;
+}
+
 void DropDownList::ApplyAttributes()
 void DropDownList::ApplyAttributes()
 {
 {
     // Hack: if the placeholder has any child elements defined, move them to the list
     // Hack: if the placeholder has any child elements defined, move them to the list
-    /// \todo This will not be serialized back to XML as expected
     while (placeholder_->GetNumChildren())
     while (placeholder_->GetNumChildren())
         AddItem(placeholder_->GetChild(0));
         AddItem(placeholder_->GetChild(0));
 }
 }

+ 2 - 0
Engine/UI/DropDownList.h

@@ -45,6 +45,8 @@ 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();
+    /// Save as XML data. Return true if successful.
+    virtual bool SaveXML(XMLElement& dest);
     /// Return UI rendering batches.
     /// Return UI rendering batches.
     virtual void GetBatches(PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, const IntRect& currentScissor);
     virtual void GetBatches(PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, const IntRect& currentScissor);
     /// React to the popup being shown.
     /// React to the popup being shown.

+ 17 - 0
Engine/UI/Menu.cpp

@@ -68,6 +68,23 @@ void Menu::OnShowPopup()
 {
 {
 }
 }
 
 
+bool Menu::SaveXML(XMLElement& dest)
+{
+    // Hack: parent the popup during serialization
+    bool popupShown = popup_ && popup_->IsVisible();
+    if (popup_)
+    {
+        InsertChild(0, popup_);
+        popup_->SetVisible(false);
+    }
+    
+    bool success = UIElement::SaveXML(dest);
+    
+    ShowPopup(popupShown);
+    
+    return success;
+}
+
 void Menu::SetPopup(UIElement* popup)
 void Menu::SetPopup(UIElement* popup)
 {
 {
     if (popup == this)
     if (popup == this)

+ 3 - 0
Engine/UI/Menu.h

@@ -41,6 +41,9 @@ public:
     /// Register object factory.
     /// Register object factory.
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
     
     
+    /// Save as XML data. Return true if successful.
+    virtual bool SaveXML(XMLElement& dest);
+    
     /// React to the popup being shown.
     /// React to the popup being shown.
     virtual void OnShowPopup();
     virtual void OnShowPopup();