namespace LivingVillage.Desktop.Tests open Microsoft.VisualStudio.TestTools.UnitTesting open LivingVillage.Desktop open LivingVillage.Kernel open LivingVillage.Kernel.Sim /// P75 回归:HUD 顶部条改为紧凑半透明药丸(去整宽深色带),信息不遮挡、文字可读。 [] type P75HudStripTests () = let world = Sim.initialWorldN 42UL 4 let control = SimulationControl.initial let placed = HudLayout.layout (HudLayout.segments world control) [] member _.TopBandIsRemovedForDayAndNight () = for mode in [ Day; Night ] do let palette = HudLayout.palette mode Assert.AreEqual(0uy, palette.BarTop.A) Assert.AreEqual(0uy, palette.BarBottom.A) Assert.AreEqual(0uy, HudLayout.bandAlpha) [] member _.PillsAreCompactInsideTheStrip () = Assert.IsTrue(HudLayout.pillHeight < HudLayout.barHeight, "药丸须比窄条矮,留出上下留白") for (x, width, _) in placed do let pill = HudLayout.segmentBackdrop x width Assert.IsTrue(pill.Y >= 0 && pill.Y + pill.Height <= HudLayout.barHeight, "药丸须在窄条内") let hair = HudLayout.pillHairline x width Assert.IsTrue(hair.Height = 1, "发丝线为 1px") Assert.IsTrue(hair.X >= pill.X && hair.X + hair.Width <= pill.X + pill.Width, "发丝线须在药丸内") Assert.AreEqual(max 1 (pill.Width - 2), hair.Width) [] member _.StripLeavesWhitespaceAndDoesNotOverlapDateCard () = Assert.IsTrue(placed.Length > 0) let firstX = placed |> List.head |> fun (x, _, _) -> x Assert.AreEqual(HudLayout.paddingX, firstX) let lastEnd = placed |> List.last |> fun (x, width, _) -> x + width // 药丸总跨度远小于通栏宽度,右侧留白充足(不再铺满整宽)。 Assert.IsTrue(lastEnd < 1280 / 2, sprintf "HUD 只占左半,右侧留白;lastEnd=%d" lastEnd) let reading = HudLayout.calendarReading world.Tick let cal = HudLayout.calendarCardRect 1280 reading Assert.IsTrue(cal.Y >= HudLayout.barHeight + HudLayout.accentHeight, "日历卡不压顶部条") [] member _.TextStaysReadableOnTranslucentPills () = for mode in [ Day; Night ] do let palette = HudLayout.palette mode Assert.IsTrue(palette.SegmentBackdrop.A > 0uy && palette.SegmentBackdrop.A < 255uy, "药丸半透明") let valueLuma = int palette.Value.R + int palette.Value.G + int palette.Value.B let outlineLuma = int palette.Outline.R + int palette.Outline.G + int palette.Outline.B Assert.IsTrue(valueLuma > 600, "数值色须够亮") Assert.IsTrue(valueLuma > outlineLuma + 400, "亮字 vs 深描边对比须足够") // 图标与数值并排:文本起始在图标右侧。 for (x, _, segment) in placed do Assert.AreEqual(x + HudLayout.iconWidth + HudLayout.iconGap, HudLayout.textOrigin x) Assert.IsFalse(System.String.IsNullOrEmpty segment.Value)