Update to include presenter context.
This commit is contained in:
@@ -4,7 +4,10 @@ using FlaxEditor.CustomEditors;
|
|||||||
using FlaxEditor.CustomEditors.Elements;
|
using FlaxEditor.CustomEditors.Elements;
|
||||||
using FlaxEditor.GUI;
|
using FlaxEditor.GUI;
|
||||||
using FlaxEditor.GUI.Drag;
|
using FlaxEditor.GUI.Drag;
|
||||||
|
using FlaxEditor.SceneGraph;
|
||||||
using FlaxEditor.SceneGraph.GUI;
|
using FlaxEditor.SceneGraph.GUI;
|
||||||
|
using FlaxEditor.Windows;
|
||||||
|
using FlaxEditor.Windows.Assets;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
using FlaxEngine.Utilities;
|
using FlaxEngine.Utilities;
|
||||||
@@ -31,6 +34,11 @@ public class UIControlRefPickerControl : Control
|
|||||||
private DragActors _dragActors;
|
private DragActors _dragActors;
|
||||||
private DragHandlers _dragHandlers;
|
private DragHandlers _dragHandlers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The presenter using this control.
|
||||||
|
/// </summary>
|
||||||
|
public IPresenterOwner PresenterContext;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when value gets changed.
|
/// Occurs when value gets changed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -126,7 +134,7 @@ public class UIControlRefPickerControl : Control
|
|||||||
Value = actor as UIControl;
|
Value = actor as UIControl;
|
||||||
RootWindow.Focus();
|
RootWindow.Focus();
|
||||||
Focus();
|
Focus();
|
||||||
});
|
}, PresenterContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +142,24 @@ public class UIControlRefPickerControl : Control
|
|||||||
{
|
{
|
||||||
return actor == null || actor is UIControl a && a.Control.GetType() == _controlType;
|
return actor == null || actor is UIControl a && a.Control.GetType() == _controlType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
@@ -365,7 +391,7 @@ public class UIControlRefPickerControl : Control
|
|||||||
|
|
||||||
// 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 (_dragHandlers == null)
|
if (_dragHandlers == null)
|
||||||
{
|
{
|
||||||
_dragHandlers = new DragHandlers
|
_dragHandlers = new DragHandlers
|
||||||
@@ -448,6 +474,7 @@ public class ControlReferenceEditor : CustomEditor
|
|||||||
Type genType = ValuesTypes[0].GetGenericArguments()[0];
|
Type genType = ValuesTypes[0].GetGenericArguments()[0];
|
||||||
if (typeof(Control).IsAssignableFrom(genType))
|
if (typeof(Control).IsAssignableFrom(genType))
|
||||||
{
|
{
|
||||||
|
_element.CustomControl.PresenterContext = Presenter.Owner;
|
||||||
_element.CustomControl.ControlType = genType;
|
_element.CustomControl.ControlType = genType;
|
||||||
}
|
}
|
||||||
_element.CustomControl.ValueChanged += () =>
|
_element.CustomControl.ValueChanged += () =>
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public struct ControlReference<T> : IControlReference where T : Control
|
|||||||
return t;
|
return t;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.LogWarning("Trying to get Control from ControlReference but UIControl is null, or UIControl.Control is null, or UIControl.Control is not the correct type.");
|
Debug.Write(LogType.Warning, "Trying to get Control from ControlReference but UIControl is null, or UIControl.Control is null, or UIControl.Control is not the correct type.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ public struct ControlReference<T> : IControlReference where T : Control
|
|||||||
if (uiControl.Control is T castedControl)
|
if (uiControl.Control is T castedControl)
|
||||||
_uiControl = uiControl;
|
_uiControl = uiControl;
|
||||||
else
|
else
|
||||||
Debug.LogWarning("Trying to set ControlReference but UIControl.Control is null or UIControl.Control is not the correct type.");
|
Debug.Write(LogType.Warning, "Trying to set ControlReference but UIControl.Control is null or UIControl.Control is not the correct type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user