188 lines
7.0 KiB
C#
188 lines
7.0 KiB
C#
using Microsoft.ML.Runtime;
|
||
using System;
|
||
using System.Collections.Concurrent;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.ComponentModel;
|
||
using System.Diagnostics;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Input;
|
||
using System.Windows.Media;
|
||
using System.Windows.Media.Animation;
|
||
using Wpf_AiSportsMicrospace.Common;
|
||
using Wpf_AiSportsMicrospace.Enum;
|
||
using Wpf_AiSportsMicrospace.MyUserControl;
|
||
using Wpf_AiSportsMicrospace.Views;
|
||
using Yztob.AiSports.Inferences.Abstractions;
|
||
using Yztob.AiSports.Inferences.Things;
|
||
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;
|
||
namespace Wpf_AiSportsMicrospace.Views
|
||
{
|
||
/// <summary>
|
||
/// Home.xaml 的交互逻辑
|
||
/// </summary>
|
||
public partial class CenterHome : UserControl
|
||
{
|
||
private SportOperate _sportOperate;
|
||
private Main _mainWin => Application.Current.MainWindow as Main;
|
||
|
||
public String _nowSelect = "test"; //测试吧:test 游戏吧:play
|
||
public String NowSelect
|
||
{
|
||
get => _nowSelect;
|
||
set
|
||
{
|
||
if (_nowSelect != value)
|
||
{
|
||
_nowSelect = value;
|
||
InitImg();
|
||
}
|
||
}
|
||
}
|
||
|
||
public CenterHome()
|
||
{
|
||
InitializeComponent();
|
||
//string imgPath = Path.Combine(projectRoot, "Resources", "Img" , _nowSelect == "test" ? "test_img" : "play_img");
|
||
|
||
// 默认选中第1张
|
||
coverFlow.SelectedIndex = 0;
|
||
|
||
InitImg();
|
||
|
||
Loaded += Window_Loaded;
|
||
Unloaded += CenterHome_Unloaded;
|
||
//AnimationBehavior.SetSourceUri(LoadingImage, loadingImage);
|
||
}
|
||
|
||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||
{
|
||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||
Utils.PlayBackgroundMusic("homeprojectselected.mp3");
|
||
}
|
||
|
||
private void CenterHome_Unloaded(object sender, RoutedEventArgs e)
|
||
{
|
||
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
||
}
|
||
|
||
private void OnHumanFrameUpdated(object sender, List<Human> humans)
|
||
{
|
||
var human = humans.FirstOrDefault();
|
||
|
||
if (human == null) return;
|
||
|
||
//检测挥手动作
|
||
var wavingaction = _mainWin.SportOperate.VerifyWavingAction(human);
|
||
|
||
switch (wavingaction)
|
||
{
|
||
case (int)WavingAction.LeftWave: // 左手挥动
|
||
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.SlideRight());
|
||
break;
|
||
|
||
case (int)WavingAction.RightWave: // 右手挥动
|
||
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.SlideLeft());
|
||
break;
|
||
|
||
case (int)WavingAction.FirstHand: // 举手开始
|
||
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.StartSelectedProgress());
|
||
break;
|
||
|
||
case (int)WavingAction.Raising: // 举手中,实时更新进度
|
||
break;
|
||
|
||
case (int)WavingAction.RaiseHand: // 举手完成
|
||
coverFlow.ProgressCompleted += CoverFlow_ProgressCompleted;
|
||
break;
|
||
|
||
default: // 没有动作 → 取消进度
|
||
Application.Current.Dispatcher.BeginInvoke(() => coverFlow.CancelSelectedProgress());
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void CoverFlow_ProgressCompleted(CoverFlowItem item)
|
||
{
|
||
// 停止抽帧线程/释放资源
|
||
try
|
||
{
|
||
RouterGoNew();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Debug.WriteLine($"停止抽帧异常: {ex.Message}");
|
||
}
|
||
|
||
// 解绑事件,防止重复触发
|
||
//coverFlow.ProgressCompleted -= CoverFlow_ProgressCompleted;
|
||
|
||
// 根据图片跳转新窗口
|
||
string uri = item.ImageUri.ToString();
|
||
|
||
//if (uri.EndsWith("1.jpg"))
|
||
// newWindow = new GroupJumpRope();
|
||
//else if (uri.EndsWith("2.jpg"))
|
||
// newWindow = new GroupJumpRope();
|
||
//else if (uri.EndsWith("3.jpg"))
|
||
// newWindow = new GroupJumpRope();
|
||
// 找到主窗口,切换内容到 GroupJumpRopePage
|
||
|
||
//var mainWin = Application.Current.MainWindow as Main;
|
||
//if (mainWin != null)
|
||
//{
|
||
// Utils.PlayBackgroundMusic("musicjumprope1.mp3");
|
||
// mainWin.SwitchPage(new GroupJumpRope(), true);
|
||
//}
|
||
|
||
}
|
||
public void InitImg()
|
||
{
|
||
string projectRoot = Path.Combine(AppContext.BaseDirectory, @"..\..\..");
|
||
coverFlow.Images.Clear(); // 先清空原有图
|
||
if (_nowSelect == "test")
|
||
{
|
||
string imgPath = Path.Combine(projectRoot, "Resources", "Img", "test_img");
|
||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(imgPath, "test_jump.png")), ProgressColor1 = "#215bc7", ProgressColor2 = "#fc640e" });
|
||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(imgPath, "test_situp.png")), ProgressColor1 = "#e73d42", ProgressColor2 = "#fd8212" });
|
||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(imgPath, "test_rope.png")), ProgressColor1 = "#e73d42", ProgressColor2 = "#215bc7" });
|
||
}
|
||
else
|
||
{
|
||
string imgPath = Path.Combine(projectRoot, "Resources", "Img", "play_img");
|
||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(imgPath, "play_vs.png")), ProgressColor1 = "#215bc7", ProgressColor2 = "#fc640e" });
|
||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(imgPath, "play_jump.png")), ProgressColor1 = "#e73d42", ProgressColor2 = "#fd8212" });
|
||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(imgPath, "play_music.png")), ProgressColor1 = "#e73d42", ProgressColor2 = "#215bc7" });
|
||
}
|
||
|
||
}
|
||
|
||
//跳转二级页面
|
||
private void RouterGoNew()
|
||
{
|
||
// 跳转逻辑(如导航到新页面并传递参数)
|
||
// 例如:RaiseEvent、调用外部委托、或使用导航框架
|
||
var mainWin = Application.Current.MainWindow as Main;
|
||
var newPage = new GroupJumpRope();
|
||
mainWin?.SwitchPage(newPage, true);
|
||
}
|
||
|
||
private void GoNew(object sender, MouseButtonEventArgs e)
|
||
{
|
||
var mainWin = Application.Current.MainWindow as Main;
|
||
var newPage = new GroupJumpRope();
|
||
mainWin?.SwitchPage(newPage, true);
|
||
}
|
||
}
|
||
}
|