From 4e2f0cd22cf910ed8abe3151f77d71ca23c2408b Mon Sep 17 00:00:00 2001
From: whocares77 <97740209+whocares77@users.noreply.github.com>
Date: Tue, 19 Dec 2023 11:02:18 +0300
Subject: [PATCH 1/2] Added "Create parent for selected actors" context menu
button
---
Source/Editor/Modules/SceneEditingModule.cs | 32 +++++++++++++++++++
Source/Editor/Modules/UIModule.cs | 4 +++
.../Windows/SceneTreeWindow.ContextMenu.cs | 7 ++++
Source/Editor/Windows/SceneTreeWindow.cs | 2 ++
4 files changed, 45 insertions(+)
diff --git a/Source/Editor/Modules/SceneEditingModule.cs b/Source/Editor/Modules/SceneEditingModule.cs
index 970ca8e99..3b982d7ad 100644
--- a/Source/Editor/Modules/SceneEditingModule.cs
+++ b/Source/Editor/Modules/SceneEditingModule.cs
@@ -534,6 +534,38 @@ namespace FlaxEditor.Modules
Delete();
}
+ ///
+ /// Create parent for selected actors.
+ ///
+ public void CreateParentForSelectedActors()
+ {
+ Actor actor = new EmptyActor();
+ Editor.SceneEditing.Spawn(actor, null, false);
+ List selection = Editor.SceneEditing.Selection;
+ for (int i = 0; i < selection.Count; i++)
+ {
+ if (selection[i] is ActorNode node)
+ {
+ if (node.ParentNode != node.ParentScene) // if parent node is not Scene
+ {
+ if (selection.Contains(node.ParentNode))
+ {
+ return; // if parent and child nodes selected together, don't touch child nodes
+ }
+ else
+ { // put created node as child of the Parent Node of node
+ int parentOrder = node.Actor.OrderInParent;
+ actor.Parent = node.Actor.Parent;
+ actor.OrderInParent = parentOrder;
+ }
+ }
+ node.Actor.Parent = actor;
+ }
+ }
+ Editor.SceneEditing.Select(actor);
+ Editor.Scene.GetActorNode(actor).TreeNode.StartRenaming(Editor.Windows.SceneWin, Editor.Windows.SceneWin.SceneTreePanel);
+ }
+
///
/// Duplicates the selected objects. Supports undo/redo.
///
diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs
index 3386d411c..7920d5de4 100644
--- a/Source/Editor/Modules/UIModule.cs
+++ b/Source/Editor/Modules/UIModule.cs
@@ -50,6 +50,7 @@ namespace FlaxEditor.Modules
private ContextMenuButton _menuEditCut;
private ContextMenuButton _menuEditCopy;
private ContextMenuButton _menuEditPaste;
+ private ContextMenuButton _menuCreateParentForSelectedActors;
private ContextMenuButton _menuEditDelete;
private ContextMenuButton _menuEditDuplicate;
private ContextMenuButton _menuEditSelectAll;
@@ -549,6 +550,8 @@ namespace FlaxEditor.Modules
_menuEditCopy = cm.AddButton("Copy", inputOptions.Copy, Editor.SceneEditing.Copy);
_menuEditPaste = cm.AddButton("Paste", inputOptions.Paste, Editor.SceneEditing.Paste);
cm.AddSeparator();
+ _menuCreateParentForSelectedActors = cm.AddButton("Create parent for selected actors", Editor.SceneEditing.CreateParentForSelectedActors);
+ cm.AddSeparator();
_menuEditDelete = cm.AddButton("Delete", inputOptions.Delete, Editor.SceneEditing.Delete);
_menuEditDuplicate = cm.AddButton("Duplicate", inputOptions.Duplicate, Editor.SceneEditing.Duplicate);
cm.AddSeparator();
@@ -858,6 +861,7 @@ namespace FlaxEditor.Modules
_menuEditCut.Enabled = hasSthSelected;
_menuEditCopy.Enabled = hasSthSelected;
_menuEditPaste.Enabled = canEditScene;
+ _menuCreateParentForSelectedActors.Enabled = canEditScene && hasSthSelected;
_menuEditDelete.Enabled = hasSthSelected;
_menuEditDuplicate.Enabled = hasSthSelected;
_menuEditSelectAll.Enabled = Level.IsAnySceneLoaded;
diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
index 0c8e0f283..fa4abfeca 100644
--- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
+++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
@@ -132,6 +132,13 @@ namespace FlaxEditor.Windows
b = contextMenu.AddButton("Cut", inputOptions.Cut, Editor.SceneEditing.Cut);
b.Enabled = canEditScene;
+ // Create a new hierarchy from selected actors
+
+ contextMenu.AddSeparator();
+
+ b = contextMenu.AddButton("Create parent for selected actors", Editor.SceneEditing.CreateParentForSelectedActors);
+ b.Enabled = canEditScene && hasSthSelected;
+
// Prefab options
contextMenu.AddSeparator();
diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs
index 63ba7b960..e4af43dee 100644
--- a/Source/Editor/Windows/SceneTreeWindow.cs
+++ b/Source/Editor/Windows/SceneTreeWindow.cs
@@ -23,6 +23,8 @@ namespace FlaxEditor.Windows
///
public partial class SceneTreeWindow : SceneEditorWindow
{
+ public Panel SceneTreePanel => _sceneTreePanel;
+
private TextBox _searchBox;
private Tree _tree;
private Panel _sceneTreePanel;
From 5e218c8da92b942e18849f3f0c62596c0214cc82 Mon Sep 17 00:00:00 2001
From: Wojtek Figat
Date: Sun, 18 Feb 2024 00:03:27 +0100
Subject: [PATCH 2/2] Improve #2100 and fix undo
---
Source/Editor/Modules/SceneEditingModule.cs | 21 +++++++++++--------
Source/Editor/Modules/UIModule.cs | 4 +---
.../Windows/SceneTreeWindow.ContextMenu.cs | 6 +-----
3 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/Source/Editor/Modules/SceneEditingModule.cs b/Source/Editor/Modules/SceneEditingModule.cs
index 3b982d7ad..35b85bfa8 100644
--- a/Source/Editor/Modules/SceneEditingModule.cs
+++ b/Source/Editor/Modules/SceneEditingModule.cs
@@ -542,24 +542,27 @@ namespace FlaxEditor.Modules
Actor actor = new EmptyActor();
Editor.SceneEditing.Spawn(actor, null, false);
List selection = Editor.SceneEditing.Selection;
- for (int i = 0; i < selection.Count; i++)
+ var actors = selection.Where(x => x is ActorNode).Select(x => ((ActorNode)x).Actor);
+ using (new UndoMultiBlock(Undo, actors, "Reparent actors"))
{
- if (selection[i] is ActorNode node)
+ for (int i = 0; i < selection.Count; i++)
{
- if (node.ParentNode != node.ParentScene) // if parent node is not Scene
+ if (selection[i] is ActorNode node)
{
- if (selection.Contains(node.ParentNode))
+ if (node.ParentNode != node.ParentScene) // If parent node is not a scene
{
- return; // if parent and child nodes selected together, don't touch child nodes
- }
- else
- { // put created node as child of the Parent Node of node
+ if (selection.Contains(node.ParentNode))
+ {
+ return; // If parent and child nodes selected together, don't touch child nodes
+ }
+
+ // Put created node as child of the Parent Node of node
int parentOrder = node.Actor.OrderInParent;
actor.Parent = node.Actor.Parent;
actor.OrderInParent = parentOrder;
}
+ node.Actor.Parent = actor;
}
- node.Actor.Parent = actor;
}
}
Editor.SceneEditing.Select(actor);
diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs
index 7920d5de4..4537d732e 100644
--- a/Source/Editor/Modules/UIModule.cs
+++ b/Source/Editor/Modules/UIModule.cs
@@ -549,13 +549,11 @@ namespace FlaxEditor.Modules
_menuEditCut = cm.AddButton("Cut", inputOptions.Cut, Editor.SceneEditing.Cut);
_menuEditCopy = cm.AddButton("Copy", inputOptions.Copy, Editor.SceneEditing.Copy);
_menuEditPaste = cm.AddButton("Paste", inputOptions.Paste, Editor.SceneEditing.Paste);
- cm.AddSeparator();
- _menuCreateParentForSelectedActors = cm.AddButton("Create parent for selected actors", Editor.SceneEditing.CreateParentForSelectedActors);
- cm.AddSeparator();
_menuEditDelete = cm.AddButton("Delete", inputOptions.Delete, Editor.SceneEditing.Delete);
_menuEditDuplicate = cm.AddButton("Duplicate", inputOptions.Duplicate, Editor.SceneEditing.Duplicate);
cm.AddSeparator();
_menuEditSelectAll = cm.AddButton("Select all", inputOptions.SelectAll, Editor.SceneEditing.SelectAllScenes);
+ _menuCreateParentForSelectedActors = cm.AddButton("Create parent for selected actors", Editor.SceneEditing.CreateParentForSelectedActors);
_menuEditFind = cm.AddButton("Find", inputOptions.Search, Editor.Windows.SceneWin.Search);
cm.AddSeparator();
cm.AddButton("Game Settings", () =>
diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
index fa4abfeca..abad36829 100644
--- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
+++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
@@ -132,17 +132,13 @@ namespace FlaxEditor.Windows
b = contextMenu.AddButton("Cut", inputOptions.Cut, Editor.SceneEditing.Cut);
b.Enabled = canEditScene;
- // Create a new hierarchy from selected actors
+ // Create option
contextMenu.AddSeparator();
b = contextMenu.AddButton("Create parent for selected actors", Editor.SceneEditing.CreateParentForSelectedActors);
b.Enabled = canEditScene && hasSthSelected;
- // Prefab options
-
- contextMenu.AddSeparator();
-
b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab);
b.Enabled = isSingleActorSelected &&
((ActorNode)Editor.SceneEditing.Selection[0]).CanCreatePrefab &&