From 82b63a0c3ea61cee2c48e466798d4a396fdd4f07 Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Tue, 4 Mar 2025 16:48:50 +0800 Subject: [PATCH] =?UTF-8?q?rft:=20Wpf=E5=9F=BA=E5=BB=BA=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=E8=B0=83=E6=95=B4=20(#12053)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * rft: Wpf基建任务序列化 * rft: 迁移遗漏的CustomInfrastEnabled --- src/MaaWpfGui/Main/AsstProxy.cs | 106 +++--------------- .../Models/AsstTasks/AsstInfrastTask.cs | 104 +++++++++++++++++ .../ViewModels/UI/TaskQueueViewModel.cs | 51 ++++----- .../InfrastSettingsUserControlModel.cs | 4 +- .../TaskQueue/FightSettingsUserControl.xaml | 6 +- .../TaskQueue/InfrastSettingsUserControl.xaml | 2 +- 6 files changed, 144 insertions(+), 129 deletions(-) create mode 100644 src/MaaWpfGui/Models/AsstTasks/AsstInfrastTask.cs diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index a8eda2a955..faa812e934 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -2244,88 +2244,6 @@ namespace MaaWpfGui.Main return id != 0; } - private static JObject SerializeInfrastTaskParams( - IEnumerable order, - string usesOfDrones, - bool continueTraining, - double dormThreshold, - bool dormFilterNotStationedEnabled, - bool dormDormTrustEnabled, - bool originiumShardAutoReplenishment, - bool isCustom, - string filename, - int planIndex) - { - var taskParams = new JObject - { - ["facility"] = new JArray(order.ToArray()), - ["drones"] = usesOfDrones, - ["continue_training"] = continueTraining, - ["threshold"] = dormThreshold, - ["dorm_notstationed_enabled"] = dormFilterNotStationedEnabled, - ["dorm_trust_enabled"] = dormDormTrustEnabled, - ["replenish"] = originiumShardAutoReplenishment, - ["mode"] = isCustom ? 10000 : 0, - ["filename"] = filename, - ["plan_index"] = planIndex, - }; - - return taskParams; - } - - /// - /// 基建换班。 - /// - /// 要换班的设施(有序)。 - /// - /// 无人机用途。可用值包括: - /// - /// _NotUse - /// Money - /// SyntheticJade - /// CombatRecord - /// PureGold - /// OriginStone - /// Chip - /// - /// - /// 训练室是否尝试连续专精 - /// 宿舍进驻心情阈值。 - /// 宿舍是否使用未进驻筛选标签 - /// 宿舍是否使用蹭信赖功能 - /// 制造站搓玉是否补货 - /// 是否开启自定义配置 - /// 自定义配置文件路径 - /// 自定义配置计划编号 - /// 是否成功。 - public bool AsstAppendInfrast( - IEnumerable order, - string usesOfDrones, - bool continueTraining, - double dormThreshold, - bool dormFilterNotStationedEnabled, - bool dormDormTrustEnabled, - bool originiumShardAutoReplenishment, - bool isCustom, - string filename, - int planIndex) - { - var taskParams = SerializeInfrastTaskParams( - order, - usesOfDrones, - continueTraining, - dormThreshold, - dormFilterNotStationedEnabled, - dormDormTrustEnabled, - originiumShardAutoReplenishment, - isCustom, - filename, - planIndex); - AsstTaskId id = AsstAppendTaskWithEncoding(AsstTaskType.Infrast, taskParams); - _taskStatus.Add(id, TaskType.Infrast); - return id != 0; - } - public bool AsstSetInfrastTaskParams( IEnumerable order, string usesOfDrones, @@ -2345,17 +2263,19 @@ namespace MaaWpfGui.Main return false; } - var taskParams = SerializeInfrastTaskParams( - order, - usesOfDrones, - continueTraining, - dormThreshold, - dormFilterNotStationedEnabled, - dormDormTrustEnabled, - originiumShardAutoReplenishment, - isCustom, - filename, - planIndex); + var taskParams = new AsstInfrastTask + { + Facilitys = order.ToList(), + UsesOfDrones = usesOfDrones, + ContinueTraining = continueTraining, + DormThreshold = dormThreshold, + DormFilterNotStationedEnabled = dormFilterNotStationedEnabled, + DormDormTrustEnabled = dormDormTrustEnabled, + OriginiumShardAutoReplenishment = originiumShardAutoReplenishment, + IsCustom = isCustom, + Filename = filename, + PlanIndex = planIndex, + }.Serialize().Params; return AsstSetTaskParamsWithEncoding(id, taskParams); } diff --git a/src/MaaWpfGui/Models/AsstTasks/AsstInfrastTask.cs b/src/MaaWpfGui/Models/AsstTasks/AsstInfrastTask.cs new file mode 100644 index 0000000000..cc6f639ef4 --- /dev/null +++ b/src/MaaWpfGui/Models/AsstTasks/AsstInfrastTask.cs @@ -0,0 +1,104 @@ +// +// MaaWpfGui - A part of the MaaCoreArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License v3.0 only as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY +// +#nullable enable +using System.Collections.Generic; +using MaaWpfGui.Services; +using Newtonsoft.Json.Linq; + +namespace MaaWpfGui.Models.AsstTasks; + +/// +/// 基建任务 +/// +public class AsstInfrastTask : AsstBaseTask +{ + public override AsstTaskType TaskType => AsstTaskType.Infrast; + + /// + /// Gets or sets 要换班的设施(有序) + /// + public List Facilitys { get; set; } = []; + + /// + /// Gets or sets 无人机用途。可用值包括: + /// + /// _NotUse + /// Money + /// SyntheticJade + /// CombatRecord + /// PureGold + /// OriginStone + /// Chip + /// + /// + public string UsesOfDrones { get; set; } + + /// + /// Gets or sets a value indicating whether 训练室是否尝试连续专精 + /// + public bool ContinueTraining { get; set; } + + /// + /// Gets or sets 宿舍进驻心情阈值 + /// + public double DormThreshold { get; set; } + + /// + /// Gets or sets a value indicating whether 宿舍是否使用未进驻筛选标签 + /// + public bool DormFilterNotStationedEnabled { get; set; } + + /// + /// Gets or sets a value indicating whether 宿舍是否使用蹭信赖功能 + /// + public bool DormDormTrustEnabled { get; set; } + + /// + /// Gets or sets a value indicating whether 制造站搓玉是否补货 + /// + public bool OriginiumShardAutoReplenishment { get; set; } + + /// + /// Gets or sets a value indicating whether 是否开启自定义配置 + /// + public bool IsCustom { get; set; } + + /// + /// Gets or sets 自定义配置文件路径 + /// + public string Filename { get; set; } + + /// + /// Gets or sets 自定义配置计划编号 + /// + public int PlanIndex { get; set; } + + public override (AsstTaskType TaskType, JObject Params) Serialize() + { + var taskParams = new JObject + { + ["facility"] = JArray.FromObject(Facilitys), + ["drones"] = UsesOfDrones, + ["continue_training"] = ContinueTraining, + ["threshold"] = DormThreshold, + ["dorm_notstationed_enabled"] = DormFilterNotStationedEnabled, + ["dorm_trust_enabled"] = DormDormTrustEnabled, + ["replenish"] = OriginiumShardAutoReplenishment, + ["mode"] = IsCustom ? 10000 : 0, + ["filename"] = Filename, + ["plan_index"] = PlanIndex, + }; + + return (TaskType, taskParams); + } +} diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index a6e73b9f9d..e5b68cb22d 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -1370,6 +1370,7 @@ namespace MaaWpfGui.ViewModels.UI { ResetTaskSelection(); } + return; } @@ -1715,24 +1716,28 @@ namespace MaaWpfGui.ViewModels.UI private bool AppendInfrast() { + // 被RemoteControlService反射调用,暂不移除 if (InfrastTask.CustomInfrastEnabled && (!File.Exists(InfrastTask.CustomInfrastFile) || CustomInfrastPlanInfoList.Count == 0)) { AddLog(LocalizationHelper.GetString("CustomizeInfrastSelectionEmpty"), UiLogColor.Error); return false; } - var order = InfrastTask.GetInfrastOrderList(); - return Instances.AsstProxy.AsstAppendInfrast( - order, - InfrastTask.UsesOfDrones, - InfrastTask.ContinueTraining, - InfrastTask.DormThreshold / 100.0, - InfrastTask.DormFilterNotStationedEnabled, - InfrastTask.DormTrustEnabled, - InfrastTask.OriginiumShardAutoReplenishment, - InfrastTask.CustomInfrastEnabled, - InfrastTask.CustomInfrastFile, - CustomInfrastPlanIndex); + var (type, param) = new AsstInfrastTask + { + Facilitys = InfrastTask.GetInfrastOrderList(), + UsesOfDrones = InfrastTask.UsesOfDrones, + ContinueTraining = InfrastTask.ContinueTraining, + DormThreshold = InfrastTask.DormThreshold / 100.0, + DormFilterNotStationedEnabled = InfrastTask.DormFilterNotStationedEnabled, + DormDormTrustEnabled = InfrastTask.DormTrustEnabled, + OriginiumShardAutoReplenishment = InfrastTask.OriginiumShardAutoReplenishment, + IsCustom = InfrastTask.CustomInfrastEnabled, + Filename = InfrastTask.CustomInfrastFile, + PlanIndex = CustomInfrastPlanIndex, + }.Serialize(); + + return Instances.AsstProxy.AsstAppendTaskWithEncoding(AsstProxy.TaskType.Infrast, type, param); } private readonly Dictionary> _blackCharacterListMapping = new() @@ -1962,18 +1967,6 @@ namespace MaaWpfGui.ViewModels.UI } */ - private bool _customInfrastEnabled = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CustomInfrastEnabled, bool.FalseString)); - - public bool CustomInfrastEnabled - { - get => _customInfrastEnabled; - set - { - SetAndNotify(ref _customInfrastEnabled, value); - RefreshCustomInfrastPlan(); - } - } - public bool NeedAddCustomInfrastPlanInfo { get; set; } = true; private int _customInfrastPlanIndex = Convert.ToInt32(ConfigurationHelper.GetValue(ConfigurationKeys.CustomInfrastPlanIndex, "0")); @@ -2031,7 +2024,7 @@ namespace MaaWpfGui.ViewModels.UI } } - public ObservableCollection> CustomInfrastPlanList { get; } = new(); + public ObservableCollection> CustomInfrastPlanList { get; } = []; public struct CustomInfrastPlanInfo { @@ -2056,7 +2049,7 @@ namespace MaaWpfGui.ViewModels.UI // ReSharper restore InconsistentNaming } - private List CustomInfrastPlanInfoList { get; } = new(); + private List CustomInfrastPlanInfoList { get; } = []; private bool _customInfrastPlanHasPeriod; private bool _customInfrastInfoOutput; @@ -2067,7 +2060,7 @@ namespace MaaWpfGui.ViewModels.UI CustomInfrastPlanList.Clear(); _customInfrastPlanHasPeriod = false; - if (!CustomInfrastEnabled) + if (!InfrastTask.CustomInfrastEnabled) { return; } @@ -2179,7 +2172,7 @@ namespace MaaWpfGui.ViewModels.UI public void RefreshCustomInfrastPlanIndexByPeriod() { - if (!CustomInfrastEnabled || !_customInfrastPlanHasPeriod || InfrastTaskRunning) + if (!InfrastTask.CustomInfrastEnabled || !_customInfrastPlanHasPeriod || InfrastTaskRunning) { return; } @@ -2206,7 +2199,7 @@ namespace MaaWpfGui.ViewModels.UI public void IncreaseCustomInfrastPlanIndex() { - if (!CustomInfrastEnabled || _customInfrastPlanHasPeriod || CustomInfrastPlanInfoList.Count == 0) + if (!InfrastTask.CustomInfrastEnabled || _customInfrastPlanHasPeriod || CustomInfrastPlanInfoList.Count == 0) { return; } diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs index 428fe7a63f..77f5a5e594 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs @@ -201,8 +201,6 @@ public class InfrastSettingsUserControlModel : TaskViewModel } } - public static TaskQueueViewModel CustomInfrastPlanDataContext { get => Instances.TaskQueueViewModel; } - private string _usesOfDrones = ConfigurationHelper.GetValue(ConfigurationKeys.UsesOfDrones, "Money"); /// @@ -329,7 +327,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel { SetAndNotify(ref _customInfrastEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.CustomInfrastEnabled, value.ToString()); - Instances.TaskQueueViewModel.CustomInfrastEnabled = value; + Instances.TaskQueueViewModel.RefreshCustomInfrastPlan(); } } diff --git a/src/MaaWpfGui/Views/UserControl/TaskQueue/FightSettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/TaskQueue/FightSettingsUserControl.xaml index 1d7f0e6240..7cc378eca0 100644 --- a/src/MaaWpfGui/Views/UserControl/TaskQueue/FightSettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/TaskQueue/FightSettingsUserControl.xaml @@ -10,10 +10,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:s="https://github.com/canton7/Stylet" xmlns:setting="clr-namespace:MaaWpfGui.ViewModels.UI" - xmlns:taskQueue="clr-namespace:MaaWpfGui.ViewModels.UserControl.TaskQueue" + xmlns:task="clr-namespace:MaaWpfGui.ViewModels.UserControl.TaskQueue" xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI" d:Background="White" - d:DataContext="{d:DesignInstance {x:Type taskQueue:FightSettingsUserControlModel}}" + d:DataContext="{d:DesignInstance {x:Type task:FightSettingsUserControlModel}}" d:DesignWidth="220" s:View.ActionTarget="{Binding}" mc:Ignorable="d"> @@ -317,7 +317,7 @@ - + diff --git a/src/MaaWpfGui/Views/UserControl/TaskQueue/InfrastSettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/TaskQueue/InfrastSettingsUserControl.xaml index c3243febe6..477d2b891a 100644 --- a/src/MaaWpfGui/Views/UserControl/TaskQueue/InfrastSettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/TaskQueue/InfrastSettingsUserControl.xaml @@ -146,7 +146,7 @@ -