Improve connections drawing for BehaviorTree and AnimGraph
This commit is contained in:
@@ -694,11 +694,14 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
float rotation = Float2.Dot(dir, Float2.UnitY);
|
float rotation = Float2.Dot(dir, Float2.UnitY);
|
||||||
if (endPos.X < startPos.X)
|
if (endPos.X < startPos.X)
|
||||||
rotation = 2 - rotation;
|
rotation = 2 - rotation;
|
||||||
// TODO: make it look better (fix the math)
|
var sprite = Editor.Instance.Icons.VisjectArrowClosed32;
|
||||||
var arrowTransform = Matrix3x3.Translation2D(new Float2(-16.0f, -8.0f)) * Matrix3x3.RotationZ(rotation * Mathf.PiOverTwo) * Matrix3x3.Translation2D(endPos);
|
var arrowTransform =
|
||||||
|
Matrix3x3.Translation2D(-6.5f, -8) *
|
||||||
|
Matrix3x3.RotationZ(rotation * Mathf.PiOverTwo) *
|
||||||
|
Matrix3x3.Translation2D(endPos - dir * 8);
|
||||||
|
|
||||||
Render2D.PushTransform(ref arrowTransform);
|
Render2D.PushTransform(ref arrowTransform);
|
||||||
Render2D.DrawSprite(Editor.Instance.Icons.VisjectArrowClosed32, arrowRect, color);
|
Render2D.DrawSprite(sprite, arrowRect, color);
|
||||||
Render2D.PopTransform();
|
Render2D.PopTransform();
|
||||||
|
|
||||||
endPos -= dir * 4.0f;
|
endPos -= dir * 4.0f;
|
||||||
|
|||||||
@@ -341,6 +341,8 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
// Setup boxes
|
// Setup boxes
|
||||||
_input = (InputBox)GetBox(0);
|
_input = (InputBox)GetBox(0);
|
||||||
_output = (OutputBox)GetBox(1);
|
_output = (OutputBox)GetBox(1);
|
||||||
|
_input.ConnectionOffset = new Float2(0, FlaxEditor.Surface.Constants.BoxSize * -0.5f);
|
||||||
|
_output.ConnectionOffset = new Float2(0, FlaxEditor.Surface.Constants.BoxSize * 0.5f);
|
||||||
|
|
||||||
// Setup node type and data
|
// Setup node type and data
|
||||||
var flagsRoot = NodeFlags.NoRemove | NodeFlags.NoCloseButton | NodeFlags.NoSpawnViaPaste;
|
var flagsRoot = NodeFlags.NoRemove | NodeFlags.NoCloseButton | NodeFlags.NoSpawnViaPaste;
|
||||||
|
|||||||
@@ -675,12 +675,17 @@ namespace FlaxEditor.Surface.Elements
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Connections origin offset.
|
||||||
|
/// </summary>
|
||||||
|
public Float2 ConnectionOffset;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Float2 ConnectionOrigin
|
public Float2 ConnectionOrigin
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var center = Center;
|
var center = Center + ConnectionOffset;
|
||||||
return Parent.PointToParent(ref center);
|
return Parent.PointToParent(ref center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ namespace FlaxEditor.Surface.Elements
|
|||||||
/// <param name="mousePosition">The mouse position</param>
|
/// <param name="mousePosition">The mouse position</param>
|
||||||
public bool IntersectsConnection(Box targetBox, ref Float2 mousePosition)
|
public bool IntersectsConnection(Box targetBox, ref Float2 mousePosition)
|
||||||
{
|
{
|
||||||
var startPos = Parent.PointToParent(Center);
|
var startPos = ConnectionOrigin;
|
||||||
var endPos = targetBox.Parent.PointToParent(targetBox.Center);
|
var endPos = targetBox.ConnectionOrigin;
|
||||||
return IntersectsConnection(ref startPos, ref endPos, ref mousePosition, MouseOverConnectionDistance);
|
return IntersectsConnection(ref startPos, ref endPos, ref mousePosition, MouseOverConnectionDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,12 +132,12 @@ namespace FlaxEditor.Surface.Elements
|
|||||||
// Draw all the connections
|
// Draw all the connections
|
||||||
var style = Surface.Style;
|
var style = Surface.Style;
|
||||||
var mouseOverDistance = MouseOverConnectionDistance;
|
var mouseOverDistance = MouseOverConnectionDistance;
|
||||||
var startPos = Parent.PointToParent(Center);
|
var startPos = ConnectionOrigin;
|
||||||
var startHighlight = ConnectionsHighlightIntensity;
|
var startHighlight = ConnectionsHighlightIntensity;
|
||||||
for (int i = 0; i < Connections.Count; i++)
|
for (int i = 0; i < Connections.Count; i++)
|
||||||
{
|
{
|
||||||
Box targetBox = Connections[i];
|
Box targetBox = Connections[i];
|
||||||
var endPos = targetBox.Parent.PointToParent(targetBox.Center);
|
var endPos = targetBox.ConnectionOrigin;
|
||||||
var highlight = 1 + Mathf.Max(startHighlight, targetBox.ConnectionsHighlightIntensity);
|
var highlight = 1 + Mathf.Max(startHighlight, targetBox.ConnectionsHighlightIntensity);
|
||||||
var color = _currentTypeColor * highlight;
|
var color = _currentTypeColor * highlight;
|
||||||
|
|
||||||
@@ -157,8 +157,8 @@ namespace FlaxEditor.Surface.Elements
|
|||||||
public void DrawSelectedConnection(Box targetBox)
|
public void DrawSelectedConnection(Box targetBox)
|
||||||
{
|
{
|
||||||
// Draw all the connections
|
// Draw all the connections
|
||||||
var startPos = Parent.PointToParent(Center);
|
var startPos = ConnectionOrigin;
|
||||||
var endPos = targetBox.Parent.PointToParent(targetBox.Center);
|
var endPos = targetBox.ConnectionOrigin;
|
||||||
DrawConnection(Surface.Style, ref startPos, ref endPos, ref _currentTypeColor, 2.5f);
|
DrawConnection(Surface.Style, ref startPos, ref endPos, ref _currentTypeColor, 2.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user