提示框
This commit is contained in:
parent
954225396b
commit
a72c560145
BIN
Wpf_AiSportsMicrospace/Resources/Img/提示图.png
Normal file
BIN
Wpf_AiSportsMicrospace/Resources/Img/提示图.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 641 KiB |
@ -69,8 +69,7 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
{
|
||||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||
|
||||
Utils.PlayBackgroundMusic("homeprojectselected.mp3", true);
|
||||
|
||||
//Utils.PlayBackgroundMusic("homeprojectselected.mp3", true);
|
||||
}
|
||||
|
||||
private void CenterHome_Unloaded(object sender, RoutedEventArgs e)
|
||||
|
||||
@ -15,6 +15,7 @@ using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
@ -64,12 +65,64 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
{
|
||||
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
||||
}
|
||||
private void ShowCenterTip(string imagePath, TimeSpan duration)
|
||||
{
|
||||
var tipImage = new Image
|
||||
{
|
||||
Source = new BitmapImage(new Uri(imagePath, UriKind.Absolute)),
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
Opacity = 0
|
||||
};
|
||||
|
||||
// 增加图片的大小,调整比例
|
||||
tipImage.Width = overlayCanvas.ActualWidth * 0.9; // 宽度为 Canvas 宽度的 90%
|
||||
tipImage.Height = overlayCanvas.ActualHeight * 0.6; // 高度为 Canvas 高度的 60%
|
||||
|
||||
// 将图片添加到 Overlay Canvas
|
||||
overlayCanvas.Children.Add(tipImage);
|
||||
Canvas.SetLeft(tipImage, (overlayCanvas.ActualWidth - tipImage.Width) / 2); // 居中
|
||||
Canvas.SetTop(tipImage, (overlayCanvas.ActualHeight - tipImage.Height) / 2); // 居中
|
||||
|
||||
// 渐变出现动画
|
||||
var fadeInAnimation = new DoubleAnimation
|
||||
{
|
||||
From = 0,
|
||||
To = 1,
|
||||
Duration = TimeSpan.FromSeconds(1.5)
|
||||
};
|
||||
tipImage.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
|
||||
|
||||
// 定时移除,并且渐变消失
|
||||
Task.Delay(duration).ContinueWith(_ =>
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 渐变消失动画
|
||||
var fadeOutAnimation = new DoubleAnimation
|
||||
{
|
||||
From = 1,
|
||||
To = 0,
|
||||
Duration = TimeSpan.FromSeconds(1.5)
|
||||
};
|
||||
tipImage.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation);
|
||||
|
||||
// 完成后移除图片
|
||||
fadeOutAnimation.Completed += (s, e) =>
|
||||
{
|
||||
overlayCanvas.Children.Remove(tipImage);
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void PlayMusic(string musicFileName)
|
||||
{
|
||||
// 获取项目根目录
|
||||
string projectRoot = System.IO.Path.Combine(AppContext.BaseDirectory, @"..\..\..");
|
||||
string musicPath = System.IO.Path.Combine(projectRoot, "Resources", "Music", musicFileName);
|
||||
string imgPath = System.IO.Path.Combine(projectRoot, "Resources", "Img", "提示图.png");
|
||||
|
||||
if (!File.Exists(musicPath))
|
||||
{
|
||||
@ -79,6 +132,8 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
|
||||
_mediaPlayer.Open(new Uri(musicPath, UriKind.Absolute));
|
||||
|
||||
ShowCenterTip(imgPath, TimeSpan.FromSeconds(3));
|
||||
|
||||
// 监听播放完成事件
|
||||
_mediaPlayer.MediaEnded += MediaPlayer_MediaEnded;
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
<None Remove="Resources\Img\test_img\test_jump.png" />
|
||||
<None Remove="Resources\Img\test_img\test_rope.png" />
|
||||
<None Remove="Resources\Img\test_img\test_situp.png" />
|
||||
<None Remove="Resources\Img\提示图.png" />
|
||||
<None Remove="Resources\Music\comeon.mp3" />
|
||||
<None Remove="Resources\Music\countdown_3.mp3" />
|
||||
<None Remove="Resources\Music\homeprojectselected.mp3" />
|
||||
@ -213,6 +214,9 @@
|
||||
<Resource Include="Resources\Img\test_img\test_situp.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
<Resource Include="Resources\Img\提示图.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
<Resource Include="Resources\Music\comeon.mp3">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user