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>
This commit is contained in:
Erik 2026-08-11 00:06:43 +02:00
parent 0df0a60424
commit df9c7a35eb
17 changed files with 51896 additions and 1 deletions

View file

@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using AcDream.App.UI.Layout;
namespace AcDream.App.UI;
/// <summary>
/// Retail <c>UIOption_CheckboxBitfield64</c> (Type <c>0x10000044</c>) — a block of
/// individually toggleable mask checkboxes, built ENTIRELY at runtime. Its authored
/// dat template (<c>0x10000520</c> in <c>0x2100002B</c>, 272x100) carries NO children
/// and NO media — verified against the regenerated <c>options_2100002B.json</c>
/// fixture. Retail C++ populates it by calling <c>AddChild(lowMask, highMask,
/// labelId, tooltipId)</c> once per checkbox (research doc §5.2:
/// <c>gmChatOptionsUI::InitOptions</c> / <c>AddCheckboxBitfield64Option</c>), N times
/// per window, then <c>CreateChildren()</c>. This widget ports that shape:
/// <see cref="AddChild(ulong, ulong, string, string?)"/> appends one row, reusing
/// <see cref="UiButton"/> (with retail's toggle-behavior property <c>0x0B</c> seeded)
/// for the clickable/labelled row itself rather than drawing anything new —
/// consistent with the campaign contract's "compose existing primitives" directive.
/// </summary>
/// <remarks>
/// Click semantics: retail's exact bit-toggle algorithm (what
/// <c>UIOption_CheckboxBitfield64</c>'s own click handler does to <c>m_current</c>, as
/// opposed to <c>UIOption_CheckboxBitfield64::Apply</c>'s documented WRITE side in
/// research doc §3.7) is not in the decompiled excerpt this campaign pulled. This
/// widget applies the conservative, retail-consistent reading — a row is "on" when
/// ALL its mask bits are set, and a click SETS (turns on) or CLEARS (turns off)
/// exactly those bits — and raises <see cref="ValueChanged"/> so a page controller can
/// verify/replace the exact algorithm against the real decomp before wiring the
/// authoritative <c>PlayerModule::SetChatWindowOption</c> transaction (Campaign OP
/// slice OP5).
/// </remarks>
public sealed class UiCheckboxBitfield64 : UiPanel
{
/// <summary>One added checkbox row.</summary>
public readonly record struct Row(
ulong LowMask, ulong HighMask, string Label, string? Tooltip, UiButton Toggle);
private readonly List<Row> _rows = new();
/// <summary>The rows added so far, in <see cref="AddChild(ulong, ulong, string, string?)"/> call order.</summary>
public IReadOnlyList<Row> Rows => _rows;
/// <summary>Current low 64 bits of the option's bitfield value.</summary>
public ulong CurrentLow { get; private set; }
/// <summary>Current high 64 bits of the option's bitfield value.</summary>
public ulong CurrentHigh { get; private set; }
private ulong _defaultLow, _defaultHigh;
/// <summary>Row height in px for the stacked layout. Rows lay out top-to-bottom in
/// call order, matching retail's authored call sequence. No authored row height
/// exists for this block (it is unauthored in the dat) — a page controller may
/// override before the first <see cref="AddChild(ulong, ulong, string, string?)"/> call.</summary>
public float RowHeight { get; set; } = 14f;
/// <summary>Dat font for row labels.</summary>
public UiDatFont? LabelFont { get; set; }
// SpriteResolve (forwarded to each row's UiButton) is inherited from UiPanel —
// same resolver shape, no need to redeclare it.
/// <summary>Fired with the new (low, high) value after any row toggles.</summary>
public Action<ulong, ulong>? ValueChanged { get; set; }
public UiCheckboxBitfield64()
{
BackgroundColor = Vector4.Zero;
BorderColor = Vector4.Zero;
}
/// <summary>
/// Retail <c>UIOption::SetDefaultValue(low, high)</c>: sets the restore-to-defaults
/// target. Also seeds the current value while no rows exist yet (construction
/// order mirrors retail: <c>SetDefaultValue</c> then N <c>AddChild</c> calls, so
/// each row's initial checked state reads the seeded default).
/// </summary>
public void SetDefaultValue(ulong low, ulong high)
{
_defaultLow = low;
_defaultHigh = high;
if (_rows.Count == 0)
{
CurrentLow = low;
CurrentHigh = high;
}
}
/// <summary>Reverts to the last <see cref="SetDefaultValue"/> target and refreshes
/// every row's checked state — the Defaults-button verb (research doc §3.3).</summary>
public void RestoreDefaultValue()
{
CurrentLow = _defaultLow;
CurrentHigh = _defaultHigh;
RefreshRowVisuals();
ValueChanged?.Invoke(CurrentLow, CurrentHigh);
}
/// <summary>
/// Retail <c>UIOption_CheckboxBitfield64::AddChild(lowMask, highMask, labelId,
/// tooltipId)</c>: appends one toggleable row for the given mask, stacked below
/// the previous row. <paramref name="label"/>/<paramref name="tooltip"/> are
/// already-resolved strings — string-table lookup is the caller's job (matches
/// <see cref="UiMenu.MenuItem"/>'s own already-resolved-Label convention).
/// </summary>
public UiButton AddChild(ulong lowMask, ulong highMask, string label, string? tooltip = null)
{
var rowInfo = new ElementInfo { Type = 1u, Width = Width, Height = RowHeight };
var direct = new UiStateInfo { Id = UiStateInfo.DirectStateId, Name = "" };
direct.Properties.Values[0x0Bu] = new UiPropertyValue
{
Kind = UiPropertyKind.Bool,
BoolValue = true, // ToggleBehavior (property 0x0B) — UiButton reads this in its ctor.
};
rowInfo.States[UiStateInfo.DirectStateId] = direct;
var toggle = new UiButton(rowInfo, SpriteResolve ?? (_ => (0u, 0, 0)))
{
Label = label,
LabelFont = LabelFont,
LabelAlign = UiButton.LabelAlignment.Left,
Left = 0f,
Top = _rows.Count * RowHeight,
Width = Width,
Height = RowHeight,
Selected = IsSet(lowMask, highMask),
};
toggle.OnClick = () => ToggleRow(lowMask, highMask, toggle);
_rows.Add(new Row(lowMask, highMask, label, tooltip, toggle));
AddChild(toggle);
return toggle;
}
private bool IsSet(ulong lowMask, ulong highMask)
=> (CurrentLow & lowMask) == lowMask && (CurrentHigh & highMask) == highMask;
private void ToggleRow(ulong lowMask, ulong highMask, UiButton toggle)
{
bool turnOn = !IsSet(lowMask, highMask);
if (turnOn)
{
CurrentLow |= lowMask;
CurrentHigh |= highMask;
}
else
{
CurrentLow &= ~lowMask;
CurrentHigh &= ~highMask;
}
toggle.Selected = turnOn;
ValueChanged?.Invoke(CurrentLow, CurrentHigh);
}
private void RefreshRowVisuals()
{
foreach (Row row in _rows)
row.Toggle.Selected = IsSet(row.LowMask, row.HighMask);
}
}