Two mechanisms, both live-verified (register row AD-108 updated to match): 1. RESOLUTION. The player/house icons (0x100001ED/0x100001EE) are authored as nested dat children of m_pMap (0x100001EC), itself a Type-1 button whose UiButton.ConsumesDatChildren swallows them at build. The old ResolveSwallowedIcon re-imported them standalone via ImportInfos(hostLayout, iconId) — which returns null on the live DAT: FindDesc walks the raw top-level Elements table (one entry for 0x2100006E) and never reaches them. Their ElementInfos only materialize inside the full panel-slot resolve (ImportInfos(0x2100006E, 0x1000018C)) that MountMapHousePanel already imports — the pageInfo Bind already receives. The fix finds each icon's info under m_pMap's own resolved info subtree and BUILDS it through the new Bindings.IconBuilder seam (production: LayoutImporter.Build under the DAT lock — the build half of RowTemplateResolver's shape). An icon the normal walk DID build is preferred (FindDescendant first), so a future ConsumesDatChildren policy change cannot double-build. 2. POSITION. Found by this fix's own F1 live verification: the resolved ring rendered pinned to m_pMap's top-left. PlaceMarker owns marker position outright (retail's gmMapUI::Update re-places every tick; retail's UpdateForParentSizeChange runs only on real parent resize), but acdream re-runs ApplyAnchor per frame and the icon's compatibility anchor had captured the authored (0,0) rect while the panel was still hidden, re-asserting it over PlaceMarker's writes every frame. PrepareIcon now sets Anchors=None (clearing any imported LayoutPolicy), the established runtime-positioned-element convention. Live numeric gate (session character +Acdream, cell 0xF07E003F): independent computation (gid_to_lcoord -> display (90.8E, 0.5S) -> byte-decoded PlaceMarkerOnMap formula, 17x16 icon, marker area (6,8)-(247,258)) predicts local pixel (226,125); the connected client's UI-tree dump shows the icon at screen (1166,195) under m_pMap (940,70) = local (226,125) — exact match in both panel-open dumps. Coordinate text "0.5S,90.8E", Holtburg town-marker tooltip (real-mouse hover), and the House tab's "You may buy another house immediately." sentence all confirmed on screen; ACE-confirmed graceful logout. New pin: MapHousePanelLiveDatMountTests ([InstalledDatFact]) reproduces the production mount recipe against the installed DATs — the test that would have caught this at Batch C: pins the cold-import null, the panel-slot resolution of both icons with non-degenerate extents, AND that PlaceMarker's writes survive the per-frame ApplyAnchor pass. Gates: Release build green; App suite (live-DAT mode) 5479/3 skips (baseline 5478 + the new pin); Runtime 1744/0; full solution green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
249 lines
11 KiB
C#
249 lines
11 KiB
C#
using System.Linq;
|
|
using AcDream.App.UI;
|
|
using AcDream.App.UI.Layout;
|
|
using AcDream.Core.Net.Messages;
|
|
using AcDream.Core.World;
|
|
|
|
namespace AcDream.App.Tests.UI.Layout;
|
|
|
|
/// <summary>
|
|
/// Controller-level tests for <see cref="MapHousePanelController"/> against
|
|
/// the committed <c>map_house_2100006E_1000018C.json</c> fixture (Batch C,
|
|
/// overnight hover/UI round) — the SAME <c>LayoutImporter.ImportInfos(dats,
|
|
/// 0x2100006Eu, 0x1000018Cu)</c> catalog import
|
|
/// <see cref="RetailUiRuntime.MountMapHousePanel"/> performs against real
|
|
/// DATs. No DAT access, no live runtime — dat-free per the established
|
|
/// <see cref="FixtureLoader"/> pattern.
|
|
/// </summary>
|
|
public sealed class MapHousePanelControllerTests
|
|
{
|
|
/// <summary>Serves the town-hotspot template. Returns a
|
|
/// <see cref="UiButton"/> — matching the live template's own authored
|
|
/// Type 1 (<c>MapHousePanelSlotProbeTests</c>: "hotspot template
|
|
/// type=1") — so <see cref="MapPageController.BuildTownMarkers"/>'s
|
|
/// <c>marker is UiButton</c> tooltip-text branch is actually exercised
|
|
/// by these tests. A real <see cref="RowTemplateResolver"/> would set
|
|
/// <c>DatElementId</c> the same way <see cref="LayoutImporter.Build"/>
|
|
/// does, so tests that need to find these markers back by id after the
|
|
/// fact need it too.</summary>
|
|
private static UiElement? FakeHotspotTemplate(uint layoutId, uint elementId)
|
|
=> new UiButton(new ElementInfo(), static _ => (0u, 0, 0))
|
|
{
|
|
Width = 10f,
|
|
Height = 10f,
|
|
DatElementId = elementId,
|
|
};
|
|
|
|
/// <summary>The <see cref="MapPageController.Bindings.IconBuilder"/>
|
|
/// seam: builds m_pMap's two button-swallowed icon children from their
|
|
/// OWN <see cref="ElementInfo"/>s inside the panel-slot resolve tree
|
|
/// (register row AD-108 — a standalone re-import cannot find them on
|
|
/// the live DAT, so the icons are found under the already-resolved
|
|
/// <c>pageInfo</c> and built through this seam instead). Mirrors
|
|
/// production's <c>LayoutImporter.Build(info, ...).Root</c>, which sets
|
|
/// <c>DatElementId</c> from the info's own id.</summary>
|
|
private static UiElement? FakeIconBuilder(ElementInfo info)
|
|
=> new UiButton(new ElementInfo(), static _ => (0u, 0, 0))
|
|
{
|
|
Width = 10f,
|
|
Height = 10f,
|
|
DatElementId = info.Id,
|
|
};
|
|
|
|
/// <summary>The House ListBox's own row template resolves to a
|
|
/// <see cref="UiText"/> in the live DAT (<c>MapHousePanelSlotProbeTests</c>:
|
|
/// "row template type=12" — <c>UIElement_Text</c>), unlike the Map tab's
|
|
/// UiButton hotspots above — a fresh instance per call, matching
|
|
/// production's real resolver.</summary>
|
|
private static UiElement? FakeHouseRowTemplate(uint layoutId, uint elementId)
|
|
=> new UiText { Width = 280f, Height = 28f };
|
|
|
|
private static MapHousePanelController.Callbacks MakeCallbacks(
|
|
List<string>? calls = null,
|
|
Func<DerethDateTime.Calendar>? currentCalendar = null,
|
|
Func<uint>? playerCellId = null,
|
|
Func<CreateObject.ServerPosition?>? housePosition = null,
|
|
Func<IReadOnlyList<string>>? houseLines = null)
|
|
{
|
|
calls ??= new List<string>();
|
|
return new MapHousePanelController.Callbacks(
|
|
Toggle: () => calls.Add("toggle"),
|
|
Map: new MapPageController.Bindings(
|
|
CurrentCalendar: currentCalendar ?? (static () => default),
|
|
PlayerCellId: playerCellId ?? (static () => 0u),
|
|
HousePosition: housePosition ?? (static () => null),
|
|
TemplateResolver: FakeHotspotTemplate,
|
|
IconBuilder: FakeIconBuilder),
|
|
House: new HousePageController.Bindings(
|
|
Lines: houseLines ?? (static () => Array.Empty<string>()),
|
|
OnShown: () => calls.Add("house-shown"),
|
|
TemplateResolver: FakeHouseRowTemplate));
|
|
}
|
|
|
|
[Fact]
|
|
public void Bind_RootBuildsAsUiTabPanel()
|
|
{
|
|
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
|
|
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
|
|
|
|
MapHousePanelController? controller =
|
|
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks());
|
|
|
|
Assert.NotNull(controller);
|
|
Assert.IsType<UiTabPanel>(controller!.Root);
|
|
}
|
|
|
|
/// <summary>Pins the authored tab table exactly as read from the live
|
|
/// DATs (<c>MapHousePanelSlotProbeTests</c>): two entries, Map is the
|
|
/// sole default.</summary>
|
|
[Fact]
|
|
public void TabTable_MatchesLiveDatPairing_MapIsDefault()
|
|
{
|
|
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
|
|
var tabs = Assert.IsType<UiTabPanel>(layout.Root);
|
|
|
|
Assert.Equal(2, tabs.Tabs.Count);
|
|
Assert.Contains(tabs.Tabs, e =>
|
|
e.ButtonElementId == 0x100001F3u && e.PageElementId == 0x100001F6u && e.IsDefault);
|
|
Assert.Contains(tabs.Tabs, e =>
|
|
e.ButtonElementId == 0x100001F4u && e.PageElementId == 0x100001F7u && !e.IsDefault);
|
|
Assert.Single(tabs.Tabs, e => e.IsDefault);
|
|
}
|
|
|
|
[Fact]
|
|
public void Bind_Succeeds_AndActivateTabs_SelectsMapByDefault()
|
|
{
|
|
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
|
|
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
|
|
MapHousePanelController? controller =
|
|
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks());
|
|
|
|
Assert.NotNull(controller);
|
|
controller!.ActivateTabs();
|
|
|
|
Assert.Empty(controller.TabPanel.UnresolvedEntries);
|
|
Assert.False(controller.IsShowingHouse);
|
|
}
|
|
|
|
[Fact]
|
|
public void SwitchToHouse_FiresOnShown_OnlyWhenPanelIsVisible()
|
|
{
|
|
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
|
|
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
|
|
var calls = new List<string>();
|
|
MapHousePanelController? controller =
|
|
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks(calls));
|
|
Assert.NotNull(controller);
|
|
controller!.ActivateTabs();
|
|
|
|
// Not visible yet: switching tabs must not fire OnShown.
|
|
controller.TabPanel.SwitchTo(0x100001F7u);
|
|
Assert.DoesNotContain("house-shown", calls);
|
|
|
|
controller.OnShown();
|
|
Assert.Contains("house-shown", calls);
|
|
}
|
|
|
|
[Fact]
|
|
public void CloseButton_InvokesToggle()
|
|
{
|
|
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
|
|
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
|
|
var calls = new List<string>();
|
|
MapHousePanelController? controller =
|
|
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks(calls));
|
|
Assert.NotNull(controller);
|
|
|
|
UiElement? close = layout.FindElement(0x100001F5u);
|
|
Assert.IsType<UiButton>(close);
|
|
((UiButton)close!).OnClick?.Invoke();
|
|
|
|
Assert.Contains("toggle", calls);
|
|
}
|
|
|
|
[Fact]
|
|
public void Bind_BuildsAll53TownHotspots_UnderTheMapWidget()
|
|
{
|
|
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
|
|
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
|
|
MapHousePanelController? controller =
|
|
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks());
|
|
Assert.NotNull(controller);
|
|
|
|
UiElement? map = UiElement.FindDescendant(controller!.Root, MapPageController.MapWidgetId);
|
|
Assert.NotNull(map);
|
|
// m_pMap's own children are the player/house icons (found under the
|
|
// panel-slot resolve tree and rebuilt via Bindings.IconBuilder — see
|
|
// MapPageController.Bind's doc on why m_pMap being a Button swallows
|
|
// its authored nested children) PLUS the 53 town hotspots.
|
|
var townMarkers = map!.Children
|
|
.Where(c => c.DatElementId != MapPageController.PlayerIconId
|
|
&& c.DatElementId != MapPageController.HouseIconId)
|
|
.ToList();
|
|
Assert.Equal(55, map.Children.Count);
|
|
Assert.Equal(53, townMarkers.Count);
|
|
Assert.All(townMarkers, c => Assert.Contains(
|
|
MapLocations.All, loc => loc.Width == c.Width && loc.Height == c.Height));
|
|
// Runtime tooltip text (UiButton.TooltipText, backing
|
|
// GetTooltipText()) — the retail SetTooltip/m_TTText mechanism, NOT
|
|
// the DAT-authored AuthoredTooltipText path. The popup-skin locator
|
|
// is unconditionally required even on the runtime-text path (see
|
|
// RetailTooltipPresenter.SharedPopupSkinRootElementId's doc).
|
|
Assert.All(townMarkers, c => Assert.NotEqual(0u, c.AuthoredTooltipRootElementId));
|
|
Assert.All(townMarkers, c => Assert.NotEqual(0u, c.AuthoredTooltipLayoutDid));
|
|
Assert.All(townMarkers, c => Assert.IsType<UiButton>(c));
|
|
Assert.All(townMarkers, c => Assert.False(string.IsNullOrEmpty(((UiButton)c).TooltipText)));
|
|
Assert.Contains(townMarkers, c => ((UiButton)c).TooltipText == "Holtburg");
|
|
}
|
|
|
|
[Fact]
|
|
public void Bind_HouseListBoxStartsEmpty_MatchingRetailPostInit()
|
|
{
|
|
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
|
|
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
|
|
MapHousePanelController? controller =
|
|
MapHousePanelController.Bind(rootInfo, layout, MakeCallbacks());
|
|
Assert.NotNull(controller);
|
|
|
|
UiElement? box = UiElement.FindDescendant(controller!.Root, HousePageController.TextBoxId);
|
|
var listBox = Assert.IsType<UiTemplateListBox>(box);
|
|
Assert.Equal(0, listBox.ContentHeight);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Batch C House-ownership-text closer (2026-08-17): the ONE
|
|
/// decomp-verified <c>gmHouseUI::DisplayPurchaseTimeText @0x004a3110</c>
|
|
/// line a houseless character's HouseQuery response renders — proves
|
|
/// <see cref="HousePageController"/>'s revision-gated
|
|
/// <see cref="MapHousePanelController.Tick"/> poll actually rebuilds the
|
|
/// authored row template with real text end-to-end, the same way
|
|
/// <see cref="RuntimeHouseStateTests"/> proves the text composition in
|
|
/// isolation.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Tick_RendersHouseLinesIntoTheAuthoredRowTemplate()
|
|
{
|
|
ElementInfo rootInfo = FixtureLoader.LoadMapHouseHostInfos();
|
|
ImportedLayout layout = FixtureLoader.LoadMapHouseHost();
|
|
string[] lines = ["You may buy another house immediately."];
|
|
MapHousePanelController? controller = MapHousePanelController.Bind(
|
|
rootInfo, layout, MakeCallbacks(houseLines: () => lines));
|
|
Assert.NotNull(controller);
|
|
|
|
controller!.Tick(0.016);
|
|
|
|
UiElement? box = UiElement.FindDescendant(controller.Root, HousePageController.TextBoxId);
|
|
var listBox = Assert.IsType<UiTemplateListBox>(box);
|
|
// Rows land in the ListBox's internal scrollable viewport (AddChild
|
|
// there, not directly on the ListBox itself — UiTemplateListBox's
|
|
// own #372/#412 dormancy machinery), exposed to tests via
|
|
// ViewportForTest.
|
|
UiScrollablePanel viewport = Assert.IsType<UiScrollablePanel>(
|
|
listBox.ViewportForTest);
|
|
Assert.Single(viewport.Children);
|
|
var row = Assert.IsType<UiText>(viewport.Children[0]);
|
|
Assert.Equal(
|
|
"You may buy another house immediately.",
|
|
Assert.Single(row.LinesProvider()).Text);
|
|
}
|
|
}
|