using System.Text.Json; using XFEEDToolBox.Controls; using XFEEDToolBox.Core.Galaxy; namespace XFEEDToolBox; public partial class App { private static async Task RunGalaxyStateOptionsProbeAsync(string directory) { static void Require(bool value,string text){if(!value)throw new InvalidOperationException(text);} var previous=MainWindow.Content; var previousPosition=MainWindow.AppWindow.Position; var original=new HashSet{"None","Boom","Unpopulated","Frontline"}; var filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Category=GalaxyFilterCategory.State,RequireOriginalStateFacts=true,Values=null, OriginalRouteOptionKeys=new Dictionary>{{GalaxyFilterCategory.State,original}}}; var panel=new GalaxyFilterPanel{Filter=filter,Systems=Array.Empty(),Width=420, QueryChoices=new[]{new GalaxyFilterChoice("publiconly","公共兼容项(本夹具不应显示)")}}; var host=new Grid{Background=new Microsoft.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(255,11,16,23))}; host.Children.Add(new Border{Child=panel,HorizontalAlignment=HorizontalAlignment.Left,Margin=new(20)});MainWindow.Content=host; Panel? choiceContainer=null; // The visual tree retains removed rows during WinUI exit transitions. // After locating the source list, inspect its current logical children. CheckBox[] Rows()=>choiceContainer is{} current?current.Children.OfType().ToArray(): Descendants(panel).OfType().Where(c=>c.Content is StackPanel stack&&stack.Children.OfType().Any()).ToArray(); string Text(CheckBox row)=>((StackPanel)row.Content).Children.OfType().Single().Text; try { MainWindow.AppWindow.Move(new(-30000,-30000));MainWindow.AppWindow.Show(false); await Task.Delay(100);host.UpdateLayout(); var rows=Rows();Require(rows.Length==4&&rows.All(c=>c.IsChecked==true),"Original State rows were replaced by static/public choices."); choiceContainer=rows[0].Parent as Panel??throw new InvalidOperationException("Original State source list has no logical container."); var search=Descendants(panel).OfType().Single(t=>t.PlaceholderText=="查找筛选值(中文或原名)"); var scroll=Descendants(panel).OfType().First(); if(scroll.Content is UIElement content) {var offset=search.TransformToVisual(content).TransformPoint(new(0,0)).Y;scroll.ChangeView(null,Math.Max(0,offset-60),null,true);} await CaptureRefinementElementAsync(host,Path.Combine(directory,"state-options-all.png")); search.Text="boom";await Task.Delay(40);host.UpdateLayout(); var searched=Rows();var boomLabel=GalaxyStateFilterChoices.FromOriginal(filter)!.Single(c=>c.Key=="boom").Label; Require(searched.Length==1&&Text(searched.Single()).StartsWith(boomLabel+" ",StringComparison.Ordinal), "Original State search did not narrow the shown rows: "+string.Join("; ",searched.Select(Text))); Rows().Single().IsChecked=false;await Task.Delay(40); Require(panel.Filter.Values is{} selected&&selected.SetEquals(new[]{"none","unpopulated","frontline"}),"Cancelling a searched State row lost source rows outside the search."); search.Text="";await Task.Delay(40); rows=Rows();Require(rows.Length==4&&rows.Count(c=>c.IsChecked==true)==3&&rows.Any(c=>Text(c).Contains("unpopulated"))&&rows.Any(c=>Text(c).Contains("frontline")),"Dynamic original State options were lost after an edit."); await CaptureRefinementElementAsync(host,Path.Combine(directory,"state-options-after-search.png")); var result=new{syntheticOriginalOptions=true,noCatalogueCoordinatesSupplied=true,staticAndPublicRowsExcluded=true, allFourInitiallySelected=true,searchThenUncheckPreservesOtherThree=true,labels=rows.Select(Text).ToArray(),selectedKeys=panel.Filter.Values!.Order().ToArray(),gameAccess=false}; await File.WriteAllTextAsync(Path.Combine(directory,"state-options-probe.json"),JsonSerializer.Serialize(result,new JsonSerializerOptions{WriteIndented=true})); return result; } finally{MainWindow.AppWindow.Hide();MainWindow.AppWindow.Move(previousPosition);MainWindow.Content=previous;} } }