using Microsoft.UI.Xaml.Controls.Primitives; using XFEEDToolBox.Core.Navigation; using XFEEDToolBox.Core.Galaxy; namespace XFEEDToolBox.Controls; public sealed partial class GalaxyRouteSettingsPanel:UserControl { public static readonly DependencyProperty OptionsProperty=DependencyProperty.Register(nameof(Options),typeof(GameRoutePlotOptions),typeof(GalaxyRouteSettingsPanel),new PropertyMetadata(null,Changed)); public static readonly DependencyProperty CargoCapacityProperty=DependencyProperty.Register(nameof(CargoCapacity),typeof(double),typeof(GalaxyRouteSettingsPanel),new PropertyMetadata(0d,Changed)); public static readonly DependencyProperty CurrentFilterProperty=DependencyProperty.Register(nameof(CurrentFilter),typeof(GalaxyMapFilter),typeof(GalaxyRouteSettingsPanel),new PropertyMetadata(null,Changed)); public GameRoutePlotOptions Options {get=>(GameRoutePlotOptions?)GetValue(OptionsProperty)??new();set=>SetValue(OptionsProperty,value);} public double CargoCapacity {get=>(double)GetValue(CargoCapacityProperty);set=>SetValue(CargoCapacityProperty,value);} public GalaxyMapFilter? CurrentFilter {get=>(GalaxyMapFilter?)GetValue(CurrentFilterProperty);set=>SetValue(CurrentFilterProperty,value);} private readonly ComboBox mode=new(){Header="航线模式",HorizontalAlignment=HorizontalAlignment.Stretch}; private readonly ComboBox boost=new(){Header="FSD 增益等级",HorizontalAlignment=HorizontalAlignment.Stretch}; private readonly CheckBox jet=new(){Content="使用喷流增益",IsThreeState=true}; private readonly NumberBox cargo=new(){Header="规划货重 / t",PlaceholderText="沿用游戏当前货重",Minimum=0,SmallChange=1,SpinButtonPlacementMode=NumberBoxSpinButtonPlacementMode.Compact}; private bool updating; public GalaxyRouteSettingsPanel() { Resources[typeof(CheckBox)]=GalaxyFilterPanel.CreateStaticCheckBoxStyle(); foreach(var title in new[]{"沿用游戏当前模式","经济路线","最快路线","FSD 增益路线"})mode.Items.Add(title); foreach(var title in new[]{"沿用游戏当前等级","0 · 无增益","1 · 基础增益","2 · 标准增益","3 · 高级增益"})boost.Items.Add(title); var clear=new Button{Content="恢复使用游戏当前设置",HorizontalAlignment=HorizontalAlignment.Stretch}; var root=new StackPanel{Spacing=6};root.Children.Add(mode);root.Children.Add(jet);root.Children.Add(boost);root.Children.Add(cargo);root.Children.Add(clear); AddStarClassControls(root); root.Children.Add(new TextBlock{Text="横线和空值表示沿用游戏设置。长按目标规划时应用。",FontSize=11,TextWrapping=TextWrapping.Wrap});Content=root; AddMapFilterControls(root); mode.SelectionChanged+=(_,_)=>Update();boost.SelectionChanged+=(_,_)=>Update();jet.Click+=(_,_)=>Update();cargo.ValueChanged+=(_,_)=>Update(); clear.Click+=(_,_)=>Options=new();Refresh(); } private static void Changed(DependencyObject value,DependencyPropertyChangedEventArgs _)=>((GalaxyRouteSettingsPanel)value).Refresh(); private void Refresh() { updating=true; try { var value=Options;mode.SelectedIndex=value.Mode is{} m&&Enum.IsDefined(m)?(int)m+1:0; boost.SelectedIndex=value.FsdBoostLevel is >=0 and <=3?value.FsdBoostLevel.Value+1:0; boost.IsEnabled=value.Mode==GameRoutePlotMode.FsdBoost;jet.IsChecked=value.UseJetConeBoost; cargo.Maximum=Math.Clamp(double.IsFinite(CargoCapacity)?CargoCapacity:0,0,2048);cargo.Value=value.VirtualCargoMass??double.NaN; RefreshStarClassControls(value.StarClassFilter); RefreshMapFilterControls(value.MapFilter); } finally{updating=false;} } private void Update() { if(updating)return; var selected=mode.SelectedIndex>0?(GameRoutePlotMode?)(mode.SelectedIndex-1):null; Options=Options with{Mode=selected,UseJetConeBoost=jet.IsChecked,FsdBoostLevel=selected==GameRoutePlotMode.FsdBoost&&boost.SelectedIndex>0?boost.SelectedIndex-1:null, VirtualCargoMass=double.IsFinite(cargo.Value)?cargo.Value:null}; } }