From e6549f0bf68611d7bc8dacc8596295bd22c9e804 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Sat, 3 May 2025 12:54:14 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=E6=B8=90=E5=8F=98?= =?UTF-8?q?=E9=99=84=E5=8A=A0=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/UIBehaviors/FadeBehavior.cs | 92 +++++++++++++++++++ src/MaaWpfGui/Res/Localizations/en-us.xaml | 1 + src/MaaWpfGui/Res/Localizations/ja-jp.xaml | 1 + src/MaaWpfGui/Res/Localizations/ko-kr.xaml | 1 + src/MaaWpfGui/Res/Localizations/zh-cn.xaml | 1 + src/MaaWpfGui/Res/Localizations/zh-tw.xaml | 1 + src/MaaWpfGui/Views/UI/RecognizerView.xaml | 21 ++++- 7 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 src/MaaWpfGui/Extensions/UIBehaviors/FadeBehavior.cs diff --git a/src/MaaWpfGui/Extensions/UIBehaviors/FadeBehavior.cs b/src/MaaWpfGui/Extensions/UIBehaviors/FadeBehavior.cs new file mode 100644 index 0000000000..b09f6833a7 --- /dev/null +++ b/src/MaaWpfGui/Extensions/UIBehaviors/FadeBehavior.cs @@ -0,0 +1,92 @@ +// +// 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 Affero General Public License v3.0 only 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 +// + +#nullable enable + +using System; +using System.Windows; +using System.Windows.Media.Animation; + +namespace MaaWpfGui.Extensions.UIBehaviors; + +public static class FadeBehavior +{ + #region IsActive 属性 + + public static readonly DependencyProperty IsActiveProperty = + DependencyProperty.RegisterAttached("IsActive", typeof(bool), typeof(FadeBehavior), + new(false, OnIsActiveChanged)); + + public static bool GetIsActive(DependencyObject obj) => (bool)obj.GetValue(IsActiveProperty); + + public static void SetIsActive(DependencyObject obj, bool value) => obj.SetValue(IsActiveProperty, value); + + #endregion + + #region Duration 属性(新增) + + public static readonly DependencyProperty DurationProperty = + DependencyProperty.RegisterAttached("Duration", typeof(TimeSpan), typeof(FadeBehavior), + new(TimeSpan.FromSeconds(0.3))); + + public static TimeSpan GetDuration(DependencyObject obj) => (TimeSpan)obj.GetValue(DurationProperty); + + public static void SetDuration(DependencyObject obj, TimeSpan value) => obj.SetValue(DurationProperty, value); + + #endregion + + private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is not FrameworkElement element) + { + return; + } + + // 获取动画持续时间(使用附加属性或默认值) + var duration = GetDuration(d); + + var storyboard = new Storyboard(); + var animation = new DoubleAnimation + { + Duration = new(duration), + FillBehavior = FillBehavior.HoldEnd, + }; + + if ((bool)e.NewValue) + { + // 显示动画 + animation.From = 0; + animation.To = 1; + element.Visibility = Visibility.Visible; + } + else + { + // 隐藏动画 + animation.From = 1; + animation.To = 0; + animation.Completed += (s, _) => + { + // 动画完成后才真正隐藏元素 + if (element.Opacity == 0) // 确保没有其他动画改变透明度 + { + element.Visibility = Visibility.Collapsed; + } + }; + } + + Storyboard.SetTarget(animation, element); + Storyboard.SetTargetProperty(animation, new PropertyPath(UIElement.OpacityProperty)); + storyboard.Children.Add(animation); + storyboard.Begin(); + } +} diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml index 319c190b4d..3654110982 100644 --- a/src/MaaWpfGui/Res/Localizations/en-us.xaml +++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml @@ -682,6 +682,7 @@ The video aspect ratio needs to be 16:9 without interference factors such as bla Peep + See the world through Pallas? Target Frame Rate diff --git a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml index 32b92f710c..6ee30fec26 100644 --- a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml +++ b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml @@ -684,6 +684,7 @@ C:\\leidian\\LDPlayer9 Peep + パラスの目に映る世界を見てみませんか? 目標フレームレート diff --git a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml index 9baea8b068..cc02cace6d 100644 --- a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml +++ b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml @@ -685,6 +685,7 @@ C:\\leidian\\LDPlayer9 Peep + 팔라스의 눈에 비친 세상을 보시겠어요? 목표 프레임 속도 diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index 925e8f5174..7c60e1dfc8 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -685,6 +685,7 @@ C:\\leidian\\LDPlayer9。\n 牛牛监控 + 看看牛牛眼中的世界? 目标帧率 diff --git a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml index 1bcdf6e66f..2a12a17e07 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml @@ -684,6 +684,7 @@ C:\\leidian\\LDPlayer9。\n 牛牛監控 + 看看牛牛眼中的世界? 目標幀率 diff --git a/src/MaaWpfGui/Views/UI/RecognizerView.xaml b/src/MaaWpfGui/Views/UI/RecognizerView.xaml index ff50a4ef5a..c10aba2244 100644 --- a/src/MaaWpfGui/Views/UI/RecognizerView.xaml +++ b/src/MaaWpfGui/Views/UI/RecognizerView.xaml @@ -10,6 +10,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:s="https://github.com/canton7/Stylet" xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI" + xmlns:uiBehaviors="clr-namespace:MaaWpfGui.Extensions.UIBehaviors" d:DataContext="{d:DesignInstance {x:Type ui:RecognizerViewModel}}" d:DesignHeight="600" d:DesignWidth="800" @@ -416,7 +417,9 @@ Margin="10" HorizontalAlignment="Center" VerticalAlignment="Center" - Source="{Binding PeepImage}" /> + uiBehaviors:FadeBehavior.IsActive="{c:Binding Peeping}" + Source="{Binding PeepImage}" + Visibility="Collapsed" /> + + VerticalAlignment="Center" + uiBehaviors:FadeBehavior.IsActive="{c:Binding Peeping}" + Visibility="Collapsed"> - + + Content="{c:Binding 'Idle ? "Link Start!" : "Stop!"'}" />