From a2902fdd297cd9b20c1914cd4235fb012b5547d5 Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Sun, 17 Nov 2024 13:08:43 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"rft:=20=E6=8B=86=E5=88=86=20=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=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 This reverts commit 1c14b211d39fb47e1097b5cdfcf87473c02e4a60. # Conflicts: # src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs --- 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 | 505 +++++++++++++++++- .../Settings/GUISettingsUserControlModel.cs | 478 ----------------- src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs | 7 +- src/MaaWpfGui/Views/UI/SettingsView.xaml | 5 +- .../GUISettingsUserControl.xaml | 20 +- .../GUISettingsUserControl.xaml.cs | 2 +- .../Views/UserControl/GuideUserControl.xaml | 4 +- 11 files changed, 511 insertions(+), 536 deletions(-) delete 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 4e168891fc..bf9f4b0c07 100644 --- a/src/MaaWpfGui/Configuration/GUI.cs +++ b/src/MaaWpfGui/Configuration/GUI.cs @@ -32,6 +32,8 @@ 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 10b32a7244..6a9859beb7 100755 --- a/src/MaaWpfGui/Constants/ConfigurationKeys.cs +++ b/src/MaaWpfGui/Constants/ConfigurationKeys.cs @@ -35,8 +35,7 @@ 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 2d3b39dd6c..090d262509 100644 --- a/src/MaaWpfGui/Helper/DataHelper.cs +++ b/src/MaaWpfGui/Helper/DataHelper.cs @@ -17,7 +17,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using MaaWpfGui.Constants; -using MaaWpfGui.ViewModels.UI; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -33,17 +32,6 @@ 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(); @@ -172,7 +160,7 @@ namespace MaaWpfGui.Helper return null; } - language ??= SettingsViewModel.GuiSettings.OperNameLocalization; + language ??= Instances.SettingsViewModel.OperNameLocalization; return language switch { diff --git a/src/MaaWpfGui/ViewModels/LogItemViewModel.cs b/src/MaaWpfGui/ViewModels/LogItemViewModel.cs index 139a502d8e..5e5072251c 100644 --- a/src/MaaWpfGui/ViewModels/LogItemViewModel.cs +++ b/src/MaaWpfGui/ViewModels/LogItemViewModel.cs @@ -14,7 +14,6 @@ using System; using MaaWpfGui.Constants; using MaaWpfGui.Helper; -using MaaWpfGui.ViewModels.UI; using Stylet; namespace MaaWpfGui.ViewModels @@ -33,7 +32,11 @@ 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) { - dateFormat = SettingsViewModel.GuiSettings.LogItemDateFormatString; + if (Instances.SettingsViewModel.UseLogItemDateFormat) + { + dateFormat = Instances.SettingsViewModel.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 bd4c0fa54c..070613e53c 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -48,7 +48,6 @@ 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; @@ -72,6 +71,11 @@ 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. /// @@ -182,17 +186,6 @@ 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[] @@ -267,6 +260,18 @@ 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); @@ -288,11 +293,6 @@ 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)); /// @@ -362,7 +362,7 @@ namespace MaaWpfGui.ViewModels.UI public void Sober() { - if (!Cheers || GuiSettings.Language != PallasLangKey) + if (!Cheers || Language != PallasLangKey) { return; } @@ -402,7 +402,7 @@ namespace MaaWpfGui.ViewModels.UI } string[] wineList = ["酒", "liquor", "drink", "wine", "beer", "술", "🍷", "🍸", "🍺", "🍻", "🥃", "🍶"]; - return wineList.Any(Instances.SettingsViewModel.CreditFirstList.Contains); + return wineList.Any(CreditFirstList.Contains); } #endregion EasterEggs @@ -1180,7 +1180,7 @@ namespace MaaWpfGui.ViewModels.UI continue; } - var localizedName = DataHelper.GetLocalizedCharacterName(name, GuiSettings.OperNameLocalization); + var localizedName = DataHelper.GetLocalizedCharacterName(name, OperNameLocalization); if (!string.IsNullOrEmpty(localizedName) && !(_clientType.Contains("YoStar") && DataHelper.GetLocalizedCharacterName(name, "en-us") == DataHelper.GetLocalizedCharacterName(name, "zh-cn"))) { roguelikeCoreCharList.Add(localizedName); @@ -2742,6 +2742,465 @@ 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 /// @@ -2962,9 +3421,9 @@ namespace MaaWpfGui.ViewModels.UI prefix += " - "; } - List windowTitleSelectShowList = GuiSettings.WindowTitleSelectShowList - .Where(x => GUISettingsUserControlModel.WindowTitleAllShowDict.ContainsKey(x?.ToString() ?? string.Empty)) - .Select(x => GUISettingsUserControlModel.WindowTitleAllShowDict[x?.ToString() ?? string.Empty]).ToList(); + List windowTitleSelectShowList = _windowTitleSelectShowList + .Where(x => _windowTitleAllShowDict.ContainsKey(x?.ToString() ?? string.Empty)) + .Select(x => _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 deleted file mode 100644 index b4bfdc2d37..0000000000 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/GUISettingsUserControlModel.cs +++ /dev/null @@ -1,478 +0,0 @@ -// -// 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 1568681e76..fb725d95f6 100644 --- a/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs +++ b/src/MaaWpfGui/Views/UI/NotifyIcon.xaml.cs @@ -18,7 +18,6 @@ using MaaWpfGui.Constants; using MaaWpfGui.Helper; using MaaWpfGui.Main; using MaaWpfGui.ViewModels.UI; -using MaaWpfGui.ViewModels.UserControl.Settings; using Serilog; namespace MaaWpfGui.Views.UI @@ -66,7 +65,7 @@ namespace MaaWpfGui.Views.UI var langMenu = new MenuItem() { Header = lang.Value }; langMenu.Click += (_, _) => { - SettingsViewModel.GuiSettings.Language = lang.Key; + Instances.SettingsViewModel.Language = lang.Key; }; switchLangMenu.Items.Add(langMenu); @@ -123,8 +122,8 @@ namespace MaaWpfGui.Views.UI { Instances.MainWindowManager?.Show(); - SettingsViewModel.GuiSettings.UseTray = !SettingsViewModel.GuiSettings.UseTray; - _logger.Information("Use tray icon: {0}", SettingsViewModel.GuiSettings.UseTray); + Instances.SettingsViewModel.UseTray = !Instances.SettingsViewModel.UseTray; + _logger.Information("Use tray icon: {0}", Instances.SettingsViewModel.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 8dc1278956..9bc04ab91e 100644 --- a/src/MaaWpfGui/Views/UI/SettingsView.xaml +++ b/src/MaaWpfGui/Views/UI/SettingsView.xaml @@ -78,10 +78,7 @@ - + --> + IsChecked="{Binding WindowTitleScrollable}" /> + --> + Style="{StaticResource ComboBoxExtend}" + Visibility="{c:Binding UseLogItemDateFormat}" /> diff --git a/src/MaaWpfGui/Views/UserControl/Settings/GUISettingsUserControl.xaml.cs b/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml.cs similarity index 95% rename from src/MaaWpfGui/Views/UserControl/Settings/GUISettingsUserControl.xaml.cs rename to src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml.cs index a27e459315..85752b228d 100644 --- a/src/MaaWpfGui/Views/UserControl/Settings/GUISettingsUserControl.xaml.cs +++ b/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml.cs @@ -11,7 +11,7 @@ // but WITHOUT ANY WARRANTY // -namespace MaaWpfGui.Views.UserControl.Settings +namespace MaaWpfGui.Views.UserControl { /// /// GUISettingsUserControl.xaml 的交互逻辑 diff --git a/src/MaaWpfGui/Views/UserControl/GuideUserControl.xaml b/src/MaaWpfGui/Views/UserControl/GuideUserControl.xaml index d2273e238e..741fa1e378 100644 --- a/src/MaaWpfGui/Views/UserControl/GuideUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/GuideUserControl.xaml @@ -10,11 +10,11 @@ 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: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:DesignWidth="400" mc:Ignorable="d"> @@ -90,7 +90,7 @@ Width="240" TransitionMode="{Binding GuideTransitionMode}" Visibility="{c:Binding 'GuideStepIndex less= 0'}"> - +