SquadSkillLinkCanvas.cs

UI panel that draws squad skill link routes on a Painter. Scales route points from a geometry size to panel bounds and highlights the focused slot or link while dimming the rest.

using System;
using Sandbox;
using Sandbox.UI;
using Socer;

public sealed class SquadSkillLinkCanvas : Panel
{
    public SquadSkillRoute[] Routes {get;set;}=Array.Empty<SquadSkillRoute>();
    public int FocusedSlot {get;set;}=-1;
    public int FocusedLink {get;set;}=-1;
    public Point GeometrySize {get;set;}

    public override void OnDraw(Painter painter)
    {
        if(Routes.Length==0)return;
        if(GeometrySize.X<=0 || GeometrySize.Y<=0)return;
        using var scope=painter.Scope();painter.Scale(painter.Bounds.Width/GeometrySize.X,painter.Bounds.Height/GeometrySize.Y);
        painter.Fill=Fill.None;
        foreach(var route in Routes)
        {
            var link=route.Connection;
            bool focus=FocusedLink>=0?link.Key==FocusedLink:FocusedSlot>=0 && (link.FirstSlot==FocusedSlot || link.SecondSlot==FocusedSlot);
            bool dim=(FocusedLink>=0 || FocusedSlot>=0) && !focus;
            var color=link.Golden?new Color(.87f,.75f,.45f):new Color(.57f,.83f,.72f);
            for(int layer=0;layer<2;layer++)
            {
                painter.Stroke=layer==0?Stroke.Solid(new Color(.025f,.12f,.10f,dim?.25f:.75f),focus?6:4):
                    Stroke.Solid(color.WithAlpha(dim?.15f:focus?.95f:.65f),focus?3:2);
                for(int i=1;i<route.Points.Length;i++)
                {
                    var a=route.Points[i-1];var b=route.Points[i];
                    painter.Line(new Vector2(a.X,a.Y),new Vector2(b.X,b.Y));
                }
            }
        }
    }
}