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

@@ -8,6 +8,7 @@ using FlaxEditor.CustomEditors;
using FlaxEditor.CustomEditors.Elements;
using FlaxEngine;
using FlaxEngine.GUI;
using static FlaxEditor.Viewport.EditorViewport;
namespace FlaxEditor.Options
{
@@ -18,7 +19,7 @@ namespace FlaxEditor.Options
[HideInEditor]
[TypeConverter(typeof(InputBindingConverter))]
[CustomEditor(typeof(InputBindingEditor))]
public struct InputBinding
public struct InputBinding : IEquatable<InputBinding>
{
/// <summary>
/// The key to bind.
@@ -251,6 +252,40 @@ namespace FlaxEditor.Options
}
return result;
}
/// <inheritdoc />
public bool Equals(InputBinding other)
{
return Key == other.Key && Modifier1 == other.Modifier1 && Modifier2 == other.Modifier2;
}
/// <inheritdoc />
public override bool Equals(object obj)
{
return obj is InputBinding other && Equals(other);
}
/// <inheritdoc />
public override int GetHashCode()
{
return HashCode.Combine((int)Key, (int)Modifier1, (int)Modifier2);
}
/// <summary>
/// Compares two values.
/// </summary>
public static bool operator ==(InputBinding left, InputBinding right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two values.
/// </summary>
public static bool operator !=(InputBinding left, InputBinding right)
{
return !left.Equals(right);
}
}
class InputBindingConverter : TypeConverter
@@ -522,5 +557,27 @@ namespace FlaxEditor.Options
return false;
}
/// <summary>
/// Invokes a specific binding.
/// </summary>
/// <param name="editor">The editor instance.</param>
/// <param name="binding">The binding to execute.</param>
/// <returns>True if event has been handled, otherwise false.</returns>
public bool Invoke(Editor editor, InputBinding binding)
{
if (binding == new InputBinding())
return false;
var options = editor.Options.Options.Input;
for (int i = 0; i < Bindings.Count; i++)
{
if (Bindings[i].Binder(options) == binding)
{
Bindings[i].Callback();
return true;
}
}
return false;
}
}
}

View File

@@ -7,6 +7,32 @@ using FlaxEngine;
namespace FlaxEditor.Options
{
/// <summary>
/// Action to perform when a Scene Node receive a double mouse left click.
/// </summary>
public enum SceneNodeDoubleClick
{
/// <summary>
/// Toggles expand/state of the node.
/// </summary>
Expand,
/// <summary>
/// Rename the node.
/// </summary>
RenameActor,
/// <summary>
/// Focus the object in the viewport.
/// </summary>
FocusActor,
/// <summary>
/// If possible, open the scene node in an associated Editor (eg. Prefab Editor).
/// </summary>
OpenPrefab,
}
/// <summary>
/// Input editor options data container.
/// </summary>
@@ -344,9 +370,10 @@ namespace FlaxEditor.Options
[EditorDisplay("Interface"), EditorOrder(2020)]
public InputBinding PreviousTab = new InputBinding(KeyboardKeys.Tab, KeyboardKeys.Control, KeyboardKeys.Shift);
[DefaultValue(Windows.SceneNodeDoubleClick.None)]
[DefaultValue(SceneNodeDoubleClick.None)]
[EditorDisplay("Interface"), EditorOrder(2030)]
public Windows.SceneNodeDoubleClick DoubleClickSceneNode = Windows.SceneNodeDoubleClick.None;
public SceneNodeDoubleClick DoubleClickSceneNode = SceneNodeDoubleClick.None;
#endregion
}
}