TrajectView now draws an arrow at each endpoint (since pieces oscillate between start and end, both directions are relevant) and runs a looped width/alpha tween that breathes between 0.3 and 0.75 over ~2.2s. The pulse makes stationary relays visually distinct from static board art without competing with active cargo/particle animations.
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using Godot;
|
|
|
|
namespace Chessistics.Scripts.Pieces;
|
|
|
|
public partial class TrajectView : Line2D
|
|
{
|
|
public int PieceId { get; private set; }
|
|
private Polygon2D? _arrowEnd;
|
|
private Polygon2D? _arrowStart;
|
|
private Tween? _pulseTween;
|
|
private Color _baseColor;
|
|
|
|
public void Setup(int pieceId, Vector2 from, Vector2 to, Color color)
|
|
{
|
|
PieceId = pieceId;
|
|
_baseColor = color;
|
|
Width = 3f;
|
|
DefaultColor = new Color(color, 0.4f);
|
|
Antialiased = true;
|
|
ClearPoints();
|
|
AddPoint(from);
|
|
AddPoint(to);
|
|
ZIndex = -1;
|
|
|
|
_arrowEnd = BuildArrow(from, to, color);
|
|
_arrowStart = BuildArrow(to, from, color);
|
|
AddChild(_arrowEnd);
|
|
AddChild(_arrowStart);
|
|
|
|
StartPulse();
|
|
}
|
|
|
|
private static Polygon2D BuildArrow(Vector2 from, Vector2 to, Color color)
|
|
{
|
|
var dir = (to - from).Normalized();
|
|
var perp = new Vector2(-dir.Y, dir.X);
|
|
const float arrowSize = 9f;
|
|
var tip = to - dir * 4f;
|
|
var baseL = tip - dir * arrowSize + perp * arrowSize * 0.5f;
|
|
var baseR = tip - dir * arrowSize - perp * arrowSize * 0.5f;
|
|
return new Polygon2D
|
|
{
|
|
Polygon = [tip, baseL, baseR],
|
|
Color = new Color(color, 0.5f)
|
|
};
|
|
}
|
|
|
|
private void StartPulse()
|
|
{
|
|
_pulseTween?.Kill();
|
|
_pulseTween = CreateTween();
|
|
_pulseTween.SetLoops();
|
|
_pulseTween.TweenProperty(this, "default_color:a", 0.75f, 1.1f)
|
|
.SetEase(Tween.EaseType.InOut).SetTrans(Tween.TransitionType.Sine);
|
|
_pulseTween.TweenProperty(this, "default_color:a", 0.3f, 1.1f)
|
|
.SetEase(Tween.EaseType.InOut).SetTrans(Tween.TransitionType.Sine);
|
|
}
|
|
}
|