Mounts host 0x2100006E slot 0x1000018C (RetailPanelCatalog.MapHouse = 16) as a two-tab UiTabPanel (Map default, House second) through the OP3/FA3 recipe (LayoutImporter.Build -> Bind -> ActivateTabBehavior). Toolbar button 0x1000019A un-ghosts (added to both RetailPanelCatalog.Mounted and .Toolbar). Combined into one commit because MapHousePanelController.Bind depends on both MapPageController and HousePageController existing — splitting them would mean landing dead code first. Map tab (gmMapUI, MapPageController): - Calendar formatter matching gmMapUI::Update's "Date: %s\nTime: %s" shape, reusing WorldTimeService.CurrentCalendar (new Func<DerethDateTime.Calendar> dependency threaded through InteractionRetainedUiDependencies/GameWindow — a stable long-lived service, not routed through the deferred-binding machinery Radar's per-session state needs). MonthName enum values already match retail display text; HourName's "AndHalf" suffix is rewritten to "-and-Half". - Coordinate math + marker placement reuse RadarCoordinates/ LandDefs.GidToLcoord verbatim (both already byte-exact ports of CPlayerSystem::InqPlayerCoords/LandDefs::gid_to_lcoord) — no re-port. PlaceMarkerOnMap's centering math (m_x0 + x - w/2) ported from gmMapUI::PlaceMarkerOnMap @0x004a18b0. Indoor gating clears the coordinate text and hides the player marker, matching gmMapUI::Update's else branch. - 53-town s_rgLocations table ported verbatim into MapLocations.cs. Markers built once at bind time via the panel's own RowTemplateResolver against m_pMap's authored hotspot-template attrs (0x47/0x48), with literal-string tooltips through AuthoredTooltipText/Enabled (RetailTooltipPresenter) — closes divergence-register row TS-85's last item, gmMapUI::AddMapNote @0x004A1C51. - Structural finding: m_pMap (0x100001EC) is itself authored as a Type-1 BUTTON (the GM click-to-teleport hook at gmMapUI::ListenToElementMessage), and the player/house icons (0x100001ED/EE) are its own NESTED children, not siblings — UiButton.ConsumesDatChildren swallows them from the normally-built tree. Both are re-resolved standalone through the same template resolver the town hotspots use and reattached under m_pMap. House tab (gmHouseUI, HousePageController): mounts the ListBox (0x100001E6) with its authored row template, wired to an empty Lines() source by default — genuinely empty until Slice 4's wire lands, matching retail's own PostInit (no Update call, no static content). 21 new tests (7 MapHousePanelControllerTests, 14 MapPageControllerTests): tab table pairing, close button, town-hotspot count/tooltips, calendar formatter golden values (Frostfell 27/119 P.Y., every HourName incl. AndHalf), player/house marker placement and indoor-gating reproduced against the real fixture via already-tested RadarCoordinates (no re-derivation). Fixture map_house_2100006E_1000018C.json captured via the shared RetailLayoutFixtureGenerator (other 34 fixtures deliberately NOT regenerated — out of scope for this batch, would touch unrelated panels' schema drift). Full solution builds clean; App suite 5391/0 failed/71 skipped (non-live; one earlier flaky streaming failure unrelated to this change, confirmed pre-existing on the branch before these commits). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
171 lines
7.2 KiB
C#
171 lines
7.2 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 BOTH the town-hotspot template (any (layoutId,
|
|
/// elementId) pair not the player/house icon ids) and the two icons
|
|
/// <see cref="MapPageController.Bind"/> re-resolves standalone
|
|
/// (<c>m_pMap</c>'s own button-swallowed children) — 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 icons back by id after the fact need it too.</summary>
|
|
private static UiElement? FakeHotspotTemplate(uint layoutId, uint elementId)
|
|
=> new UiText { Width = 10f, Height = 10f, DatElementId = elementId };
|
|
|
|
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),
|
|
House: new HousePageController.Bindings(
|
|
Lines: houseLines ?? (static () => Array.Empty<string>()),
|
|
OnShown: () => calls.Add("house-shown")));
|
|
}
|
|
|
|
[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 (re-resolved
|
|
// standalone — 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));
|
|
Assert.All(townMarkers, c => Assert.True(c.AuthoredTooltipEnabled));
|
|
Assert.Contains(townMarkers, c => c.AuthoredTooltipText == "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);
|
|
}
|
|
}
|