From 66684553a5014d84d70ea6cecb644a7ff4688cd1 Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:47:16 +0800 Subject: [PATCH] =?UTF-8?q?rft:=20=E6=8B=86=E5=88=86=20=E8=AE=BE=E7=BD=AE-?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E8=AE=BE=E7=BD=AE=20(#11185)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * rft: 拆分 设置-游戏设置 * perf: 简化数据绑定 --- src/MaaWpfGui/Main/AsstProxy.cs | 4 +- .../ViewModels/UI/SettingsViewModel.cs | 123 ++++++------------ .../ViewModels/UI/TaskQueueViewModel.cs | 10 +- .../Settings/GameSettingsUserControlModel.cs | 51 ++++++++ .../Settings/StartSettingsUserControlModel.cs | 4 +- .../ReclamationSettingsUserControlModel.cs | 3 +- src/MaaWpfGui/Views/UI/SettingsView.xaml | 6 +- .../ConnectSettingsOnWakeUpUserControl.xaml | 6 +- .../Views/UserControl/GuideUserControl.xaml | 5 +- .../InfrastSettingsUserControl.xaml | 6 +- .../PerformanceUserControl.xaml.cs | 4 +- .../GameSettingsUserControl.xaml} | 32 +++-- .../GameSettingsUserControl.xaml.cs} | 12 +- 13 files changed, 138 insertions(+), 128 deletions(-) create mode 100644 src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs rename src/MaaWpfGui/Views/UserControl/{GameClientUserControl.xaml => Settings/GameSettingsUserControl.xaml} (73%) rename src/MaaWpfGui/Views/UserControl/{GameClientUserControl.xaml.cs => Settings/GameSettingsUserControl.xaml.cs} (60%) diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 48addc72e5..7e0a540415 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -251,7 +251,7 @@ namespace MaaWpfGui.Main { _logger.Information("Load Resource"); - string clientType = Instances.SettingsViewModel.ClientType; + string clientType = SettingsViewModel.GameSettings.ClientType; string mainRes = Directory.GetCurrentDirectory(); string globalResource = mainRes + @"\resource\global\" + clientType; string mainCache = Directory.GetCurrentDirectory() + @"\cache"; @@ -2013,7 +2013,7 @@ namespace MaaWpfGui.Main }; } - taskParams["client_type"] = Instances.SettingsViewModel.ClientType; + taskParams["client_type"] = SettingsViewModel.GameSettings.ClientType; taskParams["penguin_id"] = Instances.SettingsViewModel.PenguinId; taskParams["DrGrandet"] = Instances.SettingsViewModel.IsDrGrandet; taskParams["expiring_medicine"] = isMainFight && Instances.SettingsViewModel.UseExpiringMedicine ? 9999 : 0; diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index c03123948d..e625da8388 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -17,15 +17,10 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; -using System.ComponentModel; -using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; -using System.Management; using System.Runtime.InteropServices; -using System.Runtime.InteropServices.ComTypes; -using System.Threading; using System.Threading.Tasks; using System.Windows; using HandyControl.Controls; @@ -37,9 +32,7 @@ using MaaWpfGui.Helper; using MaaWpfGui.Main; using MaaWpfGui.Models; using MaaWpfGui.Services.HotKeys; -using MaaWpfGui.Services.RemoteControl; using MaaWpfGui.States; -using MaaWpfGui.Utilities; using MaaWpfGui.Utilities.ValueType; using MaaWpfGui.ViewModels.UserControl.Settings; using MaaWpfGui.ViewModels.UserControl.TaskQueue; @@ -48,8 +41,8 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Serilog; using Stylet; +using static MaaWpfGui.Configuration.GUI; using ComboBox = System.Windows.Controls.ComboBox; -using DarkModeType = MaaWpfGui.Configuration.GUI.DarkModeType; using Timer = System.Timers.Timer; namespace MaaWpfGui.ViewModels.UI @@ -97,6 +90,11 @@ namespace MaaWpfGui.ViewModels.UI #region 设置界面Model + /// + /// Gets 游戏设置model + /// + public static GameSettingsUserControlModel GameSettings { get; } = new(); + /// /// Gets 连接设置model /// @@ -493,24 +491,6 @@ namespace MaaWpfGui.ViewModels.UI #endregion Performance - #region 游戏设置 - - /// - /// Gets the list of the client types. - /// - public List ClientTypeList { get; } = - [ - new() { Display = LocalizationHelper.GetString("NotSelected"), Value = string.Empty }, - new() { Display = LocalizationHelper.GetString("Official"), Value = "Official" }, - new() { Display = LocalizationHelper.GetString("Bilibili"), Value = "Bilibili" }, - new() { Display = LocalizationHelper.GetString("YoStarEN"), Value = "YoStarEN" }, - new() { Display = LocalizationHelper.GetString("YoStarJP"), Value = "YoStarJP" }, - new() { Display = LocalizationHelper.GetString("YoStarKR"), Value = "YoStarKR" }, - new() { Display = LocalizationHelper.GetString("Txwy"), Value = "txwy" }, - ]; - - #endregion - #region 开始唤醒 private string _accountName = ConfigurationHelper.GetValue(ConfigurationKeys.AccountName, string.Empty); @@ -532,61 +512,6 @@ namespace MaaWpfGui.ViewModels.UI Instances.TaskQueueViewModel.QuickSwitchAccount(); } - private string _clientType = ConfigurationHelper.GetValue(ConfigurationKeys.ClientType, string.Empty); - - /// - /// Gets or sets the client type. - /// - public string ClientType - { - get => _clientType; - set - { - SetAndNotify(ref _clientType, value); - ConfigurationHelper.SetValue(ConfigurationKeys.ClientType, value); - VersionUpdateSettings.ResourceInfo = VersionUpdateSettingsUserControlModel.GetResourceVersionByClientType(_clientType); - VersionUpdateSettings.ResourceVersion = VersionUpdateSettings.ResourceInfo.VersionName; - VersionUpdateSettings.ResourceDateTime = VersionUpdateSettings.ResourceInfo.DateTime; - Instances.SettingsViewModel.UpdateWindowTitle(); // 每次修改客户端时更新WindowTitle - Instances.TaskQueueViewModel.UpdateStageList(); - Instances.TaskQueueViewModel.UpdateDatePrompt(); - Instances.AsstProxy.LoadResource(); - AskRestartToApplySettings(_clientType is "YoStarEN"); - } - } - - /// - /// Gets the client type. - /// - public string ClientName - { - get - { - foreach (var item in Instances.SettingsViewModel.ClientTypeList.Where(item => item.Value == ClientType)) - { - return item.Display; - } - - return "Unknown Client"; - } - } - - private readonly Dictionary _serverMapping = new() - { - { string.Empty, "CN" }, - { "Official", "CN" }, - { "Bilibili", "CN" }, - { "YoStarEN", "US" }, - { "YoStarJP", "JP" }, - { "YoStarKR", "KR" }, - { "txwy", "ZH_TW" }, - }; - - /// - /// Gets the server type. - /// - public string ServerType => _serverMapping[ClientType]; - #endregion 开始唤醒 #region 基建设置 @@ -1176,7 +1101,7 @@ namespace MaaWpfGui.ViewModels.UI } var localizedName = DataHelper.GetLocalizedCharacterName(name, OperNameLocalization); - if (!string.IsNullOrEmpty(localizedName) && !(_clientType.Contains("YoStar") && DataHelper.GetLocalizedCharacterName(name, "en-us") == DataHelper.GetLocalizedCharacterName(name, "zh-cn"))) + if (!string.IsNullOrEmpty(localizedName) && !(GameSettings.ClientType.Contains("YoStar") && DataHelper.GetLocalizedCharacterName(name, "en-us") == DataHelper.GetLocalizedCharacterName(name, "zh-cn"))) { roguelikeCoreCharList.Add(localizedName); } @@ -3166,7 +3091,7 @@ namespace MaaWpfGui.ViewModels.UI { if (_operNameLanguage == "OperNameLanguageClient") { - return DataHelper.ClientLanguageMapper[_clientType]; + return DataHelper.ClientLanguageMapper[GameSettings.ClientType]; } if (!_operNameLanguage.Contains('.')) @@ -3451,5 +3376,37 @@ namespace MaaWpfGui.ViewModels.UI : string.Empty; rvm.WindowTitle = $"{prefix}MAA{currentConfiguration} - {VersionUpdateSettingsUserControlModel.CoreVersion}{resourceVersion}{connectConfigName}{connectAddress}{clientName}"; } + + /// + /// Gets the client type. + /// + private string ClientName + { + get + { + foreach (var item in GameSettings.ClientTypeList.Where(item => item.Value == GameSettings.ClientType)) + { + return item.Display; + } + + return "Unknown Client"; + } + } + + private readonly Dictionary _serverMapping = new() + { + { string.Empty, "CN" }, + { "Official", "CN" }, + { "Bilibili", "CN" }, + { "YoStarEN", "US" }, + { "YoStarJP", "JP" }, + { "YoStarKR", "KR" }, + { "txwy", "ZH_TW" }, + }; + + /// + /// Gets the server type. + /// + public string ServerType => _serverMapping[GameSettings.ClientType]; } } diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index 9f829a1a43..afe373eb90 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -128,7 +128,7 @@ namespace MaaWpfGui.ViewModels.UI if (actions.ExitArknights) { - var mode = Instances.SettingsViewModel.ClientType; + var mode = SettingsViewModel.GameSettings.ClientType; if (!Instances.AsstProxy.AsstStartCloseDown(mode)) { AddLog(LocalizationHelper.GetString("CloseArknightsFailed"), UiLogColor.Error); @@ -536,7 +536,7 @@ namespace MaaWpfGui.ViewModels.UI SetStopped(); } - var mode = Instances.SettingsViewModel.ClientType; + var mode = SettingsViewModel.GameSettings.ClientType; if (!Instances.AsstProxy.AsstAppendCloseDown(mode)) { AddLog(LocalizationHelper.GetString("CloseArknightsFailed"), UiLogColor.Error); @@ -599,7 +599,7 @@ namespace MaaWpfGui.ViewModels.UI "AutoRoguelike", ]; - if (Instances.SettingsViewModel.ClientType is not "txwy") + if (SettingsViewModel.GameSettings.ClientType is not "txwy") { taskList.Add("Reclamation"); } @@ -1466,7 +1466,7 @@ namespace MaaWpfGui.ViewModels.UI private static bool AppendStart() { - var mode = Instances.SettingsViewModel.ClientType; + var mode = SettingsViewModel.GameSettings.ClientType; var enable = mode.Length != 0; Instances.SettingsViewModel.AccountName = Instances.SettingsViewModel.AccountName.Trim(); var accountName = Instances.SettingsViewModel.AccountName; @@ -1667,7 +1667,7 @@ namespace MaaWpfGui.ViewModels.UI var blackList = Instances.SettingsViewModel.CreditBlackList.Split(';', ';') .Select(s => s.Trim()); - blackList = blackList.Union(_blackCharacterListMapping[Instances.SettingsViewModel.ClientType]); + blackList = blackList.Union(_blackCharacterListMapping[SettingsViewModel.GameSettings.ClientType]); return Instances.AsstProxy.AsstAppendMall( !string.IsNullOrEmpty(this.Stage) && Instances.SettingsViewModel.CreditFightTaskEnabled, diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs new file mode 100644 index 0000000000..eebf922577 --- /dev/null +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs @@ -0,0 +1,51 @@ +#nullable enable +using System.Collections.Generic; +using MaaWpfGui.Constants; +using MaaWpfGui.Helper; +using MaaWpfGui.Utilities.ValueType; +using MaaWpfGui.ViewModels.UI; +using Stylet; + +namespace MaaWpfGui.ViewModels.UserControl.Settings; + +public class GameSettingsUserControlModel : PropertyChangedBase +{ + private static VersionUpdateSettingsUserControlModel VersionUpdateSettings => SettingsViewModel.VersionUpdateSettings; + + /// + /// Gets the list of the client types. + /// + public List ClientTypeList { get; } = + [ + new() { Display = LocalizationHelper.GetString("NotSelected"), Value = string.Empty }, + new() { Display = LocalizationHelper.GetString("Official"), Value = "Official" }, + new() { Display = LocalizationHelper.GetString("Bilibili"), Value = "Bilibili" }, + new() { Display = LocalizationHelper.GetString("YoStarEN"), Value = "YoStarEN" }, + new() { Display = LocalizationHelper.GetString("YoStarJP"), Value = "YoStarJP" }, + new() { Display = LocalizationHelper.GetString("YoStarKR"), Value = "YoStarKR" }, + new() { Display = LocalizationHelper.GetString("Txwy"), Value = "txwy" }, + ]; + + private string _clientType = ConfigurationHelper.GetValue(ConfigurationKeys.ClientType, string.Empty); + + /// + /// Gets or sets the client type. + /// + public string ClientType + { + get => _clientType; + set + { + SetAndNotify(ref _clientType, value); + ConfigurationHelper.SetValue(ConfigurationKeys.ClientType, value); + VersionUpdateSettings.ResourceInfo = VersionUpdateSettingsUserControlModel.GetResourceVersionByClientType(_clientType); + VersionUpdateSettings.ResourceVersion = VersionUpdateSettings.ResourceInfo.VersionName; + VersionUpdateSettings.ResourceDateTime = VersionUpdateSettings.ResourceInfo.DateTime; + Instances.SettingsViewModel.UpdateWindowTitle(); // 每次修改客户端时更新WindowTitle + Instances.TaskQueueViewModel.UpdateStageList(); + Instances.TaskQueueViewModel.UpdateDatePrompt(); + Instances.AsstProxy.LoadResource(); + SettingsViewModel.AskRestartToApplySettings(_clientType is "YoStarEN"); + } + } +} diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs index 425af3b5e6..4de144ec03 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs @@ -110,9 +110,9 @@ public class StartSettingsUserControlModel : PropertyChangedBase { SetAndNotify(ref _openEmulatorAfterLaunch, value); ConfigurationHelper.SetValue(ConfigurationKeys.StartEmulator, value.ToString()); - if (Instances.SettingsViewModel.ClientType == string.Empty && _runningState.GetIdle()) + if (SettingsViewModel.GameSettings.ClientType == string.Empty && _runningState.GetIdle()) { - Instances.SettingsViewModel.ClientType = "Official"; + SettingsViewModel.GameSettings.ClientType = "Official"; } } } diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/ReclamationSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/ReclamationSettingsUserControlModel.cs index 4c78da1aaf..8d5490ff64 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/ReclamationSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/ReclamationSettingsUserControlModel.cs @@ -17,6 +17,7 @@ using System.Collections.Generic; using MaaWpfGui.Constants; using MaaWpfGui.Helper; using MaaWpfGui.Utilities.ValueType; +using MaaWpfGui.ViewModels.UI; using Stylet; namespace MaaWpfGui.ViewModels.UserControl.TaskQueue; @@ -79,7 +80,7 @@ public class ReclamationSettingsUserControlModel : PropertyChangedBase { if (string.IsNullOrEmpty(_reclamationToolToCraft)) { - return LocalizationHelper.GetString("ReclamationToolToCraftPlaceholder", DataHelper.ClientLanguageMapper[Instances.SettingsViewModel.ClientType]); + return LocalizationHelper.GetString("ReclamationToolToCraftPlaceholder", DataHelper.ClientLanguageMapper[SettingsViewModel.GameSettings.ClientType]); } return _reclamationToolToCraft; diff --git a/src/MaaWpfGui/Views/UI/SettingsView.xaml b/src/MaaWpfGui/Views/UI/SettingsView.xaml index 006229e009..c139a66d95 100644 --- a/src/MaaWpfGui/Views/UI/SettingsView.xaml +++ b/src/MaaWpfGui/Views/UI/SettingsView.xaml @@ -15,7 +15,6 @@ xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI" xmlns:userControl="clr-namespace:MaaWpfGui.Views.UserControl" xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels" - xmlns:vm="clr-namespace:MaaWpfGui" d:Background="White" d:DataContext="{d:DesignInstance {x:Type ui:SettingsViewModel}}" d:DesignHeight="4000" @@ -59,7 +58,10 @@ IsEnabled="{Binding Idle}" /> - + - + @@ -127,8 +127,8 @@ hc:InfoElement.Title="{DynamicResource ClientType}" DisplayMemberPath="Display" IsHitTestVisible="{Binding Idle}" - ItemsSource="{Binding ClientTypeList}" - SelectedValue="{Binding ClientType}" + ItemsSource="{Binding ClientTypeList, Source={x:Static ui:SettingsViewModel.GameSettings}}" + SelectedValue="{Binding ClientType, Source={x:Static ui:SettingsViewModel.GameSettings}}" SelectedValuePath="Value" Style="{StaticResource ComboBoxExtend}" Visibility="{c:Binding !TaskSettingVisibilities.Guide}" /> diff --git a/src/MaaWpfGui/Views/UserControl/GuideUserControl.xaml b/src/MaaWpfGui/Views/UserControl/GuideUserControl.xaml index 741fa1e378..e63aa97714 100644 --- a/src/MaaWpfGui/Views/UserControl/GuideUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/GuideUserControl.xaml @@ -10,11 +10,10 @@ xmlns:helper="clr-namespace:MaaWpfGui.Helper" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:s="https://github.com/canton7/Stylet" - xmlns:styles="clr-namespace:MaaWpfGui.Styles" + xmlns:settingsViews="clr-namespace:MaaWpfGui.Views.UserControl.Settings" xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI" xmlns:userControl="clr-namespace:MaaWpfGui.Views.UserControl" xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels" - xmlns:vm="clr-namespace:MaaWpfGui" d:DataContext="{d:DesignInstance {x:Type ui:SettingsViewModel}}" d:DesignWidth="400" mc:Ignorable="d"> @@ -115,7 +114,7 @@ - + + IsEnabled="{c:Binding '!(ClientType == "Official" or ClientType == "Bilibili" or ClientType == "")', + Source={x:Static ui:SettingsViewModel.GameSettings}}"> + Visibility="{c:Binding 'ClientType == "Official" or ClientType == "Bilibili" or ClientType == ""', + Source={x:Static ui:SettingsViewModel.GameSettings}}" /> diff --git a/src/MaaWpfGui/Views/UserControl/PerformanceUserControl.xaml.cs b/src/MaaWpfGui/Views/UserControl/PerformanceUserControl.xaml.cs index 42f45d64e4..a78a6a58b9 100644 --- a/src/MaaWpfGui/Views/UserControl/PerformanceUserControl.xaml.cs +++ b/src/MaaWpfGui/Views/UserControl/PerformanceUserControl.xaml.cs @@ -1,4 +1,4 @@ -// +// // MaaWpfGui - A part of the MaaCoreArknights project // Copyright (C) 2021 MistEO and Contributors // @@ -14,7 +14,7 @@ namespace MaaWpfGui.Views.UserControl { /// - /// GameClientUserControl.xaml 的交互逻辑 + /// GameSettingsUserControl.xaml 的交互逻辑 /// public partial class PerformanceUserControl : System.Windows.Controls.UserControl { diff --git a/src/MaaWpfGui/Views/UserControl/GameClientUserControl.xaml b/src/MaaWpfGui/Views/UserControl/Settings/GameSettingsUserControl.xaml similarity index 73% rename from src/MaaWpfGui/Views/UserControl/GameClientUserControl.xaml rename to src/MaaWpfGui/Views/UserControl/Settings/GameSettingsUserControl.xaml index 0ef0b219b9..64eeef1d94 100644 --- a/src/MaaWpfGui/Views/UserControl/GameClientUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/Settings/GameSettingsUserControl.xaml @@ -1,5 +1,5 @@ - + - + NavigateUri="{Binding Source={x:Static constants:MaaUrls.YostarENResolution}}" + TextDecorations="None"> + - + NavigateUri="{Binding Source={x:Static constants:MaaUrls.OverseasAdaptation}}" + TextDecorations="None"> + diff --git a/src/MaaWpfGui/Views/UserControl/GameClientUserControl.xaml.cs b/src/MaaWpfGui/Views/UserControl/Settings/GameSettingsUserControl.xaml.cs similarity index 60% rename from src/MaaWpfGui/Views/UserControl/GameClientUserControl.xaml.cs rename to src/MaaWpfGui/Views/UserControl/Settings/GameSettingsUserControl.xaml.cs index 91fa168406..2284763598 100644 --- a/src/MaaWpfGui/Views/UserControl/GameClientUserControl.xaml.cs +++ b/src/MaaWpfGui/Views/UserControl/Settings/GameSettingsUserControl.xaml.cs @@ -1,4 +1,4 @@ -// +// // MaaWpfGui - A part of the MaaCoreArknights project // Copyright (C) 2021 MistEO and Contributors // @@ -11,17 +11,17 @@ // but WITHOUT ANY WARRANTY // -namespace MaaWpfGui.Views.UserControl +namespace MaaWpfGui.Views.UserControl.Settings { /// - /// GameClientUserControl.xaml 的交互逻辑 + /// GameSettingsUserControl.xaml 的交互逻辑 /// - public partial class GameClientUserControl : System.Windows.Controls.UserControl + public partial class GameSettingsUserControl : System.Windows.Controls.UserControl { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public GameClientUserControl() + public GameSettingsUserControl() { InitializeComponent(); }