diff --git a/Wpf_AiSportsMicrospace/Resources/Music/whackamole.mp3 b/Wpf_AiSportsMicrospace/Resources/Music/whackamole.mp3 new file mode 100644 index 0000000..687b367 Binary files /dev/null and b/Wpf_AiSportsMicrospace/Resources/Music/whackamole.mp3 differ diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs index 4437563..cbf442e 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs @@ -509,73 +509,100 @@ namespace Wpf_AiSportsMicrospace.Views public void ShowRankingBoard(List list) { - var scoreGrid = FindName("ScoreGrid") as Grid; - name1.Text = list[0].Name; - name2.Text = list[1].Name; - name3.Text = list[2].Name; - number1.Text = list[0].Number.ToString(); - number2.Text = list[1].Number.ToString(); - number3.Text = list[2].Number.ToString(); - foreach (var item in list) + if (list == null || list.Count == 0) return; + + // 排序(建议加上) + list = list.OrderByDescending(x => x.Number).ToList(); + + // 清空旧UI + ScoreGrid.Children.Clear(); + + // ===== 前三名(完全动态,永不越界)===== + var nameControls = new[] { name1, name2, name3 }; + var numberControls = new[] { number1, number2, number3 }; + + for (int i = 0; i < nameControls.Length; i++) { + var item = list.ElementAtOrDefault(i); + + if (item != null) + { + nameControls[i].Text = item.Name; + numberControls[i].Text = item.Number.ToString(); + } + else + { + // 不够3个时填空 + nameControls[i].Text = "-"; + numberControls[i].Text = "-"; + } + } + + // ===== 榜单列表 ===== + for (int i = 0; i < list.Count; i++) + { + var item = list[i]; + var grid = new Grid { Width = 1344, Height = 71, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, - Margin = new Thickness(0, 69 * item.Rank, 0, 0) + Margin = new Thickness(0, 69 * i, 0, 0) }; + var border = new Border { - Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")) + Background = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#FFFFFF")) }; grid.Children.Add(border); - var rankText = new TextBlock + + // 排名 + grid.Children.Add(new TextBlock { - Text = item.Rank.ToString(), + Text = (i + 1).ToString(), FontSize = 24, FontWeight = FontWeights.Bold, - Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")), + Foreground = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#999999")), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, - TextAlignment = TextAlignment.Center, - Width = 200 - }; - grid.Children.Add(rankText); + Width = 200, + TextAlignment = TextAlignment.Center + }); - var positionText = new TextBlock + // 名字 + grid.Children.Add(new TextBlock { Text = item.Name, FontSize = 24, FontWeight = FontWeights.Bold, - Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")), + Foreground = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#999999")), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center - }; - grid.Children.Add(positionText); + }); - var scoreText = new TextBlock + // 分数 + grid.Children.Add(new TextBlock { Text = item.Number.ToString(), FontSize = 24, FontWeight = FontWeights.Bold, - Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")), + Foreground = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#999999")), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center, - TextAlignment = TextAlignment.Center, - Width = 200 - }; - grid.Children.Add(scoreText); + Width = 200, + TextAlignment = TextAlignment.Center + }); + ScoreGrid.Children.Add(grid); } - showElement("RankingGrid"); - //var rankingGrid = FindName("RankingGrid") as Grid; - //if (rankingGrid == null) return; - //rankingGrid.Visibility = Visibility.Visible; - //var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(600)); - //rankingGrid.BeginAnimation(UIElement.OpacityProperty, fadeIn); + showElement("RankingGrid"); } /* diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs index 67b67b9..f4c88d2 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs @@ -354,8 +354,6 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope // 停止实时检测和视频流 countdownGrid.Visibility = Visibility.Hidden; - _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; - _mainWin.WebcamClient.StopExtract(); // 计算排名 var rankList = _musicJumpRopeContext.UpdateRankList(); @@ -366,15 +364,17 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope _currentGameState = GameState.NotStarted; _isCountdownStarted = false; + showRank(); + // 恢复视频流 - Application.Current.Dispatcher.Invoke(() => - { - _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; - _mainWin.WebcamClient.StartExtract(); - showRank(); - // 更新 UI(排行榜或分数板) - // ShowRankingBoard(rankList); - }); + //Application.Current.Dispatcher.Invoke(() => + //{ + // _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; + // _mainWin.WebcamClient.StartExtract(); + // showRank(); + // // 更新 UI(排行榜或分数板) + // // ShowRankingBoard(rankList); + //}); } public void showRank() diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs index 5abc090..30f54b9 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/TrainingRecords.xaml.cs @@ -103,67 +103,91 @@ namespace Views.JumpRope } public void ShowRankingBoard(List list) { - var scoreGrid = FindName("ScoreGrid") as Grid; - if (list.Count <= 0) return; - name1.Text = list[0].Name; - name2.Text = list[1].Name; - name3.Text = list[2].Name; - number1.Text = list[0].Number.ToString(); - number2.Text = list[1].Number.ToString(); - number3.Text = list[2].Number.ToString(); - foreach (var item in list) + if (scoreGrid == null || list == null || list.Count == 0) return; + + // 排序(建议加) + list = list.OrderByDescending(x => x.Number).ToList(); + + // 清空旧数据(必须) + scoreGrid.Children.Clear(); + + // ===== 前三名(完全动态,不越界)===== + var nameControls = new[] { name1, name2, name3 }; + var numberControls = new[] { number1, number2, number3 }; + + for (int i = 0; i < nameControls.Length; i++) { + var item = list.ElementAtOrDefault(i); + + nameControls[i].Text = item?.Name ?? "-"; + numberControls[i].Text = item?.Number.ToString() ?? "-"; + } + + // ===== 榜单列表 ===== + for (int i = 0; i < list.Count; i++) + { + var item = list[i]; + var grid = new Grid { Width = 1344, Height = 71, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, - Margin = new Thickness(0, 69 * item.Rank, 0, 0) + + // ❗不要用 item.Rank,改用 i + Margin = new Thickness(0, 69 * i, 0, 0) }; + var border = new Border { - Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")) + Background = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#FFFFFF")) }; grid.Children.Add(border); - var rankText = new TextBlock + + // 排名 + grid.Children.Add(new TextBlock { - Text = item.Rank.ToString(), + Text = (i + 1).ToString(), // 用 i+1 FontSize = 24, FontWeight = FontWeights.Bold, - Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")), + Foreground = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#999999")), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center, Width = 200 - }; - grid.Children.Add(rankText); + }); - var positionText = new TextBlock + // 名字 + grid.Children.Add(new TextBlock { Text = item.Name, FontSize = 24, FontWeight = FontWeights.Bold, - Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")), + Foreground = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#999999")), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center - }; - grid.Children.Add(positionText); + }); - var scoreText = new TextBlock + // 分数 + grid.Children.Add(new TextBlock { Text = item.Number.ToString(), FontSize = 24, FontWeight = FontWeights.Bold, - Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")), + Foreground = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#999999")), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center, Width = 200 - }; - grid.Children.Add(scoreText); - ScoreGrid.Children.Add(grid); + }); + + scoreGrid.Children.Add(grid); } } diff --git a/Wpf_AiSportsMicrospace/Views/JumpingJack/BambooDragonfly.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpingJack/BambooDragonfly.xaml.cs index 3a518f0..2e7bb25 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpingJack/BambooDragonfly.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpingJack/BambooDragonfly.xaml.cs @@ -308,9 +308,6 @@ namespace Views.JumpingJack x.ImageState = "1"; }); - _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; - _mainWin.WebcamClient.StopExtract(); - RankingItemList = _groupJumpRopeContext.UpdateRankList(); ShowRankingBoard(RankingItemList); Utils.StopBackgroundMusic(); @@ -318,8 +315,6 @@ namespace Views.JumpingJack _currentGameState = GameState.NotStarted; _isCountdownStarted = false; - _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; - _mainWin.WebcamClient.StartExtract(); } private DateTime? _raiseStartTime; diff --git a/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs b/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs index 2846a99..4540e0d 100644 --- a/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/SquatFu/WhackAMole.xaml.cs @@ -113,7 +113,6 @@ namespace Views.SquatFu _mediaPlayer.MediaEnded += MediaPlayer_MediaEnded; //_mainWin.WebcamClient.StartExtract(); _mediaPlayer.Play(); - _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; } private void ShowCenterTip(string imagePath, TimeSpan duration) @@ -220,19 +219,6 @@ namespace Views.SquatFu case GameState.Running: // 游戏进行中 UpdateCircleCounts(humans); break; - //case GameState.Finished: // 游戏结束 - // int leftWave = sportOperate.VerifyLeftWavingAction(humans); - // if (leftWave == 5) - // { - // _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; - // _mainWin.WebcamClient.StopExtract(); - - // // 举左手逻辑,例如结束动画或退出 - // var newPage = new Home(); - // _mainWin?.SwitchPageWithMaskAnimation(newPage, true); - // return; // 提前退出 - // } - // break; } } catch (Exception ex) @@ -245,9 +231,6 @@ namespace Views.SquatFu private DateTime _lastUpdateTime = DateTime.Now; private async void StartCountdown(int start = 3) { - - //_currentGameState = GameState.Running; - _mainWin.ShowCountDownAnimation(); Utils.PlayBackgroundMusic("countdown_3.mp3", false); @@ -287,23 +270,6 @@ namespace Views.SquatFu FinishCountdown(); } - private void UpdateCountdown() - { - if ((DateTime.Now - _lastUpdateTime).TotalMilliseconds >= 600) - { - _lastUpdateTime = DateTime.Now; - _currentCountdown -= 600; - - if (_currentCountdown > 0) - { - countdownText.Text = _currentCountdown.ToString(); - } - else - { - FinishCountdown(); - } - } - } private System.Timers.Timer _gameTimer; private Random _random = new Random(); @@ -381,18 +347,13 @@ namespace Views.SquatFu //x.TriggerValue = Tiggle; }); - _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; - _mainWin.WebcamClient.StopExtract(); - RankingItemList = _WhackAMoleContext.UpdateWhackAMoleRankList(); ShowRankingBoard(RankingItemList); Utils.StopBackgroundMusic(); - _currentGameState = GameState.Finished; + _currentGameState = GameState.NotStarted; _isCountdownStarted = false; - _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; - _mainWin.WebcamClient.StartExtract(); } private DateTime? _raiseStartTime; @@ -545,77 +506,102 @@ namespace Views.SquatFu //return userItem; // } - - public void ShowRankingBoard(List list) { - var scoreGrid = FindName("ScoreGrid") as Grid; - name1.Text = list[0].Name; - name2.Text = list[1].Name; - name3.Text = list[2].Name; - number1.Text = list[0].Number.ToString(); - number2.Text = list[1].Number.ToString(); - number3.Text = list[2].Number.ToString(); - foreach (var item in list) + if (list == null || list.Count == 0) return; + + // 排序(建议加上) + list = list.OrderByDescending(x => x.Number).ToList(); + + // 清空旧UI + ScoreGrid.Children.Clear(); + + // ===== 前三名(完全动态,永不越界)===== + var nameControls = new[] { name1, name2, name3 }; + var numberControls = new[] { number1, number2, number3 }; + + for (int i = 0; i < nameControls.Length; i++) { + var item = list.ElementAtOrDefault(i); + + if (item != null) + { + nameControls[i].Text = item.Name; + numberControls[i].Text = item.Number.ToString(); + } + else + { + // 不够3个时填空 + nameControls[i].Text = "-"; + numberControls[i].Text = "-"; + } + } + + // ===== 榜单列表 ===== + for (int i = 0; i < list.Count; i++) + { + var item = list[i]; + var grid = new Grid { Width = 1344, Height = 71, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, - Margin = new Thickness(0, 69 * item.Rank, 0, 0) + Margin = new Thickness(0, 69 * i, 0, 0) }; + var border = new Border { - Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")) + Background = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#FFFFFF")) }; grid.Children.Add(border); - var rankText = new TextBlock + + // 排名 + grid.Children.Add(new TextBlock { - Text = item.Rank.ToString(), + Text = (i + 1).ToString(), FontSize = 24, FontWeight = FontWeights.Bold, - Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")), + Foreground = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#999999")), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, - TextAlignment = TextAlignment.Center, - Width = 200 - }; - grid.Children.Add(rankText); + Width = 200, + TextAlignment = TextAlignment.Center + }); - var positionText = new TextBlock + // 名字 + grid.Children.Add(new TextBlock { Text = item.Name, FontSize = 24, FontWeight = FontWeights.Bold, - Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")), + Foreground = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#999999")), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center - }; - grid.Children.Add(positionText); + }); - var scoreText = new TextBlock + // 分数 + grid.Children.Add(new TextBlock { Text = item.Number.ToString(), FontSize = 24, FontWeight = FontWeights.Bold, - Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")), + Foreground = new SolidColorBrush( + (Color)ColorConverter.ConvertFromString("#999999")), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center, - TextAlignment = TextAlignment.Center, - Width = 200 - }; - grid.Children.Add(scoreText); + Width = 200, + TextAlignment = TextAlignment.Center + }); + ScoreGrid.Children.Add(grid); } - showElement("RankingGrid"); - //var rankingGrid = FindName("RankingGrid") as Grid; - //if (rankingGrid == null) return; - //rankingGrid.Visibility = Visibility.Visible; - //var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(600)); - //rankingGrid.BeginAnimation(UIElement.OpacityProperty, fadeIn); + showElement("RankingGrid"); } /* diff --git a/Wpf_AiSportsMicrospace/Wpf_AiSportsMicrospace.csproj b/Wpf_AiSportsMicrospace/Wpf_AiSportsMicrospace.csproj index 500f8fd..e77d6cb 100644 --- a/Wpf_AiSportsMicrospace/Wpf_AiSportsMicrospace.csproj +++ b/Wpf_AiSportsMicrospace/Wpf_AiSportsMicrospace.csproj @@ -152,6 +152,7 @@ + @@ -648,6 +649,9 @@ Always + + Always +