Add IPresenterOwner to editor Custom Editor for more context and advanced interactions

This commit is contained in:
Wojtek Figat
2023-07-12 12:36:30 +02:00
parent 159beae8ae
commit 15b2d4e041
4 changed files with 37 additions and 9 deletions

View File

@@ -37,6 +37,23 @@ namespace FlaxEditor.CustomEditors
UseDefault = 1 << 2, UseDefault = 1 << 2,
} }
/// <summary>
/// The interface for Editor context that owns the presenter. Can be <see cref="FlaxEditor.Windows.PropertiesWindow"/> or <see cref="FlaxEditor.Windows.Assets.PrefabWindow"/> or other window/panel - custom editor scan use it for more specific features.
/// </summary>
public interface IPresenterOwner
{
/// <summary>
/// Gets the viewport linked with properties presenter (optional, null if unused).
/// </summary>
public Viewport.EditorViewport PresenterViewport { get; }
/// <summary>
/// Selects the scene objects.
/// </summary>
/// <param name="nodes">The nodes to select</param>
public void Select(List<SceneGraph.SceneGraphNode> nodes);
}
/// <summary> /// <summary>
/// Main class for Custom Editors used to present selected objects properties and allow to modify them. /// Main class for Custom Editors used to present selected objects properties and allow to modify them.
/// </summary> /// </summary>
@@ -254,7 +271,7 @@ namespace FlaxEditor.CustomEditors
/// <summary> /// <summary>
/// The Editor context that owns this presenter. Can be <see cref="FlaxEditor.Windows.PropertiesWindow"/> or <see cref="FlaxEditor.Windows.Assets.PrefabWindow"/> or other window/panel - custom editor scan use it for more specific features. /// The Editor context that owns this presenter. Can be <see cref="FlaxEditor.Windows.PropertiesWindow"/> or <see cref="FlaxEditor.Windows.Assets.PrefabWindow"/> or other window/panel - custom editor scan use it for more specific features.
/// </summary> /// </summary>
public object Owner; public IPresenterOwner Owner;
/// <summary> /// <summary>
/// Gets or sets the text to show when no object is selected. /// Gets or sets the text to show when no object is selected.
@@ -278,7 +295,7 @@ namespace FlaxEditor.CustomEditors
/// <param name="undo">The undo. It's optional.</param> /// <param name="undo">The undo. It's optional.</param>
/// <param name="noSelectionText">The custom text to display when no object is selected. Default is No selection.</param> /// <param name="noSelectionText">The custom text to display when no object is selected. Default is No selection.</param>
/// <param name="owner">The owner of the presenter.</param> /// <param name="owner">The owner of the presenter.</param>
public CustomEditorPresenter(Undo undo, string noSelectionText = null, object owner = null) public CustomEditorPresenter(Undo undo, string noSelectionText = null, IPresenterOwner owner = null)
{ {
Undo = undo; Undo = undo;
Owner = owner; Owner = owner;

View File

@@ -50,7 +50,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
grid.Button("Remove bone").Button.ButtonClicked += OnRemoveBone; grid.Button("Remove bone").Button.ButtonClicked += OnRemoveBone;
} }
if (Presenter.Owner is Windows.PropertiesWindow || Presenter.Owner is Windows.Assets.PrefabWindow) if (Presenter.Owner != null)
{ {
// Selection // Selection
var grid = editorGroup.CustomContainer<UniformGridPanel>(); var grid = editorGroup.CustomContainer<UniformGridPanel>();
@@ -309,10 +309,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
if (node != null) if (node != null)
selection.Add(node); selection.Add(node);
} }
if (Presenter.Owner is Windows.PropertiesWindow propertiesWindow) Presenter.Owner.Select(selection);
propertiesWindow.Editor.SceneEditing.Select(selection);
else if (Presenter.Owner is Windows.Assets.PrefabWindow prefabWindow)
prefabWindow.Select(selection);
} }
} }
} }

View File

@@ -19,7 +19,7 @@ namespace FlaxEditor.Windows.Assets
/// </summary> /// </summary>
/// <seealso cref="Prefab" /> /// <seealso cref="Prefab" />
/// <seealso cref="FlaxEditor.Windows.Assets.AssetEditorWindow" /> /// <seealso cref="FlaxEditor.Windows.Assets.AssetEditorWindow" />
public sealed partial class PrefabWindow : AssetEditorWindowBase<Prefab> public sealed partial class PrefabWindow : AssetEditorWindowBase<Prefab>, IPresenterOwner
{ {
private readonly SplitPanel _split1; private readonly SplitPanel _split1;
private readonly SplitPanel _split2; private readonly SplitPanel _split2;
@@ -520,5 +520,8 @@ namespace FlaxEditor.Windows.Assets
base.OnDestroy(); base.OnDestroy();
} }
/// <inheritdoc />
public EditorViewport PresenterViewport => _viewport;
} }
} }

View File

@@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml; using System.Xml;
using FlaxEditor.CustomEditors; using FlaxEditor.CustomEditors;
using FlaxEditor.SceneGraph;
using FlaxEditor.Viewport;
using FlaxEngine.GUI; using FlaxEngine.GUI;
namespace FlaxEditor.Windows namespace FlaxEditor.Windows
@@ -13,7 +15,7 @@ namespace FlaxEditor.Windows
/// </summary> /// </summary>
/// <seealso cref="FlaxEditor.Windows.EditorWindow" /> /// <seealso cref="FlaxEditor.Windows.EditorWindow" />
/// <seealso cref="FlaxEditor.Windows.SceneEditorWindow" /> /// <seealso cref="FlaxEditor.Windows.SceneEditorWindow" />
public class PropertiesWindow : SceneEditorWindow public class PropertiesWindow : SceneEditorWindow, IPresenterOwner
{ {
private IEnumerable<object> undoRecordObjects; private IEnumerable<object> undoRecordObjects;
@@ -82,5 +84,14 @@ namespace FlaxEditor.Windows
if (bool.TryParse(node.GetAttribute("UIPivotRelative"), out value1)) if (bool.TryParse(node.GetAttribute("UIPivotRelative"), out value1))
UIPivotRelative = value1; UIPivotRelative = value1;
} }
/// <inheritdoc />
public EditorViewport PresenterViewport => Editor.Windows.EditWin.Viewport;
/// <inheritdoc />
public void Select(List<SceneGraphNode> nodes)
{
Editor.SceneEditing.Select(nodes);
}
} }
} }