Merge branch 'Tryibion-add-context-to-obj-ref-editor'
This commit is contained in:
@@ -9,6 +9,8 @@ using FlaxEditor.GUI.Drag;
|
|||||||
using FlaxEditor.SceneGraph;
|
using FlaxEditor.SceneGraph;
|
||||||
using FlaxEditor.SceneGraph.GUI;
|
using FlaxEditor.SceneGraph.GUI;
|
||||||
using FlaxEditor.Scripting;
|
using FlaxEditor.Scripting;
|
||||||
|
using FlaxEditor.Windows;
|
||||||
|
using FlaxEditor.Windows.Assets;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
using FlaxEngine.Utilities;
|
using FlaxEngine.Utilities;
|
||||||
@@ -40,6 +42,11 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
private DragScripts _dragScripts;
|
private DragScripts _dragScripts;
|
||||||
private DragHandlers _dragHandlers;
|
private DragHandlers _dragHandlers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The presenter using this control.
|
||||||
|
/// </summary>
|
||||||
|
public IPresenterOwner PresenterContext;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the allowed objects type (given type and all sub classes). Must be <see cref="Object"/> type of any subclass.
|
/// Gets or sets the allowed objects type (given type and all sub classes). Must be <see cref="Object"/> type of any subclass.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -159,7 +166,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
Value = actor;
|
Value = actor;
|
||||||
RootWindow.Focus();
|
RootWindow.Focus();
|
||||||
Focus();
|
Focus();
|
||||||
});
|
}, PresenterContext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -168,7 +175,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
Value = script;
|
Value = script;
|
||||||
RootWindow.Focus();
|
RootWindow.Focus();
|
||||||
Focus();
|
Focus();
|
||||||
});
|
}, PresenterContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,13 +434,13 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
|
|
||||||
// Ensure to have valid drag helpers (uses lazy init)
|
// Ensure to have valid drag helpers (uses lazy init)
|
||||||
if (_dragActors == null)
|
if (_dragActors == null)
|
||||||
_dragActors = new DragActors(x => IsValid(x.Actor));
|
_dragActors = new DragActors(ValidateDragActor);
|
||||||
if (_dragActorsWithScript == null)
|
if (_dragActorsWithScript == null)
|
||||||
_dragActorsWithScript = new DragActors(ValidateDragActorWithScript);
|
_dragActorsWithScript = new DragActors(ValidateDragActorWithScript);
|
||||||
if (_dragAssets == null)
|
if (_dragAssets == null)
|
||||||
_dragAssets = new DragAssets(ValidateDragAsset);
|
_dragAssets = new DragAssets(ValidateDragAsset);
|
||||||
if (_dragScripts == null)
|
if (_dragScripts == null)
|
||||||
_dragScripts = new DragScripts(IsValid);
|
_dragScripts = new DragScripts(ValidateDragScript);
|
||||||
if (_dragHandlers == null)
|
if (_dragHandlers == null)
|
||||||
{
|
{
|
||||||
_dragHandlers = new DragHandlers
|
_dragHandlers = new DragHandlers
|
||||||
@@ -458,6 +465,43 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
return DragEffect;
|
return DragEffect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool ValidateDragActor(ActorNode a)
|
||||||
|
{
|
||||||
|
if (!IsValid(a.Actor))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (PresenterContext is PrefabWindow prefabWindow)
|
||||||
|
{
|
||||||
|
if (prefabWindow.Tree == a.TreeNode.ParentTree)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (PresenterContext is PropertiesWindow || PresenterContext == null)
|
||||||
|
{
|
||||||
|
if (a.ParentScene != null)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ValidateDragScript(Script script)
|
||||||
|
{
|
||||||
|
if (!IsValid(script))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (PresenterContext is PrefabWindow prefabWindow)
|
||||||
|
{
|
||||||
|
var actorNode = prefabWindow.Graph.Root.Find(script.Actor);
|
||||||
|
if (actorNode != null)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (PresenterContext is PropertiesWindow || PresenterContext == null)
|
||||||
|
{
|
||||||
|
if (script.Actor.HasScene)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool ValidateDragAsset(AssetItem assetItem)
|
private bool ValidateDragAsset(AssetItem assetItem)
|
||||||
{
|
{
|
||||||
// Check if can accept assets
|
// Check if can accept assets
|
||||||
@@ -476,7 +520,18 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
|
|
||||||
private bool ValidateDragActorWithScript(ActorNode node)
|
private bool ValidateDragActorWithScript(ActorNode node)
|
||||||
{
|
{
|
||||||
return node.Actor.Scripts.Any(IsValid);
|
bool isCorrectContext = false;
|
||||||
|
if (PresenterContext is PrefabWindow prefabWindow)
|
||||||
|
{
|
||||||
|
if (prefabWindow.Tree == node.TreeNode.ParentTree)
|
||||||
|
isCorrectContext = true;
|
||||||
|
}
|
||||||
|
else if (PresenterContext is PropertiesWindow || PresenterContext == null)
|
||||||
|
{
|
||||||
|
if (node.ParentScene != null)
|
||||||
|
isCorrectContext = true;
|
||||||
|
}
|
||||||
|
return node.Actor.Scripts.Any(IsValid) && isCorrectContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -548,6 +603,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
if (!HasDifferentTypes)
|
if (!HasDifferentTypes)
|
||||||
{
|
{
|
||||||
_element = layout.Custom<FlaxObjectRefPickerControl>();
|
_element = layout.Custom<FlaxObjectRefPickerControl>();
|
||||||
|
_element.CustomControl.PresenterContext = Presenter.Owner;
|
||||||
_element.CustomControl.Type = Values.Type.Type != typeof(object) || Values[0] == null ? Values.Type : TypeUtils.GetObjectType(Values[0]);
|
_element.CustomControl.Type = Values.Type.Type != typeof(object) || Values[0] == null ? Values.Type : TypeUtils.GetObjectType(Values[0]);
|
||||||
_element.CustomControl.ValueChanged += () => SetValue(_element.CustomControl.Value);
|
_element.CustomControl.ValueChanged += () => SetValue(_element.CustomControl.Value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using FlaxEditor.Windows;
|
||||||
|
using FlaxEditor.Windows.Assets;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
|
|
||||||
@@ -55,18 +57,26 @@ namespace FlaxEditor.GUI
|
|||||||
private IsValidDelegate _isValid;
|
private IsValidDelegate _isValid;
|
||||||
private Action<Actor> _selected;
|
private Action<Actor> _selected;
|
||||||
|
|
||||||
private ActorSearchPopup(IsValidDelegate isValid, Action<Actor> selected)
|
private ActorSearchPopup(IsValidDelegate isValid, Action<Actor> selected, CustomEditors.IPresenterOwner context)
|
||||||
{
|
{
|
||||||
_isValid = isValid;
|
_isValid = isValid;
|
||||||
_selected = selected;
|
_selected = selected;
|
||||||
|
|
||||||
ItemClicked += OnItemClicked;
|
ItemClicked += OnItemClicked;
|
||||||
|
|
||||||
|
if (context is PropertiesWindow propertiesWindow || context == null)
|
||||||
|
{
|
||||||
// TODO: use async thread to search scenes
|
// TODO: use async thread to search scenes
|
||||||
for (int i = 0; i < Level.ScenesCount; i++)
|
for (int i = 0; i < Level.ScenesCount; i++)
|
||||||
{
|
{
|
||||||
Find(Level.GetScene(i));
|
Find(Level.GetScene(i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (context is PrefabWindow prefabWindow)
|
||||||
|
{
|
||||||
|
Find(prefabWindow.Graph.MainActor);
|
||||||
|
}
|
||||||
|
|
||||||
SortItems();
|
SortItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,10 +108,11 @@ namespace FlaxEditor.GUI
|
|||||||
/// <param name="showTargetLocation">The show target location.</param>
|
/// <param name="showTargetLocation">The show target location.</param>
|
||||||
/// <param name="isValid">Event called to check if a given actor item is valid to be used.</param>
|
/// <param name="isValid">Event called to check if a given actor item is valid to be used.</param>
|
||||||
/// <param name="selected">Event called on actor item pick.</param>
|
/// <param name="selected">Event called on actor item pick.</param>
|
||||||
|
/// <param name="context">The presenter owner context (i.e. PrefabWindow, PropertiesWindow).</param>
|
||||||
/// <returns>The dialog.</returns>
|
/// <returns>The dialog.</returns>
|
||||||
public static ActorSearchPopup Show(Control showTarget, Float2 showTargetLocation, IsValidDelegate isValid, Action<Actor> selected)
|
public static ActorSearchPopup Show(Control showTarget, Float2 showTargetLocation, IsValidDelegate isValid, Action<Actor> selected, CustomEditors.IPresenterOwner context)
|
||||||
{
|
{
|
||||||
var popup = new ActorSearchPopup(isValid, selected);
|
var popup = new ActorSearchPopup(isValid, selected, context);
|
||||||
popup.Show(showTarget, showTargetLocation);
|
popup.Show(showTarget, showTargetLocation);
|
||||||
return popup;
|
return popup;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using FlaxEditor.Windows;
|
||||||
|
using FlaxEditor.Windows.Assets;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
using FlaxEngine.Utilities;
|
using FlaxEngine.Utilities;
|
||||||
@@ -66,18 +68,26 @@ namespace FlaxEditor.GUI
|
|||||||
private IsValidDelegate _isValid;
|
private IsValidDelegate _isValid;
|
||||||
private Action<Script> _selected;
|
private Action<Script> _selected;
|
||||||
|
|
||||||
private ScriptSearchPopup(IsValidDelegate isValid, Action<Script> selected)
|
private ScriptSearchPopup(IsValidDelegate isValid, Action<Script> selected, CustomEditors.IPresenterOwner context)
|
||||||
{
|
{
|
||||||
_isValid = isValid;
|
_isValid = isValid;
|
||||||
_selected = selected;
|
_selected = selected;
|
||||||
|
|
||||||
ItemClicked += OnItemClicked;
|
ItemClicked += OnItemClicked;
|
||||||
|
|
||||||
|
if (context is PropertiesWindow propertiesWindow || context == null)
|
||||||
|
{
|
||||||
// TODO: use async thread to search scenes
|
// TODO: use async thread to search scenes
|
||||||
for (int i = 0; i < Level.ScenesCount; i++)
|
for (int i = 0; i < Level.ScenesCount; i++)
|
||||||
{
|
{
|
||||||
Find(Level.GetScene(i));
|
Find(Level.GetScene(i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (context is PrefabWindow prefabWindow)
|
||||||
|
{
|
||||||
|
Find(prefabWindow.Graph.MainActor);
|
||||||
|
}
|
||||||
|
|
||||||
SortItems();
|
SortItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,10 +123,11 @@ namespace FlaxEditor.GUI
|
|||||||
/// <param name="showTargetLocation">The show target location.</param>
|
/// <param name="showTargetLocation">The show target location.</param>
|
||||||
/// <param name="isValid">Event called to check if a given script item is valid to be used.</param>
|
/// <param name="isValid">Event called to check if a given script item is valid to be used.</param>
|
||||||
/// <param name="selected">Event called on script item pick.</param>
|
/// <param name="selected">Event called on script item pick.</param>
|
||||||
|
/// <param name="context">The presenter owner context (i.e. PrefabWindow, PropertiesWindow).</param>
|
||||||
/// <returns>The dialog.</returns>
|
/// <returns>The dialog.</returns>
|
||||||
public static ScriptSearchPopup Show(Control showTarget, Float2 showTargetLocation, IsValidDelegate isValid, Action<Script> selected)
|
public static ScriptSearchPopup Show(Control showTarget, Float2 showTargetLocation, IsValidDelegate isValid, Action<Script> selected, CustomEditors.IPresenterOwner context)
|
||||||
{
|
{
|
||||||
var popup = new ScriptSearchPopup(isValid, selected);
|
var popup = new ScriptSearchPopup(isValid, selected, context);
|
||||||
popup.Show(showTarget, showTargetLocation);
|
popup.Show(showTarget, showTargetLocation);
|
||||||
return popup;
|
return popup;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ namespace FlaxEditor.GUI.Timeline.Tracks
|
|||||||
|
|
||||||
private void OnClickedSelect()
|
private void OnClickedSelect()
|
||||||
{
|
{
|
||||||
ActorSearchPopup.Show(this, PointFromScreen(FlaxEngine.Input.MouseScreenPosition), IsActorValid, SetActor);
|
ActorSearchPopup.Show(this, PointFromScreen(FlaxEngine.Input.MouseScreenPosition), IsActorValid, SetActor, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClickedSelectActor(Image image, MouseButton button)
|
private void OnClickedSelectActor(Image image, MouseButton button)
|
||||||
|
|||||||
Reference in New Issue
Block a user