acdream/src/AcDream.App/UI/UiTabControl.cs
Erik df9c7a35eb feat(ui): Campaign OP slice OP2 — tab control, template ListBox, UIOption widget mappings
Ships the two new widget primitives the retail Options panel needs plus the
four remaining UIOption_* factory mappings, so every tab page (OP3-OP6) has
somewhere to mount.

- ElementReader/ElementInfo gain three new dat-property readers, following
  the existing effective-state-resolution pattern (never a per-state
  first-wins scan, per the round-5 N1 lesson): the Type-8 tab table
  (property 0x2E -> TabTable), a ListBox's row-template list (property
  0x64 -> TemplateList), and scrollbar linkage (property 0x72 ->
  ScrollbarElementId). LayoutImporter gains one hook
  (IUiChildrenAttachedListener) so a widget can resolve cross-references
  its own dat properties name by id once its subtree actually exists.

- UiTabControl (Type 8): switches exactly one page-slot child visible,
  syncs each tab button's Open/Closed state via the existing
  RetailTabBinding helper, and honors the authored default tab on mount.

- UiTemplateListBox (Type 5 with an authored template list): wraps a
  UiScrollablePanel viewport (sealed, so composition not inheritance) and
  ports AddItemFromTemplateList(index) — the resolver seam a page
  controller wires with real DAT access via the SAME
  LayoutImporter.ImportInfos(dats, layoutId, elementId) overload
  RetailDialogFactory already uses for its catalog LayoutDesc.

- DatWidgetFactory maps the four remaining UIOption_* widgets, each
  verified against the regenerated options_2100002B.json fixture before
  writing any code: 0x10000037 (Slider) is structurally an ordinary
  horizontal UIElement_Scrollbar, so it reuses BuildScrollbar directly;
  0x10000038 (Menu) is structurally identical to the vendor category
  dropdown UiMenu already models, so it reuses `new UiMenu()` like the
  Type-6 case; 0x10000036 (CheckboxSlider) composes an existing
  UIOption_Checkbox child + UIOption_Slider child via the new
  UiOptionToggleSlider wrapper; 0x10000044 (CheckboxBitfield64) authors
  zero children in the dat (every row is added at runtime via retail's own
  AddChild(lowMask, highMask, label, tooltip) call shape), so it's a new
  UiCheckboxBitfield64 composing UiButton per row. No new drawing code
  anywhere in this set.

- Five new committed fixtures (options_2100002B/2100002A/21000028/
  2100005C/21000029) plus 25 new conformance tests pinning the tab table
  (4 entries, Gameplay default), all three template arrays, scrollbar
  linkage, every new widget-type mapping, and a UiTabControl behavioral
  test (switch -> exactly one page visible, click-through the tab
  button). The Character ListBox's authored 6-header/49-toggle shape
  (lane B section counts) is proven reachable end-to-end through
  AddItemFromTemplateList against the committed fixture.

- Regenerating fixtures also touched 27 PRE-EXISTING, unrelated fixtures
  (an Outline/OutlineColor field pair added by an earlier commit,
  bcc34ee3, that predates when those fixtures were last regenerated).
  Per the slice contract, that drift was NOT committed — reverted back to
  HEAD, only the five new Options-panel fixtures are new files here.

- Filed TS-72: UiCheckboxBitfield64's click-toggle bit math (AND/OR
  set/clear semantics) is a documented approximation — the decompiled
  excerpt this campaign pulled covers UIOption_CheckboxBitfield64::Apply's
  WRITE side, not its own click-handler's bit math. Flagged for OP5 (the
  Chat tab controller, the first consumer that reaches the wire) to
  verify against the real decomp before any live transaction depends on
  it; nothing user-reachable can observe this yet.

Full Release suite: 12,770 passed / 4 skipped / 0 failed (was 12,745/4/0
post-OP1 — 25 net new tests, zero regressions).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 00:06:43 +02:00

112 lines
4.8 KiB
C#

using System.Collections.Generic;
using AcDream.App.UI.Layout;
namespace AcDream.App.UI;
/// <summary>
/// Retail <c>UIElement_TabControl</c> (Type 8) — the Options panel's tab strip +
/// mounted-page switcher. Owns the authored tab table (dat property <c>0x2E</c>,
/// see <see cref="UiTabTableEntry"/>): activating a tab shows exactly ONE page-slot
/// child and hides the rest, and updates the corresponding tab button's Open/Closed
/// visual state.
///
/// <para>
/// The tab buttons and page-slot children are ORDINARY imported dat elements — this
/// widget does <b>not</b> set <see cref="UiElement.ConsumesDatChildren"/>, so
/// <c>LayoutImporter</c> builds them the normal recursive way (buttons build as
/// <see cref="UiText"/> with Open/Closed states — retail's tab buttons are Type 0xC
/// text elements, not Type-1 buttons; page slots build as generic containers whose
/// OWN children are the mounted page's content via <c>BaseLayoutId</c>/
/// <c>BaseElement</c> inheritance). This widget only wires cross-references the tab
/// table names by id, which it can only resolve once that subtree exists — see
/// <see cref="IUiChildrenAttachedListener"/>.
/// </para>
///
/// <para>
/// Retail anchors: <c>docs/research/2026-08-10-options-panel-structure.md</c> §1.3
/// (the tab table property <c>0x2E</c> struct shape), §10.1 (structural inventory —
/// tab buttons `0x1000020D..0x1000020F`/`0x1000050B`, page slots
/// `0x10000211..0x10000213`/`0x1000050C`, Gameplay the authored default). Verified
/// byte-for-byte against the regenerated <c>options_2100002B.json</c> fixture: four
/// entries, Gameplay (`0x1000020D`/`0x10000212`) is the sole <c>IsDefault</c> row.
/// </para>
///
/// <para>
/// Retail's <c>OnVisibilityChanged</c> auto-apply/auto-revert semantics (research doc
/// §3.6 — hiding a page reverts uncommitted edits, showing one applies + commits) are
/// OUT of this widget's scope: they belong to the <c>OptionPage</c>/
/// <c>PlayerOptionPage</c> model a page controller owns (Campaign OP slice OP3+).
/// This widget only switches which page slot is <see cref="UiElement.Visible"/>.
/// </para>
/// </summary>
public sealed class UiTabControl : UiElement, IUiChildrenAttachedListener
{
private readonly IReadOnlyList<UiTabTableEntry> _tabs;
public UiTabControl(IReadOnlyList<UiTabTableEntry> tabs)
{
_tabs = tabs;
}
/// <summary>The authored tab table this control was built from, in authored array order.</summary>
public IReadOnlyList<UiTabTableEntry> Tabs => _tabs;
/// <summary>Dat element id of the currently active page slot. 0 before the first mount.</summary>
public uint ActivePageElementId { get; private set; }
/// <summary>
/// Retail wires the tab table's cross-references (button ↔ page ↔ default) once
/// the imported subtree exists — see <see cref="IUiChildrenAttachedListener"/>'s
/// doc for why this can't happen during <c>DatWidgetFactory.Create</c>. Every tab
/// button's click is bound to switch to its paired page, then the authored
/// default tab (the entry with <see cref="UiTabTableEntry.IsDefault"/> true, or
/// the first entry if the dat authored none) is activated.
/// </summary>
public void OnChildrenAttached()
{
UiTabTableEntry? defaultEntry = null;
foreach (UiTabTableEntry entry in _tabs)
{
UiElement? button = FindDirectChild(entry.ButtonElementId);
uint pageId = entry.PageElementId;
RetailTabBinding.SetClick(button, () => SwitchTo(pageId));
if (entry.IsDefault)
defaultEntry = entry;
}
defaultEntry ??= _tabs.Count > 0 ? _tabs[0] : null;
if (defaultEntry is { } def)
SwitchTo(def.PageElementId);
}
/// <summary>
/// Activates the page slot named <paramref name="pageElementId"/>: shows it, hides
/// every other authored page slot, and sets each tab button's Open/Closed state to
/// match (<see cref="RetailTabBinding.SetOpen"/>). No-op if the page is already active.
/// </summary>
public void SwitchTo(uint pageElementId)
{
if (ActivePageElementId == pageElementId) return;
foreach (UiTabTableEntry entry in _tabs)
{
bool active = entry.PageElementId == pageElementId;
UiElement? page = FindDirectChild(entry.PageElementId);
if (page is not null) page.Visible = active;
UiElement? button = FindDirectChild(entry.ButtonElementId);
RetailTabBinding.SetOpen(button, active);
}
ActivePageElementId = pageElementId;
}
private UiElement? FindDirectChild(uint datElementId)
{
foreach (UiElement child in Children)
if (child.DatElementId == datElementId)
return child;
return null;
}
}