Просмотр исходного кода

Fixed a few issues in Editor: reselect the nodes back after unparenting; correct the child components and nodes insertion index after unparenting or dragdropfinishing; removed duplicate call to update node attributes.

Wei Tjong Yao 13 лет назад
Родитель
Сommit
141ef101a9
2 измененных файлов с 33 добавлено и 25 удалено
  1. 21 8
      Bin/Data/Scripts/Editor/EditorScene.as
  2. 12 17
      Bin/Data/Scripts/Editor/EditorSceneWindow.as

+ 21 - 8
Bin/Data/Scripts/Editor/EditorScene.as

@@ -442,21 +442,34 @@ void SceneUnparent()
         return;
 
     // Parent selected nodes to root
+    Array<Node@> changedNodes;
     for (uint i = 0; i < selectedNodes.length; ++i)
     {
         Node@ sourceNode = selectedNodes[i];
         if (sourceNode.parent is null || sourceNode.parent is editorScene)
             continue; // Root or already parented to root
 
-        Node@ targetNode = editorScene;
-
-        // Perform the reparenting
-        BeginModify(targetNode.id);
-        BeginModify(sourceNode.id);
-        sourceNode.parent = targetNode;
-        EndModify(sourceNode.id);
-        EndModify(targetNode.id);
+        // Perform the reparenting, continue loop even if action fails
+        SceneChangeParent(sourceNode, editorScene);
+        changedNodes.Push(sourceNode);
     }
+
+    // Reselect the changed nodes at their new position in the list
+    for (uint i = 0; i < changedNodes.length; ++i)
+        hierarchyList.AddSelection(GetNodeListIndex(changedNodes[i]));
+}
+
+bool SceneChangeParent(Node@ sourceNode, Node@ targetNode)
+{
+    // Perform the reparenting
+    BeginModify(targetNode.id);
+    BeginModify(sourceNode.id);
+    sourceNode.parent = targetNode;
+    EndModify(sourceNode.id);
+    EndModify(targetNode.id);
+    
+    // Return true if success
+    return sourceNode.parent is targetNode;
 }
 
 void SceneResetPosition()

+ 12 - 17
Bin/Data/Scripts/Editor/EditorSceneWindow.as

@@ -120,7 +120,7 @@ void UpdateSceneWindow()
 }
 
 uint UpdateSceneWindowNode(uint itemIndex, Node@ node, UIElement@ parentItem)
-{  
+{
     // Whenever we're updating, disable layout update to optimize speed
     hierarchyList.contentElement.DisableLayoutUpdate();
 
@@ -158,7 +158,13 @@ uint UpdateSceneWindowNode(uint itemIndex, Node@ node, UIElement@ parentItem)
         icon.color = Color(1, 0, 0);
     }
 
-    hierarchyList.InsertItem(itemIndex++, text, parentItem);
+    hierarchyList.InsertItem(itemIndex, text, parentItem);
+
+    // Advance the index for the child components and/or nodes
+    if (itemIndex == M_MAX_UNSIGNED)
+        itemIndex = hierarchyList.numItems;
+    else
+        ++itemIndex;
 
     // Get the indent level after the item is inserted
     icon.indent = text.indent - 1;
@@ -168,8 +174,7 @@ uint UpdateSceneWindowNode(uint itemIndex, Node@ node, UIElement@ parentItem)
     for (uint i = 0; i < node.numComponents; ++i)
     {
         Component@ component = node.components[i];
-        AddComponentToSceneWindow(component, itemIndex, text);
-        ++itemIndex;
+        AddComponentToSceneWindow(component, itemIndex++, text);
     }
 
     // Then update child nodes recursively
@@ -598,21 +603,11 @@ void HandleDragDropFinish(StringHash eventType, VariantMap& eventData)
         targetNode = editorScene;
 
     // Perform the reparenting
-    BeginModify(targetNode.id);
-    BeginModify(sourceNode.id);
-    sourceNode.parent = targetNode;
-    EndModify(sourceNode.id);
-    EndModify(targetNode.id);
-
-    // Verify success
-    if (sourceNode.parent !is targetNode)
+    if (!SceneChangeParent(sourceNode, targetNode))
         return;
 
-    // Node coordinates may change as a result of the drag/drop.
-    /// \todo This should also be detected via an event
-    UpdateNodeAttributes();
-
-    FocusNode(sourceNode); // Focus the node at its new position in the list
+    // Focus the node at its new position in the list which in turn should trigger a refresh in attribute inspector
+    FocusNode(sourceNode);
 }
 
 bool TestSceneWindowElements(UIElement@ source, UIElement@ target)