XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Models;

namespace XFEEDToolBox.Controls;

public sealed partial class GalaxyMapView
{
    private GalaxyFloorCandidate[] floorCandidates=[];
    private Coordinates? floorPosition;
    private GalaxyFloorSelection floorSelection;
    private GalacticSystem? floorTarget;
    private bool updatingFloorSelection;
    private readonly List<LineVisual> floorLines=[];
    internal int VisibleFloorSelectorSegments {get;private set;}
    internal GalacticSystem? FloorTargetForProbe=>floorTarget;
    internal Coordinates FloorPositionForProbe=>floorSelection.Position;

    private void ResetFloorSelector(){floorPosition=null;floorTarget=null;floorSelection=default;}
    private void SelectionFloorChanged(GalacticSystem? selected)
    {
        if(updatingFloorSelection)return;
        floorTarget=selected;
        floorPosition=selected is {Position.IsValid:true}&&Filter?.Matches(selected)!=false
            ?GalaxyFloorSelector.Intersection(selected.Position,Camera.Focus.Y):null;
    }

    private void MoveCameraFocus(Coordinates focus)
    {
        var before=Camera.Focus;
        var selector=floorPosition??before;
        var held=floorSelection;
        applyingCameraPose=true;
        try{Centre=focus;panX=panY=0;}
        finally{applyingCameraPose=false;}
        floorSelection=held;
        floorPosition=new(selector.X+focus.X-before.X,selector.Y+focus.Y-before.Y,selector.Z+focus.Z-before.Z);
        UpdateFloorSelection(Camera);
        if(!ReferenceEquals(Selection,floorTarget))
        {
            updatingFloorSelection=true;
            try
            {
                Selection=floorTarget;
                if(floorTarget is {} target)SystemSelected?.Invoke(this,target);
                else SelectionCleared?.Invoke();
            }
            finally{updatingFloorSelection=false;}
        }
    }

    private void UpdateFloorSelection(GalaxyCamera camera)
    {
        if(sceneDirty&&vectors is not null)RebuildScene();
        var selector=floorPosition??(Selection is {Position.IsValid:true} selected&&Filter?.Matches(selected)!=false
            ?GalaxyFloorSelector.Intersection(selected.Position,camera.Focus.Y):camera.Focus);
        // Explicit tool thresholds; the original capture/release pixel sizes
        // are not recovered. Never feed unfiltered catalogue rows to snapping.
        floorSelection=GalaxyFloorSelector.Snap(camera,selector,floorCandidates,11,18,floorSelection.Target);
        floorTarget=null;
        if(floorSelection.Target is {} target)
            foreach(var sample in ordered)
                if(sample.System.SystemAddress==target.SystemAddress&&sample.System.Position==target.Position)
                {floorTarget=sample.System;break;}
    }

    private int WriteFloorSelector(Span<MapSegment> output,GalaxyCamera camera)
    {
        VisibleFloorSelectorSegments=0;
        if(Filter?.ShowGrid==false||!IsInteractive)return 0;
        UpdateFloorSelection(camera);
        var position=floorSelection.Position;
        var count=GalaxyFloorSelector.WriteRing(output,camera,position,9/Math.Max(.001,camera.Scale));
        if(floorTarget is {Position.IsValid:true} target&&count<output.Length&&
            GalaxyMapGeometry.TryProjectSegment(camera,position,target.Position,out var stalk))output[count++]=stalk;
        VisibleFloorSelectorSegments=count;return count;
    }
}