1.1.3 -> 1.1.4 第28次更新

This commit is contained in:
Space Time 2024-12-06 23:59:26 +08:00
parent 8178742f62
commit 038e9fe7e7
9 changed files with 117 additions and 5 deletions

View File

@ -1,6 +1,10 @@
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using MaterialDesignThemes.Wpf;
using Sheas_Cealer.Preses;
using Sheas_Cealer.Props;
using Sheas_Cealer.Utils;
using Sheas_Cealer.Wins;
namespace Sheas_Cealer;
@ -10,6 +14,21 @@ public partial class App : Application
protected override void OnStartup(StartupEventArgs e)
{
_ = new SettingsPres();
PaletteHelper paletteHelper = new();
Theme newTheme = paletteHelper.GetTheme();
System.Drawing.Color newColor = Settings.Default.PrimaryColor;
newTheme.SetPrimaryColor(Color.FromRgb(newColor.R, newColor.G, newColor.B));
paletteHelper.SetTheme(newTheme);
Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B);
if (foregroundColor.HasValue)
Current.Resources["MaterialDesignBackground"] = new SolidColorBrush(foregroundColor.Value);
else
Current.Resources.Remove("MaterialDesignBackground");
new MainWin(e.Args).Show();
}

View File

@ -69,6 +69,24 @@ namespace Sheas_Cealer.Consts {
}
}
/// <summary>
/// 查找类似 Switch Color (Fully random) 的本地化字符串。
/// </summary>
public static string ColorsButtonContent {
get {
return ResourceManager.GetString("ColorsButtonContent", resourceCulture);
}
}
/// <summary>
/// 查找类似 Click to switch colors 的本地化字符串。
/// </summary>
public static string ColorsButtonToolTip {
get {
return ResourceManager.GetString("ColorsButtonToolTip", resourceCulture);
}
}
/// <summary>
/// 查找类似 Switch Lang (中文 → En) 的本地化字符串。
/// </summary>
@ -97,7 +115,7 @@ namespace Sheas_Cealer.Consts {
}
/// <summary>
/// 查找类似 点击切换界面语言 的本地化字符串。
/// 查找类似 Click to switch langs 的本地化字符串。
/// </summary>
public static string LangsButtonToolTip {
get {

View File

@ -97,6 +97,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ColorsButtonContent" xml:space="preserve">
<value>Switch Color (Fully random)</value>
</data>
<data name="ColorsButtonToolTip" xml:space="preserve">
<value>Click to switch colors</value>
</data>
<data name="LangsButtonChineseLangContent" xml:space="preserve">
<value>Switch Lang (中文 → En)</value>
</data>
@ -107,7 +113,7 @@
<value>Switch Lang (Auto → 中文)</value>
</data>
<data name="LangsButtonToolTip" xml:space="preserve">
<value>点击切换界面语言</value>
<value>Click to switch langs</value>
</data>
<data name="ThemesButtonDarkThemeContent" xml:space="preserve">
<value>Switch Theme (Dark → Light)</value>

View File

@ -97,6 +97,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ColorsButtonContent" xml:space="preserve">
<value>切换颜色 (全随机)</value>
</data>
<data name="ColorsButtonToolTip" xml:space="preserve">
<value>点击切换按钮颜色</value>
</data>
<data name="LangsButtonChineseLangContent" xml:space="preserve">
<value>切换语言 (中文 → En)</value>
</data>
@ -107,7 +113,7 @@
<value>切换语言 (系统 → 中文)</value>
</data>
<data name="LangsButtonToolTip" xml:space="preserve">
<value>Click to switch langs</value>
<value>点击切换界面语言</value>
</data>
<data name="ThemesButtonDarkThemeContent" xml:space="preserve">
<value>切换主题 (暗色 → 亮色)</value>

View File

@ -82,5 +82,17 @@ namespace Sheas_Cealer.Props {
this["IsEnglishLang"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Red")]
public global::System.Drawing.Color PrimaryColor {
get {
return ((global::System.Drawing.Color)(this["PrimaryColor"]));
}
set {
this["PrimaryColor"] = value;
}
}
}
}

View File

@ -17,5 +17,8 @@
<Setting Name="IsEnglishLang" Type="System.SByte" Scope="User">
<Value Profile="(Default)">-1</Value>
</Setting>
<Setting Name="PrimaryColor" Type="System.Drawing.Color" Scope="User">
<Value Profile="(Default)">Red</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -0,0 +1,20 @@
using System;
using System.Windows.Media;
namespace Sheas_Cealer.Utils;
internal static class ForegroundGenerator
{
internal static Color? GetForeground(int red, int green, int blue)
{
double luminance = 0.2126 * GammaCorrect(red / 255.0) + 0.7152 * GammaCorrect(green / 255.0) + 0.0722 * GammaCorrect(blue / 255.0);
double blackContrast = (luminance + 0.05) / 0.05;
double whiteContrast = 1.05 / (luminance + 0.05);
return blackContrast >= 3.9 && whiteContrast >= 2.9 ? null :
blackContrast >= whiteContrast ? Color.FromRgb(0, 0, 0) : Color.FromRgb(255, 255, 255);
}
private static double GammaCorrect(double c) => c <= 0.03928 ? c / 12.92 : Math.Pow((c + 0.055) / 1.055, 2.4);
}

View File

@ -13,13 +13,14 @@
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Margin="5" d:Content="# # # #" ToolTip="{Binding Source={x:Static consts:SettingsConst.ThemesButtonToolTip}}"
<Button Grid.Row="0" Grid.Column="0" Margin="5" d:Content="# # # #" ToolTip="{Binding Source={x:Static consts:SettingsConst.ThemesButtonToolTip}}"
Click="ThemesButton_Click">
<Button.Content>
<Binding Path="IsLightTheme">
@ -30,7 +31,7 @@
</Button.Content>
</Button>
<Button Grid.Column="1" Margin="5" d:Content="# # # #" ToolTip="{Binding Source={x:Static consts:SettingsConst.LangsButtonToolTip}}"
<Button Grid.Row="0" Grid.Column="1" Margin="5" d:Content="# # # #" ToolTip="{Binding Source={x:Static consts:SettingsConst.LangsButtonToolTip}}"
Click="LangsButton_Click">
<Button.Content>
<Binding Path="IsEnglishLang">
@ -40,5 +41,8 @@
</Binding>
</Button.Content>
</Button>
<Button Grid.Row="1" Grid.Column="0" Margin="5" Content="{Binding Source={x:Static consts:SettingsConst.ColorsButtonContent}}" ToolTip="{Binding Source={x:Static consts:SettingsConst.ColorsButtonToolTip}}"
Click="ColorsButton_Click" />
</Grid>
</Window>

View File

@ -1,8 +1,11 @@
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using MaterialDesignThemes.Wpf;
using Sheas_Cealer.Consts;
using Sheas_Cealer.Preses;
using Sheas_Cealer.Props;
using Sheas_Cealer.Utils;
namespace Sheas_Cealer.Wins;
@ -30,6 +33,27 @@ public partial class SettingsWin : Window
MessageBox.Show(SettingsConst._ChangeLangSuccessMsg);
}
private void ColorsButton_Click(object sender, RoutedEventArgs e)
{
Random random = new();
PaletteHelper paletteHelper = new();
Theme newTheme = paletteHelper.GetTheme();
Color newColor = Color.FromRgb((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
newTheme.SetPrimaryColor(newColor);
paletteHelper.SetTheme(newTheme);
Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B);
if (foregroundColor.HasValue)
Application.Current.Resources["MaterialDesignBackground"] = new SolidColorBrush(foregroundColor.Value);
else
Application.Current.Resources.Remove("MaterialDesignBackground");
Settings.Default.PrimaryColor = System.Drawing.Color.FromArgb(newColor.A, newColor.R, newColor.G, newColor.B);
Settings.Default.Save();
}
private void SettingsWin_KeyDown(object sender, KeyEventArgs e)
{