Browse Source

Removed unnecessary enum from undo actions.
Fixed UIElement editor targets not getting correctly retrieved.
Enable undo/redo of UIElement attributes.

Lasse Öörni 12 years ago
parent
commit
ae9fd63bac
2 changed files with 28 additions and 22 deletions
  1. 12 21
      Bin/Data/Scripts/Editor/EditorActions.as
  2. 16 1
      Bin/Data/Scripts/Editor/EditorNodeWindow.as

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

@@ -197,18 +197,10 @@ class DeleteComponentAction : EditAction
     }
 }
 
-enum AttributeTargetType
-{
-    TARGET_NODE,
-    TARGET_COMPONENT,
-    TARGET_UIELEMENT
-}
-
 class EditAttributeAction : EditAction
 {
-    // \todo How to identify UI elements for undo/redo? They don't have IDs
+    int targetType;
     uint targetID;
-    AttributeTargetType targetType;
     uint attrIndex;
     Variant undoValue;
     Variant redoValue;
@@ -221,19 +213,18 @@ class EditAttributeAction : EditAction
 
         if (cast<Node>(target) !is null)
         {
-            Node@ targetNode = target;
-            targetType = TARGET_NODE;
-            targetID = targetNode.id;
+            targetType = ITEM_NODE;
+            targetID = cast<Node>(target).id;
         }
         else if (cast<Component>(target) !is null)
         {
-            Component@ targetComponent = target;
-            targetType = TARGET_COMPONENT;
-            targetID = targetComponent.id;
+            targetType = ITEM_COMPONENT;
+            targetID = cast<Component>(target).id;
         }
-        else
+        else if (cast<UIElement>(target) !is null)
         {
-            targetType = TARGET_UIELEMENT;
+            targetType = ITEM_UI_ELEMENT;
+            targetID = cast<UIElement>(target).vars[UI_ELEMENT_ID_VAR].GetUInt();
         }
     }
 
@@ -241,12 +232,12 @@ class EditAttributeAction : EditAction
     {
         switch (targetType)
         {
-        case TARGET_NODE:
+        case ITEM_NODE:
             return editorScene.GetNode(targetID);
-        case TARGET_COMPONENT:
+        case ITEM_COMPONENT:
             return editorScene.GetComponent(targetID);
-        default:
-            break;
+        case ITEM_UI_ELEMENT:
+            return editorUIElement.GetChild(UI_ELEMENT_ID_VAR, Variant(targetID), true);
         }
         
         return null;

+ 16 - 1
Bin/Data/Scripts/Editor/EditorNodeWindow.as

@@ -13,6 +13,7 @@ bool attributesFullDirty = false;
 const String STRIKED_OUT = "——";   // Two unicode EM DASH (U+2014)
 const ShortStringHash NODE_IDS_VAR("NodeIDs");
 const ShortStringHash COMPONENT_IDS_VAR("ComponentIDs");
+const ShortStringHash UI_ELEMENT_IDS_VAR("UIElementIDs");
 
 uint nodeContainerIndex = M_MAX_UNSIGNED;
 uint componentContainerStartIndex = 0;
@@ -346,7 +347,7 @@ void SetAttributeEditorID(UIElement@ attrEdit, Array<Serializable@>@ serializabl
         {
             for (uint i = 0; i < serializables.length; ++i)
                 ids.Push(cast<UIElement>(serializables[i]).GetVar(UI_ELEMENT_ID_VAR));
-            attrEdit.vars[COMPONENT_IDS_VAR] = ids;
+            attrEdit.vars[UI_ELEMENT_IDS_VAR] = ids;
         }
     }
 }
@@ -378,6 +379,20 @@ Array<Serializable@>@ GetAttributeEditorTargets(UIElement@ attrEdit)
                     ret.Push(component);
             }
         }
+        else
+        {
+            variant = attrEdit.GetVar(UI_ELEMENT_IDS_VAR);
+            if (!variant.empty)
+            {
+                Array<Variant>@ ids = variant.GetVariantVector();
+                for (uint i = 0; i < ids.length; ++i)
+                {
+                    UIElement@ element = editorUIElement.GetChild(UI_ELEMENT_ID_VAR, Variant(ids[i].GetUInt()), true);
+                    if (element !is null)
+                        ret.Push(element);
+                }
+            }
+        }
     }
 
     return ret;