From 2a9b19b741eeb64b0c44020e7a582d40ad54e6b3 Mon Sep 17 00:00:00 2001 From: ltx <1006158920@qq.com> Date: Thu, 22 Jan 2026 11:52:15 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=E6=8E=A7=E5=88=B6=E7=82=B9?= =?UTF-8?q?=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AiSportsMicrospaceDB/Entities/GroupPoints.cs | 2 + Wpf_AiSportsMicrospace/Common/AppSettings.cs | 20 +- .../Views/Setting/MultiJumpRope.xaml | 9 +- .../Views/Setting/MultiJumpRope.xaml.cs | 177 +++++++++++++++++- 4 files changed, 201 insertions(+), 7 deletions(-) diff --git a/AiSportsMicrospaceDB/Entities/GroupPoints.cs b/AiSportsMicrospaceDB/Entities/GroupPoints.cs index 4d888d3..409ab58 100644 --- a/AiSportsMicrospaceDB/Entities/GroupPoints.cs +++ b/AiSportsMicrospaceDB/Entities/GroupPoints.cs @@ -39,6 +39,8 @@ namespace AiSportsMicrospaceDB.Entities public Point? Point9 { get; set; } public Point? Point10 { get; set; } public Point? ControlPoint { get; set; } + + public int? KeyPointIndex { get; set; } public Point? AreaSize { get; set; } } } diff --git a/Wpf_AiSportsMicrospace/Common/AppSettings.cs b/Wpf_AiSportsMicrospace/Common/AppSettings.cs index ba60cad..415eed3 100644 --- a/Wpf_AiSportsMicrospace/Common/AppSettings.cs +++ b/Wpf_AiSportsMicrospace/Common/AppSettings.cs @@ -40,8 +40,24 @@ namespace Common ControlPoint = groupData.ControlPoint; AreaSize = groupData.AreaSize; } - else - HandyControl.Controls.MessageBox.Show("请先设置点位并重启应用!"); + else + { + db.GroupPoints.Add(new AiSportsMicrospaceDB.Entities.GroupPoints + { + Code= Code, + Point1 = new AiSportsMicrospaceDB.Entities.Point { X = 0.21, Y = 0.88 }, + Point2 = new AiSportsMicrospaceDB.Entities.Point { X = 0.36, Y = 0.58 }, + Point3 = new AiSportsMicrospaceDB.Entities.Point { X = 0.50, Y = 0.88 }, + Point4 = new AiSportsMicrospaceDB.Entities.Point { X = 0.64, Y = 0.58 }, + Point5 = new AiSportsMicrospaceDB.Entities.Point { X = 0.78, Y = 0.88 }, + Point6 = new AiSportsMicrospaceDB.Entities.Point { X = 0.92, Y = 0.58 }, + ControlPoint = new AiSportsMicrospaceDB.Entities.Point { X = 0.50, Y = 0.88 }, + KeyPointIndex = 3, + }); + ControlPoint = new AiSportsMicrospaceDB.Entities.Point { X = 0.50, Y = 0.88 }; + db.SaveChanges(); + } + //HandyControl.Controls.MessageBox.Show("请先设置点位并重启应用!"); SchoolCode = configuration["SchoolCode"] ?? ""; BackendUrl = configuration["BackendUrl"] ?? ""; diff --git a/Wpf_AiSportsMicrospace/Views/Setting/MultiJumpRope.xaml b/Wpf_AiSportsMicrospace/Views/Setting/MultiJumpRope.xaml index d96763f..d769e32 100644 --- a/Wpf_AiSportsMicrospace/Views/Setting/MultiJumpRope.xaml +++ b/Wpf_AiSportsMicrospace/Views/Setting/MultiJumpRope.xaml @@ -119,7 +119,14 @@ Click="ResetPointsButton_Click" Margin="0,5" Height="35" Background="#EF4444" Foreground="White" FontSize="14" FontWeight="Bold"/> - + + + + + + /// 重要点位索引(0 表示不设置) + /// + private int _keyPointIndex = 0; + #endregion #region 构造函数 @@ -277,8 +283,8 @@ namespace Wpf_AiSportsMicrospace.Views if (xProp != null && yProp != null) { - point.X = (double)(xProp.GetValue(dbPoint) ?? 0) * 1080; - point.Y = (double)(yProp.GetValue(dbPoint) ?? 0) * 1920; + point.X = (double)(xProp.GetValue(dbPoint) ?? 0) * 1920; + point.Y = (double)(yProp.GetValue(dbPoint) ?? 0) * 1080; } } } @@ -292,9 +298,21 @@ namespace Wpf_AiSportsMicrospace.Views _points.Add(point); CreatePointControl(point); } + // 加载控制点位索引 + var keyPointProperty = typeof(GroupPoints).GetProperty("KeyPointIndex"); + if (keyPointProperty != null) + { + _keyPointIndex = (int)(keyPointProperty.GetValue(data) ?? 0); + } + else + { + _keyPointIndex = 0; + } + RefreshPointsDataList(); UpdateConnectionLine(); + RefreshKeyPointComboBox(); } /// @@ -319,6 +337,7 @@ namespace Wpf_AiSportsMicrospace.Views RefreshPointsDataList(); UpdateConnectionLine(); + RefreshKeyPointComboBox(); } /// @@ -463,6 +482,141 @@ namespace Wpf_AiSportsMicrospace.Views PointsDataList.ItemsSource = items; } + /// + /// 刷新控制点位下拉框 + /// + private void RefreshKeyPointComboBox() + { + // 保存当前选择 + int previousSelection = KeyPointComboBox.SelectedIndex; + + // 清除并重新填充选项 + KeyPointComboBox.Items.Clear(); + + // 添加"不设置"选项 + var noneItem = new ComboBoxItem + { + Content = "不设置", + Tag = 0 + }; + KeyPointComboBox.Items.Add(noneItem); + + // 添加所有点位选项 + foreach (var point in _points) + { + var item = new ComboBoxItem + { + Content = $"点位 {point.Id}", + Tag = point.Id + }; + KeyPointComboBox.Items.Add(item); + } + + // 恢复选择或默认选择 + if (previousSelection > 0 && previousSelection <= _points.Count) + { + KeyPointComboBox.SelectedIndex = previousSelection; + } + else if (_keyPointIndex > 0) + { + // 恢复保存的控制点位选择 + int comboIndex = _points.FindIndex(p => p.Id == _keyPointIndex); + if (comboIndex >= 0) + { + KeyPointComboBox.SelectedIndex = comboIndex + 1; // +1 因为第一个是"不设置" + } + else + { + KeyPointComboBox.SelectedIndex = 0; + } + } + else + { + KeyPointComboBox.SelectedIndex = 0; + } + } + + /// + /// 控制点位选择改变事件 + /// + private void KeyPointComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (KeyPointComboBox.SelectedItem is ComboBoxItem selectedItem) + { + _keyPointIndex = (int)(selectedItem.Tag ?? 0); + + if (_keyPointIndex > 0) + { + UpdateStatus($"已设置点位 {_keyPointIndex} 为控制点位"); + HighlightKeyPoint(_keyPointIndex); + } + else + { + UpdateStatus("已取消控制点位设置"); + ResetAllPointsHighlight(); + } + } + } + + /// + /// 高亮显示控制点位 + /// + private void HighlightKeyPoint(int pointId) + { + // 重置所有点位样式 + ResetAllPointsHighlight(); + + // 高亮控制点位 + var ellipse = MainCanvas.Children + .OfType() + .FirstOrDefault(e => e.Name == $"PointEllipse_{pointId}"); + + if (ellipse != null) + { + ellipse.Fill = new LinearGradientBrush + { + StartPoint = new Point(0.5, 0), + EndPoint = new Point(0.5, 1), + GradientStops = new GradientStopCollection + { + new GradientStop((Color)ColorConverter.ConvertFromString("#EF4444"), 0), + new GradientStop((Color)ColorConverter.ConvertFromString("#DC2626"), 1) + } + }; + ellipse.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#B91C1C")); + ellipse.StrokeThickness = 3; + } + } + + /// + /// 重置所有点位的高亮样式 + /// + private void ResetAllPointsHighlight() + { + foreach (var point in _points) + { + var ellipse = MainCanvas.Children + .OfType() + .FirstOrDefault(e => e.Name == $"PointEllipse_{point.Id}"); + + if (ellipse != null) + { + ellipse.Fill = new LinearGradientBrush + { + StartPoint = new Point(0.5, 0), + EndPoint = new Point(0.5, 1), + GradientStops = new GradientStopCollection + { + new GradientStop((Color)ColorConverter.ConvertFromString("#34D399"), 0), + new GradientStop((Color)ColorConverter.ConvertFromString("#059669"), 1) + } + }; + ellipse.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#059669")); + ellipse.StrokeThickness = 2; + } + } + } + /// /// 更新连接线 /// @@ -903,14 +1057,29 @@ namespace Wpf_AiSportsMicrospace.Views if (pointProperty != null) { // 创建 Point 实例并保存 - var pointInstance = Activator.CreateInstance(pointType, point.X / 1080, point.Y / 1920); + var pointInstance = Activator.CreateInstance(pointType, point.X / 1920, point.Y / 1080); var pointNew = new AiSportsMicrospaceDB.Entities.Point { - X =point.X / 1080,Y= point.Y / 1920 + X =point.X / 1920,Y= point.Y / 1080 }; pointProperty.SetValue(pointsData, pointNew); } } } + + // 保存重要点位索引 + var keyPointProperty = typeof(GroupPoints).GetProperty("KeyPointIndex"); + var controlPoint = typeof(GroupPoints).GetProperty("ControlPoint"); + var controlPointNew = new AiSportsMicrospaceDB.Entities.Point + { + X = _points[_keyPointIndex].X / 1920, + Y = _points[_keyPointIndex].Y / 1080 + }; + if (keyPointProperty != null) + { + keyPointProperty.SetValue(pointsData, _keyPointIndex); + controlPoint.SetValue(pointsData, controlPointNew); + } + db.SaveChanges(); UpdateStatus("点数据保存成功"); }