Refactor ISceneContextWindow into ISceneEditingContext with more utilities

#3257
This commit is contained in:
Wojtek Figat
2025-03-03 23:32:27 +01:00
parent e82bb639ed
commit 819ce2222d
10 changed files with 91 additions and 30 deletions

View File

@@ -41,7 +41,7 @@ namespace FlaxEditor.Modules
public override Undo Undo => Editor.Instance.Undo;
/// <inheritdoc />
public override List<SceneGraphNode> Selection => _editor.SceneEditing.Selection;
public override ISceneEditingContext SceneContext => _editor.Windows.EditWin;
}
/// <summary>

View File

@@ -0,0 +1,47 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using FlaxEditor.SceneGraph;
using FlaxEditor.Viewport;
namespace FlaxEditor
{
/// <summary>
/// Shared interface for scene editing utilities.
/// </summary>
public interface ISceneEditingContext
{
/// <summary>
/// Gets the main or last editor viewport used for scene editing within this context.
/// </summary>
EditorViewport Viewport { get; }
/// <summary>
/// Gets the list of selected scene graph nodes in the editor context.
/// </summary>
List<SceneGraphNode> Selection { get; }
/// <summary>
/// Selects the specified node.
/// </summary>
/// <param name="node">The node.</param>
/// <param name="additive">if set to <c>true</c> will use additive mode, otherwise will clear previous selection.</param>
void Select(SceneGraphNode node, bool additive = false);
/// <summary>
/// Deselects node.
/// </summary>
/// <param name="node">The node to deselect.</param>
void Deselect(SceneGraphNode node);
/// <summary>
/// Opends popup for renaming selected objects.
/// </summary>
void RenameSelection();
/// <summary>
/// Focuses selected objects.
/// </summary>
void FocusSelection();
}
}

View File

@@ -168,7 +168,14 @@ namespace FlaxEditor.SceneGraph
/// <summary>
/// Gets the list of selected scene graph nodes in the editor context.
/// [Deprecated in v1.10]
/// </summary>
public abstract List<SceneGraphNode> Selection { get; }
[Obsolete("Use SceneContext.Selection instead.")]
public List<SceneGraphNode> Selection => SceneContext.Selection;
/// <summary>
/// Gets the list of selected scene graph nodes in the editor context.
/// </summary>
public abstract ISceneEditingContext SceneContext { get; }
}
}

View File

@@ -1545,11 +1545,11 @@ namespace FlaxEditor.Utilities
return path;
}
internal static ISceneContextWindow GetSceneContext(this Control c)
internal static ISceneEditingContext GetSceneContext(this Control c)
{
while (c != null && !(c is ISceneContextWindow))
while (c != null && !(c is ISceneEditingContext))
c = c.Parent;
return c as ISceneContextWindow;
return c as ISceneEditingContext;
}
}
}

View File

@@ -10,7 +10,6 @@ using FlaxEditor.SceneGraph;
using FlaxEditor.Scripting;
using FlaxEditor.Viewport.Cameras;
using FlaxEditor.Viewport.Previews;
using FlaxEditor.Viewport.Widgets;
using FlaxEditor.Windows.Assets;
using FlaxEngine;
using FlaxEngine.GUI;

View File

@@ -41,7 +41,7 @@ namespace FlaxEditor.Windows.Assets
public override Undo Undo => _window.Undo;
/// <inheritdoc />
public override List<SceneGraphNode> Selection => _window.Selection;
public override ISceneEditingContext SceneContext => _window;
}
/// <summary>

View File

@@ -12,10 +12,7 @@ namespace FlaxEditor.Windows.Assets
{
public sealed partial class PrefabWindow
{
/// <summary>
/// The current selection (readonly).
/// </summary>
public readonly List<SceneGraphNode> Selection = new List<SceneGraphNode>();
private readonly List<SceneGraphNode> _selection = new List<SceneGraphNode>();
/// <summary>
/// Occurs when selection gets changed.

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System;
using System.Collections.Generic;
using System.Xml;
using FlaxEditor.Content;
using FlaxEditor.CustomEditors;
@@ -19,7 +20,7 @@ namespace FlaxEditor.Windows.Assets
/// </summary>
/// <seealso cref="Prefab" />
/// <seealso cref="FlaxEditor.Windows.Assets.AssetEditorWindow" />
public sealed partial class PrefabWindow : AssetEditorWindowBase<Prefab>, IPresenterOwner, ISceneContextWindow
public sealed partial class PrefabWindow : AssetEditorWindowBase<Prefab>, IPresenterOwner, ISceneEditingContext
{
private readonly SplitPanel _split1;
private readonly SplitPanel _split2;
@@ -54,6 +55,9 @@ namespace FlaxEditor.Windows.Assets
/// </summary>
public PrefabWindowViewport Viewport => _viewport;
/// <inheritdoc />
public List<SceneGraphNode> Selection => _selection;
/// <summary>
/// Gets the prefab objects properties editor.
/// </summary>
@@ -557,5 +561,8 @@ namespace FlaxEditor.Windows.Assets
/// <inheritdoc />
public EditorViewport PresenterViewport => _viewport;
/// <inheritdoc />
EditorViewport ISceneEditingContext.Viewport => Viewport;
}
}

View File

@@ -130,7 +130,7 @@ namespace FlaxEditor.Windows
/// <summary>
/// The viewport control.
/// </summary>
public readonly MainEditorGizmoViewport Viewport;
public new readonly MainEditorGizmoViewport Viewport;
/// <summary>
/// Initializes a new instance of the <see cref="EditGameWindow"/> class.

View File

@@ -1,32 +1,18 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using FlaxEditor.SceneGraph;
using FlaxEditor.Viewport;
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.Windows
{
/// <summary>
/// Shared interface for scene editing utilities.
/// </summary>
public interface ISceneContextWindow
{
/// <summary>
/// Opends popup for renaming selected objects.
/// </summary>
void RenameSelection();
/// <summary>
/// Focuses selected objects.
/// </summary>
void FocusSelection();
}
/// <summary>
/// Base class for editor windows dedicated to scene editing.
/// </summary>
/// <seealso cref="FlaxEditor.Windows.EditorWindow" />
public abstract class SceneEditorWindow : EditorWindow, ISceneContextWindow
public abstract class SceneEditorWindow : EditorWindow, ISceneEditingContext
{
/// <summary>
/// Initializes a new instance of the <see cref="SceneEditorWindow"/> class.
@@ -46,6 +32,24 @@ namespace FlaxEditor.Windows
Editor.Windows.EditWin.Viewport.FocusSelection();
}
/// <inheritdoc />
public EditorViewport Viewport => Editor.Windows.EditWin.Viewport;
/// <inheritdoc />
public List<SceneGraphNode> Selection => Editor.SceneEditing.Selection;
/// <inheritdoc />
public void Select(SceneGraphNode node, bool additive = false)
{
Editor.SceneEditing.Select(node, additive);
}
/// <inheritdoc />
public void Deselect(SceneGraphNode node)
{
Editor.SceneEditing.Deselect(node);
}
/// <inheritdoc />
public void RenameSelection()
{