diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index eb70fb63d1..f0d0d25c34 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -19,6 +19,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Net.Sockets; +using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -32,6 +33,7 @@ using MaaWpfGui.Helper; using MaaWpfGui.Services; using MaaWpfGui.Services.Notification; using MaaWpfGui.States; +using MaaWpfGui.ViewModels; using MaaWpfGui.ViewModels.UI; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -436,6 +438,7 @@ namespace MaaWpfGui.Main case AsstMsg.SubTaskCompleted: case AsstMsg.SubTaskExtraInfo: ProcSubTaskMsg(msg, details); + TaskQueueViewModel.InvokeProcSubTaskMsg(msg, details); break; case AsstMsg.SubTaskStopped: @@ -1693,9 +1696,6 @@ namespace MaaWpfGui.Main Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("StageQueue") + $" {subTaskDetails!["stage_code"]} - {subTaskDetails["stars"]} ★", UiLogColor.Info); break; - case "AccountSwitch": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AccountSwitch") + $" -->> {subTaskDetails!["account_name"]}", UiLogColor.Info); // subTaskDetails!["current_account"] - break; case "RoguelikeCollapsalParadigms": string deepen_or_weaken_str = subTaskDetails!["deepen_or_weaken"]?.ToString() ?? "Unknown"; if (!int.TryParse(deepen_or_weaken_str, out int deepen_or_weaken)) diff --git a/src/MaaWpfGui/ViewModels/TaskViewModel.cs b/src/MaaWpfGui/ViewModels/TaskViewModel.cs new file mode 100644 index 0000000000..b68e167223 --- /dev/null +++ b/src/MaaWpfGui/ViewModels/TaskViewModel.cs @@ -0,0 +1,25 @@ +// +// 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 MaaWpfGui.Main; +using Newtonsoft.Json.Linq; +using Stylet; + +namespace MaaWpfGui.ViewModels; + +public class TaskViewModel : PropertyChangedBase +{ + public virtual void ProcSubTaskMsg(AsstMsg msg, JObject details) + { + } +} diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index 8b9dd6bbba..104ba31891 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -18,7 +18,7 @@ using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; -using System.Runtime.InteropServices; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -117,6 +117,8 @@ namespace MaaWpfGui.ViewModels.UI #endregion 长草任务Model + private static readonly IEnumerable TaskViewModelTypes = InitTaskViewModelList(); + /// /// 实时更新任务顺序 /// @@ -2249,5 +2251,31 @@ namespace MaaWpfGui.ViewModels.UI ++CustomInfrastPlanIndex; } + + private static IEnumerable InitTaskViewModelList() + { + var types = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == "MaaWpfGui.ViewModels.UserControl.TaskQueue" && t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(TaskViewModel))); + foreach (var type in types) + { + // 获取 Instance 字段 + if (type.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static) is PropertyInfo property) + { + // 获取实例 + if (property.GetValue(null) is TaskViewModel instance) + { + yield return instance; + } + } + } + } + + public static void InvokeProcSubTaskMsg(AsstMsg msg, JObject details) + { + foreach (var instance in TaskViewModelTypes) + { + // 调用 ProcSubTaskMsg 方法 + instance.ProcSubTaskMsg(msg, details); + } + } } } diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs index ba498d8493..977eec311b 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs @@ -1,4 +1,4 @@ -// +// // MaaWpfGui - A part of the MaaCoreArknights project // Copyright (C) 2021 MistEO and Contributors // @@ -13,11 +13,12 @@ #nullable enable using MaaWpfGui.Constants; using MaaWpfGui.Helper; -using Stylet; +using MaaWpfGui.Main; +using Newtonsoft.Json.Linq; namespace MaaWpfGui.ViewModels.UserControl.TaskQueue; -public class StartUpSettingsUserControlModel : PropertyChangedBase +public class StartUpSettingsUserControlModel : TaskViewModel { static StartUpSettingsUserControlModel() { @@ -44,4 +45,12 @@ public class StartUpSettingsUserControlModel : PropertyChangedBase { Instances.TaskQueueViewModel.QuickSwitchAccount(); } + + public override void ProcSubTaskMsg(AsstMsg msg, JObject details) + { + if (msg == AsstMsg.SubTaskExtraInfo && details["what"]?.ToString() == "AccountSwitch") + { + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AccountSwitch") + $" -->> {details["details"]!["account_name"]}", UiLogColor.Info); // subTaskDetails!["current_account"] + } + } }