// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using FlaxEditor.SceneGraph;
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.Windows
{
///
/// Shared interface for scene editing utilities.
///
public interface ISceneContextWindow
{
///
/// Opends popup for renaming selected objects.
///
void RenameSelection();
///
/// Focuses selected objects.
///
void FocusSelection();
}
///
/// Base class for editor windows dedicated to scene editing.
///
///
public abstract class SceneEditorWindow : EditorWindow, ISceneContextWindow
{
///
/// Initializes a new instance of the class.
///
/// The editor.
/// True if hide window on closing, otherwise it will be destroyed.
/// The scroll bars.
protected SceneEditorWindow(Editor editor, bool hideOnClose, ScrollBars scrollBars)
: base(editor, hideOnClose, scrollBars)
{
FlaxEditor.Utilities.Utils.SetupCommonInputActions(this);
}
///
public void FocusSelection()
{
Editor.Windows.EditWin.Viewport.FocusSelection();
}
///
public void RenameSelection()
{
var selection = Editor.SceneEditing.Selection;
var selectionCount = selection.Count;
// Show a window with options to rename multiple actors.
if (selectionCount > 1)
{
var selectedActors = new Actor[selectionCount];
for (int i = 0; i < selectionCount; i++)
if (selection[i] is ActorNode actorNode)
selectedActors[i] = actorNode.Actor;
RenameWindow.Show(selectedActors, Editor);
return;
}
if (selectionCount != 0 && selection[0] is ActorNode actor)
{
Editor.SceneEditing.Select(actor);
var sceneWindow = Editor.Windows.SceneWin;
actor.TreeNode.StartRenaming(sceneWindow, sceneWindow.SceneTreePanel);
}
}
}
}