160 lines
5.7 KiB
C#
Raw Normal View History

2025-09-23 16:04:47 +08:00
using Microsoft.ML.Runtime;
using System;
2025-09-26 16:46:22 +08:00
using System.Collections.Concurrent;
2025-09-22 09:47:35 +08:00
using System.Collections.Generic;
2025-09-22 16:49:49 +08:00
using System.Collections.ObjectModel;
using System.ComponentModel;
2025-09-26 16:46:22 +08:00
using System.Diagnostics;
2025-09-23 10:15:06 +08:00
using System.IO;
2025-09-22 09:47:35 +08:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
2025-09-23 10:15:06 +08:00
using System.Windows.Controls;
2025-10-11 14:40:01 +08:00
using System.Windows.Input;
2025-09-23 10:15:06 +08:00
using System.Windows.Media;
using System.Windows.Media.Animation;
2025-10-11 14:40:01 +08:00
using Wpf_AiSportsMicrospace;
2025-09-23 16:04:47 +08:00
using Wpf_AiSportsMicrospace.Common;
2025-09-26 16:46:22 +08:00
using Wpf_AiSportsMicrospace.Enum;
2025-09-22 17:02:19 +08:00
using Wpf_AiSportsMicrospace.MyUserControl;
2025-09-26 16:46:22 +08:00
using Wpf_AiSportsMicrospace.Views;
2025-10-15 14:14:59 +08:00
using Wpf_AiSportsMicrospace.Views.JumpRope;
2025-09-23 16:04:47 +08:00
using Yztob.AiSports.Inferences.Abstractions;
2025-10-12 10:20:08 +08:00
using Yztob.AiSports.Inferences.Things;
2025-09-23 16:04:47 +08:00
using Yztob.AiSports.Postures;
using Yztob.AiSports.Postures.Abstractions;
using Yztob.AiSports.Postures.Sports;
using Yztob.AiSports.Postures.Things;
using Yztob.AiSports.Sensors.Abstractions;
using Yztob.AiSports.Sensors.Things;
2025-09-22 09:47:35 +08:00
namespace Wpf_AiSportsMicrospace
{
/// <summary>
/// Home.xaml 的交互逻辑
/// </summary>
2025-09-28 16:45:46 +08:00
public partial class Home : UserControl
2025-09-22 17:02:19 +08:00
{
2025-10-09 10:22:55 +08:00
public static Uri loadingImage = new Uri("/Resources/Img/Album/1.gif", UriKind.Relative);
2025-10-12 10:20:08 +08:00
private Main _mainWin => Application.Current.MainWindow as Main;
2025-09-22 09:47:35 +08:00
public Home()
{
InitializeComponent();
2025-09-22 16:49:49 +08:00
2025-09-23 10:15:06 +08:00
string projectRoot = Path.Combine(AppContext.BaseDirectory, @"..\..\..");
2025-10-15 14:14:59 +08:00
string albumPath = Path.Combine(projectRoot, "Resources", "Img");
2025-09-22 16:49:49 +08:00
2025-10-15 14:14:59 +08:00
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(albumPath, "test_img/test_rope.png")), ProgressColor1 = "#215bc7", ProgressColor2 = "#fc640e" });
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(albumPath, "play_img/play_music.png")), ProgressColor1 = "#e73d42", ProgressColor2 = "#fd8212" });
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(albumPath, "Album/home_history.png")), ProgressColor1 = "#e73d42", ProgressColor2 = "#215bc7" });
2025-09-22 17:02:19 +08:00
2025-09-23 10:15:06 +08:00
// 默认选中第3张
2025-09-26 16:46:22 +08:00
coverFlow.SelectedIndex = 0;
2025-10-12 10:20:08 +08:00
Loaded += Window_Loaded;
Unloaded += Home_Unloaded;
2025-10-09 10:22:55 +08:00
2025-10-12 17:21:15 +08:00
Utils.PlayBackgroundMusic("homeprojectselected.mp3", true);
2025-09-22 09:47:35 +08:00
}
2025-10-13 14:36:18 +08:00
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
}
2025-10-12 10:20:08 +08:00
private void Home_Unloaded(object sender, RoutedEventArgs e)
{
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
}
private void OnHumanFrameUpdated(object sender, List<Human> humans)
2025-09-23 16:04:47 +08:00
{
2025-10-12 10:20:08 +08:00
var human = humans.FirstOrDefault();
if (human == null) return;
//检测挥手动作
2025-10-15 10:01:58 +08:00
var wavingaction = _mainWin.SportOperate.VerifyWavingAction(humans);
2025-09-24 17:33:09 +08:00
2025-10-12 10:20:08 +08:00
switch (wavingaction)
2025-10-11 14:40:01 +08:00
{
2025-10-12 10:20:08 +08:00
case (int)WavingAction.LeftWave: // 左手挥动
2025-10-12 16:13:44 +08:00
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.SlideRight());
2025-10-12 10:20:08 +08:00
break;
case (int)WavingAction.RightWave: // 右手挥动
2025-10-12 16:13:44 +08:00
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.SlideLeft());
2025-10-12 10:20:08 +08:00
break;
2025-09-23 16:04:47 +08:00
2025-10-12 10:20:08 +08:00
case (int)WavingAction.FirstHand: // 举手开始
2025-10-12 16:13:44 +08:00
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.StartSelectedProgress());
2025-10-12 10:20:08 +08:00
break;
case (int)WavingAction.Raising: // 举手中,实时更新进度
break;
case (int)WavingAction.RaiseHand: // 举手完成
coverFlow.ProgressCompleted += CoverFlow_ProgressCompleted;
break;
default: // 没有动作 → 取消进度
2025-10-12 16:13:44 +08:00
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.CancelSelectedProgress());
2025-10-12 10:20:08 +08:00
break;
}
}
2025-09-26 16:46:22 +08:00
private void CoverFlow_ProgressCompleted(CoverFlowItem item)
2025-09-23 16:04:47 +08:00
{
2025-09-26 16:46:22 +08:00
// 停止抽帧线程/释放资源
try
{
2025-10-12 10:20:08 +08:00
RouterGoNew();
2025-09-26 16:46:22 +08:00
}
catch (Exception ex)
{
Debug.WriteLine($"停止抽帧异常: {ex.Message}");
}
}
2025-10-11 14:40:01 +08:00
//测试点击
private void GoNew(object sender, MouseButtonEventArgs e)
{
// 跳转逻辑(如导航到新页面并传递参数)
2025-10-12 10:20:08 +08:00
//例如RaiseEvent、调用外部委托、或使用导航框架
2025-10-11 14:40:01 +08:00
var mainWin = Application.Current.MainWindow as Main;
2025-10-15 14:14:59 +08:00
//var newPage = new CenterHome
//{
// NowSelect = coverFlow.SelectedIndex == 0 ? "test" : "play"
//};
//mainWin?.SwitchPage(newPage, true);
if (coverFlow.SelectedIndex == 0)
{
var newPage = new GroupJumpRope();
mainWin?.SwitchPage(newPage, true);
}
else
2025-10-11 14:40:01 +08:00
{
2025-10-15 14:14:59 +08:00
var newPage = new MusicJumpRope();
mainWin?.SwitchPage(newPage, true);
}
2025-10-11 14:40:01 +08:00
}
//跳转二级页面
private void RouterGoNew()
{
// 跳转逻辑(如导航到新页面并传递参数)
// 例如RaiseEvent、调用外部委托、或使用导航框架
var mainWin = Application.Current.MainWindow as Main;
2025-10-15 14:14:59 +08:00
if (coverFlow.SelectedIndex == 0)
{
var newPage = new GroupJumpRope();
mainWin?.SwitchPage(newPage, true);
}
else
2025-10-11 14:40:01 +08:00
{
2025-10-15 14:14:59 +08:00
var newPage = new MusicJumpRope();
mainWin?.SwitchPage(newPage, true);
}
2025-10-11 14:40:01 +08:00
}
2025-09-22 09:47:35 +08:00
}
2025-09-23 10:15:06 +08:00
}