From 4d9407e4e9087307e2e6a0bde2caf14705443990 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 2 Jun 2025 11:03:16 +0200 Subject: [PATCH] Merge code on properties objects locking to use the same path for prefab and scene properties panels --- .../CustomEditors/CustomEditorPresenter.cs | 11 +++++++ .../CustomEditors/Dedicated/ActorEditor.cs | 33 ++++++------------- .../Windows/Assets/BehaviorTreeWindow.cs | 6 ++++ .../Windows/Assets/PrefabWindow.Selection.cs | 2 +- Source/Editor/Windows/Assets/PrefabWindow.cs | 2 +- Source/Editor/Windows/PropertiesWindow.cs | 8 ++--- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Source/Editor/CustomEditors/CustomEditorPresenter.cs b/Source/Editor/CustomEditors/CustomEditorPresenter.cs index a518d92a1..1030abfda 100644 --- a/Source/Editor/CustomEditors/CustomEditorPresenter.cs +++ b/Source/Editor/CustomEditors/CustomEditorPresenter.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; +using FlaxEditor.SceneGraph; using FlaxEditor.Scripting; using FlaxEngine; using FlaxEngine.GUI; @@ -52,6 +53,16 @@ namespace FlaxEditor.CustomEditors /// /// The nodes to select public void Select(List nodes); + + /// + /// Gets the current selection. + /// + public List Selection { get; } + + /// + /// Indication of if the properties window is locked on specific objects. + /// + public bool LockSelection { get; set; } } /// diff --git a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs index 0c17cf9fa..98eeb881b 100644 --- a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs @@ -132,35 +132,22 @@ namespace FlaxEditor.CustomEditors.Dedicated var actor = (Actor)Values[0]; var scriptType = TypeUtils.GetType(actor.TypeName); var item = scriptType.ContentItem; - if (Presenter.Owner is PropertiesWindow propertiesWindow) + if (Presenter.Owner != null) { - var lockButton = cm.AddButton(propertiesWindow.LockObjects ? "Unlock" : "Lock"); + var lockButton = cm.AddButton(Presenter.Owner.LockSelection ? "Unlock" : "Lock"); lockButton.ButtonClicked += button => { - propertiesWindow.LockObjects = !propertiesWindow.LockObjects; + var owner = Presenter?.Owner; + if (owner == null) + return; + owner.LockSelection = !owner.LockSelection; // Reselect current selection - if (!propertiesWindow.LockObjects && Editor.Instance.SceneEditing.SelectionCount > 0) + if (!owner.LockSelection && owner.Selection.Count > 0) { - var cachedSelection = Editor.Instance.SceneEditing.Selection.ToArray(); - Editor.Instance.SceneEditing.Select(null); - Editor.Instance.SceneEditing.Select(cachedSelection); - } - }; - } - else if (Presenter.Owner is PrefabWindow prefabWindow) - { - var lockButton = cm.AddButton(prefabWindow.LockSelectedObjects ? "Unlock" : "Lock"); - lockButton.ButtonClicked += button => - { - prefabWindow.LockSelectedObjects = !prefabWindow.LockSelectedObjects; - - // Reselect current selection - if (!prefabWindow.LockSelectedObjects && prefabWindow.Selection.Count > 0) - { - var cachedSelection = prefabWindow.Selection.ToList(); - prefabWindow.Select(null); - prefabWindow.Select(cachedSelection); + var cachedSelection = owner.Selection.ToList(); + owner.Select(null); + owner.Select(cachedSelection); } }; } diff --git a/Source/Editor/Windows/Assets/BehaviorTreeWindow.cs b/Source/Editor/Windows/Assets/BehaviorTreeWindow.cs index 2fd71d860..2b86664f2 100644 --- a/Source/Editor/Windows/Assets/BehaviorTreeWindow.cs +++ b/Source/Editor/Windows/Assets/BehaviorTreeWindow.cs @@ -635,5 +635,11 @@ namespace FlaxEditor.Windows.Assets public void Select(List nodes) { } + + /// + public List Selection => new List(); + + /// + public bool LockSelection { get; set; } } } diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs b/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs index f6d3f1669..03e2a9652 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs @@ -51,7 +51,7 @@ namespace FlaxEditor.Windows.Assets /// The selection before the change. public void OnSelectionChanged(SceneGraphNode[] before) { - if (LockSelectedObjects) + if (LockSelection) return; Undo.AddAction(new SelectionChangeAction(before, Selection.ToArray(), OnSelectionUndo)); diff --git a/Source/Editor/Windows/Assets/PrefabWindow.cs b/Source/Editor/Windows/Assets/PrefabWindow.cs index 1b2ca48bc..44c21d863 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.cs @@ -78,7 +78,7 @@ namespace FlaxEditor.Windows.Assets /// /// Indication of if the prefab window selection is locked on specific objects. /// - public bool LockSelectedObjects + public bool LockSelection { get => _lockSelection; set diff --git a/Source/Editor/Windows/PropertiesWindow.cs b/Source/Editor/Windows/PropertiesWindow.cs index 5ca2d3f53..e90003038 100644 --- a/Source/Editor/Windows/PropertiesWindow.cs +++ b/Source/Editor/Windows/PropertiesWindow.cs @@ -45,7 +45,7 @@ namespace FlaxEditor.Windows /// /// Indication of if the properties window is locked on specific objects. /// - public bool LockObjects + public bool LockSelection { get => _lockObjects; set @@ -87,9 +87,9 @@ namespace FlaxEditor.Windows if (Level.ScenesCount > 1) return; _actorScrollValues.Clear(); - if (LockObjects) + if (LockSelection) { - LockObjects = false; + LockSelection = false; Presenter.Deselect(); } } @@ -122,7 +122,7 @@ namespace FlaxEditor.Windows private void OnSelectionChanged() { - if (LockObjects) + if (LockSelection) return; // Update selected objects