From bb5cc0e1efad97f2a5eee670e2af4e05bc90f2c2 Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Sat, 16 Nov 2024 11:07:37 +0800 Subject: [PATCH] =?UTF-8?q?rft:=20=E6=8B=86=E5=88=86=20=E8=AE=BE=E7=BD=AE-?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E8=AE=BE=E7=BD=AE=20(#11153)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * rft: 拆分 设置-界面设置 * rft: 还原菜单相关内容到SettingsViewModel --- src/MaaWpfGui/Configuration/GUI.cs | 2 - src/MaaWpfGui/Constants/ConfigurationKeys.cs | 3 +- src/MaaWpfGui/Helper/DataHelper.cs | 14 +- src/MaaWpfGui/ViewModels/LogItemViewModel.cs | 7 +- .../ViewModels/UI/SettingsViewModel.cs | 512 +----------------- .../Settings/GUISettingsUserControlModel.cs | 478 ++++++++++++++++ src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs | 7 +- src/MaaWpfGui/Views/UI/SettingsView.xaml | 5 +- .../Views/UserControl/GuideUserControl.xaml | 4 +- .../GUISettingsUserControl.xaml | 20 +- .../GUISettingsUserControl.xaml.cs | 2 +- 11 files changed, 542 insertions(+), 512 deletions(-) create mode 100644 src/MaaWpfGui/ViewModels/UserControl/Settings/GUISettingsUserControlModel.cs rename src/MaaWpfGui/Views/UserControl/{ => Settings}/GUISettingsUserControl.xaml (86%) rename src/MaaWpfGui/Views/UserControl/{ => Settings}/GUISettingsUserControl.xaml.cs (95%) diff --git a/src/MaaWpfGui/Configuration/GUI.cs b/src/MaaWpfGui/Configuration/GUI.cs index bf9f4b0c07..4e168891fc 100644 --- a/src/MaaWpfGui/Configuration/GUI.cs +++ b/src/MaaWpfGui/Configuration/GUI.cs @@ -32,8 +32,6 @@ namespace MaaWpfGui.Configuration public bool HideCloseButton { get; set; } = false; - public bool UseLogItemDateFormat { get; set; } = false; - public string LogItemDateFormat { get; set; } = "HH:mm:ss"; public WindowPlacement? WindowPlacement { get; set; } = null; diff --git a/src/MaaWpfGui/Constants/ConfigurationKeys.cs b/src/MaaWpfGui/Constants/ConfigurationKeys.cs index 6a9859beb7..10b32a7244 100755 --- a/src/MaaWpfGui/Constants/ConfigurationKeys.cs +++ b/src/MaaWpfGui/Constants/ConfigurationKeys.cs @@ -35,7 +35,8 @@ namespace MaaWpfGui.Constants public const string MinimizeToTray = "GUI.MinimizeToTray"; public const string HideCloseButton = "GUI.HideCloseButton"; public const string WindowTitleScrollable = "GUI.WindowTitleScrollable"; - public const string UseLogItemDateFormat = "GUI.UseLogItemDateFormat"; + + // public const string UseLogItemDateFormat = "GUI.UseLogItemDateFormat"; 是否使用自定义的时间格式 public const string LogItemDateFormat = "GUI.LogItemDateFormatString"; public const string WindowPlacement = "GUI.Placement"; public const string LoadWindowPlacement = "GUI.Placement.Load"; diff --git a/src/MaaWpfGui/Helper/DataHelper.cs b/src/MaaWpfGui/Helper/DataHelper.cs index 090d262509..2d3b39dd6c 100644 --- a/src/MaaWpfGui/Helper/DataHelper.cs +++ b/src/MaaWpfGui/Helper/DataHelper.cs @@ -17,6 +17,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using MaaWpfGui.Constants; +using MaaWpfGui.ViewModels.UI; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -32,6 +33,17 @@ namespace MaaWpfGui.Helper { "ko-kr", "YoStarKR" }, }; + public static readonly Dictionary ClientLanguageMapper = new() + { + { string.Empty, "zh-cn" }, + { "Official", "zh-cn" }, + { "Bilibili", "zh-cn" }, + { "YoStarEN", "en-us" }, + { "YoStarJP", "ja-jp" }, + { "YoStarKR", "ko-kr" }, + { "txwy", "zh-tw" }, + }; + // 储存角色信息的字典 public static Dictionary Characters { get; } = new(); @@ -160,7 +172,7 @@ namespace MaaWpfGui.Helper return null; } - language ??= Instances.SettingsViewModel.OperNameLocalization; + language ??= SettingsViewModel.GuiSettings.OperNameLocalization; return language switch { diff --git a/src/MaaWpfGui/ViewModels/LogItemViewModel.cs b/src/MaaWpfGui/ViewModels/LogItemViewModel.cs index 5e5072251c..139a502d8e 100644 --- a/src/MaaWpfGui/ViewModels/LogItemViewModel.cs +++ b/src/MaaWpfGui/ViewModels/LogItemViewModel.cs @@ -14,6 +14,7 @@ using System; using MaaWpfGui.Constants; using MaaWpfGui.Helper; +using MaaWpfGui.ViewModels.UI; using Stylet; namespace MaaWpfGui.ViewModels @@ -32,11 +33,7 @@ namespace MaaWpfGui.ViewModels /// The Date format string public LogItemViewModel(string content, string color = UiLogColor.Message, string weight = "Regular", string dateFormat = "MM'-'dd' 'HH':'mm':'ss", bool showTime = true) { - if (Instances.SettingsViewModel.UseLogItemDateFormat) - { - dateFormat = Instances.SettingsViewModel.LogItemDateFormatString; - } - + dateFormat = SettingsViewModel.GuiSettings.LogItemDateFormatString; Time = DateTime.Now.ToString(dateFormat); Content = content; Color = color; diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index c0eeccb273..0cf2638333 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -47,6 +47,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Serilog; using Stylet; +using Windows.Globalization; using ComboBox = System.Windows.Controls.ComboBox; using DarkModeType = MaaWpfGui.Configuration.GUI.DarkModeType; using Timer = System.Timers.Timer; @@ -70,11 +71,6 @@ namespace MaaWpfGui.ViewModels.UI [DllImport("user32.dll")] private static extern bool IsIconic(IntPtr hWnd); - /// - /// The Pallas language key. - /// - public const string PallasLangKey = "pallas"; - /// /// Gets the visibility of task setting views. /// @@ -85,6 +81,11 @@ namespace MaaWpfGui.ViewModels.UI /// public PostActionSetting PostActionSetting { get; } = PostActionSetting.Current; + /// + /// Gets 界面设置model + /// + public static GUISettingsUserControlModel GuiSettings { get; } = new(); + /// /// Gets 连接设置model /// @@ -162,6 +163,17 @@ namespace MaaWpfGui.ViewModels.UI InitVersionUpdate(); } + private void InitUiSettings() + { + var languageList = (from pair in LocalizationHelper.SupportedLanguages + where pair.Key != PallasLangKey || Cheers + select new CombinedData { Display = pair.Value, Value = pair.Key }) + .ToList(); + + GuiSettings.LanguageList = languageList; + GuiSettings.SwitchDarkMode(); + } + private void InitInfrast() { var facilityList = new[] @@ -236,18 +248,6 @@ namespace MaaWpfGui.ViewModels.UI ConfigurationList = configurations; } - private void InitUiSettings() - { - var languageList = (from pair in LocalizationHelper.SupportedLanguages - where pair.Key != PallasLangKey || Cheers - select new CombinedData { Display = pair.Value, Value = pair.Key }) - .ToList(); - - LanguageList = languageList; - - SwitchDarkMode(); - } - private void InitConnectConfig() { var addressListJson = ConfigurationHelper.GetValue(ConfigurationKeys.AddressHistory, string.Empty); @@ -269,6 +269,11 @@ namespace MaaWpfGui.ViewModels.UI #region EasterEggs + /// + /// The Pallas language key. + /// + public const string PallasLangKey = "pallas"; + private bool _cheers = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.Cheers, bool.FalseString)); /// @@ -338,7 +343,7 @@ namespace MaaWpfGui.ViewModels.UI public void Sober() { - if (!Cheers || Language != PallasLangKey) + if (!Cheers || GuiSettings.Language != PallasLangKey) { return; } @@ -378,7 +383,7 @@ namespace MaaWpfGui.ViewModels.UI } string[] wineList = ["酒", "liquor", "drink", "wine", "beer", "술", "🍷", "🍸", "🍺", "🍻", "🥃", "🍶"]; - return wineList.Any(CreditFirstList.Contains); + return wineList.Any(Instances.SettingsViewModel.CreditFirstList.Contains); } #endregion EasterEggs @@ -1565,7 +1570,7 @@ namespace MaaWpfGui.ViewModels.UI continue; } - var localizedName = DataHelper.GetLocalizedCharacterName(name, OperNameLocalization); + var localizedName = DataHelper.GetLocalizedCharacterName(name, GuiSettings.OperNameLocalization); if (!string.IsNullOrEmpty(localizedName) && !(_clientType.Contains("YoStar") && DataHelper.GetLocalizedCharacterName(name, "en-us") == DataHelper.GetLocalizedCharacterName(name, "zh-cn"))) { roguelikeCoreCharList.Add(localizedName); @@ -2122,7 +2127,7 @@ namespace MaaWpfGui.ViewModels.UI { if (string.IsNullOrEmpty(_reclamationToolToCraft)) { - return LocalizationHelper.GetString("ReclamationToolToCraftPlaceholder", _clientLanguageMapper[_clientType]); + return LocalizationHelper.GetString("ReclamationToolToCraftPlaceholder", DataHelper.ClientLanguageMapper[_clientType]); } return _reclamationToolToCraft; @@ -3233,465 +3238,6 @@ namespace MaaWpfGui.ViewModels.UI #endregion 自动公招设置 - #region 界面设置 - - /// - /// Gets or sets the language list. - /// - public List LanguageList { get; set; } - - /// - /// Gets or sets the list of operator name language settings - /// - public List OperNameLanguageModeList { get; set; } = - [ - new() { Display = LocalizationHelper.GetString("OperNameLanguageMAA"), Value = "OperNameLanguageMAA" }, - new() { Display = LocalizationHelper.GetString("OperNameLanguageClient"), Value = "OperNameLanguageClient" } - ]; - - /// - /// Gets the list of dark mode. - /// - public List> DarkModeList { get; } = - [ - new() { Display = LocalizationHelper.GetString("Light"), Value = DarkModeType.Light }, - new() { Display = LocalizationHelper.GetString("Dark"), Value = DarkModeType.Dark }, - new() { Display = LocalizationHelper.GetString("SyncWithOs"), Value = DarkModeType.SyncWithOs }, - ]; - - /// - /// Gets the list of inverse clear modes. - /// - public List InverseClearModeList { get; } = - [ - new() { Display = LocalizationHelper.GetString("Clear"), Value = "Clear" }, - new() { Display = LocalizationHelper.GetString("Inverse"), Value = "Inverse" }, - new() { Display = LocalizationHelper.GetString("Switchable"), Value = "ClearInverse" }, - ]; - - private bool _useTray = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.UseTray, bool.TrueString)); - - /// - /// Gets or sets a value indicating whether to use tray icon. - /// - public bool UseTray - { - get => _useTray; - set - { - if (!value) - { - MinimizeToTray = false; - } - - SetAndNotify(ref _useTray, value); - ConfigurationHelper.SetValue(ConfigurationKeys.UseTray, value.ToString()); - Instances.MainWindowManager.SetUseTrayIcon(value); - } - } - - private bool _minimizeToTray = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.MinimizeToTray, bool.FalseString)); - - /// - /// Gets or sets a value indicating whether to minimize to tray. - /// - public bool MinimizeToTray - { - get => _minimizeToTray; - set - { - SetAndNotify(ref _minimizeToTray, value); - ConfigurationHelper.SetValue(ConfigurationKeys.MinimizeToTray, value.ToString()); - Instances.MainWindowManager.SetMinimizeToTray(value); - } - } - - private bool _windowTitleScrollable = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.WindowTitleScrollable, bool.FalseString)); - - /// - /// Gets or sets a value indicating whether to make window title scrollable. - /// - public bool WindowTitleScrollable - { - get => _windowTitleScrollable; - set - { - SetAndNotify(ref _windowTitleScrollable, value); - ConfigurationHelper.SetValue(ConfigurationKeys.WindowTitleScrollable, value.ToString()); - var rvm = (RootViewModel)this.Parent; - rvm.WindowTitleScrollable = value; - } - } - - private bool _hideCloseButton = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.HideCloseButton, bool.FalseString)); - - /// - /// Gets or sets a value indicating whether to hide close button. - /// - public bool HideCloseButton - { - get => _hideCloseButton; - set - { - SetAndNotify(ref _hideCloseButton, value); - ConfigurationHelper.SetValue(ConfigurationKeys.HideCloseButton, value.ToString()); - var rvm = (RootViewModel)this.Parent; - rvm.ShowCloseButton = !value; - } - } - - /// - /// Gets or sets a value indicating whether to use notification. - /// - public bool UseNotify - { - get => ConfigFactory.CurrentConfig.GUI.UseNotify; - set - { - ConfigFactory.CurrentConfig.GUI.UseNotify = value; - NotifyOfPropertyChange(); - if (value) - { - ToastNotification.ShowDirect("Test test"); - } - } - } - - private bool _useLogItemDateFormat = true; // Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.UseLogItemDateFormat, bool.FalseString)); - - public bool UseLogItemDateFormat - { - get => _useLogItemDateFormat; - set - { - SetAndNotify(ref _useLogItemDateFormat, value); - ConfigurationHelper.SetValue(ConfigurationKeys.UseLogItemDateFormat, value.ToString()); - } - } - - public List LogItemDateFormatStringList { get; } = - [ - "HH:mm:ss", - "MM-dd HH:mm:ss", - "MM/dd HH:mm:ss", - "MM.dd HH:mm:ss", - "dd-MM HH:mm:ss", - "dd/MM HH:mm:ss", - "dd.MM HH:mm:ss", - ]; - - private string _logItemDateFormatString = ConfigurationHelper.GetValue(ConfigurationKeys.LogItemDateFormat, "HH:mm:ss"); - - public string LogItemDateFormatString - { - get => _logItemDateFormatString; - set - { - SetAndNotify(ref _logItemDateFormatString, value); - ConfigurationHelper.SetValue(ConfigurationKeys.LogItemDateFormat, value); - } - } - - /// - /// Gets or sets the dark mode. - /// - public DarkModeType DarkMode - { - get => ConfigFactory.CurrentConfig.GUI.DarkMode; - set - { - ConfigFactory.CurrentConfig.GUI.DarkMode = value; - NotifyOfPropertyChange(); - SwitchDarkMode(); - - /* - AskToRestartToApplySettings(); - */ - } - } - - public void SwitchDarkMode() - { - DarkModeType darkModeType = ConfigFactory.CurrentConfig.GUI.DarkMode; - switch (darkModeType) - { - case DarkModeType.Light: - ThemeHelper.SwitchToLightMode(); - break; - - case DarkModeType.Dark: - ThemeHelper.SwitchToDarkMode(); - break; - - case DarkModeType.SyncWithOs: - ThemeHelper.SwitchToSyncWithOsMode(); - break; - - default: - throw new ArgumentOutOfRangeException(); - } - } - - private enum InverseClearType - { - Clear, - Inverse, - ClearInverse, - } - - private InverseClearType _inverseClearMode = - Enum.TryParse(ConfigurationHelper.GetValue(ConfigurationKeys.InverseClearMode, InverseClearType.Clear.ToString()), out InverseClearType temp) - ? temp - : InverseClearType.Clear; - - /// - /// Gets or sets the inverse clear mode. - /// - public string InverseClearMode - { - get => _inverseClearMode.ToString(); - set - { - if (!Enum.TryParse(value, out InverseClearType tempEnumValue)) - { - return; - } - - SetAndNotify(ref _inverseClearMode, tempEnumValue); - ConfigurationHelper.SetValue(ConfigurationKeys.InverseClearMode, value); - switch (tempEnumValue) - { - case InverseClearType.Clear: - Instances.TaskQueueViewModel.InverseMode = false; - Instances.TaskQueueViewModel.ShowInverse = false; - Instances.TaskQueueViewModel.SelectedAllWidth = 90; - break; - - case InverseClearType.Inverse: - Instances.TaskQueueViewModel.InverseMode = true; - Instances.TaskQueueViewModel.ShowInverse = false; - Instances.TaskQueueViewModel.SelectedAllWidth = 90; - break; - - case InverseClearType.ClearInverse: - Instances.TaskQueueViewModel.ShowInverse = true; - Instances.TaskQueueViewModel.SelectedAllWidth = TaskQueueViewModel.SelectedAllWidthWhenBoth; - break; - - default: - throw new ArgumentOutOfRangeException(); - } - } - } - - private static readonly Dictionary _windowTitleAllShowDict = new() - { - { LocalizationHelper.GetString("ConfigurationName"), "1" }, - { LocalizationHelper.GetString("ConnectionPreset"), "2" }, - { LocalizationHelper.GetString("ConnectionAddress"), "3" }, - { LocalizationHelper.GetString("ClientType"), "4" }, - }; - - private List _windowTitleAllShowList = [.. _windowTitleAllShowDict.Keys]; - - public List WindowTitleAllShowList - { - get => _windowTitleAllShowList; - set => SetAndNotify(ref _windowTitleAllShowList, value); - } - - private object[] _windowTitleSelectShowList = ConfigurationHelper.GetValue(ConfigurationKeys.WindowTitleSelectShowList, "1 2 3 4") - .Split(' ') - .Where(s => _windowTitleAllShowDict.ContainsValue(s.ToString())) - .Select(s => _windowTitleAllShowDict.FirstOrDefault(pair => pair.Value == s).Key) - .ToArray(); - - public object[] WindowTitleSelectShowList - { - get => _windowTitleSelectShowList; - set - { - SetAndNotify(ref _windowTitleSelectShowList, value); - UpdateWindowTitle(); - var config = string.Join(' ', _windowTitleSelectShowList.Cast().Select(s => _windowTitleAllShowDict[s])); - ConfigurationHelper.SetValue(ConfigurationKeys.WindowTitleSelectShowList, config); - } - } - - private string _language = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage); - - /// - /// Gets or sets the language. - /// - public string Language - { - get => _language; - set - { - if (value == _language) - { - return; - } - - if (_language == PallasLangKey) - { - Hangover = true; - Cheers = false; - } - - if (value != PallasLangKey) - { - SoberLanguage = value; - } - - // var backup = _language; - ConfigurationHelper.SetValue(ConfigurationKeys.Localization, value); - - var mainWindow = Application.Current.MainWindow; - - if (mainWindow != null) - { - mainWindow.Show(); - mainWindow.WindowState = mainWindow.WindowState = WindowState.Normal; - mainWindow.Activate(); - } - - var result = MessageBoxHelper.Show( - FormatText("{0}\n{1}", "LanguageChangedTip"), - FormatText("{0}({1})", "Tip"), - MessageBoxButton.OKCancel, - MessageBoxImage.Question, - ok: FormatText("{0}({1})", "Ok"), - cancel: FormatText("{0}({1})", "ManualRestart")); - if (result == MessageBoxResult.OK) - { - Bootstrapper.ShutdownAndRestartWithoutArgs(); - } - - SetAndNotify(ref _language, value); - - return; - - string FormatText(string text, string key) - => string.Format(text, LocalizationHelper.GetString(key, value), LocalizationHelper.GetString(key, _language)); - } - } - - /// - /// Gets the language info. - /// - public string LanguageInfo - { - get - { - var language = (string)Application.Current.Resources["Language"]; - return language == "Language" ? language : language + " / Language"; - } - } - - private static readonly Dictionary _clientLanguageMapper = new() - { - { string.Empty, "zh-cn" }, - { "Official", "zh-cn" }, - { "Bilibili", "zh-cn" }, - { "YoStarEN", "en-us" }, - { "YoStarJP", "ja-jp" }, - { "YoStarKR", "ko-kr" }, - { "txwy", "zh-tw" }, - }; - - /// - /// Opername display language, can set force display when it was set as "OperNameLanguageForce.en-us" - /// - private string _operNameLanguage = ConfigurationHelper.GetValue(ConfigurationKeys.OperNameLanguage, "OperNameLanguageMAA"); - - public string OperNameLanguage - { - get - { - if (!_operNameLanguage.Contains('.')) - { - return _operNameLanguage; - } - - if (_operNameLanguage.Split('.')[0] != "OperNameLanguageForce" || !LocalizationHelper.SupportedLanguages.ContainsKey(_operNameLanguage.Split('.')[1])) - { - return _operNameLanguage; - } - - OperNameLanguageModeList.Add(new CombinedData { Display = LocalizationHelper.GetString("OperNameLanguageForce"), Value = "OperNameLanguageForce" }); - return "OperNameLanguageForce"; - } - - set - { - if (value == _operNameLanguage.Split('.')[0]) - { - return; - } - - switch (value) - { - case "OperNameLanguageClient": - ConfigurationHelper.SetValue(ConfigurationKeys.OperNameLanguage, value); - break; - - case "OperNameLanguageMAA": - default: - ConfigurationHelper.SetValue(ConfigurationKeys.OperNameLanguage, "OperNameLanguageMAA"); - break; - } - - var mainWindow = Application.Current.MainWindow; - - if (mainWindow != null) - { - mainWindow.Show(); - mainWindow.WindowState = mainWindow.WindowState = WindowState.Normal; - mainWindow.Activate(); - } - - var result = MessageBoxHelper.Show( - LocalizationHelper.GetString("LanguageChangedTip"), - LocalizationHelper.GetString("Tip"), - MessageBoxButton.OKCancel, - MessageBoxImage.Question, - ok: LocalizationHelper.GetString("Ok"), - cancel: LocalizationHelper.GetString("ManualRestart")); - if (result == MessageBoxResult.OK) - { - Bootstrapper.ShutdownAndRestartWithoutArgs(); - } - - SetAndNotify(ref _operNameLanguage, value); - } - } - - public string OperNameLocalization - { - get - { - if (_operNameLanguage == "OperNameLanguageClient") - { - return _clientLanguageMapper[_clientType]; - } - - if (!_operNameLanguage.Contains('.')) - { - return _language; - } - - if (_operNameLanguage.Split('.')[0] == "OperNameLanguageForce" && LocalizationHelper.SupportedLanguages.ContainsKey(_operNameLanguage.Split('.')[1])) - { - return _operNameLanguage.Split('.')[1]; - } - - return _language; - } - } - - #endregion 界面设置 - #region HotKey /// @@ -3912,9 +3458,9 @@ namespace MaaWpfGui.ViewModels.UI prefix += " - "; } - List windowTitleSelectShowList = _windowTitleSelectShowList - .Where(x => _windowTitleAllShowDict.ContainsKey(x?.ToString() ?? string.Empty)) - .Select(x => _windowTitleAllShowDict[x?.ToString() ?? string.Empty]).ToList(); + List windowTitleSelectShowList = GuiSettings.WindowTitleSelectShowList + .Where(x => GUISettingsUserControlModel.WindowTitleAllShowDict.ContainsKey(x?.ToString() ?? string.Empty)) + .Select(x => GUISettingsUserControlModel.WindowTitleAllShowDict[x?.ToString() ?? string.Empty]).ToList(); string currentConfiguration = string.Empty; string connectConfigName = string.Empty; diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/GUISettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/GUISettingsUserControlModel.cs new file mode 100644 index 0000000000..b4bfdc2d37 --- /dev/null +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/GUISettingsUserControlModel.cs @@ -0,0 +1,478 @@ +// +// 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; +using System.Collections.Generic; +using System.Linq; +using System.Windows; +using MaaWpfGui.Configuration; +using MaaWpfGui.Constants; +using MaaWpfGui.Helper; +using MaaWpfGui.Main; +using MaaWpfGui.Utilities.ValueType; +using MaaWpfGui.ViewModels.UI; +using Stylet; +using DarkModeType = MaaWpfGui.Configuration.GUI.DarkModeType; + +namespace MaaWpfGui.ViewModels.UserControl.Settings; + +public class GUISettingsUserControlModel : PropertyChangedBase +{ + /// + /// Gets or sets a value indicating whether it is idle. + /// + public bool Idle + { + get => Instances.SettingsViewModel.Idle; + set + { + Instances.SettingsViewModel.Idle = value; + NotifyOfPropertyChange(nameof(Idle)); + } + } + + /// + /// Gets or sets the language list. + /// + public List LanguageList { get; set; } = []; + + /// + /// Gets or sets the list of operator name language settings + /// + public List OperNameLanguageModeList { get; set; } = + [ + new() { Display = LocalizationHelper.GetString("OperNameLanguageMAA"), Value = "OperNameLanguageMAA" }, + new() { Display = LocalizationHelper.GetString("OperNameLanguageClient"), Value = "OperNameLanguageClient" } + ]; + + /// + /// Gets the list of dark mode. + /// + public List> DarkModeList { get; } = + [ + new() { Display = LocalizationHelper.GetString("Light"), Value = DarkModeType.Light }, + new() { Display = LocalizationHelper.GetString("Dark"), Value = DarkModeType.Dark }, + new() { Display = LocalizationHelper.GetString("SyncWithOs"), Value = DarkModeType.SyncWithOs }, + ]; + + /// + /// Gets the list of inverse clear modes. + /// + public List InverseClearModeList { get; } = + [ + new() { Display = LocalizationHelper.GetString("Clear"), Value = "Clear" }, + new() { Display = LocalizationHelper.GetString("Inverse"), Value = "Inverse" }, + new() { Display = LocalizationHelper.GetString("Switchable"), Value = "ClearInverse" }, + ]; + + private bool _useTray = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.UseTray, bool.TrueString)); + + /// + /// Gets or sets a value indicating whether to use tray icon. + /// + public bool UseTray + { + get => _useTray; + set + { + if (!value) + { + MinimizeToTray = false; + } + + SetAndNotify(ref _useTray, value); + ConfigurationHelper.SetValue(ConfigurationKeys.UseTray, value.ToString()); + Instances.MainWindowManager.SetUseTrayIcon(value); + } + } + + private bool _minimizeToTray = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.MinimizeToTray, bool.FalseString)); + + /// + /// Gets or sets a value indicating whether to minimize to tray. + /// + public bool MinimizeToTray + { + get => _minimizeToTray; + set + { + SetAndNotify(ref _minimizeToTray, value); + ConfigurationHelper.SetValue(ConfigurationKeys.MinimizeToTray, value.ToString()); + Instances.MainWindowManager.SetMinimizeToTray(value); + } + } + + private bool _windowTitleScrollable = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.WindowTitleScrollable, bool.FalseString)); + + /// + /// Gets or sets a value indicating whether to make window title scrollable. + /// + public bool WindowTitleScrollable + { + get => _windowTitleScrollable; + set + { + SetAndNotify(ref _windowTitleScrollable, value); + ConfigurationHelper.SetValue(ConfigurationKeys.WindowTitleScrollable, value.ToString()); + var rvm = (RootViewModel)Instances.SettingsViewModel.Parent; + rvm.WindowTitleScrollable = value; + } + } + + private bool _hideCloseButton = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.HideCloseButton, bool.FalseString)); + + /// + /// Gets or sets a value indicating whether to hide close button. + /// + public bool HideCloseButton + { + get => _hideCloseButton; + set + { + SetAndNotify(ref _hideCloseButton, value); + ConfigurationHelper.SetValue(ConfigurationKeys.HideCloseButton, value.ToString()); + var rvm = (RootViewModel)Instances.SettingsViewModel.Parent; + rvm.ShowCloseButton = !value; + } + } + + /// + /// Gets or sets a value indicating whether to use notification. + /// + public bool UseNotify + { + get => ConfigFactory.CurrentConfig.GUI.UseNotify; + set + { + ConfigFactory.CurrentConfig.GUI.UseNotify = value; + NotifyOfPropertyChange(); + if (value) + { + ToastNotification.ShowDirect("Test test"); + } + } + } + + public List LogItemDateFormatStringList { get; } = + [ + "HH:mm:ss", + "MM-dd HH:mm:ss", + "MM/dd HH:mm:ss", + "MM.dd HH:mm:ss", + "dd-MM HH:mm:ss", + "dd/MM HH:mm:ss", + "dd.MM HH:mm:ss", + ]; + + private string _logItemDateFormatString = ConfigurationHelper.GetValue(ConfigurationKeys.LogItemDateFormat, "HH:mm:ss"); + + public string LogItemDateFormatString + { + get => _logItemDateFormatString; + set + { + SetAndNotify(ref _logItemDateFormatString, value); + ConfigurationHelper.SetValue(ConfigurationKeys.LogItemDateFormat, value); + } + } + + /// + /// Gets or sets the dark mode. + /// + public DarkModeType DarkMode + { + get => ConfigFactory.CurrentConfig.GUI.DarkMode; + set + { + ConfigFactory.CurrentConfig.GUI.DarkMode = value; + NotifyOfPropertyChange(); + SwitchDarkMode(); + + /* + AskToRestartToApplySettings(); + */ + } + } + + public void SwitchDarkMode() + { + DarkModeType darkModeType = ConfigFactory.CurrentConfig.GUI.DarkMode; + switch (darkModeType) + { + case DarkModeType.Light: + ThemeHelper.SwitchToLightMode(); + break; + + case DarkModeType.Dark: + ThemeHelper.SwitchToDarkMode(); + break; + + case DarkModeType.SyncWithOs: + ThemeHelper.SwitchToSyncWithOsMode(); + break; + + default: + throw new ArgumentOutOfRangeException(); + } + } + + private enum InverseClearType + { + Clear, + Inverse, + ClearInverse, + } + + private InverseClearType _inverseClearMode = + Enum.TryParse(ConfigurationHelper.GetValue(ConfigurationKeys.InverseClearMode, InverseClearType.Clear.ToString()), out InverseClearType temp) + ? temp + : InverseClearType.Clear; + + /// + /// Gets or sets the inverse clear mode. + /// + public string InverseClearMode + { + get => _inverseClearMode.ToString(); + set + { + if (!Enum.TryParse(value, out InverseClearType tempEnumValue)) + { + return; + } + + SetAndNotify(ref _inverseClearMode, tempEnumValue); + ConfigurationHelper.SetValue(ConfigurationKeys.InverseClearMode, value); + switch (tempEnumValue) + { + case InverseClearType.Clear: + Instances.TaskQueueViewModel.InverseMode = false; + Instances.TaskQueueViewModel.ShowInverse = false; + Instances.TaskQueueViewModel.SelectedAllWidth = 90; + break; + + case InverseClearType.Inverse: + Instances.TaskQueueViewModel.InverseMode = true; + Instances.TaskQueueViewModel.ShowInverse = false; + Instances.TaskQueueViewModel.SelectedAllWidth = 90; + break; + + case InverseClearType.ClearInverse: + Instances.TaskQueueViewModel.ShowInverse = true; + Instances.TaskQueueViewModel.SelectedAllWidth = TaskQueueViewModel.SelectedAllWidthWhenBoth; + break; + + default: + throw new ArgumentOutOfRangeException(); + } + } + } + + private static readonly Dictionary _windowTitleAllShowDict = new() + { + { LocalizationHelper.GetString("ConfigurationName"), "1" }, + { LocalizationHelper.GetString("ConnectionPreset"), "2" }, + { LocalizationHelper.GetString("ConnectionAddress"), "3" }, + { LocalizationHelper.GetString("ClientType"), "4" }, + }; + + public static Dictionary WindowTitleAllShowDict { get => _windowTitleAllShowDict; } + + private List _windowTitleAllShowList = [.. _windowTitleAllShowDict.Keys]; + + public List WindowTitleAllShowList + { + get => _windowTitleAllShowList; + set => SetAndNotify(ref _windowTitleAllShowList, value); + } + + private object[] _windowTitleSelectShowList = ConfigurationHelper.GetValue(ConfigurationKeys.WindowTitleSelectShowList, "1 2 3 4") + .Split(' ') + .Where(s => _windowTitleAllShowDict.ContainsValue(s.ToString())) + .Select(s => _windowTitleAllShowDict.FirstOrDefault(pair => pair.Value == s).Key) + .ToArray(); + + public object[] WindowTitleSelectShowList + { + get => _windowTitleSelectShowList; + set + { + SetAndNotify(ref _windowTitleSelectShowList, value); + Instances.SettingsViewModel.UpdateWindowTitle(); + var config = string.Join(' ', _windowTitleSelectShowList.Cast().Select(s => _windowTitleAllShowDict[s])); + ConfigurationHelper.SetValue(ConfigurationKeys.WindowTitleSelectShowList, config); + } + } + + private string _language = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage); + + /// + /// Gets or sets the language. + /// + public string Language + { + get => _language; + set + { + if (value == _language) + { + return; + } + + if (_language == SettingsViewModel.PallasLangKey) + { + Instances.SettingsViewModel.Hangover = true; + Instances.SettingsViewModel.Cheers = false; + } + + if (value != SettingsViewModel.PallasLangKey) + { + Instances.SettingsViewModel.SoberLanguage = value; + } + + // var backup = _language; + ConfigurationHelper.SetValue(ConfigurationKeys.Localization, value); + + var mainWindow = Application.Current.MainWindow; + + if (mainWindow != null) + { + mainWindow.Show(); + mainWindow.WindowState = mainWindow.WindowState = WindowState.Normal; + mainWindow.Activate(); + } + + var result = MessageBoxHelper.Show( + FormatText("{0}\n{1}", "LanguageChangedTip"), + FormatText("{0}({1})", "Tip"), + MessageBoxButton.OKCancel, + MessageBoxImage.Question, + ok: FormatText("{0}({1})", "Ok"), + cancel: FormatText("{0}({1})", "ManualRestart")); + if (result == MessageBoxResult.OK) + { + Bootstrapper.ShutdownAndRestartWithoutArgs(); + } + + SetAndNotify(ref _language, value); + + return; + + string FormatText(string text, string key) + => string.Format(text, LocalizationHelper.GetString(key, value), LocalizationHelper.GetString(key, _language)); + } + } + + /// + /// Gets the language info. + /// + public string LanguageInfo + { + get + { + var language = (string)Application.Current.Resources["Language"]; + return language == "Language" ? language : language + " / Language"; + } + } + + /// + /// Opername display language, can set force display when it was set as "OperNameLanguageForce.en-us" + /// + private string _operNameLanguage = ConfigurationHelper.GetValue(ConfigurationKeys.OperNameLanguage, "OperNameLanguageMAA"); + + public string OperNameLanguage + { + get + { + if (!_operNameLanguage.Contains('.')) + { + return _operNameLanguage; + } + + if (_operNameLanguage.Split('.')[0] != "OperNameLanguageForce" || !LocalizationHelper.SupportedLanguages.ContainsKey(_operNameLanguage.Split('.')[1])) + { + return _operNameLanguage; + } + + OperNameLanguageModeList.Add(new CombinedData { Display = LocalizationHelper.GetString("OperNameLanguageForce"), Value = "OperNameLanguageForce" }); + return "OperNameLanguageForce"; + } + + set + { + if (value == _operNameLanguage.Split('.')[0]) + { + return; + } + + switch (value) + { + case "OperNameLanguageClient": + ConfigurationHelper.SetValue(ConfigurationKeys.OperNameLanguage, value); + break; + + case "OperNameLanguageMAA": + default: + ConfigurationHelper.SetValue(ConfigurationKeys.OperNameLanguage, "OperNameLanguageMAA"); + break; + } + + var mainWindow = Application.Current.MainWindow; + + if (mainWindow != null) + { + mainWindow.Show(); + mainWindow.WindowState = mainWindow.WindowState = WindowState.Normal; + mainWindow.Activate(); + } + + var result = MessageBoxHelper.Show( + LocalizationHelper.GetString("LanguageChangedTip"), + LocalizationHelper.GetString("Tip"), + MessageBoxButton.OKCancel, + MessageBoxImage.Question, + ok: LocalizationHelper.GetString("Ok"), + cancel: LocalizationHelper.GetString("ManualRestart")); + if (result == MessageBoxResult.OK) + { + Bootstrapper.ShutdownAndRestartWithoutArgs(); + } + + SetAndNotify(ref _operNameLanguage, value); + } + } + + public string OperNameLocalization + { + get + { + if (_operNameLanguage == "OperNameLanguageClient") + { + return DataHelper.ClientLanguageMapper[Instances.SettingsViewModel.ClientType]; + } + + if (!_operNameLanguage.Contains('.')) + { + return _language; + } + + if (_operNameLanguage.Split('.')[0] == "OperNameLanguageForce" && LocalizationHelper.SupportedLanguages.ContainsKey(_operNameLanguage.Split('.')[1])) + { + return _operNameLanguage.Split('.')[1]; + } + + return _language; + } + } +} diff --git a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs index fb725d95f6..1568681e76 100644 --- a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs +++ b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs @@ -18,6 +18,7 @@ using MaaWpfGui.Constants; using MaaWpfGui.Helper; using MaaWpfGui.Main; using MaaWpfGui.ViewModels.UI; +using MaaWpfGui.ViewModels.UserControl.Settings; using Serilog; namespace MaaWpfGui.Views.UI @@ -65,7 +66,7 @@ namespace MaaWpfGui.Views.UI var langMenu = new MenuItem() { Header = lang.Value }; langMenu.Click += (_, _) => { - Instances.SettingsViewModel.Language = lang.Key; + SettingsViewModel.GuiSettings.Language = lang.Key; }; switchLangMenu.Items.Add(langMenu); @@ -122,8 +123,8 @@ namespace MaaWpfGui.Views.UI { Instances.MainWindowManager?.Show(); - Instances.SettingsViewModel.UseTray = !Instances.SettingsViewModel.UseTray; - _logger.Information("Use tray icon: {0}", Instances.SettingsViewModel.UseTray); + SettingsViewModel.GuiSettings.UseTray = !SettingsViewModel.GuiSettings.UseTray; + _logger.Information("Use tray icon: {0}", SettingsViewModel.GuiSettings.UseTray); } private static void App_restart(object sender, RoutedEventArgs e) diff --git a/src/MaaWpfGui/Views/UI/SettingsView.xaml b/src/MaaWpfGui/Views/UI/SettingsView.xaml index 6d22e39457..3ffed2ce9d 100644 --- a/src/MaaWpfGui/Views/UI/SettingsView.xaml +++ b/src/MaaWpfGui/Views/UI/SettingsView.xaml @@ -75,7 +75,10 @@ - + @@ -90,7 +90,7 @@ Width="240" TransitionMode="{Binding GuideTransitionMode}" Visibility="{c:Binding 'GuideStepIndex less= 0'}"> - + - --> + IsChecked="{Binding WindowTitleScrollable}" />--> + Style="{StaticResource ComboBoxExtend}" /> diff --git a/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml.cs b/src/MaaWpfGui/Views/UserControl/Settings/GUISettingsUserControl.xaml.cs similarity index 95% rename from src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml.cs rename to src/MaaWpfGui/Views/UserControl/Settings/GUISettingsUserControl.xaml.cs index 85752b228d..a27e459315 100644 --- a/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml.cs +++ b/src/MaaWpfGui/Views/UserControl/Settings/GUISettingsUserControl.xaml.cs @@ -11,7 +11,7 @@ // but WITHOUT ANY WARRANTY // -namespace MaaWpfGui.Views.UserControl +namespace MaaWpfGui.Views.UserControl.Settings { /// /// GUISettingsUserControl.xaml 的交互逻辑