Task G1: two gaps blocked chat window static sprite elements from rendering. Change 1 — DatWidgetFactory: only skip Type-12 elements that have no own state media (pure style prototypes). A Type-12 element that carries sprites (e.g. a chat Send button whose derived Type-0 element inherited Type 12 from its base prototype) now renders as a UiDatElement. Change 2 — ElementInfo: add DefaultStateName field (string, default ""). Change 3 — LayoutImporter.ToInfo: read ElementDesc.DefaultState.ToString() into DefaultStateName; normalize Undef/Undefined/0 sentinels to "". Change 4 — ElementReader.Merge: inherit DefaultStateName (derived wins if non-empty, else base). Change 5 — UiDatElement ctor: initialize ActiveState to DefaultStateName when set; else "Normal" when a Normal-state sprite is present (retail's implicit default for buttons/tabs); else "" (DirectState). This makes the Send button, max/min button, and numbered tabs render their default sprite without requiring explicit state assignment at runtime. Vitals neutrality: all vitals chrome/grip elements carry DirectState-only sprites with no "Normal" named state and DefaultStateName="" (Undef in dat), so their ActiveState stays "" and their existing conformance tests are unaffected. Vitals text labels (Type 0→12 via Merge, no StateMedia) are still skipped by the refined Type-12 guard (StateMedia.Count==0). Tests: 4 new tests (2 in DatWidgetFactoryTests, 3 in UiDatElementTests). All 386 pass; 387 total (1 pre-existing skip). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
90 lines
3.4 KiB
C#
90 lines
3.4 KiB
C#
using AcDream.App.UI.Layout;
|
|
namespace AcDream.App.Tests.UI.Layout;
|
|
|
|
public class UiDatElementTests
|
|
{
|
|
[Fact]
|
|
public void ActiveMedia_PrefersNamedStateOverDirect()
|
|
{
|
|
var info = new ElementInfo();
|
|
info.StateMedia[""] = (0x06000001, 1); // DirectState (DrawMode Normal=1)
|
|
info.StateMedia["ShowDetail"] = (0x06000002, 3); // named (Alphablend=3)
|
|
var e = new UiDatElement(info, _ => (0, 0, 0)) { ActiveState = "ShowDetail" };
|
|
Assert.Equal(0x06000002u, e.ActiveMedia().File);
|
|
Assert.Equal(3, e.ActiveMedia().DrawMode);
|
|
e.ActiveState = "";
|
|
Assert.Equal(0x06000001u, e.ActiveMedia().File);
|
|
Assert.Equal(1, e.ActiveMedia().DrawMode);
|
|
}
|
|
|
|
[Fact]
|
|
public void ActiveMedia_NoMedia_ReturnsZero()
|
|
{
|
|
var e = new UiDatElement(new ElementInfo(), _ => (0, 0, 0));
|
|
Assert.Equal(0u, e.ActiveMedia().File);
|
|
Assert.Equal(0, e.ActiveMedia().DrawMode);
|
|
}
|
|
|
|
[Fact]
|
|
public void ActiveMedia_MissingNamedState_FallsBackToDirect()
|
|
{
|
|
var info = new ElementInfo();
|
|
info.StateMedia[""] = (0x06000005, 1);
|
|
var e = new UiDatElement(info, _ => (0, 0, 0)) { ActiveState = "NoSuchState" };
|
|
Assert.Equal(0x06000005u, e.ActiveMedia().File);
|
|
}
|
|
|
|
// ── G1 tests: DefaultStateName + "Normal" implicit default ───────────────
|
|
|
|
/// <summary>
|
|
/// Task G1 change 5: when an element has no DefaultStateName but does have a "Normal"
|
|
/// state sprite, the ctor should default ActiveState to "Normal" so the element
|
|
/// renders its normal-state sprite without requiring explicit state assignment.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UiDatElement_DefaultsActiveStateToNormal_WhenNormalPresent()
|
|
{
|
|
var info = new ElementInfo();
|
|
info.StateMedia["Normal"] = (0x0000AAAAu, 1);
|
|
info.StateMedia["Hover"] = (0x0000BBBBu, 1);
|
|
|
|
var e = new UiDatElement(info, _ => (0, 0, 0));
|
|
|
|
// Should have defaulted to "Normal" state.
|
|
Assert.Equal(0x0000AAAAu, e.ActiveMedia().File);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Task G1 change 5: when DefaultStateName is set (e.g. "Minimized"),
|
|
/// it takes priority over the "Normal" implicit default.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UiDatElement_DefaultsActiveStateToDefaultStateName_WhenSet()
|
|
{
|
|
var info = new ElementInfo { DefaultStateName = "Minimized" };
|
|
info.StateMedia["Minimized"] = (0x0000BBBBu, 1);
|
|
info.StateMedia["Maximized"] = (0x0000CCCCu, 1);
|
|
info.StateMedia["Normal"] = (0x0000DDDDu, 1);
|
|
|
|
var e = new UiDatElement(info, _ => (0, 0, 0));
|
|
|
|
// DefaultStateName "Minimized" wins over "Normal" implicit default.
|
|
Assert.Equal(0x0000BBBBu, e.ActiveMedia().File);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Task G1 change 5: elements with only a DirectState sprite and no "Normal" state
|
|
/// should still default to "" (DirectState) — no regression for chrome/grip elements.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UiDatElement_NoDefaultStateName_NoNormal_DefaultsToDirectState()
|
|
{
|
|
var info = new ElementInfo();
|
|
info.StateMedia[""] = (0x06007777u, 1); // DirectState only (e.g. vitals chrome corner)
|
|
|
|
var e = new UiDatElement(info, _ => (0, 0, 0));
|
|
|
|
// No DefaultStateName, no "Normal" state → ActiveState stays "" (DirectState).
|
|
Assert.Equal(0x06007777u, e.ActiveMedia().File);
|
|
}
|
|
}
|