Refactor new scene tree double click feature to support both prefab and scene editing

#1502
This commit is contained in:
Wojtek Figat
2025-02-23 21:23:09 +01:00
parent 618027b181
commit fc4b79239b
10 changed files with 208 additions and 103 deletions

View File

@@ -96,7 +96,7 @@ namespace FlaxEditor.Windows
InputActions.Add(options => options.ScaleMode, () => Editor.MainTransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale);
InputActions.Add(options => options.FocusSelection, () => Editor.Windows.EditWin.Viewport.FocusSelection());
InputActions.Add(options => options.LockFocusSelection, () => Editor.Windows.EditWin.Viewport.LockFocusSelection());
InputActions.Add(options => options.Rename, Rename);
InputActions.Add(options => options.Rename, RenameSelection);
}
/// <summary>
@@ -143,31 +143,6 @@ namespace FlaxEditor.Windows
PerformLayout();
}
private void Rename()
{
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);
actor.TreeNode.StartRenaming(this, _sceneTreePanel);
}
}
private void Spawn(Type type)
{
// Create actor
@@ -197,7 +172,7 @@ namespace FlaxEditor.Windows
Editor.SceneEditing.Spawn(actor, parentActor);
Editor.SceneEditing.Select(actor);
Rename();
RenameSelection();
}
/// <summary>
@@ -293,7 +268,7 @@ namespace FlaxEditor.Windows
{
return Editor.Instance.CodeEditing.Actors.Get().Contains(actorType);
}
private static bool ValidateDragControlType(ScriptType controlType)
{
return Editor.Instance.CodeEditing.Controls.Get().Contains(controlType);
@@ -382,29 +357,6 @@ namespace FlaxEditor.Windows
return false;
}
/// <inheritdoc />
public override bool OnMouseDoubleClick(Float2 location, MouseButton button)
{
if(button == MouseButton.Left)
{
switch (Editor.Options.Options.Input.DoubleClickSceneNode)
{
case SceneNodeDoubleClick.RenameActor:
Rename();
return true;
case SceneNodeDoubleClick.FocusActor:
Editor.Windows.EditWin.Viewport.FocusSelection();
return true;
case SceneNodeDoubleClick.OpenPrefab:
return Editor.Prefabs.OpenPrefab();
case SceneNodeDoubleClick.None:
default:
return base.OnMouseDoubleClick(location, button);
}
}
return base.OnMouseDoubleClick(location, button);
}
/// <inheritdoc />
public override void OnLostFocus()
@@ -593,28 +545,4 @@ namespace FlaxEditor.Windows
base.OnDestroy();
}
}
/// <summary>
/// Action to perform when a Scene Node receive a double mouse click (Left)
/// </summary>
[Serializable]
public enum SceneNodeDoubleClick
{
/// <summary>
/// No action is performed
/// </summary>
None,
/// <summary>
/// Rename the Scene Node
/// </summary>
RenameActor,
/// <summary>
/// Focus the Scene Node object in the Scene View
/// </summary>
FocusActor,
/// <summary>
/// If possible, open the scene node in an associated Editor (e.g. Prefab Editor)
/// </summary>
OpenPrefab
}
}