From a6e51afcd907323627611962203a6cf431f0cfb6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9E=AB=E9=9B=A8?= <737345039@qq.com>
Date: Sat, 15 Apr 2023 21:43:03 +0800
Subject: [PATCH 1/3] chore: add ThemeHelper again
---
src/MaaWpfGui/Helper/ThemeHelper.cs | 55 +++++++++++++++++++
.../ViewModels/UI/SettingsViewModel.cs | 22 +-------
2 files changed, 58 insertions(+), 19 deletions(-)
create mode 100644 src/MaaWpfGui/Helper/ThemeHelper.cs
diff --git a/src/MaaWpfGui/Helper/ThemeHelper.cs b/src/MaaWpfGui/Helper/ThemeHelper.cs
new file mode 100644
index 0000000000..b9e30f9f39
--- /dev/null
+++ b/src/MaaWpfGui/Helper/ThemeHelper.cs
@@ -0,0 +1,55 @@
+//
+// 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 General Public License 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
+//
+
+using System.Windows;
+using System.Windows.Media;
+using HandyControl.Themes;
+using HandyControl.Tools;
+using Microsoft.Win32;
+using Newtonsoft.Json.Linq;
+
+namespace MaaWpfGui.Helper
+{
+ public static class ThemeHelper
+ {
+ private static void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
+ {
+ ThemeManager.Current.ApplicationTheme = ThemeManager.GetSystemTheme(isSystemTheme: false);
+ ThemeManager.Current.AccentColor = ThemeManager.Current.GetAccentColorFromSystem();
+ Application.Current.Resources["TitleBrush"] = ThemeManager.Current.AccentColor;
+ }
+
+ public static void SwitchToLightMode()
+ {
+ SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;
+ ThemeManager.Current.UsingWindowsAppTheme = false;
+ ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
+ Application.Current.Resources["TitleBrush"] = ThemeManager.Current.AccentColor;
+ }
+
+ public static void SwitchToDarkMode()
+ {
+ SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;
+ ThemeManager.Current.UsingWindowsAppTheme = false;
+ ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
+ Application.Current.Resources["TitleBrush"] = ThemeManager.Current.AccentColor;
+ }
+
+ public static void SwitchToSyncWithOSMode()
+ {
+ ThemeManager.Current.UsingWindowsAppTheme = true;
+ Application.Current.Resources["TitleBrush"] = ThemeManager.Current.AccentColor;
+ SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
+ }
+ }
+}
diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
index ad3beee33c..62412a35f1 100644
--- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
+++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
@@ -27,12 +27,10 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
-using HandyControl.Themes;
using MaaWpfGui.Constants;
using MaaWpfGui.Extensions;
using MaaWpfGui.Helper;
using MaaWpfGui.Main;
-using MaaWpfGui.Services;
using MaaWpfGui.Services.HotKeys;
using MaaWpfGui.Services.Managers;
using MaaWpfGui.Services.Web;
@@ -2575,31 +2573,17 @@ namespace MaaWpfGui.ViewModels.UI
switch (darkModeType)
{
case DarkModeType.Light:
- SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;
- ThemeManager.Current.UsingWindowsAppTheme = false;
- ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
+ ThemeHelper.SwitchToLightMode();
break;
case DarkModeType.Dark:
- SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;
- ThemeManager.Current.UsingWindowsAppTheme = false;
- ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
+ ThemeHelper.SwitchToDarkMode();
break;
case DarkModeType.SyncWithOS:
- ThemeManager.Current.UsingWindowsAppTheme = true;
- SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
+ ThemeHelper.SwitchToSyncWithOSMode();
break;
}
-
- Application.Current.Resources["TitleBrush"] = ThemeManager.Current.AccentColor;
- }
-
- private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
- {
- ThemeManager.Current.ApplicationTheme = ThemeManager.GetSystemTheme(isSystemTheme: false);
- ThemeManager.Current.AccentColor = ThemeManager.Current.GetAccentColorFromSystem();
- Application.Current.Resources["TitleBrush"] = ThemeManager.Current.AccentColor;
}
private enum InverseClearType
From 7a4e47329a0e1cc089536f4ab446e4f8d6e3eec4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9E=AB=E9=9B=A8?= <737345039@qq.com>
Date: Sat, 15 Apr 2023 21:46:33 +0800
Subject: [PATCH 2/3] =?UTF-8?q?feat:=20UiColor=E9=80=82=E9=85=8DDarkMode?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/MaaWpfGui/Constants/UILogColor.cs | 19 +++--
src/MaaWpfGui/Helper/ThemeHelper.cs | 94 +++++++++++++++++++++-
src/MaaWpfGui/Res/Themes/Dark.xaml | 16 +++-
src/MaaWpfGui/Res/Themes/Light.xaml | 12 ++-
src/MaaWpfGui/Styles/Controls/TextBlock.cs | 41 +++++++++-
src/MaaWpfGui/Views/UI/CopilotView.xaml | 4 +-
src/MaaWpfGui/Views/UI/SettingsView.xaml | 56 ++++++-------
src/MaaWpfGui/Views/UI/TaskQueueView.xaml | 8 +-
8 files changed, 202 insertions(+), 48 deletions(-)
diff --git a/src/MaaWpfGui/Constants/UILogColor.cs b/src/MaaWpfGui/Constants/UILogColor.cs
index 407eff82bc..e3ff2b1015 100644
--- a/src/MaaWpfGui/Constants/UILogColor.cs
+++ b/src/MaaWpfGui/Constants/UILogColor.cs
@@ -21,41 +21,44 @@ namespace MaaWpfGui.Constants
///
/// The recommended color for error logs.
///
- public const string Error = "DarkRed";
+ public const string Error = "ErrorLogBrush";
///
/// The recommended color for warning logs.
///
- public const string Warning = "DarkGoldenrod";
+ public const string Warning = "WarningLogBrush";
///
/// The recommended color for info logs.
///
- public const string Info = "DarkCyan";
+ public const string Info = "InfoLogBrush";
///
/// The recommended color for trace logs.
///
- public const string Trace = "Gray";
+ public const string Trace = "TraceLogBrush";
///
/// The recommended color for message logs.
///
- public const string Message = "Black";
+ public const string Message = "MessageLogBrush";
///
/// The recommended color for rare operator logs.
///
- public const string RareOperator = "DarkOrange";
+ public const string RareOperator = "RareOperatorLogBrush";
///
/// The recommended color for robot operator logs.
///
- public const string RobotOperator = "DarkGray";
+ public const string RobotOperator = "RobotOperatorLogBrush";
///
/// The recommended color for file downloading or downloaded or download failed.
///
- public const string Download = "BlueViolet";
+ public const string Download = "DownloadLogBrush";
+
+ // 颜色在MaaWpfGui\Res\Themes中定义
+ // Brushs are defined in MaaWpfGui\Res\Themes
}
}
diff --git a/src/MaaWpfGui/Helper/ThemeHelper.cs b/src/MaaWpfGui/Helper/ThemeHelper.cs
index b9e30f9f39..d97683899d 100644
--- a/src/MaaWpfGui/Helper/ThemeHelper.cs
+++ b/src/MaaWpfGui/Helper/ThemeHelper.cs
@@ -15,13 +15,15 @@ using System.Windows;
using System.Windows.Media;
using HandyControl.Themes;
using HandyControl.Tools;
+using MaaWpfGui.Constants;
using Microsoft.Win32;
-using Newtonsoft.Json.Linq;
namespace MaaWpfGui.Helper
{
public static class ThemeHelper
{
+ #region Swith Theme
+
private static void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
ThemeManager.Current.ApplicationTheme = ThemeManager.GetSystemTheme(isSystemTheme: false);
@@ -51,5 +53,95 @@ namespace MaaWpfGui.Helper
Application.Current.Resources["TitleBrush"] = ThemeManager.Current.AccentColor;
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
}
+
+ #endregion
+
+ #region Check UiLogColor
+
+ // In official version, using ResourceHelper.GetSkin
+ private static readonly Color LightBackground = ((SolidColorBrush)ThemeResources.Current.GetThemeDictionary("Light")["RegionBrush"]).Color;
+
+ private static readonly Color DarkBackground = ((SolidColorBrush)ThemeResources.Current.GetThemeDictionary("Dark")["RegionBrush"]).Color;
+
+ public static bool SimilarToBackground(Color color)
+ {
+ return ColorDistance(color, LightBackground) == 0 || ColorDistance(color, DarkBackground) == 0;
+ }
+
+ ///
+ /// Gets the distance between colors c1 and c2.
+ ///
+ /// The color c1.
+ /// The color c2.
+ /// The distance from 0 to 35.
+ public static int ColorDistance(Color c1, Color c2)
+ {
+ // https://www.compuphase.com/cmetric.htm
+ long rmean = (c1.R + c2.R) / 2;
+ long r = c1.R - c2.R;
+ long g = c1.G - c2.G;
+ long b = c1.B - c2.B;
+ return (int)(((((512 + rmean) * r * r) >> 8) + (4 * g * g) + (((767 - rmean) * b * b) >> 8)) >> 14);
+ }
+
+ #endregion
+
+ #region Convert
+
+ public const string DefaultKey = UiLogColor.Message;
+
+ public static SolidColorBrush DefaultBrush => ResourceHelper.GetResource(DefaultKey);
+
+ public static Color DefaultColor => DefaultBrush.Color;
+
+ public static string DefaultHexString => $"#{DefaultColor.A:X2}{DefaultColor.R:X2}{DefaultColor.G:X2}{DefaultColor.B:X2}";
+
+ public static string Color2HexString(Color color, bool keepAlpha = false)
+ {
+ if (keepAlpha)
+ {
+ return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
+ }
+
+ return $"#FF{color.R:X2}{color.G:X2}{color.B:X2}";
+ }
+
+ public static string Brush2HexString(SolidColorBrush brush, bool keepAlpha = false)
+ {
+ if (brush != null)
+ {
+ return Color2HexString(brush.Color, keepAlpha);
+ }
+
+ return DefaultHexString;
+ }
+
+ public static Color String2Color(string str)
+ {
+ if (!string.IsNullOrWhiteSpace(str))
+ {
+ try
+ {
+ object obj = ColorConverter.ConvertFromString(str);
+ if (obj is Color color)
+ {
+ return color;
+ }
+ }
+ catch
+ {
+ return DefaultColor;
+ }
+ }
+
+ return DefaultColor;
+ }
+
+ public static SolidColorBrush String2Brush(string str)
+ {
+ return new SolidColorBrush(String2Color(str));
+ }
+
+ #endregion
}
}
diff --git a/src/MaaWpfGui/Res/Themes/Dark.xaml b/src/MaaWpfGui/Res/Themes/Dark.xaml
index 00e424a79d..05bb215bd1 100644
--- a/src/MaaWpfGui/Res/Themes/Dark.xaml
+++ b/src/MaaWpfGui/Res/Themes/Dark.xaml
@@ -8,10 +8,10 @@
-
+
-
-
+
+
@@ -26,4 +26,14 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/MaaWpfGui/Res/Themes/Light.xaml b/src/MaaWpfGui/Res/Themes/Light.xaml
index fc14bd8f0d..1276b5fa7d 100644
--- a/src/MaaWpfGui/Res/Themes/Light.xaml
+++ b/src/MaaWpfGui/Res/Themes/Light.xaml
@@ -5,5 +5,15 @@
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/MaaWpfGui/Styles/Controls/TextBlock.cs b/src/MaaWpfGui/Styles/Controls/TextBlock.cs
index 34b2c0962c..7aab6fb35a 100644
--- a/src/MaaWpfGui/Styles/Controls/TextBlock.cs
+++ b/src/MaaWpfGui/Styles/Controls/TextBlock.cs
@@ -13,6 +13,7 @@
using System.Windows;
using System.Windows.Media;
+using MaaWpfGui.Helper;
namespace MaaWpfGui.Styles.Controls
{
@@ -23,12 +24,50 @@ namespace MaaWpfGui.Styles.Controls
DefaultStyleKeyProperty.OverrideMetadata(typeof(TextBlock), new FrameworkPropertyMetadata(typeof(TextBlock)));
}
- public static readonly DependencyProperty CustomForegroundProperty = DependencyProperty.Register("CustomForeground", typeof(Brush), typeof(TextBlock), new PropertyMetadata(Brushes.Black));
+ public static readonly DependencyProperty CustomForegroundProperty = DependencyProperty.Register("CustomForeground", typeof(Brush), typeof(TextBlock), new PropertyMetadata(ThemeHelper.DefaultBrush));
public Brush CustomForeground
{
get { return (Brush)GetValue(CustomForegroundProperty); }
set { SetValue(CustomForegroundProperty, value); }
}
+
+ public static readonly DependencyProperty ForegroundKeyProperty = DependencyProperty.Register("ForegroundKey", typeof(string), typeof(TextBlock), new PropertyMetadata(ThemeHelper.DefaultKey, OnForegroundKeyChanged));
+
+ private static void OnForegroundKeyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var element = (TextBlock)d;
+ if (e.NewValue != null)
+ {
+ element.ForegroundKey = (string)e.NewValue;
+ }
+ }
+
+ public string ForegroundKey
+ {
+ get
+ {
+ return (string)GetValue(ForegroundKeyProperty);
+ }
+
+ set
+ {
+ SetValue(ForegroundKeyProperty, value);
+ if (Application.Current.Resources.Contains(value))
+ {
+ SetResourceReference(ForegroundProperty, value);
+ return;
+ }
+
+ var brush = ThemeHelper.String2Brush(value);
+ if (ThemeHelper.SimilarToBackground(brush.Color))
+ {
+ SetResourceReference(ForegroundProperty, ThemeHelper.DefaultKey);
+ return;
+ }
+
+ SetValue(ForegroundProperty, brush);
+ }
+ }
}
}
diff --git a/src/MaaWpfGui/Views/UI/CopilotView.xaml b/src/MaaWpfGui/Views/UI/CopilotView.xaml
index f3e9fa7758..9064592603 100644
--- a/src/MaaWpfGui/Views/UI/CopilotView.xaml
+++ b/src/MaaWpfGui/Views/UI/CopilotView.xaml
@@ -1,4 +1,4 @@
-
diff --git a/src/MaaWpfGui/Views/UI/SettingsView.xaml b/src/MaaWpfGui/Views/UI/SettingsView.xaml
index 30d85e079c..6aa1d6a858 100644
--- a/src/MaaWpfGui/Views/UI/SettingsView.xaml
+++ b/src/MaaWpfGui/Views/UI/SettingsView.xaml
@@ -1,4 +1,4 @@
-
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
+ Fill="{DynamicResource BorderBrush}" />
-
+
diff --git a/src/MaaWpfGui/Views/UI/TaskQueueView.xaml b/src/MaaWpfGui/Views/UI/TaskQueueView.xaml
index 71b4fe1f86..c163fad1d2 100644
--- a/src/MaaWpfGui/Views/UI/TaskQueueView.xaml
+++ b/src/MaaWpfGui/Views/UI/TaskQueueView.xaml
@@ -1,4 +1,4 @@
-
-
+
From e00cd8472790b38cd619cb75a094d33f3d56d5c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9E=AB=E9=9B=A8?= <737345039@qq.com>
Date: Mon, 17 Apr 2023 18:29:11 +0800
Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E5=9C=A8=E4=B8=BB=E7=95=8C?=
=?UTF-8?q?=E9=9D=A2=E4=BF=9D=E5=AD=98=E4=BD=8D=E7=BD=AE=E6=97=B6=E8=BF=9B?=
=?UTF-8?q?=E8=A1=8C=E6=A3=80=E6=9F=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
index 62412a35f1..b9baed5290 100644
--- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
+++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
@@ -2418,6 +2418,13 @@ namespace MaaWpfGui.ViewModels.UI
return;
}
+ var mainWindowRect = new Rect(mainWindow.Left + 25, mainWindow.Top + 25, mainWindow.Width - 50, mainWindow.Height - 50);
+ var virtualScreenRect = new Rect(SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight);
+ if (!virtualScreenRect.IntersectsWith(mainWindowRect))
+ {
+ return;
+ }
+
// 请在配置文件中修改该部分配置,暂不支持从GUI设置
// Please modify this part of configuration in the configuration file.
ConfigurationHelper.SetValue(ConfigurationKeys.LoadPositionAndSize, LoadGUIParameters.ToString());