using System.Numerics; using Windows.Foundation; using XFEEDToolBox.Core.Galaxy; namespace XFEEDToolBox.Controls; public sealed partial class GalaxyMapView { public static readonly DependencyProperty HistoricalTradeFlowsProperty=DependencyProperty.Register(nameof(HistoricalTradeFlows),typeof(IReadOnlyList),typeof(GalaxyMapView),new PropertyMetadata(null,Changed)); public IReadOnlyList? HistoricalTradeFlows {get=>(IReadOnlyList?)GetValue(HistoricalTradeFlowsProperty);set=>SetValue(HistoricalTradeFlowsProperty,value);} internal int VisibleHistoricalTradeSegments {get;private set;} private void DrawHistoricalTradeFlows(GalaxyCamera camera,ref int count) { VisibleHistoricalTradeSegments=0; if(graphics is null||Filter is not{ShowHistoricalTradeFlows:true} filter)return; var colour=filter.HistoricalTradeSource switch{GalaxyTradeFlowSource.Players=>new Vector4(1,.55f,.12f,.65f),GalaxyTradeFlowSource.Npc=>new Vector4(.2f,.65f,1,.4f),_=>new Vector4(.12f,.75f,.7f,.55f)}; foreach(var flow in HistoricalTradeFlows??[]) { var edge=flow.Edge;var amount=edge.Amount(filter.HistoricalTradeSource); if(!double.IsFinite(amount)||amount<=0||filter.HistoricalTradeCommodities is {} commodities&&!commodities.Contains(GalaxyMapFilter.Normalize(edge.Commodity))|| flow.From.SystemAddress!=edge.FromSystemAddress||flow.To.SystemAddress!=edge.ToSystemAddress||!flow.From.Position.IsValid||!flow.To.Position.IsValid)continue; if(count+6>lineVertices.Length)break; if(!GalaxyMapGeometry.TryProjectSegment(camera,flow.From.Position,flow.To.Position,out var line))continue; var from=new Point(line.X1,line.Y1);var to=new Point(line.X2,line.Y2);var dx=to.X-from.X;var dy=to.Y-from.Y;var length=Math.Sqrt(dx*dx+dy*dy);if(length<2)continue; AppendHistoricalLine(from,to,colour,ref count);VisibleHistoricalTradeSegments++; if(length<16)continue; var tip=new Point(from.X+dx*.67,from.Y+dy*.67);var ux=dx/length;var uy=dy/length; AppendHistoricalLine(tip,new(tip.X-ux*6+uy*3,tip.Y-uy*6-ux*3),colour,ref count); AppendHistoricalLine(tip,new(tip.X-ux*6-uy*3,tip.Y-uy*6+ux*3),colour,ref count); } } private void AppendHistoricalLine(Point from,Point to,Vector4 colour,ref int count) { var length=(float)Math.Sqrt((to.X-from.X)*(to.X-from.X)+(to.Y-from.Y)*(to.Y-from.Y)); lineVertices[count++]=new(new((float)from.X,(float)from.Y),0,0,colour); lineVertices[count++]=new(new((float)to.X,(float)to.Y),length,0,colour); } }