Fix 1: Added a <para> to the VitalsController class summary citing docs/research/2026-06-15-layoutdesc-format.md §11 as the source of the three dat element ids, giving a paper trail back to the evidence per the project's cite-in-comments rule. Fix 2: Changed FakeLayout in VitalsBindingTests to accept (uint id, UiElement e) tuples instead of (string idHex, UiElement e), and updated all three call sites to pass VitalsController.Health/.Stamina/.Mana. Tests now follow the constants automatically if they ever change rather than silently passing with stale hex literals. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
2.9 KiB
C#
68 lines
2.9 KiB
C#
using System;
|
|
|
|
namespace AcDream.App.UI.Layout;
|
|
|
|
/// <summary>
|
|
/// Per-window controller for the vitals layout (LayoutDesc 0x2100006C).
|
|
/// Mirrors retail <c>gmVitalsUI::PostInit</c>: grab the three meter elements
|
|
/// by their dat element ids and bind live data providers (fill fraction + cur/max
|
|
/// text) to each. This is the ONLY per-window code in the whole importer — pure
|
|
/// data wiring, not graphics.
|
|
///
|
|
/// <para>The slice sprites + dat font on each <see cref="UiMeter"/> are already
|
|
/// set by <see cref="DatWidgetFactory"/> during tree construction; this controller
|
|
/// only binds the dynamic vitals data. Do not touch meter rendering fields here.</para>
|
|
///
|
|
/// <para>Element ids confirmed from
|
|
/// <c>docs/research/2026-06-15-layoutdesc-format.md §11</c>
|
|
/// (vitals window 0x2100006C dump).</para>
|
|
/// </summary>
|
|
public static class VitalsController
|
|
{
|
|
/// <summary>Dat element id for the Health meter (0x100000E6).</summary>
|
|
public const uint Health = 0x100000E6;
|
|
/// <summary>Dat element id for the Stamina meter (0x100000EC).</summary>
|
|
public const uint Stamina = 0x100000EC;
|
|
/// <summary>Dat element id for the Mana meter (0x100000EE).</summary>
|
|
public const uint Mana = 0x100000EE;
|
|
|
|
/// <summary>
|
|
/// Bind live vitals data providers to the Health, Stamina, and Mana meter
|
|
/// elements found in <paramref name="layout"/>. Any meter whose id is absent
|
|
/// from the layout is silently skipped — partial layouts (e.g. test fakes)
|
|
/// do not cause errors.
|
|
/// </summary>
|
|
/// <param name="layout">Imported vitals layout tree.</param>
|
|
/// <param name="healthPct">Provider returning Health fill fraction [0..1].</param>
|
|
/// <param name="staminaPct">Provider returning Stamina fill fraction [0..1].</param>
|
|
/// <param name="manaPct">Provider returning Mana fill fraction [0..1].</param>
|
|
/// <param name="healthText">Provider returning Health "cur/max" overlay text.</param>
|
|
/// <param name="staminaText">Provider returning Stamina "cur/max" overlay text.</param>
|
|
/// <param name="manaText">Provider returning Mana "cur/max" overlay text.</param>
|
|
public static void Bind(
|
|
ImportedLayout layout,
|
|
Func<float> healthPct,
|
|
Func<float> staminaPct,
|
|
Func<float> manaPct,
|
|
Func<string> healthText,
|
|
Func<string> staminaText,
|
|
Func<string> manaText)
|
|
{
|
|
BindMeter(layout, Health, healthPct, healthText);
|
|
BindMeter(layout, Stamina, staminaPct, staminaText);
|
|
BindMeter(layout, Mana, manaPct, manaText);
|
|
}
|
|
|
|
private static void BindMeter(
|
|
ImportedLayout layout, uint id,
|
|
Func<float> pct,
|
|
Func<string> text)
|
|
{
|
|
if (layout.FindElement(id) is UiMeter m)
|
|
{
|
|
m.Fill = () => pct();
|
|
m.Label = () => text();
|
|
}
|
|
// Silently skip if the id is absent — missing meters are not an error.
|
|
}
|
|
}
|