From cda7c1ed33ce28ceca68660f285ea7bd6cc9b135 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9E=AB=E9=9B=A8?= <737345039@qq.com>
Date: Sat, 8 Apr 2023 15:22:35 +0800
Subject: [PATCH] =?UTF-8?q?perf:=20=E6=94=B9=E7=94=A8HandyControls?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
src/MaaWpfGui/App.xaml | 11 ++++-
src/MaaWpfGui/App.xaml.cs | 45 -------------------
src/MaaWpfGui/Helper/ThemeHelper.cs | 22 ---------
src/MaaWpfGui/MaaWpfGui.csproj | 4 +-
src/MaaWpfGui/Main/Bootstrapper.cs | 2 +
src/MaaWpfGui/Res/Themes/Colors.xaml | 7 ---
src/MaaWpfGui/Res/Themes/ColorsDark.xaml | 8 ----
src/MaaWpfGui/Res/Themes/Dark.xaml | 26 +++++++++++
src/MaaWpfGui/Res/Themes/Light.xaml | 7 +++
src/MaaWpfGui/Res/Themes/SkinDark.xaml | 7 ---
src/MaaWpfGui/Res/Themes/SkinDefault.xaml | 7 ---
.../ViewModels/UI/SettingsViewModel.cs | 33 ++++++++++++--
.../RoguelikeSettingsUserControl.xaml | 26 ++++++++---
14 files changed, 95 insertions(+), 112 deletions(-)
delete mode 100644 src/MaaWpfGui/Helper/ThemeHelper.cs
delete mode 100644 src/MaaWpfGui/Res/Themes/Colors.xaml
delete mode 100644 src/MaaWpfGui/Res/Themes/ColorsDark.xaml
create mode 100644 src/MaaWpfGui/Res/Themes/Dark.xaml
create mode 100644 src/MaaWpfGui/Res/Themes/Light.xaml
delete mode 100644 src/MaaWpfGui/Res/Themes/SkinDark.xaml
delete mode 100644 src/MaaWpfGui/Res/Themes/SkinDefault.xaml
diff --git a/README.md b/README.md
index 2a92990242..2f1ad71aa8 100644
--- a/README.md
+++ b/README.md
@@ -108,7 +108,7 @@ MAA 的意思是 MAA Assistant Arknights
- 安卓触控事件器:[minitouch](https://github.com/openstf/minitouch)
- 安卓触控事件器:[MaaTouch](https://github.com/MaaAssistantArknights/MaaTouch)
- WPF MVVM框架:[Stylet](https://github.com/canton7/Stylet)
-- WPF控件库:[HandyControl](https://github.com/HandyOrg/HandyControl)
+- WPF控件库:[HandyControl](https://github.com/HandyOrg/HandyControl) -> [HandyControls](https://github.com/ghost1372/HandyControls)
- C# 日志:[Serilog](https://github.com/serilog/serilog)
- C# JSON库:[Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) & [System.Text.Json](https://github.com/dotnet/runtime)
- ~~下载器:[aria2](https://github.com/aria2/aria2)~~
diff --git a/src/MaaWpfGui/App.xaml b/src/MaaWpfGui/App.xaml
index fb043af190..34ffa9cf1b 100644
--- a/src/MaaWpfGui/App.xaml
+++ b/src/MaaWpfGui/App.xaml
@@ -28,8 +28,15 @@
-
-
+
+
+
+
+
+
+
+
+
diff --git a/src/MaaWpfGui/App.xaml.cs b/src/MaaWpfGui/App.xaml.cs
index 5f99ef404e..5bb5c3a998 100644
--- a/src/MaaWpfGui/App.xaml.cs
+++ b/src/MaaWpfGui/App.xaml.cs
@@ -15,8 +15,6 @@ using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Documents;
-using System.Windows.Media;
-using HandyControl.Data;
using HandyControl.Themes;
using MaaWpfGui.Constants;
using MaaWpfGui.Helper;
@@ -38,51 +36,8 @@ namespace MaaWpfGui
}
}
- private void UpdateTheme(SkinType skin)
- {
- SharedResourceDictionary.SharedDictionaries.Clear();
- Theme.GetTheme("HandyTheme", Resources).Skin = skin;
- Theme.GetTheme("MaaTheme", Resources).Skin = skin;
- Current.MainWindow?.OnApplyTemplate();
- }
-
- private void UpdateTheme(bool syncWithSystem)
- {
- SharedResourceDictionary.SharedDictionaries.Clear();
- Theme.GetTheme("HandyTheme", Resources).SyncWithSystem = syncWithSystem;
- Theme.GetTheme("MaaTheme", Resources).SyncWithSystem = syncWithSystem;
- Current.MainWindow?.OnApplyTemplate();
- }
-
- private void SwitchDarkMode()
- {
- SettingsViewModel.DarkModeType darkModeType =
- Enum.TryParse(ConfigurationHelper.GetValue(ConfigurationKeys.DarkMode, SettingsViewModel.DarkModeType.Light.ToString()),
- out SettingsViewModel.DarkModeType temp)
- ? temp
- : SettingsViewModel.DarkModeType.Light;
- switch (darkModeType)
- {
- case SettingsViewModel.DarkModeType.Light:
- UpdateTheme(skin: SkinType.Default);
- return;
-
- case SettingsViewModel.DarkModeType.Dark:
- UpdateTheme(skin: SkinType.Dark);
- return;
-
- case SettingsViewModel.DarkModeType.SyncWithOS:
- UpdateTheme(syncWithSystem: true);
- return;
- }
- }
-
protected override void OnStartup(StartupEventArgs e)
{
- ConfigurationHelper.Load();
- LocalizationHelper.Load();
- SwitchDarkMode();
-
base.OnStartup(e);
}
}
diff --git a/src/MaaWpfGui/Helper/ThemeHelper.cs b/src/MaaWpfGui/Helper/ThemeHelper.cs
deleted file mode 100644
index 43a424fb81..0000000000
--- a/src/MaaWpfGui/Helper/ThemeHelper.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System;
-using System.Windows;
-using HandyControl.Data;
-using HandyControl.Themes;
-using HandyControl.Tools;
-
-namespace MaaWpfGui.Helper
-{
- ///
- /// The theme class.
- ///
- public class ThemeHelper : Theme
- {
- public override ResourceDictionary GetSkin(SkinType skinType) =>
- ResourceHelper.GetSkin(typeof(App).Assembly, "Res/Themes", skinType);
-
- public override ResourceDictionary GetTheme() => new ResourceDictionary()
- {
- Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml"),
- };
- }
-}
diff --git a/src/MaaWpfGui/MaaWpfGui.csproj b/src/MaaWpfGui/MaaWpfGui.csproj
index a06c7c87f5..49fd62a0c8 100644
--- a/src/MaaWpfGui/MaaWpfGui.csproj
+++ b/src/MaaWpfGui/MaaWpfGui.csproj
@@ -64,8 +64,8 @@
3.1.1
-
- 3.3.0
+
+ 3.4.5
1.15.0
diff --git a/src/MaaWpfGui/Main/Bootstrapper.cs b/src/MaaWpfGui/Main/Bootstrapper.cs
index 8ae00df52e..de99a6978b 100644
--- a/src/MaaWpfGui/Main/Bootstrapper.cs
+++ b/src/MaaWpfGui/Main/Bootstrapper.cs
@@ -135,6 +135,8 @@ namespace MaaWpfGui.Main
}
base.OnStart();
+ ConfigurationHelper.Load();
+ LocalizationHelper.Load();
}
///
diff --git a/src/MaaWpfGui/Res/Themes/Colors.xaml b/src/MaaWpfGui/Res/Themes/Colors.xaml
deleted file mode 100644
index 1600501c4b..0000000000
--- a/src/MaaWpfGui/Res/Themes/Colors.xaml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- #ffffff
-
-
diff --git a/src/MaaWpfGui/Res/Themes/ColorsDark.xaml b/src/MaaWpfGui/Res/Themes/ColorsDark.xaml
deleted file mode 100644
index c23cdd510e..0000000000
--- a/src/MaaWpfGui/Res/Themes/ColorsDark.xaml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- #ddd
- #ddd
-
-
diff --git a/src/MaaWpfGui/Res/Themes/Dark.xaml b/src/MaaWpfGui/Res/Themes/Dark.xaml
new file mode 100644
index 0000000000..5615ddca34
--- /dev/null
+++ b/src/MaaWpfGui/Res/Themes/Dark.xaml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/MaaWpfGui/Res/Themes/Light.xaml b/src/MaaWpfGui/Res/Themes/Light.xaml
new file mode 100644
index 0000000000..808ae9da0f
--- /dev/null
+++ b/src/MaaWpfGui/Res/Themes/Light.xaml
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/src/MaaWpfGui/Res/Themes/SkinDark.xaml b/src/MaaWpfGui/Res/Themes/SkinDark.xaml
deleted file mode 100644
index 4dbcdbb645..0000000000
--- a/src/MaaWpfGui/Res/Themes/SkinDark.xaml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/MaaWpfGui/Res/Themes/SkinDefault.xaml b/src/MaaWpfGui/Res/Themes/SkinDefault.xaml
deleted file mode 100644
index a123b219ed..0000000000
--- a/src/MaaWpfGui/Res/Themes/SkinDefault.xaml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
index da4cbaf750..a11b230461 100644
--- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
+++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
@@ -27,6 +27,7 @@ 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;
@@ -116,6 +117,7 @@ namespace MaaWpfGui.ViewModels.UI
InfrastInit();
+ SwitchDarkMode();
if (Hangover)
{
Hangover = false;
@@ -2531,15 +2533,13 @@ namespace MaaWpfGui.ViewModels.UI
SetAndNotify(ref _darkModeType, tempEnumValue);
ConfigurationHelper.SetValue(ConfigurationKeys.DarkMode, value);
+ SwitchDarkMode();
+ /*
MessageBoxHelper.Unregister();
MessageBoxHelper.Yes = LocalizationHelper.GetString("Ok");
MessageBoxHelper.No = LocalizationHelper.GetString("ManualRestart");
MessageBoxHelper.Register();
- Window mainWindow = Application.Current.MainWindow;
- mainWindow!.Show();
- mainWindow.WindowState = mainWindow.WindowState = WindowState.Normal;
- mainWindow.Activate();
var result = MessageBox.Show(
LocalizationHelper.GetString("DarkModeSetColorsTip"),
LocalizationHelper.GetString("Tip"),
@@ -2551,6 +2551,31 @@ namespace MaaWpfGui.ViewModels.UI
Application.Current.Shutdown();
System.Windows.Forms.Application.Restart();
}
+ */
+ }
+ }
+
+ public void SwitchDarkMode()
+ {
+ DarkModeType darkModeType =
+ Enum.TryParse(ConfigurationHelper.GetValue(ConfigurationKeys.DarkMode, DarkModeType.Light.ToString()),
+ out DarkModeType temp)
+ ? temp : DarkModeType.Light;
+ switch (darkModeType)
+ {
+ case DarkModeType.Light:
+ ThemeManager.Current.UsingSystemTheme = false;
+ ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
+ return;
+
+ case DarkModeType.Dark:
+ ThemeManager.Current.UsingSystemTheme = false;
+ ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
+ return;
+
+ case DarkModeType.SyncWithOS:
+ ThemeManager.Current.UsingSystemTheme = true;
+ return;
}
}
diff --git a/src/MaaWpfGui/Views/UserControl/RoguelikeSettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/RoguelikeSettingsUserControl.xaml
index 77ef67e7c1..ef6d35e993 100644
--- a/src/MaaWpfGui/Views/UserControl/RoguelikeSettingsUserControl.xaml
+++ b/src/MaaWpfGui/Views/UserControl/RoguelikeSettingsUserControl.xaml
@@ -1,4 +1,4 @@
-
+ TextWrapping="Wrap">
+
+
+
+
+
+
+
+
+ TextWrapping="Wrap">
+
+
+
+
+
+
+
+