mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
perf: 改用HandyControls
This commit is contained in:
@@ -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)~~
|
||||
|
||||
@@ -28,8 +28,15 @@
|
||||
<main:Bootstrapper />
|
||||
</s:ApplicationLoader.Bootstrapper>
|
||||
</s:ApplicationLoader>
|
||||
<hc:Theme Name="HandyTheme"/>
|
||||
<resources:ThemeHelper Name="MaaTheme"/>
|
||||
|
||||
<hc:ThemeResources>
|
||||
<hc:ThemeResources.ThemeDictionaries>
|
||||
<ResourceDictionary x:Key="Light" hc:ThemeDictionary.Key="Light" Source="/MAA;component/Res/Themes/Light.xaml" />
|
||||
<ResourceDictionary x:Key="Dark" hc:ThemeDictionary.Key="Dark" Source="/MAA;component/Res/Themes/Dark.xaml" />
|
||||
</hc:ThemeResources.ThemeDictionaries>
|
||||
</hc:ThemeResources>
|
||||
<hc:Theme/>
|
||||
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<!-- A Style that affects all TextBlocks -->
|
||||
<Style BasedOn="{StaticResource TextBlockDefault}" TargetType="controls:TextBlock" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Themes;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace MaaWpfGui.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// The theme class.
|
||||
/// </summary>
|
||||
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"),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -64,8 +64,8 @@
|
||||
<PackageReference Include="gong-wpf-dragdrop">
|
||||
<Version>3.1.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="HandyControl">
|
||||
<Version>3.3.0</Version>
|
||||
<PackageReference Include="HandyControls">
|
||||
<Version>3.4.5</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MdXaml">
|
||||
<Version>1.15.0</Version>
|
||||
|
||||
@@ -135,6 +135,8 @@ namespace MaaWpfGui.Main
|
||||
}
|
||||
|
||||
base.OnStart();
|
||||
ConfigurationHelper.Load();
|
||||
LocalizationHelper.Load();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
|
||||
<Color x:Key="SecondaryRegionColor">#ffffff</Color>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -1,8 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
|
||||
<Color x:Key="PrimaryTextColor">#ddd</Color>
|
||||
<Color x:Key="TextIconColor">#ddd</Color>
|
||||
|
||||
</ResourceDictionary>
|
||||
26
src/MaaWpfGui/Res/Themes/Dark.xaml
Normal file
26
src/MaaWpfGui/Res/Themes/Dark.xaml
Normal file
@@ -0,0 +1,26 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<!-- See https://github.com/ghost1372/HandyControls/blob/v3.4.5/src/Shared/HandyControl_Shared/Themes/Basic/Colors/Dark.xaml -->
|
||||
<!-- Latest Doc https://ghost1372.github.io/handycontrol/basic_xaml/brushes/ -->
|
||||
<!-- 文字颜色 -->
|
||||
<SolidColorBrush x:Key="PrimaryTextBrush" Color="White" />
|
||||
<!-- 文字颜色 -->
|
||||
<SolidColorBrush x:Key="TextIconBrush" Color="White" />
|
||||
|
||||
<!-- 背景颜色 -->
|
||||
<SolidColorBrush x:Key="RegionBrush" Color="#1c1c1c" />
|
||||
<!-- 背景颜色 没用到(建议和背景颜色一致)-->
|
||||
<SolidColorBrush x:Key="MainContentBackgroundBrush" Color="#FF1C1C1C" />
|
||||
|
||||
<!-- 发暗的主色调 没用到(DarkMode中亮暗相反)-->
|
||||
<SolidColorBrush x:Key="LightPrimaryBrush" Color="#044289" />
|
||||
<!-- 主色调 -->
|
||||
<SolidColorBrush x:Key="PrimaryBrush" Color="#326cf3" />
|
||||
<!-- 发亮的主色调 复选框的框框颜色(建议和主题色一致)-->
|
||||
<SolidColorBrush x:Key="DarkPrimaryBrush" Color="#326cf3" />
|
||||
<!-- 标题背景 没用到(建议和主题色一致)-->
|
||||
<SolidColorBrush x:Key="TitleBrush" Color="#326cf3" />
|
||||
|
||||
</ResourceDictionary>
|
||||
7
src/MaaWpfGui/Res/Themes/Light.xaml
Normal file
7
src/MaaWpfGui/Res/Themes/Light.xaml
Normal file
@@ -0,0 +1,7 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<SolidColorBrush x:Key="SecondaryRegionBrush" Color="#ffffff" />
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -1,7 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="ColorsDark.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -1,7 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Colors.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<UserControl
|
||||
<UserControl
|
||||
x:Class="MaaWpfGui.Views.UserControl.RoguelikeSettingsUserControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
@@ -67,9 +67,15 @@
|
||||
HorizontalContentAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
InputMethod.IsInputMethodEnabled="False"
|
||||
Text="{Binding RoguelikeStartsCount}"
|
||||
TextType="Int"
|
||||
TextWrapping="Wrap" />
|
||||
TextWrapping="Wrap">
|
||||
<hc:TextBox.Text>
|
||||
<Binding Path="RoguelikeStartsCount">
|
||||
<Binding.ValidationRules>
|
||||
<hc:RegexRule Type="Int"/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</hc:TextBox.Text>
|
||||
</hc:TextBox>
|
||||
</StackPanel>
|
||||
<CheckBox
|
||||
Margin="10"
|
||||
@@ -90,9 +96,15 @@
|
||||
VerticalContentAlignment="Center"
|
||||
InputMethod.IsInputMethodEnabled="False"
|
||||
IsEnabled="{Binding RoguelikeInvestmentEnabled}"
|
||||
Text="{Binding RoguelikeInvestsCount}"
|
||||
TextType="Int"
|
||||
TextWrapping="Wrap" />
|
||||
TextWrapping="Wrap">
|
||||
<hc:TextBox.Text>
|
||||
<Binding Path="RoguelikeInvestsCount">
|
||||
<Binding.ValidationRules>
|
||||
<hc:RegexRule Type="Int"/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</hc:TextBox.Text>
|
||||
</hc:TextBox>
|
||||
</StackPanel>
|
||||
<CheckBox
|
||||
Margin="10"
|
||||
|
||||
Reference in New Issue
Block a user