Add IPresenterOwner to editor Custom Editor for more context and advanced interactions
This commit is contained in:
@@ -37,6 +37,23 @@ namespace FlaxEditor.CustomEditors
|
||||
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>
|
||||
/// Main class for Custom Editors used to present selected objects properties and allow to modify them.
|
||||
/// </summary>
|
||||
@@ -254,7 +271,7 @@ namespace FlaxEditor.CustomEditors
|
||||
/// <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.
|
||||
/// </summary>
|
||||
public object Owner;
|
||||
public IPresenterOwner Owner;
|
||||
|
||||
/// <summary>
|
||||
/// 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="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>
|
||||
public CustomEditorPresenter(Undo undo, string noSelectionText = null, object owner = null)
|
||||
public CustomEditorPresenter(Undo undo, string noSelectionText = null, IPresenterOwner owner = null)
|
||||
{
|
||||
Undo = undo;
|
||||
Owner = owner;
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
grid.Button("Remove bone").Button.ButtonClicked += OnRemoveBone;
|
||||
}
|
||||
|
||||
if (Presenter.Owner is Windows.PropertiesWindow || Presenter.Owner is Windows.Assets.PrefabWindow)
|
||||
if (Presenter.Owner != null)
|
||||
{
|
||||
// Selection
|
||||
var grid = editorGroup.CustomContainer<UniformGridPanel>();
|
||||
@@ -309,10 +309,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
if (node != null)
|
||||
selection.Add(node);
|
||||
}
|
||||
if (Presenter.Owner is Windows.PropertiesWindow propertiesWindow)
|
||||
propertiesWindow.Editor.SceneEditing.Select(selection);
|
||||
else if (Presenter.Owner is Windows.Assets.PrefabWindow prefabWindow)
|
||||
prefabWindow.Select(selection);
|
||||
Presenter.Owner.Select(selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
/// </summary>
|
||||
/// <seealso cref="Prefab" />
|
||||
/// <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 _split2;
|
||||
@@ -520,5 +520,8 @@ namespace FlaxEditor.Windows.Assets
|
||||
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public EditorViewport PresenterViewport => _viewport;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using FlaxEditor.CustomEditors;
|
||||
using FlaxEditor.SceneGraph;
|
||||
using FlaxEditor.Viewport;
|
||||
using FlaxEngine.GUI;
|
||||
|
||||
namespace FlaxEditor.Windows
|
||||
@@ -13,7 +15,7 @@ namespace FlaxEditor.Windows
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Windows.EditorWindow" />
|
||||
/// <seealso cref="FlaxEditor.Windows.SceneEditorWindow" />
|
||||
public class PropertiesWindow : SceneEditorWindow
|
||||
public class PropertiesWindow : SceneEditorWindow, IPresenterOwner
|
||||
{
|
||||
private IEnumerable<object> undoRecordObjects;
|
||||
|
||||
@@ -82,5 +84,14 @@ namespace FlaxEditor.Windows
|
||||
if (bool.TryParse(node.GetAttribute("UIPivotRelative"), out value1))
|
||||
UIPivotRelative = value1;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public EditorViewport PresenterViewport => Editor.Windows.EditWin.Viewport;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Select(List<SceneGraphNode> nodes)
|
||||
{
|
||||
Editor.SceneEditing.Select(nodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user