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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using CommunityToolkit.Mvvm.ComponentModel;
using XFEEDToolBox.Core.Models;
using XFEEDToolBox.Core.Outfitting;
using XFEEDToolBox.Core.Presentation;
namespace XFEEDToolBox.ViewModels;

public partial class ToolboxViewModel
{
    [ObservableProperty] public partial ShipOverviewValues RefitOverview{get;set;}=ShipOverviewValues.Empty;
    private EquipmentStatistics? refitOverviewStatistics;
    private ShipRefitDocument? refitOverviewDocument;
    private bool refitDetailsActive;
    public LiveCollection<ShipDetailSectionLiveRow,ShipDetailSection,string> RefitDetailSections{get;}=new(s=>s.Key,s=>new(s));
    [ObservableProperty] public partial string RefitDetailsCaption{get;set;}="等待完整模拟装配";
    internal void SetRefitDetailsActive(bool active)
    {refitDetailsActive=active;if(active)RefreshRefitDetails();}
    partial void OnRefitOverviewChanged(ShipOverviewValues value)
    {if(refitDetailsActive)RefreshRefitDetails();}
    private void RefreshRefitDetails()
    {
        var stats=RefitOverview==ShipOverviewValues.Empty?null:refitOverviewStatistics;
        RefitDetailsCaption=refitDocument is {} document?$"{Core.Localization.ChineseNames.Ship(document.ShipType)} · {document.Name} {document.Ident}".Trim():"等待完整模拟装配";
        RefitDetailSections.Apply(ShipDetailValues.Create(RefitOverview,stats,refitDocument));
        foreach(var section in RefitDetailSections)section.Values.Apply(section.Record.Values);
    }
    public string RefitSelectedSpecification=>outfitting.Find(RefitSlot?.Module?.Item??"") is {} module?$"{module.Size}{module.Rating} ":"";
    public string RefitSelectedModuleLabel=>RefitSelectedName.StartsWith(RefitSelectedSpecification,StringComparison.Ordinal)?RefitSelectedName[RefitSelectedSpecification.Length..]:RefitSelectedName;
    partial void OnRefitSelectedNameChanged(string value)
    {OnPropertyChanged(nameof(RefitSelectedSpecification));OnPropertyChanged(nameof(RefitSelectedModuleLabel));}
    private void PublishRefitOverview(ShipRefitDocument? document,EquipmentStatistics? stats)
    {
        refitOverviewDocument=document;refitOverviewStatistics=stats;RefreshRefitOverview(CurrentPlayer);
    }
    private void RefreshRefitOverview(PlayerState player)
    {
        if(refitDocument is not {} document||refitOverviewDocument is not {} previous||document.ShipId!=previous.ShipId||document.ShipType!=previous.ShipType||document.EdsyHash!=previous.EdsyHash
            ||document.Slots.Count!=previous.Slots.Count||!document.Slots.Zip(previous.Slots).All(pair=>pair.First.Slot==pair.Second.Slot&&pair.First.Module==pair.Second.Module))
        {RefitOverview=ShipOverviewValues.Empty;return;}
        var live=document.EdsyHash.Length==0&&document.ShipId==player.CurrentShipId?player.Status:null;
        RefitOverview=ShipOverviewValues.From(refitOverviewStatistics,live is null?null:new(live.FuelMain,live.FuelReserve,live.Cargo,live.Pips.Count>1?live.Pips[1]:null));
    }
}