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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Automation.Provider;
using Microsoft.UI.Xaml.Media;
using XFEEDToolBox.Controls;

namespace XFEEDToolBox;

public partial class App
{
    private static async Task<object> RunEngineeringGradeProbeAsync(string directory)
    {
        static void Require(bool value,string message){if(!value)throw new InvalidOperationException(message);}
        Require(ViewModel.OfflinePreview,"Grade inspection requires an isolated offline preview.");
        var shell=Views.AppShellPage.Current!;shell.Navigate(typeof(Views.RefitPage));await Task.Delay(180);
        ViewModel.RefitEdsyLink="https://edsy.org/#/L=K100000H4C0S00,FBR00FBR00,,9p300A4Y00AKA00AZo00Ans00B1U00BH600BWQ00,,7Og0003w00mpU0nG0-0nF0-";
        await ViewModel.ImportEdsyCommand.ExecuteAsync(null);ViewModel.RefitCategoryIndex=2;await Task.Delay(150);
        ViewModel.RefitSlot=ViewModel.RefitVisibleSlots.First(s=>s.Module?.Slot=="FrameShiftDrive");
        var refit=(Views.RefitPage)shell.CurrentPage!;var tabs=(SelectorBar)refit.FindName("InspectorTabs");tabs.SelectedItem=tabs.Items[1];
        MainWindow.AppWindow.Resize(new(2200,1500));MainWindow.AppWindow.Show(false);await Task.Delay(250);refit.UpdateLayout();
        var bound=(EngineeringGradePicker)refit.FindName("EngineeringGrade");ViewModel.RefitGrade=5;await Task.Delay(100);
        Require(bound.IsEnabled&&bound.Value==5,"Editor target grade did not reach the real picker.");
        ((IInvokeProvider)new ButtonAutomationPeer(Descendants(bound).OfType<Button>().ElementAt(3)).GetPattern(PatternInterface.Invoke)).Invoke();
        Require(ViewModel.RefitGrade==4,"Picker click did not update the editor target.");ViewModel.RefitGrade=5;await Task.Delay(80);
        await CaptureRefinementElementAsync((FrameworkElement)refit.FindName("EngineeringGradePanel"),Path.Combine(directory,"refit-grade-row.png"));
        await CaptureRefinementElementAsync((FrameworkElement)refit.FindName("InspectorPanel"),Path.Combine(directory,"refit-inspector.png"));
        var stack=new StackPanel{Spacing=18,Margin=new(32)};
        stack.Children.Add(new TextBlock{Text="改装等级 · 游戏原始贴图",FontSize=24});
        var pickers=new List<EngineeringGradePicker>();
        for(var grade=0;grade<=5;grade++)
        {
            var picker=new EngineeringGradePicker{Value=grade==0?-1:grade};pickers.Add(picker);
            var row=new StackPanel{Orientation=Orientation.Horizontal,Spacing=18};
            row.Children.Add(new TextBlock{Text=grade==0?"未改装":$"等级 G{grade}",Width=95,VerticalAlignment=VerticalAlignment.Center});row.Children.Add(picker);stack.Children.Add(row);
        }
        var page=new Page{Content=stack,Background=(Brush)Current.Resources["PanelBrush"]};MainWindow.Content=page;MainWindow.AppWindow.Resize(new(750,630));
        await CapturePageAsync(page,Path.Combine(directory,"engineering-grades.png"));
        foreach(var picker in pickers)Require(Descendants(picker).OfType<Image>().Count()==5,"Each grade must have exactly one image.");
        var fourth=Descendants(pickers[1]).OfType<Button>().ElementAt(3);
        ((IInvokeProvider)new ButtonAutomationPeer(fourth).GetPattern(PatternInterface.Invoke)).Invoke();
        Require(pickers[1].Value==4,"Grade click did not update its value.");pickers[1].Value=1;
        MainWindow.AppWindow.Show(false);await Task.Delay(200);page.UpdateLayout();
        var rectangles=pickers.Select(p=>Descendants(p).OfType<Image>().Select(i=>{var point=i.TransformToVisual(p).TransformPoint(new());return new{point.X,point.Y,i.ActualWidth,i.ActualHeight};}).ToArray()).ToArray();
        await File.WriteAllTextAsync(Path.Combine(directory,"grade-rectangles.json"),System.Text.Json.JsonSerializer.Serialize(rectangles));
        Require(rectangles.All(row=>row.Length==5&&row.All(r=>r.ActualWidth>0&&r.ActualHeight>0)&&row.Max(r=>r.Y)-row.Min(r=>r.Y)<.01),"Grade images must share one row and centre.");
        pickers[5].IsEnabled=false;Require(Descendants(pickers[5]).OfType<Button>().All(b=>!b.IsEnabled),"Disabled engineering must disable every grade.");
        pickers[5].IsEnabled=true;
        return new{image="engineering-grades.png",editorImage="refit-grade-row.png",editorTwoWayBinding=true,singleImagePerGrade=true,unmodifiedValue=pickers[0].Value,clickChangedToFour=true,disabledInherited=true,
            equalRows=rectangles,version=typeof(App).Assembly.GetName().Version?.ToString(),gameFlightCommandsInvoked=false};
    }
}