mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
feat: 成就设置中的图标颜色可以随着主题色动态更新
This commit is contained in:
@@ -18,6 +18,7 @@ namespace MaaWpfGui.Extensions.UIBehaviors
|
||||
{
|
||||
public static class ResourceReferenceHelper
|
||||
{
|
||||
#region Foreground
|
||||
public static readonly DependencyProperty ForegroundResourceKeyProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"ForegroundResourceKey",
|
||||
@@ -34,7 +35,9 @@ namespace MaaWpfGui.Extensions.UIBehaviors
|
||||
public static void SetForegroundResourceKey(DependencyObject d, string value) => d.SetValue(ForegroundResourceKeyProperty, value);
|
||||
|
||||
public static string GetForegroundResourceKey(DependencyObject d) => (string)d.GetValue(ForegroundResourceKeyProperty);
|
||||
#endregion
|
||||
|
||||
#region Background
|
||||
public static readonly DependencyProperty BackgroundResourceKeyProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"BackgroundResourceKey",
|
||||
@@ -51,5 +54,48 @@ namespace MaaWpfGui.Extensions.UIBehaviors
|
||||
public static void SetBackgroundResourceKey(DependencyObject d, string value) => d.SetValue(BackgroundResourceKeyProperty, value);
|
||||
|
||||
public static string GetBackgroundResourceKey(DependencyObject d) => (string)d.GetValue(BackgroundResourceKeyProperty);
|
||||
#endregion
|
||||
|
||||
#region BorderBrush
|
||||
public static readonly DependencyProperty BorderBrushResourceKeyProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"BorderBrushResourceKey",
|
||||
typeof(string),
|
||||
typeof(ResourceReferenceHelper),
|
||||
new PropertyMetadata(null, (d, e) =>
|
||||
{
|
||||
if (d is Border border && e.NewValue is string key)
|
||||
{
|
||||
border.SetResourceReference(Border.BorderBrushProperty, key);
|
||||
}
|
||||
}));
|
||||
|
||||
public static void SetBorderBrushResourceKey(DependencyObject d, string value) =>
|
||||
d.SetValue(BorderBrushResourceKeyProperty, value);
|
||||
|
||||
public static string GetBorderBrushResourceKey(DependencyObject d) =>
|
||||
(string)d.GetValue(BorderBrushResourceKeyProperty);
|
||||
#endregion
|
||||
|
||||
#region Fill
|
||||
public static readonly DependencyProperty FillResourceKeyProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"FillResourceKey",
|
||||
typeof(string),
|
||||
typeof(ResourceReferenceHelper),
|
||||
new PropertyMetadata(null, (d, e) =>
|
||||
{
|
||||
if (d is System.Windows.Shapes.Shape shape && e.NewValue is string key)
|
||||
{
|
||||
shape.SetResourceReference(System.Windows.Shapes.Shape.FillProperty, key);
|
||||
}
|
||||
}));
|
||||
|
||||
public static void SetFillResourceKey(DependencyObject d, string value) =>
|
||||
d.SetValue(FillResourceKeyProperty, value);
|
||||
|
||||
public static string GetFillResourceKey(DependencyObject d) =>
|
||||
(string)d.GetValue(FillResourceKeyProperty);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,20 +109,6 @@ namespace MaaWpfGui.Models
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public Brush MedalBrush
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Application.Current.Resources[MedalBrushKey] is Brush brush)
|
||||
{
|
||||
return brush;
|
||||
}
|
||||
|
||||
return new SolidColorBrush(Colors.Transparent);
|
||||
}
|
||||
}
|
||||
|
||||
// 新解锁的成就放前面,仅本次关闭前生效
|
||||
[JsonIgnore]
|
||||
public bool IsNewUnlock { get; set; } = false;
|
||||
|
||||
@@ -129,10 +129,6 @@ public class AchievementSettingsUserControlModel : PropertyChangedBase
|
||||
WindowManager.ShowWindow(_achievementsWindow);
|
||||
}
|
||||
|
||||
private static readonly SolidColorBrush _hiddenMedalBrush = Application.Current.Resources["HiddenMedalBrush"] is SolidColorBrush brush ? brush : new(Colors.Gold);
|
||||
|
||||
private static readonly SolidColorBrush _normalMedalBrush = Application.Current.Resources["NormalMedalBrush"] is SolidColorBrush brush ? brush : new(Colors.Silver);
|
||||
|
||||
private int _clickCount = 0;
|
||||
private static readonly Random _random = new();
|
||||
private bool _isTriggered = false;
|
||||
@@ -171,23 +167,23 @@ public class AchievementSettingsUserControlModel : PropertyChangedBase
|
||||
private void ResetDebugState()
|
||||
{
|
||||
IsDebugVersion = false;
|
||||
MedalBrush = _normalMedalBrush;
|
||||
MedalBrushKey = "NormalMedalBrush";
|
||||
_isTriggered = false;
|
||||
}
|
||||
|
||||
private void EnableDebugMode()
|
||||
{
|
||||
IsDebugVersion = true;
|
||||
MedalBrush = _hiddenMedalBrush;
|
||||
MedalBrushKey = "HiddenMedalBrush";
|
||||
_isTriggered = true;
|
||||
}
|
||||
|
||||
private SolidColorBrush _medalBrush = _normalMedalBrush;
|
||||
private string _medalBrushKey = "NormalMedalBrush";
|
||||
|
||||
public SolidColorBrush MedalBrush
|
||||
public string MedalBrushKey
|
||||
{
|
||||
get => _medalBrush;
|
||||
set => SetAndNotify(ref _medalBrush, value);
|
||||
get => _medalBrushKey;
|
||||
set => SetAndNotify(ref _medalBrushKey, value);
|
||||
}
|
||||
|
||||
private bool _isDebugVersion = false;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:helper="clr-namespace:MaaWpfGui.Helper"
|
||||
xmlns:uiBehaviors="clr-namespace:MaaWpfGui.Extensions.UIBehaviors"
|
||||
Title="{DynamicResource AchievementList}"
|
||||
Width="600"
|
||||
Height="400"
|
||||
@@ -25,8 +26,8 @@
|
||||
<Path
|
||||
Width="40"
|
||||
Height="40"
|
||||
uiBehaviors:ResourceReferenceHelper.FillResourceKey="{Binding MedalBrushKey}"
|
||||
Data="{DynamicResource HangoverGeometry}"
|
||||
Fill="{Binding MedalBrush}"
|
||||
Stretch="Uniform" />
|
||||
<VirtualizingStackPanel Margin="8" HorizontalAlignment="Left">
|
||||
<VirtualizingStackPanel
|
||||
@@ -87,11 +88,11 @@
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
<hc:SearchBar
|
||||
Background="{DynamicResource MouseOverRegionBrushOpacity75}"
|
||||
MinWidth="200"
|
||||
Margin="25,5"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Background="{DynamicResource MouseOverRegionBrushOpacity75}"
|
||||
Command="{Binding SearchCmd, Source={x:Static helper:AchievementTrackerHelper.Instance}}"
|
||||
CommandParameter="{Binding Text, RelativeSource={RelativeSource Self}}"
|
||||
IsRealTime="True" />
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
xmlns:helper="clr-namespace:MaaWpfGui.Helper"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:uiBehaviors="clr-namespace:MaaWpfGui.Extensions.UIBehaviors"
|
||||
xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels.UserControl.Settings"
|
||||
d:Background="White"
|
||||
d:DataContext="{d:DesignInstance {x:Type viewModels:AchievementSettingsUserControlModel}}"
|
||||
@@ -47,8 +48,8 @@
|
||||
<Path
|
||||
Margin="4"
|
||||
d:Fill="{DynamicResource NormalMedalBrush}"
|
||||
uiBehaviors:ResourceReferenceHelper.FillResourceKey="{Binding MedalBrushKey}"
|
||||
Data="{DynamicResource HangoverGeometry}"
|
||||
Fill="{Binding MedalBrush}"
|
||||
Stretch="Uniform" />
|
||||
</Border>
|
||||
<StackPanel HorizontalAlignment="Center" Visibility="{c:Binding IsDebugVersion}">
|
||||
|
||||
Reference in New Issue
Block a user