From 23f4a82bbc3a9fac00fe6c070210c767dde98620 Mon Sep 17 00:00:00 2001 From: davevanegdom Date: Fri, 22 Sep 2023 18:31:54 +0200 Subject: [PATCH 1/3] Double click actions + open prefab ctxmenu --- Source/Editor/Modules/PrefabsModule.cs | 21 +++++++++ Source/Editor/Options/InputOptions.cs | 3 ++ .../Windows/SceneTreeWindow.ContextMenu.cs | 7 +-- Source/Editor/Windows/SceneTreeWindow.cs | 47 +++++++++++++++++++ 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Modules/PrefabsModule.cs b/Source/Editor/Modules/PrefabsModule.cs index 7b3ffebb3..b0be909fa 100644 --- a/Source/Editor/Modules/PrefabsModule.cs +++ b/Source/Editor/Modules/PrefabsModule.cs @@ -109,6 +109,27 @@ namespace FlaxEditor.Modules Editor.Windows.ContentWin.NewItem(proxy, actor, OnPrefabCreated, actor.Name, rename); } + /// + /// Open a prefab in a Prefab Editor + /// + /// Whether the prefab was successfully opened in a Prefab Editor + public bool OpenPrefab() + { + var selection = Editor.SceneEditing.Selection.Where(x => x is ActorNode actorNode && actorNode.HasPrefabLink).ToList().BuildNodesParents(); + if (selection.Count == 0 || !((ActorNode)selection[0]).Actor.HasPrefabLink) + return false; + + var prefabId = ((ActorNode)selection[0]).Actor.PrefabID; + var item = Editor.Instance.ContentDatabase.Find(prefabId); + + if(item != null) + { + Editor.Instance.ContentEditing.Open(item); + return true; + } + return false; + } + private void OnPrefabCreated(ContentItem contentItem) { if (contentItem is PrefabItem prefabItem) diff --git a/Source/Editor/Options/InputOptions.cs b/Source/Editor/Options/InputOptions.cs index e0a51622b..3df7a4be8 100644 --- a/Source/Editor/Options/InputOptions.cs +++ b/Source/Editor/Options/InputOptions.cs @@ -200,6 +200,9 @@ namespace FlaxEditor.Options [EditorDisplay("Interface"), EditorOrder(2020)] public InputBinding PreviousTab = new InputBinding(KeyboardKeys.Tab, KeyboardKeys.Control, KeyboardKeys.Shift); + [DefaultValue(Windows.SceneNodeDoubleClick.None)] + [EditorDisplay("Interface"), EditorOrder(2030)] + public Windows.SceneNodeDoubleClick DoubleClickSceneNode = Windows.SceneNodeDoubleClick.None; #endregion } } diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index e48e59f80..442a774fb 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -133,14 +133,15 @@ namespace FlaxEditor.Windows contextMenu.AddSeparator(); + ActorNode actorNode = (ActorNode)Editor.SceneEditing.Selection[0]; b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab); - b.Enabled = isSingleActorSelected && - ((ActorNode)Editor.SceneEditing.Selection[0]).CanCreatePrefab && + b.Enabled = isSingleActorSelected && actorNode.CanCreatePrefab && Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets; - bool hasPrefabLink = canEditScene && isSingleActorSelected && (Editor.SceneEditing.Selection[0] as ActorNode).HasPrefabLink; + bool hasPrefabLink = canEditScene && isSingleActorSelected && actorNode.HasPrefabLink; if (hasPrefabLink) { + contextMenu.AddButton("Open Prefab", () => Editor.Prefabs.OpenPrefab()); contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab); contextMenu.AddButton("Break Prefab Link", Editor.Prefabs.BreakLinks); } diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs index 609f98f83..57bf4dad5 100644 --- a/Source/Editor/Windows/SceneTreeWindow.cs +++ b/Source/Editor/Windows/SceneTreeWindow.cs @@ -346,6 +346,29 @@ namespace FlaxEditor.Windows return false; } + + /// + public override bool OnMouseDoubleClick(Float2 location, MouseButton button) + { + if(button == MouseButton.Left) + { + switch (Editor.Options.Options.Input.DoubleClickSceneNode) + { + case SceneNodeDoubleClick.Rename: + Rename(); + return true; + case SceneNodeDoubleClick.Focus: + Editor.Windows.EditWin.Viewport.FocusSelection(); + return true; + case SceneNodeDoubleClick.Open: + return Editor.Prefabs.OpenPrefab(); + case SceneNodeDoubleClick.None: + default: + return base.OnMouseDoubleClick(location, button); + } + } + return base.OnMouseDoubleClick(location, button); + } /// public override void OnLostFocus() @@ -459,4 +482,28 @@ namespace FlaxEditor.Windows base.OnDestroy(); } } + + /// + /// Action to perform when a Scene Node receive a double mouse click (Left) + /// + [Serializable] + public enum SceneNodeDoubleClick + { + /// + /// No action is performed + /// + None, + /// + /// Rename the Scene Node + /// + Rename, + /// + /// Focus the Scene Node object in the Scene View + /// + Focus, + /// + /// If possible, open the scene node in an associated Editor (e.g. Prefab Editor) + /// + Open + } } From 1b84f57a5bf9b78fe700f5fbf44a127fe0f331ad Mon Sep 17 00:00:00 2001 From: davevanegdom Date: Sat, 23 Sep 2023 03:24:19 +0200 Subject: [PATCH 2/3] Small optimization --- Source/Editor/Modules/PrefabsModule.cs | 15 +++++++++------ .../Editor/Windows/SceneTreeWindow.ContextMenu.cs | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Source/Editor/Modules/PrefabsModule.cs b/Source/Editor/Modules/PrefabsModule.cs index b0be909fa..e044e9767 100644 --- a/Source/Editor/Modules/PrefabsModule.cs +++ b/Source/Editor/Modules/PrefabsModule.cs @@ -113,15 +113,18 @@ namespace FlaxEditor.Modules /// Open a prefab in a Prefab Editor /// /// Whether the prefab was successfully opened in a Prefab Editor - public bool OpenPrefab() + public bool OpenPrefab(Guid prefabID = default) { - var selection = Editor.SceneEditing.Selection.Where(x => x is ActorNode actorNode && actorNode.HasPrefabLink).ToList().BuildNodesParents(); - if (selection.Count == 0 || !((ActorNode)selection[0]).Actor.HasPrefabLink) - return false; + if(prefabID == Guid.Empty) + { + var selection = Editor.SceneEditing.Selection.Where(x => x is ActorNode actorNode && actorNode.HasPrefabLink).ToList().BuildNodesParents(); + if (selection.Count == 0 || !((ActorNode)selection[0]).Actor.HasPrefabLink) + return false; - var prefabId = ((ActorNode)selection[0]).Actor.PrefabID; - var item = Editor.Instance.ContentDatabase.Find(prefabId); + prefabID = ((ActorNode)selection[0]).Actor.PrefabID; + } + var item = Editor.Instance.ContentDatabase.Find(prefabID); if(item != null) { Editor.Instance.ContentEditing.Open(item); diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index 442a774fb..5e7e2a3f8 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -141,7 +141,7 @@ namespace FlaxEditor.Windows bool hasPrefabLink = canEditScene && isSingleActorSelected && actorNode.HasPrefabLink; if (hasPrefabLink) { - contextMenu.AddButton("Open Prefab", () => Editor.Prefabs.OpenPrefab()); + contextMenu.AddButton("Open Prefab", () => Editor.Prefabs.OpenPrefab(actorNode.Actor.PrefabID)); contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab); contextMenu.AddButton("Break Prefab Link", Editor.Prefabs.BreakLinks); } From 22764f5362e867eb9e9db5130cacdf38b46f84a0 Mon Sep 17 00:00:00 2001 From: davevanegdom Date: Sat, 23 Sep 2023 23:28:59 +0200 Subject: [PATCH 3/3] Improved SceneNodeDoubleClick names --- Source/Editor/Windows/SceneTreeWindow.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs index 57bf4dad5..620deea07 100644 --- a/Source/Editor/Windows/SceneTreeWindow.cs +++ b/Source/Editor/Windows/SceneTreeWindow.cs @@ -354,13 +354,13 @@ namespace FlaxEditor.Windows { switch (Editor.Options.Options.Input.DoubleClickSceneNode) { - case SceneNodeDoubleClick.Rename: + case SceneNodeDoubleClick.RenameActor: Rename(); return true; - case SceneNodeDoubleClick.Focus: + case SceneNodeDoubleClick.FocusActor: Editor.Windows.EditWin.Viewport.FocusSelection(); return true; - case SceneNodeDoubleClick.Open: + case SceneNodeDoubleClick.OpenPrefab: return Editor.Prefabs.OpenPrefab(); case SceneNodeDoubleClick.None: default: @@ -496,14 +496,14 @@ namespace FlaxEditor.Windows /// /// Rename the Scene Node /// - Rename, + RenameActor, /// /// Focus the Scene Node object in the Scene View /// - Focus, + FocusActor, /// /// If possible, open the scene node in an associated Editor (e.g. Prefab Editor) /// - Open + OpenPrefab } }