From 46abd60d9dc42988a36a222ebe8fb15d4dedaa0c Mon Sep 17 00:00:00 2001 From: ManicSteiner Date: Sun, 4 Aug 2024 23:50:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8=E9=80=89=E6=8B=A9WPF?= =?UTF-8?q?GUI=E4=B8=AD=E7=9A=84=E5=B9=B2=E5=91=98=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Constants/ConfigurationKeys.cs | 1 + src/MaaWpfGui/Helper/DataHelper.cs | 2 +- src/MaaWpfGui/Res/Localizations/zh-cn.xaml | 3 + .../ViewModels/UI/SettingsViewModel.cs | 56 ++++++++++++++++++- .../UserControl/GUISettingsUserControl.xaml | 11 ++++ 5 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/MaaWpfGui/Constants/ConfigurationKeys.cs b/src/MaaWpfGui/Constants/ConfigurationKeys.cs index e6959c23ce..5f4560afaf 100644 --- a/src/MaaWpfGui/Constants/ConfigurationKeys.cs +++ b/src/MaaWpfGui/Constants/ConfigurationKeys.cs @@ -30,6 +30,7 @@ namespace MaaWpfGui.Constants public const string ConfigurationCron = "Cron"; public const string Localization = "GUI.Localization"; + public const string OperNameLanguage = "GUI.OperNameLanguage"; public const string UseTray = "GUI.UseTray"; public const string MinimizeToTray = "GUI.MinimizeToTray"; public const string HideCloseButton = "GUI.HideCloseButton"; diff --git a/src/MaaWpfGui/Helper/DataHelper.cs b/src/MaaWpfGui/Helper/DataHelper.cs index d35966fd66..a8b30d7b9b 100644 --- a/src/MaaWpfGui/Helper/DataHelper.cs +++ b/src/MaaWpfGui/Helper/DataHelper.cs @@ -100,7 +100,7 @@ namespace MaaWpfGui.Helper return null; } - language ??= Instances.SettingsViewModel.Language; + language ??= Instances.SettingsViewModel.OperNameLocalization; return language switch { diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index 440ec682e9..382bc92247 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -404,6 +404,9 @@ 自动肉鸽 生息演算·沙中之火 生息演算·沙洲遗闻 + 干员名称显示语言 + 跟随MAA + 跟随游戏客户端 亮色 暗色 与系统同步 diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index 91a3726f83..df6b6b9fa3 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -1936,7 +1936,7 @@ namespace MaaWpfGui.ViewModels.UI continue; } - var localizedName = DataHelper.GetLocalizedCharacterName(name, _language); + 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); @@ -4428,6 +4428,15 @@ namespace MaaWpfGui.ViewModels.UI /// public List LanguageList { get; set; } + /// + /// Gets the list of operator name language settings + /// + public List OperNameLanguageModeList { get; } = + [ + new() { Display = LocalizationHelper.GetString("OperNameLanguageMAA"), Value = "OperNameLanguageMAA" }, + new() { Display = LocalizationHelper.GetString("OperNameLanguageClient"), Value = "OperNameLanguageClient" } + ]; + /// /// Gets the list of dark mode. /// @@ -4763,6 +4772,51 @@ namespace MaaWpfGui.ViewModels.UI } } + 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" }, + }; + + private string _operNameLanguage = ConfigurationHelper.GetValue(ConfigurationKeys.OperNameLanguage, "OperNameLanguageMAA"); + + public string OperNameLanguage + { + get => _operNameLanguage; + + set + { + switch (value) + { + case "OperNameLanguageClient": + ConfigurationHelper.SetValue(ConfigurationKeys.OperNameLanguage, value); + break; + case "OperNameLanguageMAA": + default: + ConfigurationHelper.SetValue(ConfigurationKeys.OperNameLanguage, "OperNameLanguageMAA"); + break; + } + } + } + + public string OperNameLocalization + { + get + { + if (_operNameLanguage == "OperNameLanguageClient") + { + return _clientLanguageMapper[ConfigurationHelper.GetValue(ConfigurationKeys.ClientType, string.Empty)]; + } + + return _language; + } + } + #endregion #region HotKey diff --git a/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml index 99997ae69f..3807cf8091 100644 --- a/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/GUISettingsUserControl.xaml @@ -93,6 +93,17 @@ SelectedValue="{Binding Language}" SelectedValuePath="Value" Style="{StaticResource ComboBoxExtend}" /> +