namespace LivingVillage.Desktop.Tests open Microsoft.VisualStudio.TestTools.UnitTesting open Microsoft.Xna.Framework open LivingVillage.Desktop /// P77 回归:日历卡/浮动提示药丸化后的多尺寸不破版、面板与 hotbar 不遮挡、锚定长文本折行。 [] type P77LayoutTests () = let sizes = [ (1280, 720); (1024, 768); (800, 600); (640, 480) ] [] member _.LayoutsStayInsideEveryViewportAndClearOfHotbar () = for (w, h) in sizes do let bar = HudLayout.hotbarBarRect w h Assert.IsTrue(bar.X >= 0 && bar.Y >= 0 && bar.X + bar.Width <= w && bar.Y + bar.Height <= h, sprintf "hotbar 越界 @%dx%d" w h) let cal = HudLayout.calendarCardRect w (HudLayout.calendarReading 2592000L) Assert.IsTrue(cal.X >= 0 && cal.X + cal.Width <= w && cal.Y >= 0, sprintf "日历卡越界 @%dx%d" w h) let model = DialogOverlay.create "互动:村民 1" [ "1 闲聊"; "2 求助"; "3 交易"; "4 开玩笑"; "ESC 关闭" ] w true let dialog = DialogOverlay.rect w h model Assert.IsTrue(dialog.X >= 0 && dialog.Y >= 0 && dialog.X + dialog.Width <= w && dialog.Y + dialog.Height <= h, sprintf "对话弹层越界 @%dx%d" w h) let panel = HudLayout.panelRect w h 5 Assert.IsTrue(panel.X >= 0 && panel.Y >= 0 && panel.X + panel.Width <= w && panel.Y + panel.Height <= h, sprintf "交互面板越界 @%dx%d" w h) [] member _.DialogAndPanelNeverCoverTheHotbar () = // 上单验收问题:互动面板压住 3-8 号格子。标准与常见尺寸下面板/弹层底边须在 hotbar 顶上方。 for (w, h) in [ (1280, 720); (1024, 768); (800, 600) ] do let bar = HudLayout.hotbarBarRect w h let panel = HudLayout.panelRect w h 5 Assert.IsTrue(panel.Y + panel.Height <= bar.Y, sprintf "交互面板压 hotbar @%dx%d: panelBottom=%d barTop=%d" w h (panel.Y + panel.Height) bar.Y) let model = DialogOverlay.create "互动:村民 1" [ "1 闲聊"; "2 求助"; "3 交易"; "4 开玩笑"; "ESC 关闭" ] w true let dialog = DialogOverlay.rect w h model Assert.IsTrue(dialog.Y + dialog.Height <= bar.Y, sprintf "对话弹层压 hotbar @%dx%d: dialogBottom=%d barTop=%d" w h (dialog.Y + dialog.Height) bar.Y) [] member _.AnchoredLongPromptWrapsWithoutLossAndStaysInBands () = let text = "E 与河边的货郎交谈并查看今日货品是否齐全以及打听附近村里的传闻" let layout = FloatingPrompt.layoutWrapped 1280 720 640.0f 360.0f 0.0f 0.0f 2 text Assert.IsTrue(layout.Lines.Length >= 2, "长锚定文本须折成多行") for line in layout.Lines do Assert.IsTrue(FloatingPrompt.measureWidth line 2 <= FloatingPrompt.maxPromptWidth, sprintf "折行超宽: %s" line) Assert.AreEqual(text, System.String.Concat layout.Lines) Assert.IsTrue(layout.X >= 0 && layout.X + layout.Width <= 1280, "提示不得越界") Assert.IsTrue(layout.Y >= FloatingPrompt.hudTopBarHeight, "提示不得压顶部条") Assert.IsTrue(layout.Y + layout.Height <= 720 - FloatingPrompt.hudBottomBandHeight, "提示不得压底部带") // 短提示仍是单行,且宽度与既有单行版式一致。 let short = FloatingPrompt.layoutWrapped 1280 720 640.0f 360.0f 0.0f 0.0f 2 "E 交谈" Assert.AreEqual(1, short.Lines.Length) Assert.AreEqual(FloatingPrompt.measureWidth "E 交谈" 2, short.Width)