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"> - + - + - - + +