From c8bffaa96c08e97256bdeb87f0d2c8cedd3ad643 Mon Sep 17 00:00:00 2001 From: Space Time Date: Sat, 7 Dec 2024 12:16:10 +0800 Subject: [PATCH] =?UTF-8?q?1.1.3=20->=201.1.4=20=E7=AC=AC30=E6=AC=A1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.config | 33 ++++++++++++++++++++ Consts/SettingsMultilangConst.Designer.cs | 38 ++++++++++++++++++++++- Consts/SettingsMultilangConst.resx | 14 ++++++++- Consts/SettingsMultilangConst.zh.resx | 12 +++++++ Convs/SettingsWeightsButtonContentConv.cs | 20 ++++++++++++ Preses/SettingsPres.cs | 27 ++++++++++++++++ Props/Settings.Designer.cs | 12 +++++++ Props/Settings.settings | 3 ++ Utils/ForegroundGenerator.cs | 2 +- Wins/SettingsWin.xaml | 11 +++++++ Wins/SettingsWin.xaml.cs | 1 + 11 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 App.config create mode 100644 Convs/SettingsWeightsButtonContentConv.cs diff --git a/App.config b/App.config new file mode 100644 index 0000000..d838032 --- /dev/null +++ b/App.config @@ -0,0 +1,33 @@ + + + + +
+ + + + + + + + + + + + + + + -1 + + + -1 + + + Red + + + -1 + + + + \ No newline at end of file diff --git a/Consts/SettingsMultilangConst.Designer.cs b/Consts/SettingsMultilangConst.Designer.cs index 6594b50..d026fcb 100644 --- a/Consts/SettingsMultilangConst.Designer.cs +++ b/Consts/SettingsMultilangConst.Designer.cs @@ -70,7 +70,7 @@ namespace Sheas_Cealer.Consts { } /// - /// 查找类似 Switch Color (Fully random) 的本地化字符串。 + /// 查找类似 Switch Color (Fully Random) 的本地化字符串。 /// public static string ColorsButtonContent { get { @@ -158,5 +158,41 @@ namespace Sheas_Cealer.Consts { return ResourceManager.GetString("ThemesButtonToolTip", resourceCulture); } } + + /// + /// 查找类似 Switch Weight (Bold → Light) 的本地化字符串。 + /// + public static string WeightsButtonBoldWeightContent { + get { + return ResourceManager.GetString("WeightsButtonBoldWeightContent", resourceCulture); + } + } + + /// + /// 查找类似 Switch Weight (Light → Regular) 的本地化字符串。 + /// + public static string WeightsButtonLightWeightContent { + get { + return ResourceManager.GetString("WeightsButtonLightWeightContent", resourceCulture); + } + } + + /// + /// 查找类似 Switch Weight (Regular → Bold) 的本地化字符串。 + /// + public static string WeightsButtonRegularWeightContent { + get { + return ResourceManager.GetString("WeightsButtonRegularWeightContent", resourceCulture); + } + } + + /// + /// 查找类似 Click to switch font weights 的本地化字符串。 + /// + public static string WeightsButtonToolTip { + get { + return ResourceManager.GetString("WeightsButtonToolTip", resourceCulture); + } + } } } diff --git a/Consts/SettingsMultilangConst.resx b/Consts/SettingsMultilangConst.resx index 9a82887..5f279e7 100644 --- a/Consts/SettingsMultilangConst.resx +++ b/Consts/SettingsMultilangConst.resx @@ -98,7 +98,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Switch Color (Fully random) + Switch Color (Fully Random) Click to switch colors @@ -127,6 +127,18 @@ Click to switch themes + + Switch Weight (Bold → Light) + + + Switch Weight (Light → Regular) + + + Switch Weight (Regular → Bold) + + + Click to switch font weights + Change successfuly, restart to refresh the windows diff --git a/Consts/SettingsMultilangConst.zh.resx b/Consts/SettingsMultilangConst.zh.resx index 1068c78..b60c14b 100644 --- a/Consts/SettingsMultilangConst.zh.resx +++ b/Consts/SettingsMultilangConst.zh.resx @@ -127,6 +127,18 @@ 点击切换显示主题 + + 切换字重 (粗体 → 细体) + + + 切换字重 (细体 → 标准) + + + 切换字重 (标准 → 粗体) + + + 点击切换字体粗细 + 语言更改完成,重启以刷新界面 diff --git a/Convs/SettingsWeightsButtonContentConv.cs b/Convs/SettingsWeightsButtonContentConv.cs new file mode 100644 index 0000000..3f917e0 --- /dev/null +++ b/Convs/SettingsWeightsButtonContentConv.cs @@ -0,0 +1,20 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using Sheas_Cealer.Consts; + +namespace Sheas_Cealer.Convs; + +internal class SettingsWeightsButtonContentConv : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + bool? isLightWeight = value as bool?; + + return isLightWeight.HasValue ? + isLightWeight.GetValueOrDefault() ? SettingsConst.WeightsButtonLightWeightContent : SettingsConst.WeightsButtonBoldWeightContent : + SettingsConst.WeightsButtonRegularWeightContent; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); +} \ No newline at end of file diff --git a/Preses/SettingsPres.cs b/Preses/SettingsPres.cs index 9223b5e..5689fbd 100644 --- a/Preses/SettingsPres.cs +++ b/Preses/SettingsPres.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Threading; using System.Windows; +using System.Windows.Controls; using System.Windows.Markup; using CommunityToolkit.Mvvm.ComponentModel; using Sheas_Cealer.Props; @@ -19,6 +20,14 @@ internal partial class SettingsPres : GlobalPres 1 => true, _ => throw new UnreachableException() }; + + IsLightWeight = Settings.Default.IsLightWeight switch + { + -1 => null, + 0 => false, + 1 => true, + _ => throw new UnreachableException() + }; } [ObservableProperty] @@ -35,4 +44,22 @@ internal partial class SettingsPres : GlobalPres Settings.Default.IsEnglishLang = (sbyte)(value.HasValue ? value.Value ? 1 : 0 : -1); Settings.Default.Save(); } + + [ObservableProperty] + private static bool? isLightWeight = null; + partial void OnIsLightWeightChanged(bool? value) + { + FontWeight newWeight = value.HasValue ? value.Value ? FontWeights.Light : FontWeights.Bold : FontWeights.Regular; + + Style newStyle = new(typeof(Window), Application.Current.Resources["CommonWindow"] as Style); + newStyle.Setters.Add(new Setter(Window.FontWeightProperty, newWeight)); + Application.Current.Resources["CommonWindow"] = newStyle; + + newStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style); + newStyle.Setters.Add(new Setter(Button.FontWeightProperty, newWeight)); + Application.Current.Resources[typeof(Button)] = newStyle; + + Settings.Default.IsLightWeight = (sbyte)(value.HasValue ? value.Value ? 1 : 0 : -1); + Settings.Default.Save(); + } } \ No newline at end of file diff --git a/Props/Settings.Designer.cs b/Props/Settings.Designer.cs index debb854..6c90d4f 100644 --- a/Props/Settings.Designer.cs +++ b/Props/Settings.Designer.cs @@ -94,5 +94,17 @@ namespace Sheas_Cealer.Props { this["PrimaryColor"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] + public sbyte IsLightWeight { + get { + return ((sbyte)(this["IsLightWeight"])); + } + set { + this["IsLightWeight"] = value; + } + } } } diff --git a/Props/Settings.settings b/Props/Settings.settings index 7d39a95..714f41d 100644 --- a/Props/Settings.settings +++ b/Props/Settings.settings @@ -20,5 +20,8 @@ Red + + -1 + \ No newline at end of file diff --git a/Utils/ForegroundGenerator.cs b/Utils/ForegroundGenerator.cs index a9fec4a..2528fcc 100644 --- a/Utils/ForegroundGenerator.cs +++ b/Utils/ForegroundGenerator.cs @@ -12,7 +12,7 @@ internal static class ForegroundGenerator double blackContrast = (luminance + 0.05) / 0.05; double whiteContrast = 1.05 / (luminance + 0.05); - return blackContrast >= 3.9 && whiteContrast >= 2.9 ? null : + return blackContrast >= 4 && whiteContrast >= 3 ? null : blackContrast >= whiteContrast ? Color.FromRgb(0, 0, 0) : Color.FromRgb(255, 255, 255); } diff --git a/Wins/SettingsWin.xaml b/Wins/SettingsWin.xaml index 55f1dba..c7d75f7 100644 --- a/Wins/SettingsWin.xaml +++ b/Wins/SettingsWin.xaml @@ -44,5 +44,16 @@ \ No newline at end of file diff --git a/Wins/SettingsWin.xaml.cs b/Wins/SettingsWin.xaml.cs index 91c3421..c085d63 100644 --- a/Wins/SettingsWin.xaml.cs +++ b/Wins/SettingsWin.xaml.cs @@ -54,6 +54,7 @@ public partial class SettingsWin : Window Settings.Default.PrimaryColor = System.Drawing.Color.FromArgb(newColor.A, newColor.R, newColor.G, newColor.B); Settings.Default.Save(); } + private void WeightsButton_Click(object sender, RoutedEventArgs e) => SettingsPres!.IsLightWeight = SettingsPres.IsLightWeight.HasValue ? SettingsPres.IsLightWeight.Value ? null : true : false; private void SettingsWin_KeyDown(object sender, KeyEventArgs e) {