Browse Source

Merge pull request #1080 from LumaDigital/GF_ReparentMultipleNodes

Reparent multiple nodes
JoshEngebretson 9 years ago
parent
commit
1c2c016e21
1 changed files with 40 additions and 10 deletions
  1. 40 10
      Script/AtomicEditor/ui/frames/HierarchyFrame.ts

+ 40 - 10
Script/AtomicEditor/ui/frames/HierarchyFrame.ts

@@ -39,6 +39,7 @@ class HierarchyFrame extends Atomic.UIWidget {
     search: boolean = false;
     searchEdit: Atomic.UIEditField;
     selectedNode: Atomic.Node;
+    canReparent: boolean;
 
     constructor(parent: Atomic.UIWidget) {
 
@@ -52,6 +53,8 @@ class HierarchyFrame extends Atomic.UIWidget {
 
         this.searchEdit = <Atomic.UIEditField>this.getWidget("filter");
 
+        this.canReparent = true;
+
         var hierarchycontainer = parent.getWidget("hierarchycontainer");
         hierarchycontainer.addChild(this);
 
@@ -69,15 +72,21 @@ class HierarchyFrame extends Atomic.UIWidget {
 
         this.subscribeToEvent(EditorEvents.ActiveSceneEditorChange, (data) => this.handleActiveSceneEditorChanged(data));
 
-        // handle dropping on hierarchy, moving node, dropping prefabs, etc
-        this.subscribeToEvent(this.hierList.rootList, "DragEnded", (data) => this.handleDragEnded(data));
         // on mouse up clear the list's drag object
         this.subscribeToEvent("MouseButtonUp", () => {
+            // handle dropping on hierarchy, moving node, dropping prefabs, etc
+            this.subscribeToEvent(this.hierList.rootList, "DragEnded", (data) => this.handleDragEnded(data));
+            this.hierList.rootList.dragObject = null;
+        });
 
-          this.hierList.rootList.dragObject = null;
-
+        this.subscribeToEvent("KeyDown", () => {
+            this.canReparent = false;
         });
 
+        this.subscribeToEvent("KeyUp", () => {
+            this.canReparent = true;
+        });
+        
         this.subscribeToEvent(EditorEvents.ProjectClosed, (ev) => {
             
             this.scene = null;
@@ -340,19 +349,40 @@ class HierarchyFrame extends Atomic.UIWidget {
         if (!ev.dragObject.object)
             return;
 
-        var typeName = ev.dragObject.object.typeName;
-
         var dropNode: Atomic.Node = this.scene.getNode(Number(this.hierList.hoverItemID));
 
         if (!dropNode) return;
 
-        if (typeName == "Node") {
+        var dragNodeTypeName = ev.dragObject.object.typeName;
+
+        if (!this.canReparent)
+            return;
+
+        if (dragNodeTypeName == "Node") {
 
-            var dragNode = <Atomic.Node>ev.dragObject.object;
+            if (this.sceneEditor.selection.getSelectedNodeCount() < 2) {
 
-            this.sceneEditor.reparentNode(dragNode, dropNode);
+                var dragNode = <Atomic.Node>ev.dragObject.object;
+                this.sceneEditor.reparentNode(dragNode, dropNode);
+
+            } else {
+
+                var tempSelectedList = [];
+
+                for (var i = 0; i < this.sceneEditor.selection.getSelectedNodeCount(); i++)
+                    tempSelectedList.push(this.sceneEditor.selection.getSelectedNode(i));
+
+                for (var j in tempSelectedList) {
+
+                    var tempNode = tempSelectedList[j];
+                    var typeName = tempNode.typeName;
+
+                    if (typeName == "Node")
+                        this.sceneEditor.reparentNode(tempNode, dropNode);
+                }
+            }
 
-        } else if (typeName == "Asset") {
+        } else if (dragNodeTypeName == "Asset") {
 
             var asset = <ToolCore.Asset>ev.dragObject.object;
             var newNode = asset.instantiateNode(dropNode, asset.name);