Merge branch 'ActorRefClickHighlight' of https://github.com/xxSeys1/FlaxEngine into xxSeys1-ActorRefClickHighlight

This commit is contained in:
Wojtek Figat
2024-12-16 23:09:09 +01:00
2 changed files with 121 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ using FlaxEditor.CustomEditors.Elements;
using FlaxEditor.GUI;
using FlaxEditor.GUI.Drag;
using FlaxEditor.SceneGraph;
using FlaxEditor.SceneGraph.GUI;
using FlaxEditor.Scripting;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -23,6 +24,7 @@ namespace FlaxEditor.CustomEditors.Editors
public class FlaxObjectRefPickerControl : Control
{
private ScriptType _type;
private ActorTreeNode _linkedTreeNode;
private Object _value;
private string _valueName;
private bool _supportsPickDropDown;
@@ -300,7 +302,58 @@ namespace FlaxEditor.CustomEditors.Editors
// Picker dropdown menu
if (_supportsPickDropDown && (isSelected ? button2Rect : button1Rect).Contains(ref location))
{
ShowDropDownMenu();
return true;
}
if (button == MouseButton.Left)
{
_isMouseDown = false;
// Highlight actor reference.
if (Value is Actor a && !_hasValidDragOver)
{
if (_linkedTreeNode != null && _linkedTreeNode.Actor == a)
{
_linkedTreeNode.ExpandAllParents();
_linkedTreeNode.StartHighlight();
}
else
{
_linkedTreeNode = Editor.Instance.Scene.GetActorNode(a).TreeNode;
_linkedTreeNode.ExpandAllParents();
Editor.Instance.Windows.SceneWin.SceneTreePanel.ScrollViewTo(_linkedTreeNode, true);
_linkedTreeNode.StartHighlight();
}
return true;
}
// Highlight actor with script reference.
if (Value is Script s && !IsDragOver && !_hasValidDragOver)
{
var scriptActor = s.Actor;
if (scriptActor != null)
{
if (_linkedTreeNode != null && _linkedTreeNode.Actor == scriptActor)
{
_linkedTreeNode.ExpandAllParents();
_linkedTreeNode.StartHighlight();
}
else
{
_linkedTreeNode = Editor.Instance.Scene.GetActorNode(scriptActor).TreeNode;
_linkedTreeNode.ExpandAllParents();
Editor.Instance.Windows.SceneWin.SceneTreePanel.ScrollViewTo(_linkedTreeNode, true);
_linkedTreeNode.StartHighlight();
}
return true;
}
}
// Reset valid drag over if still true at this point.
if (_hasValidDragOver)
_hasValidDragOver = false;
}
return base.OnMouseUp(location, button);
}
@@ -326,6 +379,8 @@ namespace FlaxEditor.CustomEditors.Editors
// Check if has object selected
if (_value != null)
{
if (_linkedTreeNode != null)
_linkedTreeNode.StopHighlight();
// Select object
if (_value is Actor actor)
Editor.Instance.SceneEditing.Select(actor);
@@ -469,6 +524,7 @@ namespace FlaxEditor.CustomEditors.Editors
_value = null;
_type = ScriptType.Null;
_valueName = null;
_linkedTreeNode = null;
base.OnDestroy();
}