fix(chargen): Campaign CC gate round 1 Batch C — rich text + labels + backdrops

Commit 1/3: chargen-scoped, low blast-radius fixes.

- New DatRichText helper: escape-normalize + word-wrap + per-segment
  palette color, porting UIElement_Text::SetStringInfoWithFont /
  AppendStringInfoWithFont's composition model. Routes the Heritage
  (GF-2), Town (GF-11a), and Profession (GF-3) description boxes
  through it instead of a raw unwrapped single-Line LinesProvider.
  Heritage headers use font-color palette index 1 (green), bodies
  index 0 (white), matching AppendStringInfoWithFont's own font-index
  argument. Town's diagnosed GF-11a root cause: a single un-wrapped
  line meant the town-specific suffix rendered past the clipped
  viewport, so switching towns looked like "text never changes" even
  though the underlying composed string genuinely differed.

- GF-3: bind the Profession page's description textbox (0x100003e0,
  gmCGProfessionPage::InitializePage @0x00483068) and compose its
  per-template text (UpdateProfession @0x004821b0's CustomText/
  BowText/SwashText/LifeText/WarText/WayText/SoldierText, plain
  SetStringInfo — no palette).

- GF-4: UiButton gains a coexisting ValueLabel/ValueBox/ValueFont/
  ValueColor slot alongside Label. Retail's chargen display buttons
  (avail/health/stamina/mana credits, 0x100003e2-e5/0x100003f9)
  author their caption directly on P0x17 AND carry a separate,
  media-less Type-12 value child that UiButton.ConsumesDatChildren
  used to drop entirely — pages substituted the button's own Label,
  destroying the caption. DatWidgetFactory.BuildButton now surfaces
  that child (gated on ReferenceEquals(labelInfo, info) — own-caption
  buttons only) instead. The six Profession slider name labels
  (0x100002ed, CharGenState::GetAttributeName @0x005C3A20's six
  hardcoded literals) resolve as UiButton in this port (live-DAT-
  measured Type 1 — retail's UIElement_Button is DynamicCast(0xc)-
  compatible with UIElement_Text) and are written once at
  construction, matching retail's own single InitializePage write.

- GF-6/AP-218: gmCGAppearancePage::Update writes a heritage-flavored
  STATIC caption to the Hair/Eyes/Skin spins (plain / GearText_* /
  OlthoiText_* variants) — never an index. Removed the prior 1-based-
  ordinal/gear-name substitution entirely; the other six spins keep
  their DAT-authored caption untouched, matching retail exactly.

- Root 1d: wire the Heritage (0x100003be, 13 states) and Profession
  (0x100003d8, 7 states) backdrop SetState cascades
  (gmCGHeritagePage::Update / gmCGProfessionPage::UpdateProfession).

- AP-216/AP-217 (partial, register updated honestly): swatches beyond
  the current part's real color count now hide (DoColorSpots' blank-
  blit half); the GradCircle now blanks for Eyes (DoGradDisk's blank-
  plug half). The "paint with the actual represented/current color"
  halves stay open — they need a PalSet/Palette-id -> RGB pipeline no
  chargen page reads at runtime yet, judged disproportionate to add
  alongside this batch's other ~10 fixes.

Register: AP-215 rewritten (item 2's "ordinal" framing is stale after
GF-6; restated as the icon-thumbnail gap), AP-216/AP-217 rewritten
(partially closed), AP-218 retired, AD-103 retired (the swallowed-
child Label substitution AD-103 tracked is replaced by ValueLabel's
own-geometry surfacing).

22 new tests (DatRichText unit tests, UiButton/DatWidgetFactory
ValueLabel tests, live-DAT structural pins, controller behavioral
tests) — all green. Full App suite (Release, live-DAT):
5300 passed / 1 pre-existing unrelated flake (PortalProjectionTests
allocation test, passes in isolation) / 3 skipped, up from the
baseline 5282/3.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-16 12:18:53 +02:00
parent 7d09821fdc
commit 0591b9a026
13 changed files with 1018 additions and 66 deletions

View file

@ -1,4 +1,3 @@
using System.Globalization;
using AcDream.App.Rendering;
using AcDream.Core.CharGen;
using AcDream.Runtime;
@ -175,6 +174,7 @@ internal sealed class CharacterCreationAppearancePage : IDisposable
private readonly UiButton? _rotateCounterClockwise;
private readonly UiButton? _zoomIn;
private readonly UiButton? _zoomOut;
private readonly UiElement? _gradCircle;
private Choice _currentChoice = Choice.Face;
private Part _currentPart = Part.Hair;
@ -242,6 +242,8 @@ internal sealed class CharacterCreationAppearancePage : IDisposable
if (_shadeScroll is not null)
_shadeScroll.ScalarChanged = SetShadeFromScalar;
_gradCircle = Find<UiElement>(pageRoot, GradCircleId);
Viewport = Find<UiViewport>(pageRoot, ViewportId);
_rotateClockwise = Find<UiButton>(pageRoot, RotateClockwiseId);
@ -327,8 +329,8 @@ internal sealed class CharacterCreationAppearancePage : IDisposable
}
ApplyChoiceVisibility();
if (TryGetGender(view, snapshot, out ChargenGenderOptions? gender))
RefreshSpins(gender, snapshot.Appearance);
// GF-6: heritage-flavored, index-independent — no gender needed.
RefreshSpinCaptions(snapshot.HeritageId);
RefreshColorAndShadeControls(view, snapshot);
RebuildPreview(view, snapshot);
@ -677,6 +679,37 @@ internal sealed class CharacterCreationAppearancePage : IDisposable
overlay.Visible = colorSlot is not null && currentColor == (uint)i;
}
// AP-216 (Campaign CC gate round 1 Batch C, PARTIAL): retail's
// DoColorSpots @0x0047d850 blits ACTUAL-color art for each valid
// swatch and BLANK art for any swatch beyond the current part's
// real color count. Painting each swatch with its own represented
// color needs a PalSet/Palette-id -> RGB resolution pipeline this
// batch does not add (no chargen page currently reads DAT palette
// pixels at runtime) — register AP-216 stays open for that half.
// This ships the cheap, fully-evidenced half: hiding a swatch a
// part's color list doesn't actually have (closest faithful
// rendering the existing pipeline supports — Visible=false is the
// acdream equivalent of "blit nothing").
int colorCount = colorSlot is not null
&& TryGetGender(view, snapshot, out ChargenGenderOptions? swatchGender)
? ColorCount(_currentPart, swatchGender)
: 0;
for (int i = 0; i < _swatches.Length; i++)
{
if (_swatches[i] is { } swatch)
swatch.Visible = colorSlot is not null && i < colorCount;
}
// AP-217 (PARTIAL): gmCGAppearancePage::DoGradDisk @0x0047da90
// blits the blank "grad plug" for Eyes (DoGradDisk(this, 1),
// called from SetSelection @0x0047e85d) and a gradient graphic
// TINTED with the current part's color otherwise — the tinted
// repaint needs the same palette-to-RGB pipeline AP-216's open
// half needs, so it stays open too. This ships the evidenced
// Eyes-blank half only.
if (_gradCircle is not null)
_gradCircle.Visible = _currentPart != Part.Eyes;
ChargenShadeSlot? shadeSlot = ShadeSlotFor(_currentPart);
if (_shadeScroll is null)
return;
@ -694,36 +727,57 @@ internal sealed class CharacterCreationAppearancePage : IDisposable
}
}
// ── Spin labels ──────────────────────────────────────────────────
// ── Spin captions ────────────────────────────────────────────────
private void RefreshSpins(ChargenGenderOptions gender, RuntimeCharacterCreationAppearance a)
/// <summary>
/// GF-6/AP-218 (Campaign CC gate round 1 Batch C):
/// <c>gmCGAppearancePage::Update @ 0x0047e8f0</c> writes the Hair/Eyes/
/// Skin spins' caption to a heritage-flavored STATIC string via
/// <c>UIElement_Text::SetStringInfoWithFont</c> — never an index or a
/// style name. Normal heritage: <c>ID_CharGen_HairStyle</c>/
/// <c>_Eyes</c>/<c>_Skin</c> (@0x0047ebad/0x0047ebe3/0x0047ec6a).
/// Gearknight (heritage 6): <c>ID_CharGen_GearText_HairButton</c>/
/// <c>_EyesButton</c>/<c>_SkinButton</c> (@0x0047e9ef/0x0047ea25/
/// 0x0047eaa9). Olthoi/OlthoiAcid (heritage 0xc/0xd):
/// <c>ID_CharGen_OlthoiText_HairButton</c>/<c>_EyesButton</c>/
/// <c>_SkinButton</c> (@0x0047ed5b/0x0047ed91/0x0047ee15). The other
/// six spins (Nose/Mouth/Headgear/Shirt/Trousers/Footwear) are NEVER
/// touched by <c>Update</c> — their DAT-authored static caption
/// (already resolved at build time by
/// <c>DatWidgetFactory.BuildButton</c>'s own P0x17 lift) is left
/// alone. Retail shows NO per-style index or name anywhere on this
/// page — the live 3D preview is the player's only feedback for which
/// style/gear is currently selected; acdream's own prior "1-based
/// ordinal"/gear-name substitution here was never a retail behavior
/// (register AP-218, retired by this fix; AP-215's own icon-thumbnail
/// item stays open — a DIFFERENT gap, see that row's own text).
/// </summary>
private void RefreshSpinCaptions(uint heritageId)
{
SetStyleSpinLabel(Part.Hair, gender.HairStyles.Count, a.HairStyle);
SetStyleSpinLabel(Part.Eyes, gender.EyeStrips.Count, a.EyesStrip);
SetStyleSpinLabel(Part.Nose, gender.NoseStrips.Count, a.NoseStrip);
SetStyleSpinLabel(Part.Mouth, gender.MouthStrips.Count, a.MouthStrip);
SetGearSpinLabel(Part.Headgear, gender.Headgears, a.HeadgearStyle);
SetGearSpinLabel(Part.Shirt, gender.Shirts, a.ShirtStyle);
SetGearSpinLabel(Part.Trousers, gender.Pants, a.TrousersStyle);
SetGearSpinLabel(Part.Footwear, gender.Footwear, a.FootwearStyle);
(string hairKey, string eyesKey, string skinKey) = heritageId switch
{
(uint)ChargenHeritageGroup.Gearknight => (
"ID_CharGen_GearText_HairButton",
"ID_CharGen_GearText_EyesButton",
"ID_CharGen_GearText_SkinButton"),
(uint)ChargenHeritageGroup.Olthoi or (uint)ChargenHeritageGroup.OlthoiAcid => (
"ID_CharGen_OlthoiText_HairButton",
"ID_CharGen_OlthoiText_EyesButton",
"ID_CharGen_OlthoiText_SkinButton"),
_ => ("ID_CharGen_HairStyle", "ID_CharGen_Eyes", "ID_CharGen_Skin"),
};
SetSpinCaption(Part.Hair, hairKey);
SetSpinCaption(Part.Eyes, eyesKey);
SetSpinCaption(Part.Skin, skinKey);
}
private void SetStyleSpinLabel(Part part, int count, uint index)
private void SetSpinCaption(Part part, string key)
{
if (!_spins.TryGetValue(part, out UiButton? spin))
return;
spin.Label = index != Unset && index < (uint)count
? (index + 1).ToString(CultureInfo.InvariantCulture)
: "-";
}
private void SetGearSpinLabel(Part part, IReadOnlyList<ChargenGearOption> options, uint index)
{
if (!_spins.TryGetValue(part, out UiButton? spin))
return;
spin.Label = index != Unset && index < (uint)options.Count
? options[(int)index].Name
: "None";
if (_bindings.ResolveText?.Invoke(key) is { } text)
spin.Label = text;
}
// ── Preview rebuild ──────────────────────────────────────────────

View file

@ -1,3 +1,4 @@
using System.Numerics;
using AcDream.Core.CharGen;
using AcDream.Runtime;
using AcDream.Runtime.Session;
@ -72,10 +73,38 @@ internal sealed class CharacterCreationHeritagePage : IDisposable
[(uint)ChargenHeritageGroup.Undead] = "ID_CharGen_UndText_BonusSkills_Trained",
};
/// <summary>
/// Root 1d (Campaign CC gate round 1 Batch C): the page's own backdrop
/// element (<c>0x100003be</c>, live-DAT-measured 13 authored states)
/// switches per selected heritage — <c>gmCGHeritagePage::Update
/// @0x00483210</c>'s per-case <c>m_pBackground-&gt;SetState(...)</c>
/// calls (heritages 5/Shadowbound and 10/Penumbraen share literals
/// <c>0x10000058</c>/<c>0x10000059</c> via a shared jump target, every
/// other heritage has its own distinct state).
/// </summary>
private static readonly IReadOnlyDictionary<uint, uint> BackdropStateByHeritage =
new Dictionary<uint, uint>
{
[(uint)ChargenHeritageGroup.Aluvian] = 0x10000021u,
[(uint)ChargenHeritageGroup.Gharundim] = 0x10000022u,
[(uint)ChargenHeritageGroup.Sho] = 0x10000023u,
[(uint)ChargenHeritageGroup.Viamontian] = 0x10000024u,
[(uint)ChargenHeritageGroup.Shadowbound] = 0x10000058u,
[(uint)ChargenHeritageGroup.Gearknight] = 0x1000005Au,
[(uint)ChargenHeritageGroup.Tumerok] = 0x1000005Fu,
[(uint)ChargenHeritageGroup.Lugian] = 0x10000060u,
[(uint)ChargenHeritageGroup.Empyrean] = 0x1000005Cu,
[(uint)ChargenHeritageGroup.Penumbraen] = 0x10000059u,
[(uint)ChargenHeritageGroup.Undead] = 0x1000005Bu,
[(uint)ChargenHeritageGroup.Olthoi] = 0x1000005Du,
[(uint)ChargenHeritageGroup.OlthoiAcid] = 0x1000005Eu,
};
private readonly CharacterCreationRuntimeBindings _bindings;
private readonly Action<uint> _onButtonClicked;
private readonly Dictionary<UiButton, uint> _buttons = [];
private readonly UiText? _description;
private readonly UiElement? _backdrop;
private bool _disposed;
/// <param name="onButtonClicked">Review fix round F3 (2026-08-15):
@ -105,6 +134,7 @@ internal sealed class CharacterCreationHeritagePage : IDisposable
}
_description = UiElement.FindDescendant(pageRoot, 0x100003C4u) as UiText;
_backdrop = UiElement.FindDescendant(pageRoot, 0x100003BEu);
}
internal void Refresh(
@ -114,12 +144,24 @@ internal sealed class CharacterCreationHeritagePage : IDisposable
foreach ((UiButton button, uint heritageId) in _buttons)
button.Selected = heritageId == snapshot.HeritageId;
// Root 1d: switch the backdrop art per selected heritage. Retail
// runs this unconditionally alongside the button highlight/text
// composition below — no heritage-unset guard exists in the decomp
// beyond the dictionary lookup itself (heritageId 0 simply has no
// entry, so TryGetValue leaves the backdrop at whatever state it
// last held, matching retail's own "no case 0" switch shape).
if (_backdrop is IUiDatStateful backdropStateful
&& BackdropStateByHeritage.TryGetValue(snapshot.HeritageId, out uint backdropState))
{
backdropStateful.TrySetRetailState(backdropState);
}
if (_description is null)
return;
string composed = ComposeDescription(view, snapshot.HeritageId, _bindings.ResolveText);
_description.LinesProvider = () =>
[new UiText.Line(composed, _description.DefaultColor)];
IReadOnlyList<DatRichText.Segment> segments = ComposeSegments(
_description, view, snapshot.HeritageId, _bindings.ResolveText);
_description.LinesProvider = () => DatRichText.Compose(_description, segments);
}
internal void Randomize(RuntimeCharacterCreationSnapshot snapshot)
@ -168,38 +210,45 @@ internal sealed class CharacterCreationHeritagePage : IDisposable
/// body, the bonus-skills header, then — only once a heritage is
/// selected — that heritage's own bonus-skills line (absent for
/// Lugian/Olthoi/OlthoiAcid; see <see cref="BonusSkillsKeyByHeritage"/>).
/// <paramref name="resolveText"/> is the DAT string lookup
/// (<c>RetailUiRuntime</c>'s <c>DatStringResolver</c> over table
/// <c>0x23000002</c>) threaded through the bindings record; a missing
/// resolver or a missing key degrades to skipping that segment rather
/// than throwing.
/// Header segments use <c>SetStringInfoWithFont</c>'s own font-index
/// argument (<c>1</c> — palette index 1, live-DAT-measured GREEN);
/// body/bonus-body segments use index <c>0</c> (white). <paramref
/// name="resolveText"/> is the DAT string lookup (<c>RetailUiRuntime</c>'s
/// <c>DatStringResolver</c> over table <c>0x23000002</c>) threaded
/// through the bindings record; a missing resolver or a missing key
/// degrades to skipping that segment rather than throwing.
/// </summary>
private static string ComposeDescription(
private static IReadOnlyList<DatRichText.Segment> ComposeSegments(
UiText description,
IRuntimeCharacterCreationView view,
uint heritageId,
Func<string, string?>? resolveText)
{
Vector4 headerColor = DatRichText.PaletteColor(description, 1, new Vector4(0f, 1f, 0f, 1f));
Vector4 bodyColor = DatRichText.PaletteColor(description, 0, Vector4.One);
if (resolveText is null)
{
return view.Options.TryGetHeritage(heritageId, out ChargenHeritageOptions? named)
string name = view.Options.TryGetHeritage(heritageId, out ChargenHeritageOptions? named)
? named.Name
: string.Empty;
return [new DatRichText.Segment(name, bodyColor)];
}
var parts = new List<string>();
var segments = new List<DatRichText.Segment>();
if (resolveText("ID_CharGen_Heritage_StartingSkills_Header") is { } header)
parts.Add(header);
segments.Add(new(header, headerColor));
if (resolveText("ID_CharGen_Heritage_StartingSkills") is { } body)
parts.Add(body);
segments.Add(new(body, bodyColor));
if (resolveText("ID_CharGen_Heritage_BonusSkills_Trained_Header") is { } bonusHeader)
parts.Add(bonusHeader);
segments.Add(new(bonusHeader, headerColor));
if (heritageId != 0
&& BonusSkillsKeyByHeritage.TryGetValue(heritageId, out string? bonusKey)
&& resolveText(bonusKey) is { } bonusBody)
{
parts.Add(bonusBody);
segments.Add(new(bonusBody, bodyColor));
}
return string.Join("\n\n", parts);
return segments;
}
public void Dispose()

View file

@ -69,6 +69,65 @@ internal sealed class CharacterCreationProfessionPage : IDisposable
private sealed record SliderWidgets(UiButton? Lock, UiScrollbar? Slider, UiField? Value);
/// <summary>
/// GF-4b: the six slider containers' name-label CHILD, relative id
/// <c>0x100002ed</c> — <c>gmCGProfessionPage::InitializePage
/// @0x00482e1a-0x00482f1d</c> writes <c>CharGenState::GetAttributeName
/// @0x005C3A20</c>'s literal ONCE at page construction (no per-refresh
/// rewrite anywhere in the decomp — <c>UpdateAttributeValues</c> only
/// touches <c>pSlider</c>/<c>pAttribValue</c>, never this id). Live-DAT-
/// measured: this child resolves as Type 1 (<c>UIElement_Button</c>),
/// matching retail's own declared <c>UIElement_Button*</c> field type
/// that still accepts <c>UIElement_Text::SetText</c> — retail's button
/// class carries the same text-rendering capability
/// <see cref="UiButton.Label"/> already is in this port.
/// </summary>
private const uint SliderNameRelativeId = 0x100002EDu;
/// <summary>
/// GF-3: the description textbox — <c>gmCGProfessionPage::InitializePage
/// @0x00483068</c>'s <c>m_pTextBox</c>.
/// </summary>
private const uint DescriptionTextId = 0x100003E0u;
/// <summary>
/// Root 1d: the page's own backdrop (<c>0x100003d8</c>, live-DAT-
/// measured 7 authored states) switches per selected template —
/// <c>gmCGProfessionPage::UpdateProfession @ 0x004821b0</c>'s per-case
/// <c>eax_2-&gt;SetState(...)</c> calls, keyed by <c>ChargenTemplate</c>
/// index (0=Custom..6=Soldier), NOT the button-id map above.
/// </summary>
private static readonly IReadOnlyDictionary<uint, uint> BackdropStateByTemplate =
new Dictionary<uint, uint>
{
[0u] = 0x1000002Bu, // Custom / Adventurer
[1u] = 0x1000002Cu, // Bow Hunter
[2u] = 0x10000031u, // Swashbuckler
[3u] = 0x1000002Du, // Life Caster
[4u] = 0x1000002Eu, // War Caster
[5u] = 0x1000002Fu, // Wayfarer
[6u] = 0x10000030u, // Soldier
};
/// <summary>
/// GF-3: per-template description string id —
/// <c>gmCGProfessionPage::UpdateProfession @0x00482203-0048233d</c>'s
/// per-case <c>var_a4_1</c> literal, resolved through
/// <c>UIElement_Text::SetStringInfo</c> (NOT ...WithFont — a single
/// plain string, no per-run palette color).
/// </summary>
private static readonly IReadOnlyDictionary<uint, string> DescriptionKeyByTemplate =
new Dictionary<uint, string>
{
[0u] = "ID_CharGen_CustomText",
[1u] = "ID_CharGen_BowText",
[2u] = "ID_CharGen_SwashText",
[3u] = "ID_CharGen_LifeText",
[4u] = "ID_CharGen_WarText",
[5u] = "ID_CharGen_WayText",
[6u] = "ID_CharGen_SoldierText",
};
private readonly CharacterCreationRuntimeBindings _bindings;
private readonly Dictionary<UiButton, uint> _templateButtons = [];
private readonly Dictionary<ChargenAttributeId, SliderWidgets> _sliders = [];
@ -76,6 +135,8 @@ internal sealed class CharacterCreationProfessionPage : IDisposable
private readonly UiButton? _healthValue;
private readonly UiButton? _staminaValue;
private readonly UiButton? _manaValue;
private readonly UiText? _description;
private readonly UiElement? _backdrop;
private bool _disposed;
internal CharacterCreationProfessionPage(
@ -118,22 +179,29 @@ internal sealed class CharacterCreationProfessionPage : IDisposable
value.OnSubmit = text => SetAttributeFromText(capturedAttribute, text);
}
// GF-4b: the name-label child is static per attribute — retail
// writes it exactly once (InitializePage), never on refresh.
if (UiElement.FindDescendant(container, SliderNameRelativeId) is UiButton nameLabel)
nameLabel.Label = AttributeName(attribute);
_sliders[attribute] = new SliderWidgets(lockButton, slider, value);
}
// Live-DAT probe (CharacterCreationLiveDatTests): every one of the
// four display containers (0x100003e2..e5) authors as a Button
// whose Type-12 value child (0x100002f1/0x100002f3) is swallowed by
// UiButton.ConsumesDatChildren — the same "consumed child -> use
// the button's own Label" substitution the Skills page's credits
// meter needed (see CharacterCreationSkillsPage's ctor comment).
// Retail's own DynamicCast(0xc) on the CHILD (not the container)
// still stands as ground truth for the container's ROLE; only
// acdream's widget-level addressability differs (register AD-103).
// GF-4a (Campaign CC gate round 1 Batch C): every one of the four
// display buttons (0x100003e2..e5) authors its CAPTION directly as
// its own P0x17 and carries a SEPARATE, media-less Type-12 value
// child (0x100002f1/0x100002f3 — gmCGProfessionPage::InitializePage
// @0x00482f90-0x00483062). DatWidgetFactory.BuildButton now surfaces
// that child as UiButton.ValueLabel, coexisting with the authored
// Label caption — see that method's own doc comment. Retiring the
// prior Label-clobber substitution (register AD-103).
_availableValue = UiElement.FindDescendant(pageRoot, 0x100003E2u) as UiButton;
_healthValue = UiElement.FindDescendant(pageRoot, 0x100003E3u) as UiButton;
_staminaValue = UiElement.FindDescendant(pageRoot, 0x100003E4u) as UiButton;
_manaValue = UiElement.FindDescendant(pageRoot, 0x100003E5u) as UiButton;
_description = UiElement.FindDescendant(pageRoot, DescriptionTextId) as UiText;
_backdrop = UiElement.FindDescendant(pageRoot, 0x100003D8u);
}
internal void Refresh(
@ -173,6 +241,23 @@ internal sealed class CharacterCreationProfessionPage : IDisposable
SetDisplay(_healthValue, endurance / 2);
SetDisplay(_staminaValue, endurance);
SetDisplay(_manaValue, snapshot.Attributes.Self);
// Root 1d: backdrop art per selected template.
if (_backdrop is IUiDatStateful backdropStateful
&& BackdropStateByTemplate.TryGetValue(snapshot.Template, out uint backdropState))
{
backdropStateful.TrySetRetailState(backdropState);
}
// GF-3: description textbox — one plain segment (SetStringInfo,
// not ...WithFont), so a single DefaultColor run.
if (_description is not null
&& DescriptionKeyByTemplate.TryGetValue(snapshot.Template, out string? key))
{
string? text = _bindings.ResolveText?.Invoke(key);
var segments = new[] { new DatRichText.Segment(text, _description.DefaultColor) };
_description.LinesProvider = () => DatRichText.Compose(_description, segments);
}
}
internal void Randomize(RuntimeCharacterCreationSnapshot snapshot)
@ -205,9 +290,27 @@ internal sealed class CharacterCreationProfessionPage : IDisposable
{
if (display is null)
return;
display.Label = value.ToString(CultureInfo.InvariantCulture);
// GF-4a: the button's OWN P0x17 caption ("Attribute Credits" etc.)
// stays in Label; the live number goes in the coexisting value
// slot DatWidgetFactory.BuildButton surfaced from the button's
// media-less Type-12 child.
display.ValueLabel = value.ToString(CultureInfo.InvariantCulture);
}
/// <summary>Ports <c>CharGenState::GetAttributeName @ 0x005C3A20</c>
/// verbatim — retail hardcodes these six literals directly (not a
/// DAT/localization lookup), so this port does too.</summary>
private static string AttributeName(ChargenAttributeId id) => id switch
{
ChargenAttributeId.Strength => "Strength",
ChargenAttributeId.Endurance => "Endurance",
ChargenAttributeId.Quickness => "Quickness",
ChargenAttributeId.Coordination => "Coordination",
ChargenAttributeId.Focus => "Focus",
ChargenAttributeId.Self => "Self",
_ => string.Empty,
};
private void SelectTemplate(uint templateIndex)
{
if (_disposed)

View file

@ -126,10 +126,13 @@ internal sealed class CharacterCreationSkillsPage : IDisposable
// the mechanism our factory already uses to surface a consumed
// Type-12 child's text (register AD-103).
//
// GF-5 note: this clobbers the button's authored "Available Skill
// Credits" caption (retail's own m_pCreditsMeter is a SEPARATE
// widget from any caption text) — left as-is per the gate-round
// scope (Batch C owns the caption fix).
// GF-4a (Campaign CC gate round 1 Batch C): this used to clobber
// the button's authored "Available Skill Credits" caption (retail's
// own m_pCreditsMeter, 0x100002f3, is a SEPARATE widget from the
// caption text — gmCGSkillsPage::InitializePage @0x00481e1c).
// DatWidgetFactory.BuildButton now surfaces that media-less Type-12
// child as UiButton.ValueLabel, coexisting with Label — see
// Refresh below.
_credits = UiElement.FindDescendant(pageRoot, 0x100003F9u) as UiButton;
_infoTitle = UiElement.FindDescendant(pageRoot, 0x100003FBu) as UiText;
_infoText = UiElement.FindDescendant(pageRoot, 0x100003FCu) as UiText;
@ -150,7 +153,7 @@ internal sealed class CharacterCreationSkillsPage : IDisposable
RefreshRowValues(row, view, snapshot);
if (_credits is { } credits)
credits.Label = snapshot.RemainingSkillCredits.ToString(CultureInfo.InvariantCulture);
credits.ValueLabel = snapshot.RemainingSkillCredits.ToString(CultureInfo.InvariantCulture);
}
private void RebuildRows(IRuntimeCharacterCreationView view, uint heritageId)

View file

@ -103,9 +103,22 @@ internal sealed class CharacterCreationTownPage : IDisposable
if (_description is null)
return;
// GF-11a: gmCGTownPage::SetTownString @ 0x0047c1f0 concatenates
// howTo + a compiled "\n\n%s\n" literal format around the town
// text (the ONE composition site in this batch where retail's OWN
// code — not the authored DAT string content — inserts the blank
// line, confirmed via the format string's raw bytes,
// 0x0079c2d2 = u"\n\n%s\n") into ONE plain SetText — no per-run
// font/color argument, unlike Heritage's WithFont calls. The
// string composition itself was already byte-correct before this
// fix; what was missing was routing it through the same
// escape-normalize + word-wrap path every other description box
// needed (a single un-wrapped line meant the town-specific suffix
// rendered past the clipped viewport, which is why switching towns
// looked like the text never changed).
string composed = ComposeDescription(snapshot.StartArea, _bindings.ResolveText);
_description.LinesProvider = () =>
[new UiText.Line(composed, _description.DefaultColor)];
var segments = new[] { new DatRichText.Segment(composed, _description.DefaultColor) };
_description.LinesProvider = () => DatRichText.Compose(_description, segments);
}
internal void Randomize(IRuntimeCharacterCreationView view)

View file

@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Numerics;
namespace AcDream.App.UI.Layout;
/// <summary>
/// Shared multi-segment rich-text composer for the chargen description
/// boxes (Campaign CC gate round 1 Batch C — GF-2/GF-3/GF-11a, and the
/// Summary how-to text). Ports retail's
/// <c>UIElement_Text::SetStringInfoWithFont</c> /
/// <c>AppendStringInfoWithFont @ 0x00469D70</c> composition model: a text
/// box is built from an ORDERED list of string segments, each carrying its
/// OWN font-color palette index
/// (<c>UIElement_Text::AppendStringInfoWithFont</c>'s
/// <c>SetFontColorHelper</c> -&gt; <c>InqProperty(0x1B)</c> array lookup —
/// see <see cref="AcDream.App.UI.UiText.FontColorPalette"/>).
///
/// <para>
/// The description pages used to bypass this entirely: they assigned a raw
/// <c>LinesProvider</c> lambda returning ONE unwrapped <see cref="AcDream.App.UI.UiText.Line"/>
/// per composed string, with no escape-normalize and no word-wrap. Two
/// concrete symptoms this caused: literal two-character <c>"\n"</c>
/// escapes rendered as backslash-n instead of a real line break (the DAT
/// stores that literal escape — <c>DatWidgetFactory.BuildText</c>'s own
/// authored-string path already normalizes it for single-element authored
/// captions; this helper reproduces the SAME normalize for
/// runtime-composed multi-segment text), and — for the Town page
/// specifically — an unwrapped single line meant the town-specific SUFFIX
/// of the composed string rendered far outside the box's clipped viewport,
/// so switching towns looked like "the text never changes" even though the
/// underlying string genuinely did (only its INVISIBLE tail differed).
/// </para>
/// </summary>
internal static class DatRichText
{
/// <summary>One composed segment: text plus the color it should render
/// in. A null or empty <see cref="Text"/> is silently skipped (mirrors
/// retail's own null-string-info no-op guards throughout this text
/// composition family).</summary>
public readonly record struct Segment(string? Text, Vector4 Color);
/// <summary>
/// Escape-normalizes and word-wraps every segment (independently, so
/// each segment's wrapped lines keep ITS OWN color), then concatenates
/// the results in order. No separator is inserted between segments —
/// retail's own composition calls concatenate directly
/// (<c>AppendStringInfoWithFont</c>/<c>append_n_chars</c> with no
/// interposed literal), so any blank-line spacing between sections
/// comes from the authored DAT string content itself, not from code
/// here.
/// </summary>
public static IReadOnlyList<UiText.Line> Compose(
UiText target,
IReadOnlyList<Segment> segments)
{
ArgumentNullException.ThrowIfNull(target);
ArgumentNullException.ThrowIfNull(segments);
var lines = new List<UiText.Line>();
float maximumWidth = MathF.Max(1f, target.Width - 2f * target.Padding);
Func<string, float> measure = target.DatFont is { } font
? font.MeasureWidth
: static value => value.Length * 8f;
foreach (Segment segment in segments)
{
if (string.IsNullOrEmpty(segment.Text))
continue;
// The installed DAT stores the LITERAL two-character escape
// "\n" (0x5C 0x6E), not a real line break — same normalize
// DatWidgetFactory.BuildText's authored-string path already
// applies for single-element authored captions.
string normalized = segment.Text
.Replace("\\n", "\n")
.Replace("\r", string.Empty);
foreach (string wrapped in UiText.WrapWords(normalized, measure, maximumWidth))
lines.Add(new UiText.Line(wrapped, segment.Color));
}
return lines;
}
/// <summary>
/// Resolves <paramref name="target"/>'s own authored font-color
/// palette (dat property <c>0x1B</c>) entry at <paramref name="index"/>,
/// falling back to <paramref name="fallback"/> when the palette is
/// absent or too short. Mirrors the same fallback shape
/// <c>CharacterStatController.BuildSelectedTitleRuns</c> already uses
/// for its own palette-indexed colors.
/// </summary>
public static Vector4 PaletteColor(UiText target, int index, Vector4 fallback) =>
index >= 0 && index < target.FontColorPalette.Count
? target.FontColorPalette[index]
: fallback;
}

View file

@ -933,6 +933,39 @@ public static class DatWidgetFactory
ElementReader.BuildPerStateColorMap(labelInfo, 0x1Bu),
ElementReader.BuildPerStateBoolMap(labelInfo, 0x21u));
// GF-4a (Campaign CC gate round 1 Batch C): retail's chargen
// display buttons author the caption directly as THEIR OWN P0x17
// (so `label` above resolved from `info` itself, not a lifted
// child) AND carry a SEPARATE, media-less Type-12 child for the
// live value (gmCGProfessionPage::InitializePage
// @0x00482f90-0x00483062, gmCGSkillsPage::InitializePage
// @0x00481e1c — live-DAT-measured: exactly one Type-12 child, zero
// StateMedia entries). Gated tightly to that exact shape so this
// stays a no-op for every other button (a lifted-caption button
// never reaches here with labelInfo==info; a button with an icon/
// face child instead of a value child has no media-less Type-12
// child to find).
if (ReferenceEquals(labelInfo, info) && label is not null)
{
ElementInfo? valueChild = info.Children.FirstOrDefault(
child => child.Type == 12u && child.StateMedia.Count == 0);
if (valueChild is not null)
{
button.ValueBox = (valueChild.X, valueChild.Y, valueChild.Width, valueChild.Height);
button.ValueFont = valueChild.FontDid != 0u && fontResolve is not null
? fontResolve(valueChild.FontDid) ?? elementFont
: elementFont;
button.ValueColor = valueChild.FontColor ?? System.Numerics.Vector4.One;
button.ValueAlign = valueChild.HJustify == HJustify.Left
? UiButton.LabelAlignment.Left
: UiButton.LabelAlignment.Center;
// Seed with whatever the child itself authors (typically
// blank) so an unbound button doesn't draw stray leftover
// text before a controller writes a real value.
button.ValueLabel = ResolveAuthoredString(valueChild, stringResolve);
}
}
return button;
}

View file

@ -179,6 +179,43 @@ public sealed class UiButton : UiElement, IUiGlobalTimeListener, IUiDatStateful
/// </summary>
public (float X, float Y, float Width, float Height)? LabelBox { get; set; }
/// <summary>
/// GF-4a (Campaign CC gate round 1 Batch C): optional secondary VALUE
/// text, coexisting with <see cref="Label"/> (the authored CAPTION).
/// Retail's chargen display buttons (Attribute/Skill Credits, Health,
/// Stamina, Mana — <c>0x100003e2-e5</c>, <c>0x100003f9</c>) author the
/// caption directly as this element's own dat property <c>0x17</c>
/// AND carry a SEPARATE, media-less Type-12 child for the live value
/// (<c>gmCGProfessionPage::InitializePage @0x00482f90-0x00483062</c>,
/// <c>gmCGSkillsPage::InitializePage @0x00481e1c</c>) —
/// <see cref="UiButton"/> consumes ALL of its dat children
/// (<see cref="ConsumesDatChildren"/>), which used to mean a page
/// controller had nowhere faithful to put the value except
/// overwriting <see cref="Label"/> itself, destroying the caption.
/// <see cref="Layout.DatWidgetFactory.BuildButton"/> now surfaces that
/// child's geometry/font/color here instead. Null (default) draws
/// nothing extra — every pre-existing button that only ever wrote
/// <see cref="Label"/> is unaffected.
/// </summary>
public string? ValueLabel { get; set; }
/// <summary>Dat font for <see cref="ValueLabel"/>.</summary>
public UiDatFont? ValueFont { get; set; }
/// <summary>Color for <see cref="ValueLabel"/> (default white).</summary>
public Vector4 ValueColor { get; set; } = Vector4.One;
/// <summary>Authored rectangle for <see cref="ValueLabel"/>, LOCAL to
/// this button — the lifted value child's own rect
/// (<see cref="Layout.DatWidgetFactory.BuildButton"/> sets this). Null
/// (no value child found) means <see cref="ValueLabel"/> is never set
/// either, so this is never read in that case.</summary>
public (float X, float Y, float Width, float Height)? ValueBox { get; set; }
/// <summary>Horizontal alignment of <see cref="ValueLabel"/> within
/// <see cref="ValueBox"/> — the lifted child's own authored justify.</summary>
public LabelAlignment ValueAlign { get; set; } = LabelAlignment.Center;
/// <summary>Label horizontal alignment options.</summary>
public enum LabelAlignment { Center, Left }
@ -453,6 +490,19 @@ public sealed class UiButton : UiElement, IUiGlobalTimeListener, IUiDatStateful
ctx.DrawStringDat(lf, label, tx, ty, LabelColor, Outline, OutlineColor);
}
if (ValueLabel is { Length: > 0 } value && ValueFont is { } vf)
{
float boxX = ValueBox?.X ?? 0f;
float boxY = ValueBox?.Y ?? 0f;
float boxWidth = ValueBox?.Width ?? Width;
float boxHeight = ValueBox?.Height ?? Height;
float vx = ValueAlign == LabelAlignment.Left
? boxX + LabelOffsetX
: boxX + (boxWidth - vf.MeasureWidth(value)) * 0.5f;
float vy = boxY + (boxHeight - vf.LineHeight) * 0.5f;
ctx.DrawStringDat(vf, value, vx, vy, ValueColor, Outline, OutlineColor);
}
uint dragSprite = _itemDragAcceptance switch
{
ItemDragAcceptance.Accept => ItemDragAcceptSprite,