Double click actions + open prefab ctxmenu

This commit is contained in:
davevanegdom
2023-09-22 18:31:54 +02:00
parent faeb21a77a
commit 23f4a82bbc
4 changed files with 75 additions and 3 deletions

View File

@@ -109,6 +109,27 @@ namespace FlaxEditor.Modules
Editor.Windows.ContentWin.NewItem(proxy, actor, OnPrefabCreated, actor.Name, rename);
}
/// <summary>
/// Open a prefab in a Prefab Editor
/// </summary>
/// <returns>Whether the prefab was successfully opened in a Prefab Editor</returns>
public bool OpenPrefab()
{
var selection = Editor.SceneEditing.Selection.Where(x => x is ActorNode actorNode && actorNode.HasPrefabLink).ToList().BuildNodesParents();
if (selection.Count == 0 || !((ActorNode)selection[0]).Actor.HasPrefabLink)
return false;
var prefabId = ((ActorNode)selection[0]).Actor.PrefabID;
var item = Editor.Instance.ContentDatabase.Find(prefabId);
if(item != null)
{
Editor.Instance.ContentEditing.Open(item);
return true;
}
return false;
}
private void OnPrefabCreated(ContentItem contentItem)
{
if (contentItem is PrefabItem prefabItem)

View File

@@ -200,6 +200,9 @@ namespace FlaxEditor.Options
[EditorDisplay("Interface"), EditorOrder(2020)]
public InputBinding PreviousTab = new InputBinding(KeyboardKeys.Tab, KeyboardKeys.Control, KeyboardKeys.Shift);
[DefaultValue(Windows.SceneNodeDoubleClick.None)]
[EditorDisplay("Interface"), EditorOrder(2030)]
public Windows.SceneNodeDoubleClick DoubleClickSceneNode = Windows.SceneNodeDoubleClick.None;
#endregion
}
}

View File

@@ -133,14 +133,15 @@ namespace FlaxEditor.Windows
contextMenu.AddSeparator();
ActorNode actorNode = (ActorNode)Editor.SceneEditing.Selection[0];
b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab);
b.Enabled = isSingleActorSelected &&
((ActorNode)Editor.SceneEditing.Selection[0]).CanCreatePrefab &&
b.Enabled = isSingleActorSelected && actorNode.CanCreatePrefab &&
Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets;
bool hasPrefabLink = canEditScene && isSingleActorSelected && (Editor.SceneEditing.Selection[0] as ActorNode).HasPrefabLink;
bool hasPrefabLink = canEditScene && isSingleActorSelected && actorNode.HasPrefabLink;
if (hasPrefabLink)
{
contextMenu.AddButton("Open Prefab", () => Editor.Prefabs.OpenPrefab());
contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab);
contextMenu.AddButton("Break Prefab Link", Editor.Prefabs.BreakLinks);
}

View File

@@ -346,6 +346,29 @@ 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.Rename:
Rename();
return true;
case SceneNodeDoubleClick.Focus:
Editor.Windows.EditWin.Viewport.FocusSelection();
return true;
case SceneNodeDoubleClick.Open:
return Editor.Prefabs.OpenPrefab();
case SceneNodeDoubleClick.None:
default:
return base.OnMouseDoubleClick(location, button);
}
}
return base.OnMouseDoubleClick(location, button);
}
/// <inheritdoc />
public override void OnLostFocus()
@@ -459,4 +482,28 @@ 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>
Rename,
/// <summary>
/// Focus the Scene Node object in the Scene View
/// </summary>
Focus,
/// <summary>
/// If possible, open the scene node in an associated Editor (e.g. Prefab Editor)
/// </summary>
Open
}
}