From 87bbd07ecf97d79e098bdb3f99548bfbf0f98249 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Mon, 26 May 2025 16:48:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=80=BB=E8=BE=91=E4=B8=8E=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=95=88=E6=9E=9C=20(#12791)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 仓库识别持久化储存 * feat: 干员识别数据支持启动时显示 * fix: 小工具初始化 * perf: 干员识别使用 VirtualizingWrapPanel,加快加载速度 * perf: 掉落识别使用 VirtualizingWrapPanel,加快加载速度 * feat: 逐项滚动 --- src/MaaWpfGui/Constants/ConfigurationKeys.cs | 2 + src/MaaWpfGui/MaaWpfGui.csproj | 1 + .../ViewModels/UI/RecognizerViewModel.cs | 75 +++++++++++++++--- src/MaaWpfGui/Views/UI/RecognizerView.xaml | 76 ++++++++----------- 4 files changed, 98 insertions(+), 56 deletions(-) diff --git a/src/MaaWpfGui/Constants/ConfigurationKeys.cs b/src/MaaWpfGui/Constants/ConfigurationKeys.cs index 1e607c0e57..020bd16132 100644 --- a/src/MaaWpfGui/Constants/ConfigurationKeys.cs +++ b/src/MaaWpfGui/Constants/ConfigurationKeys.cs @@ -105,6 +105,8 @@ namespace MaaWpfGui.Constants public const string AutoSetTime = "Recruit.AutoSetTime"; public const string RecruitmentShowPotential = "Recruit.ShowPotential"; + public const string DepotResult = "Depot.DepotResult"; + public const string InfrastMode = "Infrast.InfrastMode"; public const string DormThreshold = "Infrast.DormThreshold"; public const string UsesOfDrones = "Infrast.UsesOfDrones"; diff --git a/src/MaaWpfGui/MaaWpfGui.csproj b/src/MaaWpfGui/MaaWpfGui.csproj index c7309c6676..5b8f5d90b0 100644 --- a/src/MaaWpfGui/MaaWpfGui.csproj +++ b/src/MaaWpfGui/MaaWpfGui.csproj @@ -134,6 +134,7 @@ + diff --git a/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs b/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs index 5bf5c2d08a..d61e9db479 100644 --- a/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs @@ -54,6 +54,8 @@ namespace MaaWpfGui.ViewModels.UI _peepImageTimer.Elapsed += RefreshPeepImageAsync; _peepImageTimer.Interval = 1000d / PeepTargetFps; _gachaTimer.Tick += RefreshGachaTip; + LoadDepotDetails(); + LoadOperBoxDetails(); } private void RunningState_IdleChanged(object? sender, bool e) @@ -351,6 +353,31 @@ namespace MaaWpfGui.ViewModels.UI public string? Count { get; set; } } + private void SaveDepotDetails(JObject details) + { + var json = details.ToString(Formatting.None); + ConfigurationHelper.SetValue(ConfigurationKeys.DepotResult, json); + } + + private void LoadDepotDetails() + { + var json = ConfigurationHelper.GetValue(ConfigurationKeys.DepotResult, string.Empty); + if (string.IsNullOrWhiteSpace(json)) + { + return; + } + + try + { + var details = JObject.Parse(json); + DepotParse(details); + } + catch + { + // 兼容老数据或异常时忽略 + } + } + /// /// Gets or sets the ArkPlanner result. /// @@ -424,6 +451,7 @@ namespace MaaWpfGui.ViewModels.UI } DepotInfo = LocalizationHelper.GetString("IdentificationCompleted"); + SaveDepotDetails(details); return true; } @@ -530,7 +558,7 @@ namespace MaaWpfGui.ViewModels.UI public string OperBoxExportData { get; set; } = string.Empty; - private JArray _operBoxDataArray = (JArray)(JsonConvert.DeserializeObject(ConfigurationHelper.GetValue(ConfigurationKeys.OperBoxData, new JArray().ToString())) ?? new JArray()); + private JArray _operBoxDataArray = []; public JArray OperBoxDataArray { @@ -538,7 +566,6 @@ namespace MaaWpfGui.ViewModels.UI set { SetAndNotify(ref _operBoxDataArray, value); - ConfigurationHelper.SetValue(ConfigurationKeys.OperBoxData, value.ToString()); _operBoxPotential = null; // reset } } @@ -591,10 +618,7 @@ namespace MaaWpfGui.ViewModels.UI public ObservableCollection OperBoxHaveList { get => _operBoxHaveList; - set - { - SetAndNotify(ref _operBoxHaveList, value); - } + set => SetAndNotify(ref _operBoxHaveList, value); } private ObservableCollection _operBoxNotHaveList = []; @@ -602,9 +626,31 @@ namespace MaaWpfGui.ViewModels.UI public ObservableCollection OperBoxNotHaveList { get => _operBoxNotHaveList; - set + set => SetAndNotify(ref _operBoxNotHaveList, value); + } + + private void SaveOperBoxDetails(JObject details) + { + var json = details.ToString(Formatting.None); + ConfigurationHelper.SetValue(ConfigurationKeys.OperBoxData, json); + } + + private void LoadOperBoxDetails() + { + var json = ConfigurationHelper.GetValue(ConfigurationKeys.OperBoxData, string.Empty); + if (string.IsNullOrWhiteSpace(json)) { - SetAndNotify(ref _operBoxNotHaveList, value); + return; + } + + try + { + var details = JObject.Parse(json); + OperBoxParse(details); + } + catch + { + // 兼容老数据或异常时忽略 } } @@ -613,15 +659,20 @@ namespace MaaWpfGui.ViewModels.UI public bool OperBoxParse(JObject? details) { - var allOpers = (details?["all_opers"] as JArray)?.Cast().Where(o => o["id"] != null).ToList(); - var ownOpers = (details?["own_opers"] as JArray)?.Cast().Where(o => o["id"] != null).ToList(); + if (details == null) + { + return false; + } + + var allOpers = (details["all_opers"] as JArray)?.Cast().Where(o => o["id"] != null).ToList(); + var ownOpers = (details["own_opers"] as JArray)?.Cast().Where(o => o["id"] != null).ToList(); if (allOpers == null || ownOpers == null) { return false; } - bool done = (bool)(details?["done"] ?? false); + bool done = (bool)(details["done"] ?? false); var ownOperDict = ownOpers.ToDictionary(o => (string)o["id"]!); var allOperDict = allOpers.ToDictionary(o => (string)o["id"]!); foreach (var operBox in allOpers) @@ -671,7 +722,7 @@ namespace MaaWpfGui.ViewModels.UI } OperBoxExportData = exportList.ToString(Formatting.Indented); - _runningState.SetIdle(true); + SaveOperBoxDetails(details); return true; } diff --git a/src/MaaWpfGui/Views/UI/RecognizerView.xaml b/src/MaaWpfGui/Views/UI/RecognizerView.xaml index 64adc80d18..b043883862 100644 --- a/src/MaaWpfGui/Views/UI/RecognizerView.xaml +++ b/src/MaaWpfGui/Views/UI/RecognizerView.xaml @@ -11,6 +11,7 @@ xmlns:s="https://github.com/canton7/Stylet" xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI" xmlns:uiBehaviors="clr-namespace:MaaWpfGui.Extensions.UIBehaviors" + xmlns:vwp="clr-namespace:WpfToolkit.Controls;assembly=VirtualizingWrapPanel" d:DataContext="{d:DesignInstance {x:Type ui:RecognizerViewModel}}" d:DesignHeight="600" d:DesignWidth="800" @@ -186,7 +187,7 @@ - + - - - - - - - - - + + + VirtualizingPanel.ScrollUnit="Pixel"> - + - + - + + + VirtualizingPanel.ScrollUnit="Pixel"> - + - + - - + +