Bladeren bron

Fixed duplicate ID when copying/pasting UI-elements having more than one level deep.

Wei Tjong Yao 12 jaren geleden
bovenliggende
commit
156b69e75a
2 gewijzigde bestanden met toevoegingen van 15 en 8 verwijderingen
  1. 1 1
      Bin/Data/Scripts/Editor/EditorSceneWindow.as
  2. 14 7
      Bin/Data/Scripts/Editor/EditorUIElement.as

+ 1 - 1
Bin/Data/Scripts/Editor/EditorSceneWindow.as

@@ -92,7 +92,7 @@ void ExpandCollapseHierarchy(StringHash eventType, VariantMap& eventData)
 {
     Button@ button = eventData["Element"].GetUIElement();
     bool enable = button.name == "ExpandButton";
-    CheckBox@ checkBox = cast<CheckBox>(hierarchyWindow.GetChild("AllCheckBox", true));
+    CheckBox@ checkBox = hierarchyWindow.GetChild("AllCheckBox", true);
     bool all = checkBox.checked;
     checkBox.checked = false;    // Auto-reset
 

+ 14 - 7
Bin/Data/Scripts/Editor/EditorUIElement.as

@@ -268,6 +268,17 @@ bool UIElementCopy()
     return true;
 }
 
+void ResetDuplicateID(UIElement@ element)
+{
+    // If it is a duplicate copy then the element ID need to be regenerated by resetting it now to empty
+    if (GetListIndex(element) != NO_ITEM)
+        element.vars[UI_ELEMENT_ID_VAR] = Variant();
+
+    // Perform the action recursively for child elements
+    for (uint i = 0; i < element.numChildren; ++i)
+        ResetDuplicateID(element.children[i]);
+}
+
 bool UIElementPaste()
 {
     ui.cursor.shape = CS_BUSY;
@@ -284,11 +295,7 @@ bool UIElementPaste()
         if (editUIElement.LoadXML(rootElem))
         {
             UIElement@ element = editUIElement.children[editUIElement.numChildren - 1];
-            
-            // If it is a duplicate copy then the element ID need to be regenerated by resetting it now to empty
-            if (GetListIndex(element) != NO_ITEM)
-                element.vars[UI_ELEMENT_ID_VAR] = Variant();
-            
+            ResetDuplicateID(element);
             UpdateHierarchyItem(element);
 
             // Create an undo action
@@ -299,9 +306,9 @@ bool UIElementPaste()
     }
 
     SaveEditActionGroup(group);
-    
+
     suppressUIElementChanges = false;
-    
+
     return true;
 }