Revert "rft: 拆分 设置-界面设置 (#11153)"

This reverts commit 1c14b211d3.

# Conflicts:
#	src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
This commit is contained in:
status102
2024-11-17 13:08:43 +08:00
parent 94031f7da9
commit a2902fdd29
11 changed files with 511 additions and 536 deletions

View File

@@ -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;

View File

@@ -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";

View File

@@ -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<string, string> 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<string, CharacterInfo> Characters { get; } = new();
@@ -172,7 +160,7 @@ namespace MaaWpfGui.Helper
return null;
}
language ??= SettingsViewModel.GuiSettings.OperNameLocalization;
language ??= Instances.SettingsViewModel.OperNameLocalization;
return language switch
{

View File

@@ -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
/// <param name="dateFormat">The Date format string</param>
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;

View File

@@ -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);
/// <summary>
/// The Pallas language key.
/// </summary>
public const string PallasLangKey = "pallas";
/// <summary>
/// Gets the visibility of task setting views.
/// </summary>
@@ -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
/// <summary>
/// The Pallas language key.
/// </summary>
public const string PallasLangKey = "pallas";
private bool _cheers = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.Cheers, bool.FalseString));
/// <summary>
@@ -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
/// <summary>
/// Gets or sets the language list.
/// </summary>
public List<CombinedData> LanguageList { get; set; }
/// <summary>
/// Gets or sets the list of operator name language settings
/// </summary>
public List<CombinedData> OperNameLanguageModeList { get; set; } =
[
new() { Display = LocalizationHelper.GetString("OperNameLanguageMAA"), Value = "OperNameLanguageMAA" },
new() { Display = LocalizationHelper.GetString("OperNameLanguageClient"), Value = "OperNameLanguageClient" }
];
/// <summary>
/// Gets the list of dark mode.
/// </summary>
public List<GenericCombinedData<DarkModeType>> 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 },
];
/// <summary>
/// Gets the list of inverse clear modes.
/// </summary>
public List<CombinedData> 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));
/// <summary>
/// Gets or sets a value indicating whether to use tray icon.
/// </summary>
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));
/// <summary>
/// Gets or sets a value indicating whether to minimize to tray.
/// </summary>
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));
/// <summary>
/// Gets or sets a value indicating whether to make window title scrollable.
/// </summary>
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));
/// <summary>
/// Gets or sets a value indicating whether to hide close button.
/// </summary>
public bool HideCloseButton
{
get => _hideCloseButton;
set
{
SetAndNotify(ref _hideCloseButton, value);
ConfigurationHelper.SetValue(ConfigurationKeys.HideCloseButton, value.ToString());
var rvm = (RootViewModel)this.Parent;
rvm.ShowCloseButton = !value;
}
}
/// <summary>
/// Gets or sets a value indicating whether to use notification.
/// </summary>
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<string> 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);
}
}
/// <summary>
/// Gets or sets the dark mode.
/// </summary>
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;
/// <summary>
/// Gets or sets the inverse clear mode.
/// </summary>
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<string, string> _windowTitleAllShowDict = new()
{
{ LocalizationHelper.GetString("ConfigurationName"), "1" },
{ LocalizationHelper.GetString("ConnectionPreset"), "2" },
{ LocalizationHelper.GetString("ConnectionAddress"), "3" },
{ LocalizationHelper.GetString("ClientType"), "4" },
};
private List<string> _windowTitleAllShowList = [.. _windowTitleAllShowDict.Keys];
public List<string> 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<string>().Select(s => _windowTitleAllShowDict[s]));
ConfigurationHelper.SetValue(ConfigurationKeys.WindowTitleSelectShowList, config);
}
}
private string _language = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage);
/// <summary>
/// Gets or sets the language.
/// </summary>
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));
}
}
/// <summary>
/// Gets the language info.
/// </summary>
public string LanguageInfo
{
get
{
var language = (string)Application.Current.Resources["Language"];
return language == "Language" ? language : language + " / Language";
}
}
private static readonly Dictionary<string, string> _clientLanguageMapper = new()
{
{ string.Empty, "zh-cn" },
{ "Official", "zh-cn" },
{ "Bilibili", "zh-cn" },
{ "YoStarEN", "en-us" },
{ "YoStarJP", "ja-jp" },
{ "YoStarKR", "ko-kr" },
{ "txwy", "zh-tw" },
};
/// <summary>
/// Opername display language, can set force display when it was set as "OperNameLanguageForce.en-us"
/// </summary>
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
/// <summary>
@@ -2962,9 +3421,9 @@ namespace MaaWpfGui.ViewModels.UI
prefix += " - ";
}
List<string> windowTitleSelectShowList = GuiSettings.WindowTitleSelectShowList
.Where(x => GUISettingsUserControlModel.WindowTitleAllShowDict.ContainsKey(x?.ToString() ?? string.Empty))
.Select(x => GUISettingsUserControlModel.WindowTitleAllShowDict[x?.ToString() ?? string.Empty]).ToList();
List<string> 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;

View File

@@ -1,478 +0,0 @@
// <copyright file="GUISettingsUserControlModel.cs" company="MaaAssistantArknights">
// 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
// </copyright>
#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
{
/// <summary>
/// Gets or sets a value indicating whether it is idle.
/// </summary>
public bool Idle
{
get => Instances.SettingsViewModel.Idle;
set
{
Instances.SettingsViewModel.Idle = value;
NotifyOfPropertyChange(nameof(Idle));
}
}
/// <summary>
/// Gets or sets the language list.
/// </summary>
public List<CombinedData> LanguageList { get; set; } = [];
/// <summary>
/// Gets or sets the list of operator name language settings
/// </summary>
public List<CombinedData> OperNameLanguageModeList { get; set; } =
[
new() { Display = LocalizationHelper.GetString("OperNameLanguageMAA"), Value = "OperNameLanguageMAA" },
new() { Display = LocalizationHelper.GetString("OperNameLanguageClient"), Value = "OperNameLanguageClient" }
];
/// <summary>
/// Gets the list of dark mode.
/// </summary>
public List<GenericCombinedData<DarkModeType>> 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 },
];
/// <summary>
/// Gets the list of inverse clear modes.
/// </summary>
public List<CombinedData> 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));
/// <summary>
/// Gets or sets a value indicating whether to use tray icon.
/// </summary>
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));
/// <summary>
/// Gets or sets a value indicating whether to minimize to tray.
/// </summary>
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));
/// <summary>
/// Gets or sets a value indicating whether to make window title scrollable.
/// </summary>
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));
/// <summary>
/// Gets or sets a value indicating whether to hide close button.
/// </summary>
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;
}
}
/// <summary>
/// Gets or sets a value indicating whether to use notification.
/// </summary>
public bool UseNotify
{
get => ConfigFactory.CurrentConfig.GUI.UseNotify;
set
{
ConfigFactory.CurrentConfig.GUI.UseNotify = value;
NotifyOfPropertyChange();
if (value)
{
ToastNotification.ShowDirect("Test test");
}
}
}
public List<string> 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);
}
}
/// <summary>
/// Gets or sets the dark mode.
/// </summary>
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;
/// <summary>
/// Gets or sets the inverse clear mode.
/// </summary>
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<string, string> _windowTitleAllShowDict = new()
{
{ LocalizationHelper.GetString("ConfigurationName"), "1" },
{ LocalizationHelper.GetString("ConnectionPreset"), "2" },
{ LocalizationHelper.GetString("ConnectionAddress"), "3" },
{ LocalizationHelper.GetString("ClientType"), "4" },
};
public static Dictionary<string, string> WindowTitleAllShowDict { get => _windowTitleAllShowDict; }
private List<string> _windowTitleAllShowList = [.. _windowTitleAllShowDict.Keys];
public List<string> 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<string>().Select(s => _windowTitleAllShowDict[s]));
ConfigurationHelper.SetValue(ConfigurationKeys.WindowTitleSelectShowList, config);
}
}
private string _language = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage);
/// <summary>
/// Gets or sets the language.
/// </summary>
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));
}
}
/// <summary>
/// Gets the language info.
/// </summary>
public string LanguageInfo
{
get
{
var language = (string)Application.Current.Resources["Language"];
return language == "Language" ? language : language + " / Language";
}
}
/// <summary>
/// Opername display language, can set force display when it was set as "OperNameLanguageForce.en-us"
/// </summary>
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;
}
}
}

View File

@@ -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)

View File

@@ -78,10 +78,7 @@
<userControl:RemoteControlUserControl Margin="0,20" HorizontalAlignment="Center" />
<hc:Divider Content="{Binding ListTitle[7]}" />
<settingsViews:GUISettingsUserControl
Margin="0,20"
HorizontalAlignment="Center"
DataContext="{Binding GuiSettings}" />
<userControl:GUISettingsUserControl Margin="0,20" HorizontalAlignment="Center" />
<hc:Divider Content="{Binding ListTitle[8]}" />
<settingsViews:ExternalNotificationSettingsUserControl

View File

@@ -1,5 +1,5 @@
<UserControl
x:Class="MaaWpfGui.Views.UserControl.Settings.GUISettingsUserControl"
x:Class="MaaWpfGui.Views.UserControl.GUISettingsUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
@@ -9,12 +9,13 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels.UserControl.Settings"
d:Background="White"
d:DataContext="{d:DesignInstance {x:Type viewModels:GUISettingsUserControlModel}}"
xmlns:styles="clr-namespace:MaaWpfGui.Styles"
xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI"
xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels"
xmlns:vm="clr-namespace:MaaWpfGui"
d:DataContext="{d:DesignInstance {x:Type ui:SettingsViewModel}}"
d:DesignHeight="300"
d:DesignWidth="550"
s:View.ActionTarget="{Binding}"
mc:Ignorable="d">
<Grid
Margin="10"
@@ -46,7 +47,11 @@
<!--<CheckBox
Margin="10"
Content="{DynamicResource WindowTitleScrollable}"
IsChecked="{Binding WindowTitleScrollable}" />-->
IsChecked="{Binding WindowTitleScrollable}" />
<CheckBox
Margin="10"
Content="{DynamicResource UseLogItemDateFormat}"
IsChecked="{Binding UseLogItemDateFormat}" />-->
<CheckBox
Margin="10"
Content="{DynamicResource WindowTitleScrollable}"
@@ -101,7 +106,8 @@
hc:InfoElement.Title="{DynamicResource LogItemDateFormatString}"
ItemsSource="{Binding LogItemDateFormatStringList}"
SelectedValue="{Binding LogItemDateFormatString}"
Style="{StaticResource ComboBoxExtend}" />
Style="{StaticResource ComboBoxExtend}"
Visibility="{c:Binding UseLogItemDateFormat}" />
</StackPanel>
</Grid>
</UserControl>

View File

@@ -11,7 +11,7 @@
// but WITHOUT ANY WARRANTY
// </copyright>
namespace MaaWpfGui.Views.UserControl.Settings
namespace MaaWpfGui.Views.UserControl
{
/// <summary>
/// GUISettingsUserControl.xaml 的交互逻辑

View File

@@ -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'}">
<hc:UniformSpacingPanel DataContext="{Binding GuiSettings}" Orientation="Vertical" Spacing="40">
<hc:UniformSpacingPanel Orientation="Vertical" Spacing="40">
<ComboBox
hc:InfoElement.HorizontalAlignment="Center"
hc:InfoElement.Title="{Binding LanguageInfo, Mode=OneTime}"