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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Windows.Input;
using Microsoft.UI.Xaml.Automation;
using XFEEDToolBox.Core.Galaxy;

namespace XFEEDToolBox.Controls;

public sealed partial class GalaxyFilterPanel
{
    public static readonly DependencyProperty MissionTargetsProperty=DependencyProperty.Register(nameof(MissionTargets),typeof(IReadOnlyList<GalaxyMissionMapTarget>),typeof(GalaxyFilterPanel),new PropertyMetadata(null,Changed));
    public static readonly DependencyProperty MissionsStatusProperty=DependencyProperty.Register(nameof(MissionsStatus),typeof(string),typeof(GalaxyFilterPanel),new PropertyMetadata("",Changed));
    public static readonly DependencyProperty SelectMissionCommandProperty=DependencyProperty.Register(nameof(SelectMissionCommand),typeof(ICommand),typeof(GalaxyFilterPanel),new PropertyMetadata(null,Changed));
    public IReadOnlyList<GalaxyMissionMapTarget> MissionTargets {get=>(IReadOnlyList<GalaxyMissionMapTarget>?)GetValue(MissionTargetsProperty)??[];set=>SetValue(MissionTargetsProperty,value);}
    public string MissionsStatus {get=>(string)GetValue(MissionsStatusProperty);set=>SetValue(MissionsStatusProperty,value);}
    public ICommand? SelectMissionCommand {get=>(ICommand?)GetValue(SelectMissionCommandProperty);set=>SetValue(SelectMissionCommandProperty,value);}
    private readonly TextBlock missionsStatus=new(){FontSize=11,TextWrapping=TextWrapping.Wrap};
    private readonly StackPanel missionTargets=new(){Spacing=5};
    private IReadOnlyList<GalaxyMissionMapTarget>? renderedMissionTargets;
    private ICommand? renderedMissionCommand;
    private FrameworkElement BuildMissionControls()
    {
        var content=new StackPanel{Spacing=6};content.Children.Add(missionsStatus);content.Children.Add(missionTargets);
        return new Expander{Header="原游戏任务逐条定位",Content=content,HorizontalAlignment=HorizontalAlignment.Stretch,HorizontalContentAlignment=HorizontalAlignment.Stretch};
    }
    private void RefreshMissionControls()
    {
        missionsStatus.Text=MissionsStatus;
        if(ReferenceEquals(renderedMissionTargets,MissionTargets)&&ReferenceEquals(renderedMissionCommand,SelectMissionCommand))return;
        renderedMissionTargets=MissionTargets;renderedMissionCommand=SelectMissionCommand;missionTargets.Children.Clear();
        foreach(var target in MissionTargets)
        {
            var text=new TextBlock{Text=target.Label,FontSize=12,TextWrapping=TextWrapping.Wrap};
            var button=new Button{Content=text,Command=SelectMissionCommand,CommandParameter=target,IsEnabled=target.SystemAddress is not null,HorizontalAlignment=HorizontalAlignment.Stretch,HorizontalContentAlignment=HorizontalAlignment.Stretch};AutomationProperties.SetName(button,"定位原任务 "+target.MissionId);missionTargets.Children.Add(button);
        }
    }
}