From a25a047f14fbaafb18f76f7439bae04bec80e230 Mon Sep 17 00:00:00 2001 From: denglihong2007 <98096191+denglihong2007@users.noreply.github.com> Date: Thu, 1 Jan 2026 01:28:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AB=99=E5=8F=B0=E5=8D=A0=E7=94=A8?= =?UTF-8?q?=E5=9B=BE=E7=94=9F=E6=88=90=E5=99=A8=E6=97=A0=E6=B3=95=E5=A4=84?= =?UTF-8?q?=E7=90=86=E4=B8=AD=E6=96=87=E7=AB=99=E5=8F=B0=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRSim.PlatformDiagram/PlatformDiagram.cs | 28 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/CRSim.PlatformDiagram/PlatformDiagram.cs b/CRSim.PlatformDiagram/PlatformDiagram.cs index baf6a19..d6ab7df 100644 --- a/CRSim.PlatformDiagram/PlatformDiagram.cs +++ b/CRSim.PlatformDiagram/PlatformDiagram.cs @@ -120,24 +120,42 @@ namespace CRSim.PlatformDiagram } } + // 1. 初始化字典(保持不变) Dictionary platformHeights = station.TrainStops .Select(x => x.Platform) .Where(p => p != null) .Distinct() .ToDictionary(p => p!, p => 0f); + + // 2. 绘制底线(保持不变) canvas.MoveTo(xBase, yBottom).LineTo(xEnd - TimelineExtLength, yBottom).Stroke(); + + // 3. 遍历所有站台,按索引分配高度 for (int i = 0; i < platformCount; i++) { - string name = station.Platforms[i].Name; - if (double.TryParse(name, out double platformNumber)) + var platform = station.Platforms[i]; + string name = platform.Name; + + // 计算当前站台的 Y 坐标高度 + // 逻辑:i 越大(后面的站台),高度越高 + float currentY = yBottom + (platformCount - i - 1) * PlatformHeight; + + // 直接存入字典,不再判断是否为数字 + if (platformHeights.ContainsKey(name)) { - platformHeights[name] = yBottom + (platformCount - i - 1f) * PlatformHeight; + platformHeights[name] = currentY; } + + // 绘制站台分隔线 canvas.SetLineWidth(1f); - canvas.MoveTo(xBase, yBottom + (platformCount - i) * PlatformHeight) - .LineTo(xEnd - TimelineExtLength, yBottom + (platformCount - i) * PlatformHeight) + canvas.MoveTo(xBase, currentY) + .LineTo(xEnd - TimelineExtLength, currentY) .Stroke(); } + canvas.SetLineWidth(1f); + canvas.MoveTo(xBase, yBottom + platformCount * PlatformHeight) + .LineTo(xEnd - TimelineExtLength, yBottom + platformCount * PlatformHeight) + .Stroke(); #endregion #region 列车