diff --git a/src/MaaWpfGui/Constants/UILogColor.cs b/src/MaaWpfGui/Constants/UILogColor.cs index f47489f9ca..75f35ac508 100644 --- a/src/MaaWpfGui/Constants/UILogColor.cs +++ b/src/MaaWpfGui/Constants/UILogColor.cs @@ -20,6 +20,8 @@ namespace MaaWpfGui.Constants /// public static class UiLogColor { + public const string Text = "PrimaryTextBrush"; + /// /// The recommended color for error logs. /// diff --git a/src/MaaWpfGui/Helper/ToolTipHelper.cs b/src/MaaWpfGui/Helper/ToolTipHelper.cs index 2b8370f313..5d9eb2d4ef 100644 --- a/src/MaaWpfGui/Helper/ToolTipHelper.cs +++ b/src/MaaWpfGui/Helper/ToolTipHelper.cs @@ -94,17 +94,31 @@ namespace MaaWpfGui.Helper Inline CloneInline(Inline inline) { - return inline switch + switch (inline) { - Run run => new Run(run.Text) - { - Foreground = run.Foreground, - FontWeight = run.FontWeight, - FontStyle = run.FontStyle, - }, - LineBreak => new LineBreak(), - _ => new Run(), - }; + case Run run: + var newRun = new Run(run.Text) + { + FontWeight = run.FontWeight, + FontStyle = run.FontStyle, + }; + + if (run.Tag is string resourceKey) + { + newRun.SetResourceReference(TextElement.ForegroundProperty, resourceKey); + newRun.Tag = resourceKey; + } + else + { + newRun.Foreground = run.Foreground; + } + + return newRun; + case LineBreak: + return new LineBreak(); + default: + return new Run(); + } } } diff --git a/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs b/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs index b390847663..d43b19b62e 100644 --- a/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs @@ -116,12 +116,13 @@ namespace MaaWpfGui.ViewModels.UI foreach (var combs in resultArray ?? []) { int tagLevel = (int)(combs["level"] ?? -1); - recruitResultInlines.Add(new Run($"{tagLevel}★ Tags: ")); + var tagStr = $"{tagLevel}★ Tags: "; + tagStr = ((JArray?)combs["tags"] ?? []).Aggregate(tagStr, (current, tag) => current + $"{tag} "); + var tagRun = new Run(tagStr); + tagRun.SetResourceReference(TextElement.ForegroundProperty, UiLogColor.Text); + tagRun.Tag = UiLogColor.Text; - foreach (var tag in (JArray?)combs["tags"] ?? []) - { - recruitResultInlines.Add(new Run($"{tag} ")); - } + recruitResultInlines.Add(tagRun); recruitResultInlines.Add(new LineBreak()); @@ -175,10 +176,21 @@ namespace MaaWpfGui.ViewModels.UI } var run = new Run($"{operName}{potentialText} "); - var foreground = GetColorByStarWithOpacity(operLevel, isMaxPot ? 0.4 : 1.0); - if (foreground != null) + var opacity = isMaxPot ? 0.4 : 1.0; + + if (Math.Abs(opacity - 1.0) < 1e-4) { - run.Foreground = foreground; + var brushKey = GetBrushKeyByStar(operLevel); + run.SetResourceReference(TextElement.ForegroundProperty, brushKey); + run.Tag = brushKey; + } + else + { + var brush = GetBrushWithOpacityByStar(operLevel, opacity); + if (brush != null) + { + run.Foreground = brush; + } } recruitResultInlines.Add(run); @@ -197,9 +209,9 @@ namespace MaaWpfGui.ViewModels.UI return new(Color.FromArgb(alpha, baseColor.R, baseColor.G, baseColor.B)); } - Brush? GetColorByStarWithOpacity(int level, double opacity = 1.0) + string GetBrushKeyByStar(int level) { - var brushKey = level switch + return level switch { >= 6 => UiLogColor.Star6Operator, 5 => UiLogColor.Star5Operator, @@ -208,15 +220,12 @@ namespace MaaWpfGui.ViewModels.UI 2 => UiLogColor.Star2Operator, _ => UiLogColor.Star1Operator, }; + } - var brush = Application.Current.TryFindResource(brushKey) as SolidColorBrush; - if (brush == null) - { - return null; - } - - var baseColor = brush.Color; - return GetBrushWithOpacity(baseColor, opacity); + Brush? GetBrushWithOpacityByStar(int level, double opacity) + { + var brushKey = GetBrushKeyByStar(level); + return Application.Current.TryFindResource(brushKey) is not SolidColorBrush brush ? null : GetBrushWithOpacity(brush.Color, opacity); } }