Fix valid drop not resetting, add debounce timer to highlighting for showing on double click prevention

This commit is contained in:
Chandler Cox
2024-12-11 20:43:52 -06:00
parent 1e61abdfef
commit 99e836b1fb
2 changed files with 46 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ namespace FlaxEditor.CustomEditors.Editors
public class FlaxObjectRefPickerControl : Control public class FlaxObjectRefPickerControl : Control
{ {
private ScriptType _type; private ScriptType _type;
private ActorTreeNode _linkedTreeNode;
private Object _value; private Object _value;
private string _valueName; private string _valueName;
private bool _supportsPickDropDown; private bool _supportsPickDropDown;
@@ -308,22 +309,50 @@ namespace FlaxEditor.CustomEditors.Editors
if (button == MouseButton.Left) if (button == MouseButton.Left)
{ {
_isMouseDown = false; _isMouseDown = false;
// Highlight actor reference.
if (Value is Actor a && !_hasValidDragOver) if (Value is Actor a && !_hasValidDragOver)
{ {
ActorTreeNode treeNode = Editor.Instance.Scene.GetActorNode(a).TreeNode; if (_linkedTreeNode != null && _linkedTreeNode.Actor == a)
treeNode.ExpandAllParents(); {
Editor.Instance.Windows.SceneWin.SceneTreePanel.ScrollViewTo(treeNode, true); _linkedTreeNode.ExpandAllParents();
treeNode.StartHighlight(); _linkedTreeNode.StartHighlight();
}
else
{
_linkedTreeNode = Editor.Instance.Scene.GetActorNode(a).TreeNode;
_linkedTreeNode.ExpandAllParents();
Editor.Instance.Windows.SceneWin.SceneTreePanel.ScrollViewTo(_linkedTreeNode, true);
_linkedTreeNode.StartHighlight();
}
return true; return true;
} }
// Highlight actor with script reference.
if (Value is Script s && !IsDragOver && !_hasValidDragOver) if (Value is Script s && !IsDragOver && !_hasValidDragOver)
{ {
// TODO: Highlight scripts when Value is a script 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); return base.OnMouseUp(location, button);
@@ -350,6 +379,8 @@ namespace FlaxEditor.CustomEditors.Editors
// Check if has object selected // Check if has object selected
if (_value != null) if (_value != null)
{ {
if (_linkedTreeNode != null)
_linkedTreeNode.StopHighlight();
// Select object // Select object
if (_value is Actor actor) if (_value is Actor actor)
Editor.Instance.SceneEditing.Select(actor); Editor.Instance.SceneEditing.Select(actor);
@@ -493,6 +524,7 @@ namespace FlaxEditor.CustomEditors.Editors
_value = null; _value = null;
_type = ScriptType.Null; _type = ScriptType.Null;
_valueName = null; _valueName = null;
_linkedTreeNode = null;
base.OnDestroy(); base.OnDestroy();
} }

View File

@@ -33,6 +33,8 @@ namespace FlaxEditor.GUI.Tree
private bool _isHightlighted; private bool _isHightlighted;
private float _targetHighlightTimeSec; private float _targetHighlightTimeSec;
private float _currentHighlightTimeSec; private float _currentHighlightTimeSec;
// Used to prevent showing highlight on double mouse click
private float _debounceHighlightTime;
private float _highlightScale; private float _highlightScale;
private bool _mouseOverArrow, _mouseOverHeader; private bool _mouseOverArrow, _mouseOverHeader;
private float _xOffset, _textWidth; private float _xOffset, _textWidth;
@@ -621,6 +623,7 @@ namespace FlaxEditor.GUI.Tree
_isHightlighted = true; _isHightlighted = true;
_targetHighlightTimeSec = durationSec; _targetHighlightTimeSec = durationSec;
_currentHighlightTimeSec = 0; _currentHighlightTimeSec = 0;
_debounceHighlightTime = 0;
_highlightScale = 2f; _highlightScale = 2f;
} }
@@ -632,6 +635,7 @@ namespace FlaxEditor.GUI.Tree
_isHightlighted = false; _isHightlighted = false;
_targetHighlightTimeSec = 0; _targetHighlightTimeSec = 0;
_currentHighlightTimeSec = 0; _currentHighlightTimeSec = 0;
_debounceHighlightTime = 0;
} }
/// <inheritdoc /> /// <inheritdoc />
@@ -640,6 +644,7 @@ namespace FlaxEditor.GUI.Tree
// Highlight animations // Highlight animations
if (_isHightlighted) if (_isHightlighted)
{ {
_debounceHighlightTime += deltaTime;
_currentHighlightTimeSec += deltaTime; _currentHighlightTimeSec += deltaTime;
// In the first second, animate the highlight to shrink into it's resting position // In the first second, animate the highlight to shrink into it's resting position
@@ -723,7 +728,7 @@ namespace FlaxEditor.GUI.Tree
trueTextRect.Width = textWidth; trueTextRect.Width = textWidth;
trueTextRect.Scale(_highlightScale); trueTextRect.Scale(_highlightScale);
if (_isHightlighted) if (_isHightlighted && _debounceHighlightTime > 0.1f)
{ {
Color highlightBackgroundColor = Editor.Instance.Options.Options.Visual.HighlightColor; Color highlightBackgroundColor = Editor.Instance.Options.Options.Visual.HighlightColor;
highlightBackgroundColor = highlightBackgroundColor.AlphaMultiplied(0.3f); highlightBackgroundColor = highlightBackgroundColor.AlphaMultiplied(0.3f);
@@ -784,7 +789,7 @@ namespace FlaxEditor.GUI.Tree
} }
} }
if (_isHightlighted) if (_isHightlighted && _debounceHighlightTime > 0.1f)
{ {
// Draw highlights // Draw highlights
Render2D.DrawRectangle(trueTextRect, Editor.Instance.Options.Options.Visual.HighlightColor, 3); Render2D.DrawRectangle(trueTextRect, Editor.Instance.Options.Options.Visual.HighlightColor, 3);