Browse Source

Add feature to parent selected nodes into last selected node

Add feature to parent selected nodes into last selected node
Standart key mode - U-key
Blender key mode - P + Ctrl
MonkeyFirst 10 years ago
parent
commit
c9910c8c96

+ 1 - 0
bin/Data/Scripts/Editor/EditorHierarchyWindow.as

@@ -497,6 +497,7 @@ void SelectNode(Node@ node, bool multiselect)
         return;
         return;
     }
     }
 
 
+    lastSelectedNode = node;
     uint index = GetListIndex(node);
     uint index = GetListIndex(node);
     uint numItems = hierarchyList.numItems;
     uint numItems = hierarchyList.numItems;
 
 

+ 49 - 0
bin/Data/Scripts/Editor/EditorScene.as

@@ -18,6 +18,7 @@ CreateMode instantiateMode = REPLICATED;
 bool sceneModified = false;
 bool sceneModified = false;
 bool runUpdate = false;
 bool runUpdate = false;
 
 
+Node@ lastSelectedNode;
 Array<Node@> selectedNodes;
 Array<Node@> selectedNodes;
 Array<Component@> selectedComponents;
 Array<Component@> selectedComponents;
 Node@ editNode;
 Node@ editNode;
@@ -766,6 +767,54 @@ bool SceneUnparent()
     return true;
     return true;
 }
 }
 
 
+bool NodesParentToLastSelected()
+{
+    if (lastSelectedNode is null)
+        return false;
+        
+    if (!CheckHierarchyWindowFocus() || !selectedComponents.empty || selectedNodes.empty)
+        return false;
+
+    ui.cursor.shape = CS_BUSY;
+
+    // Group for storing undo actions
+    EditActionGroup group;
+
+    // Parent selected nodes to root
+    Array<Node@> changedNodes;
+    
+    // Find new parent node it selected last
+    Node@ lastNode = lastSelectedNode;
+    
+    for (uint i = 0; i < selectedNodes.length; ++i)
+    {
+        
+        Node@ sourceNode = selectedNodes[i];
+        if ( sourceNode.id == lastNode.id)
+            continue; // Skip last node it is parent
+        
+        if (sourceNode.parent.id == lastNode.id)
+            continue; // Root or already parented to root
+
+        // Perform the reparenting, continue loop even if action fails
+        ReparentNodeAction action;
+        action.Define(sourceNode, lastNode);
+        group.actions.Push(action);
+
+        SceneChangeParent(sourceNode, lastNode, false);
+        changedNodes.Push(sourceNode);
+    }
+
+    // Reselect the changed nodes at their new position in the list
+    for (uint i = 0; i < changedNodes.length; ++i)
+        hierarchyList.AddSelection(GetListIndex(changedNodes[i]));
+
+    SaveEditActionGroup(group);
+    SetSceneModified();
+
+    return true;
+}
+
 bool SceneToggleEnable()
 bool SceneToggleEnable()
 {
 {
     if (!CheckHierarchyWindowFocus())
     if (!CheckHierarchyWindowFocus())

+ 12 - 2
bin/Data/Scripts/Editor/EditorUI.as

@@ -367,9 +367,19 @@ void CreateMenuBar()
         else if ( hotKeyMode == HOT_KEYS_MODE_BLENDER )
         else if ( hotKeyMode == HOT_KEYS_MODE_BLENDER )
             popup.AddChild(CreateMenuItem("Unparent", @SceneUnparent, 'P', QUAL_ALT));
             popup.AddChild(CreateMenuItem("Unparent", @SceneUnparent, 'P', QUAL_ALT));
 
 
-        
+        if ( hotKeyMode == HOT_KEYS_MODE_STANDART )
+            popup.AddChild(CreateMenuItem("Parent to last", @NodesParentToLastSelected, 'U'));
+        else if ( hotKeyMode == HOT_KEYS_MODE_BLENDER )
+            popup.AddChild(CreateMenuItem("Parent to last", @NodesParentToLastSelected, 'P', QUAL_CTRL));
+
         CreateChildDivider(popup);
         CreateChildDivider(popup);
-        popup.AddChild(CreateMenuItem("Toggle update", @ToggleSceneUpdate, 'P', QUAL_CTRL));
+        
+        if ( hotKeyMode == HOT_KEYS_MODE_STANDART )
+            popup.AddChild(CreateMenuItem("Toggle update", @ToggleSceneUpdate, 'P', QUAL_CTRL));
+        //else if ( hotKeyMode == HOT_KEYS_MODE_BLENDER )
+        //    popup.AddChild(CreateMenuItem("Toggle update", @ToggleSceneUpdate, 'P', QUAL_CTRL));
+        
+        
         popup.AddChild(CreateMenuItem("Stop test animation", @StopTestAnimation));
         popup.AddChild(CreateMenuItem("Stop test animation", @StopTestAnimation));
         CreateChildDivider(popup);
         CreateChildDivider(popup);
         popup.AddChild(CreateMenuItem("Rebuild navigation data", @SceneRebuildNavigation));
         popup.AddChild(CreateMenuItem("Rebuild navigation data", @SceneRebuildNavigation));