using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Navigation;
namespace XFEEDToolBox.Controls;
public sealed partial class GalaxyRouteSettingsPanel
{
private readonly TextBlock mapRouteSummary=new(){FontSize=11,TextWrapping=TextWrapping.Wrap};
private readonly CheckBox mapRoute=new(){Content="将此分类用于路线",IsThreeState=true};
private readonly StackPanel mapRouteRows=new(){Spacing=2,MaxHeight=360};
private readonly Dictionary<string,CheckBox> mapRouteChoices=new(StringComparer.Ordinal);
private string mapRouteRowsKey="";
private void AddMapFilterControls(StackPanel root)
{
var content=new StackPanel{Spacing=6};var current=new Button{Content="采用当前分类筛选",HorizontalAlignment=HorizontalAlignment.Stretch};
var saved=new Button{Content="采用游戏保存的分类筛选",HorizontalAlignment=HorizontalAlignment.Stretch};
var choose=new Button{Content="选择原分类选项…",HorizontalAlignment=HorizontalAlignment.Stretch};
var rowsScroll=new ScrollViewer{Content=mapRouteRows,VerticalScrollBarVisibility=ScrollBarVisibility.Auto,MaxHeight=360};
rowsScroll.Resources[typeof(CheckBox)]=GalaxyFilterPanel.CreateStaticCheckBoxStyle();choose.Flyout=new Flyout{Content=rowsScroll};
void Copy(bool savedSelection)
{
if(CurrentFilter is not{} filter){mapRouteSummary.Text="请先选择星图分类。";return;}
if(!GameRouteMapFilter.TryFromFilter(filter,savedSelection,out var selected,out var reason))
{mapRouteSummary.Text=reason;return;}
Options=Options with{MapFilter=selected};
}
current.Click+=(_,_)=>Copy(false);saved.Click+=(_,_)=>Copy(true);
mapRoute.Click+=(_,_)=>
{
if(updating)return;
if(mapRoute.IsChecked is not{} affects){Options=Options with{MapFilter=null};return;}
if(Options.MapFilter is{} selected)Options=Options with{MapFilter=selected with{AffectsRoutePlotting=affects}};
else
{
Copy(false);
if(Options.MapFilter is{} copied)Options=Options with{MapFilter=copied with{AffectsRoutePlotting=affects}};
else{updating=true;mapRoute.IsChecked=null;updating=false;}
}
};
content.Children.Add(current);content.Children.Add(saved);content.Children.Add(mapRoute);content.Children.Add(choose);content.Children.Add(mapRouteSummary);
root.Children.Add(new Expander{Header="其他分类路线筛选",Content=content,HorizontalAlignment=HorizontalAlignment.Stretch,HorizontalContentAlignment=HorizontalAlignment.Stretch});
}
private void RefreshMapFilterControls(GameRouteMapFilter? filter)
{
mapRoute.IsChecked=filter?.AffectsRoutePlotting;
var key=filter is null?"":filter.CategoryId+"|"+string.Join('|',filter.ExpectedKeys);
if(key!=mapRouteRowsKey)
{
mapRouteRowsKey=key;mapRouteRows.Children.Clear();mapRouteChoices.Clear();
if(filter is not null)foreach(var name in filter.ExpectedKeys)
{
var choiceCategory=GalaxyOriginalSettings.CategoryForIndex(filter.CategoryId);
var label=choiceCategory==GalaxyFilterCategory.Security&&name=="lawless"?"无法律管辖":
GalaxyFilterDefinitions.All.FirstOrDefault(d=>d.Category==choiceCategory)?.Choices.FirstOrDefault(c=>c.Key==GalaxyMapFilter.Normalize(name))?.Label;
var text=label is null||label==name?name:$"{label} · {name}";
var item=new CheckBox{Content=new TextBlock{Text=text,TextWrapping=TextWrapping.Wrap,MaxWidth=330},FontSize=12};mapRouteChoices[name]=item;mapRouteRows.Children.Add(item);
item.Click+=(_,_)=>
{
if(updating||Options.MapFilter is not{} current)return;
Options=Options with{MapFilter=current with{SelectedKeys=mapRouteChoices.Where(pair=>pair.Value.IsChecked==true).Select(pair=>pair.Key).ToArray()}};
};
}
}
if(filter is null){mapRouteSummary.Text="横线:保留游戏此类别的路线设置。支持阵营、政体、经济、状态、安全、访问及文明。";return;}
foreach(var (name,item) in mapRouteChoices)item.IsChecked=filter.SelectedKeys.Contains(name);
var category=GalaxyOriginalSettings.CategoryForIndex(filter.CategoryId);
var title=GalaxyFilterDefinitions.All.FirstOrDefault(d=>d.Category==category)?.Label??filter.CategoryId.ToString();
mapRouteSummary.Text=$"{title} · 已选 {filter.SelectedKeys.Count} / {filter.ExpectedKeys.Count} 项\n长按目标规划时同步,并切换游戏星图为此分类显示。";
}
}
using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Navigation;
namespace XFEEDToolBox.Controls;
public sealed partial class GalaxyRouteSettingsPanel
{
private readonly TextBlock mapRouteSummary=new(){FontSize=11,TextWrapping=TextWrapping.Wrap};
private readonly CheckBox mapRoute=new(){Content="将此分类用于路线",IsThreeState=true};
private readonly StackPanel mapRouteRows=new(){Spacing=2,MaxHeight=360};
private readonly Dictionary<string,CheckBox> mapRouteChoices=new(StringComparer.Ordinal);
private string mapRouteRowsKey="";
private void AddMapFilterControls(StackPanel root)
{
var content=new StackPanel{Spacing=6};var current=new Button{Content="采用当前分类筛选",HorizontalAlignment=HorizontalAlignment.Stretch};
var saved=new Button{Content="采用游戏保存的分类筛选",HorizontalAlignment=HorizontalAlignment.Stretch};
var choose=new Button{Content="选择原分类选项…",HorizontalAlignment=HorizontalAlignment.Stretch};
var rowsScroll=new ScrollViewer{Content=mapRouteRows,VerticalScrollBarVisibility=ScrollBarVisibility.Auto,MaxHeight=360};
rowsScroll.Resources[typeof(CheckBox)]=GalaxyFilterPanel.CreateStaticCheckBoxStyle();choose.Flyout=new Flyout{Content=rowsScroll};
void Copy(bool savedSelection)
{
if(CurrentFilter is not{} filter){mapRouteSummary.Text="请先选择星图分类。";return;}
if(!GameRouteMapFilter.TryFromFilter(filter,savedSelection,out var selected,out var reason))
{mapRouteSummary.Text=reason;return;}
Options=Options with{MapFilter=selected};
}
current.Click+=(_,_)=>Copy(false);saved.Click+=(_,_)=>Copy(true);
mapRoute.Click+=(_,_)=>
{
if(updating)return;
if(mapRoute.IsChecked is not{} affects){Options=Options with{MapFilter=null};return;}
if(Options.MapFilter is{} selected)Options=Options with{MapFilter=selected with{AffectsRoutePlotting=affects}};
else
{
Copy(false);
if(Options.MapFilter is{} copied)Options=Options with{MapFilter=copied with{AffectsRoutePlotting=affects}};
else{updating=true;mapRoute.IsChecked=null;updating=false;}
}
};
content.Children.Add(current);content.Children.Add(saved);content.Children.Add(mapRoute);content.Children.Add(choose);content.Children.Add(mapRouteSummary);
root.Children.Add(new Expander{Header="其他分类路线筛选",Content=content,HorizontalAlignment=HorizontalAlignment.Stretch,HorizontalContentAlignment=HorizontalAlignment.Stretch});
}
private void RefreshMapFilterControls(GameRouteMapFilter? filter)
{
mapRoute.IsChecked=filter?.AffectsRoutePlotting;
var key=filter is null?"":filter.CategoryId+"|"+string.Join('|',filter.ExpectedKeys);
if(key!=mapRouteRowsKey)
{
mapRouteRowsKey=key;mapRouteRows.Children.Clear();mapRouteChoices.Clear();
if(filter is not null)foreach(var name in filter.ExpectedKeys)
{
var choiceCategory=GalaxyOriginalSettings.CategoryForIndex(filter.CategoryId);
var label=choiceCategory==GalaxyFilterCategory.Security&&name=="lawless"?"无法律管辖":
GalaxyFilterDefinitions.All.FirstOrDefault(d=>d.Category==choiceCategory)?.Choices.FirstOrDefault(c=>c.Key==GalaxyMapFilter.Normalize(name))?.Label;
var text=label is null||label==name?name:$"{label} · {name}";
var item=new CheckBox{Content=new TextBlock{Text=text,TextWrapping=TextWrapping.Wrap,MaxWidth=330},FontSize=12};mapRouteChoices[name]=item;mapRouteRows.Children.Add(item);
item.Click+=(_,_)=>
{
if(updating||Options.MapFilter is not{} current)return;
Options=Options with{MapFilter=current with{SelectedKeys=mapRouteChoices.Where(pair=>pair.Value.IsChecked==true).Select(pair=>pair.Key).ToArray()}};
};
}
}
if(filter is null){mapRouteSummary.Text="横线:保留游戏此类别的路线设置。支持阵营、政体、经济、状态、安全、访问及文明。";return;}
foreach(var (name,item) in mapRouteChoices)item.IsChecked=filter.SelectedKeys.Contains(name);
var category=GalaxyOriginalSettings.CategoryForIndex(filter.CategoryId);
var title=GalaxyFilterDefinitions.All.FirstOrDefault(d=>d.Category==category)?.Label??filter.CategoryId.ToString();
mapRouteSummary.Text=$"{title} · 已选 {filter.SelectedKeys.Count} / {filter.ExpectedKeys.Count} 项\n长按目标规划时同步,并切换游戏星图为此分类显示。";
}
}