This reverts ceec3bc4. Two independent reasons, either sufficient.
The rendering regression. The slice deleted TextRenderGlStateScope, which
saved GL_MULTISAMPLE and GL_SAMPLE_ALPHA_TO_COVERAGE on entry, disabled them
for the text pass, and restored them on exit (TextRenderGlStateScope.cs:111-112
and 153-154 at the parent commit). Its replacement bakes that state into the
text pipeline but nothing restores it, and GlGpuPassEncoder.Dispose does not
either. Every world renderer is still raw GL at this point in the campaign, so
from the first UI frame onward the world drew with multisampling disabled.
The offline pixel gate caught it: 1,791 of 563,200 compared pixels differed,
0.318% against a 0.001 threshold. The commit message attributed this to
wall-clock-driven ambient animation shifting phase, and committed through the
failure. That explanation does not survive its own control: capturing twice at
the reverted-to commit differs by 19 pixels and twice at the slice's own commit
by 8, while base-versus-head differs by 1,791 - a 224x gap that no shared-noise
source explains. An amplified difference image settles it visually: the changed
pixels are the silhouette edges of every tree, building and rock, with terrain
interiors, water and the entire UI untouched. That is the signature of losing
edge antialiasing, not of animated sprites.
This is the exact failure mode two existing memory notes already warn about -
a mid-frame renderer must set every GL state it uses rather than inherit it,
and issue #52's lesson that a rendering migration must audit per-pass GL state
before declaring itself done.
The scope. The brief was three small leaf renderers plus additive frame-
lifecycle wiring, roughly ten files. The commit changed 334 files with 3,665
insertions and 3,845 deletions, including 323 public-to-internal visibility
conversions across the App assembly, 55 test files, two retired conformance
tests, and a self-described temporary escape hatch for bridging raw-GL viewport
textures. Even without the regression, that is not separable into the part
worth keeping and the part worth dropping.
Reverting rather than patching because the good work here - the RHI frame
lifecycle wiring and a genuine render-state-cache staleness fix - is small
enough to redo cleanly against a tightened spec, while untangling it from 300+
files of unrelated churn is not.
Post-revert: Release build clean, App suite back to 3,843 passed / 3 skipped,
offline pixel gate passing at 19 differing pixels.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
309 lines
14 KiB
C#
309 lines
14 KiB
C#
using AcDream.App.UI;
|
|
using AcDream.App.UI.Layout;
|
|
using AcDream.Core.Spells;
|
|
|
|
namespace AcDream.App.Tests.UI.Layout;
|
|
|
|
public sealed class EffectsUiControllerTests
|
|
{
|
|
private static (uint, int, int) NoTex(uint _) => (0u, 0, 0);
|
|
private static EffectRowTemplateFactory Templates()
|
|
=> new(FixtureLoader.LoadEffectRowTemplateInfos(), NoTex, defaultFont: null);
|
|
|
|
[Fact]
|
|
public void AuthoredEffectRowTemplate_HasRetailIconNameDurationAndSelectionStates()
|
|
{
|
|
ElementInfo row = FixtureLoader.LoadEffectRowTemplateInfos();
|
|
|
|
Assert.Equal(EffectsUiController.RowTemplateId, row.Id);
|
|
Assert.Equal((300f, 32f), (row.Width, row.Height));
|
|
Assert.Contains(UiButtonStateMachine.Normal, row.States.Keys);
|
|
Assert.Contains(UiButtonStateMachine.Highlight, row.States.Keys);
|
|
Assert.Equal((0f, 32f),
|
|
(FindInfo(row, EffectsUiController.RowIconId)!.X,
|
|
FindInfo(row, EffectsUiController.RowIconId)!.Width));
|
|
Assert.Equal((37f, 188f),
|
|
(FindInfo(row, EffectsUiController.RowLabelId)!.X,
|
|
FindInfo(row, EffectsUiController.RowLabelId)!.Width));
|
|
Assert.Equal((225f, 50f),
|
|
(FindInfo(row, EffectsUiController.RowDurationId)!.X,
|
|
FindInfo(row, EffectsUiController.RowDurationId)!.Width));
|
|
}
|
|
|
|
[Fact]
|
|
public void Rebuild_DoesNotAutoSelectFirstEffect_AndClearsRemovedSelection()
|
|
{
|
|
var table = SpellTable.LoadFromReader(new StringReader(
|
|
"Spell ID,Name,Flags [Hex]\n42,Boon,0x4\n"));
|
|
var spellbook = new Spellbook(table);
|
|
var root = new UiPanel { Width = 160f, Height = 100f };
|
|
var list = new UiItemList(NoTex) { Width = 160f, Height = 64f };
|
|
var info = new UiText { Width = 160f, Height = 32f };
|
|
root.AddChild(list);
|
|
root.AddChild(info);
|
|
var layout = new ImportedLayout(root, new Dictionary<uint, UiElement>
|
|
{
|
|
[EffectsUiController.ListId] = list,
|
|
[EffectsUiController.InfoTextId] = info,
|
|
});
|
|
using EffectsUiController controller = EffectsUiController.Bind(
|
|
layout, spellbook, positive: true, () => 0d, NoTex, id => id,
|
|
Templates(), "SELECT A SPELL")!;
|
|
|
|
Assert.False(info.PreserveEndOnLayout);
|
|
spellbook.OnEnchantmentAdded(new ActiveEnchantmentRecord(
|
|
42u, 1u, 60f, 1u, Bucket: 1u, SpellCategory: 42u));
|
|
spellbook.OnEnchantmentAdded(new ActiveEnchantmentRecord(
|
|
42u, 2u, 60f, 1u, Bucket: 4u, SpellCategory: 42u));
|
|
spellbook.OnEnchantmentAdded(new ActiveEnchantmentRecord(
|
|
42u, 3u, 60f, 1u, Bucket: 8u, SpellCategory: 42u));
|
|
Assert.Null(controller.SelectedSpellId);
|
|
Assert.Equal("SELECT A SPELL", Assert.Single(info.LinesProvider()).Text);
|
|
Assert.Equal(1, list.GetNumUIItems());
|
|
UiTemplateListSlot row = Assert.IsType<UiTemplateListSlot>(list.GetItem(0));
|
|
UiText duration = Assert.IsType<UiText>(
|
|
row.Content.FindElement(EffectsUiController.RowDurationId));
|
|
Assert.Equal("1:00", Assert.Single(duration.LinesProvider()).Text);
|
|
row.OnEvent(new UiEvent(0, row, UiEventType.Click));
|
|
Assert.Equal(42u, controller.SelectedSpellId);
|
|
Assert.Equal(["Boon", "", ""], info.LinesProvider().Select(line => line.Text));
|
|
|
|
spellbook.OnEnchantmentRemoved(1u, 42u);
|
|
Assert.Null(controller.SelectedSpellId);
|
|
}
|
|
|
|
[Fact]
|
|
public void DuplicateLayersOfSameSpell_ShareRetailSelection()
|
|
{
|
|
var table = SpellTable.LoadFromReader(new StringReader(
|
|
"Spell ID,Name,Flags [Hex]\n42,Boon,0x4\n"));
|
|
var spellbook = new Spellbook(table);
|
|
var root = new UiPanel { Width = 160f, Height = 100f };
|
|
var list = new UiItemList(NoTex) { Width = 160f, Height = 64f };
|
|
root.AddChild(list);
|
|
var layout = new ImportedLayout(root, new Dictionary<uint, UiElement>
|
|
{
|
|
[EffectsUiController.ListId] = list,
|
|
});
|
|
using EffectsUiController controller = EffectsUiController.Bind(
|
|
layout, spellbook, positive: true, () => 0d, NoTex, id => id,
|
|
Templates(), "SELECT A SPELL")!;
|
|
spellbook.OnEnchantmentAdded(new ActiveEnchantmentRecord(
|
|
42u, 1u, 60f, 1u, Bucket: 1u, SpellCategory: 100u));
|
|
spellbook.OnEnchantmentAdded(new ActiveEnchantmentRecord(
|
|
42u, 2u, 60f, 2u, Bucket: 2u, SpellCategory: 101u));
|
|
|
|
UiTemplateListSlot first = Assert.IsType<UiTemplateListSlot>(list.GetItem(0));
|
|
UiTemplateListSlot second = Assert.IsType<UiTemplateListSlot>(list.GetItem(1));
|
|
first.OnEvent(new UiEvent(0, first, UiEventType.Click));
|
|
|
|
Assert.Equal(42u, controller.SelectedSpellId);
|
|
Assert.True(first.Selected);
|
|
Assert.True(second.Selected);
|
|
|
|
second.OnEvent(new UiEvent(0, second, UiEventType.Click));
|
|
Assert.Null(controller.SelectedSpellId);
|
|
Assert.False(first.Selected);
|
|
Assert.False(second.Selected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void SelectedEffect_WrapsDescription_AndBindsAuthoredInfoScrollbar(
|
|
bool positive)
|
|
{
|
|
string flags = positive ? "0x4" : "0x0";
|
|
var table = SpellTable.LoadFromReader(new StringReader(
|
|
"Spell ID,Name,Description,Flags [Hex]\n"
|
|
+ $"42,Boon,This description contains enough words to wrap across several lines.,{flags}\n"));
|
|
var spellbook = new Spellbook(table);
|
|
ImportedLayout layout = LayoutImporter.Build(
|
|
positive
|
|
? FixtureLoader.LoadPositiveEffectsInfos()
|
|
: FixtureLoader.LoadNegativeEffectsInfos(),
|
|
NoTex,
|
|
datFont: null);
|
|
UiText info = Assert.IsType<UiText>(
|
|
layout.FindElement(EffectsUiController.InfoTextId));
|
|
info.Width = 96f;
|
|
|
|
using EffectsUiController controller = EffectsUiController.Bind(
|
|
layout, spellbook, positive, () => 0d, NoTex, id => id,
|
|
Templates(), "SELECT A SPELL")!;
|
|
spellbook.OnEnchantmentAdded(new ActiveEnchantmentRecord(
|
|
42u, 1u, 60f, 1u, Bucket: 1u, SpellCategory: 42u));
|
|
UiElement listHost = Assert.IsType<UiDatElement>(
|
|
layout.FindElement(EffectsUiController.ListId));
|
|
UiItemList list = Assert.IsType<UiItemList>(Assert.Single(listHost.Children));
|
|
UiTemplateListSlot row = Assert.IsType<UiTemplateListSlot>(list.GetItem(0));
|
|
row.OnEvent(new UiEvent(0, row, UiEventType.Click));
|
|
|
|
IReadOnlyList<UiText.Line> lines = info.LinesProvider();
|
|
Assert.Equal("Boon", lines[0].Text);
|
|
Assert.Equal(string.Empty, lines[1].Text);
|
|
Assert.True(lines.Count > 3);
|
|
Assert.All(lines, line => Assert.True(line.Text.Length <= 12));
|
|
Assert.True(info.WheelScrollEnabled);
|
|
Assert.False(info.ClickThrough);
|
|
UiScrollbar listScrollbar = Assert.IsType<UiScrollbar>(
|
|
layout.FindElement(EffectsUiController.ListScrollbarId));
|
|
UiScrollbar infoScrollbar = Assert.IsType<UiScrollbar>(
|
|
layout.FindElement(EffectsUiController.InfoScrollbarId));
|
|
Assert.Same(list.Scroll, listScrollbar.Model);
|
|
Assert.Same(info.Scroll, infoScrollbar.Model);
|
|
|
|
info.Scroll.SetExtents(contentHeight: 100, viewHeight: 20);
|
|
Assert.True(info.OnEvent(new UiEvent(
|
|
0, info, UiEventType.Scroll, Data0: -1)));
|
|
Assert.Equal(info.Scroll.LineHeight, info.Scroll.ScrollY);
|
|
}
|
|
|
|
[Fact]
|
|
public void PermanentEffect_LeavesRetailDurationColumnEmpty()
|
|
{
|
|
var table = SpellTable.LoadFromReader(new StringReader(
|
|
"Spell ID,Name,Flags [Hex]\n42,Boon,0x4\n"));
|
|
var spellbook = new Spellbook(table);
|
|
var root = new UiPanel { Width = 160f, Height = 100f };
|
|
var list = new UiItemList(NoTex) { Width = 160f, Height = 64f };
|
|
root.AddChild(list);
|
|
var layout = new ImportedLayout(root, new Dictionary<uint, UiElement>
|
|
{
|
|
[EffectsUiController.ListId] = list,
|
|
});
|
|
using EffectsUiController controller = EffectsUiController.Bind(
|
|
layout, spellbook, positive: true, () => 0d, NoTex, id => id,
|
|
Templates(), "SELECT A SPELL")!;
|
|
|
|
spellbook.OnEnchantmentAdded(new ActiveEnchantmentRecord(
|
|
42u, 1u, -1f, 1u, Bucket: 1u, SpellCategory: 42u));
|
|
|
|
UiTemplateListSlot row = Assert.IsType<UiTemplateListSlot>(list.GetItem(0));
|
|
UiText duration = Assert.IsType<UiText>(
|
|
row.Content.FindElement(EffectsUiController.RowDurationId));
|
|
Assert.Equal(string.Empty, Assert.Single(duration.LinesProvider()).Text);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void AuthoredEffectsFixture_InheritsListAndInfo_AndBinds(bool positive)
|
|
{
|
|
ElementInfo info = positive
|
|
? FixtureLoader.LoadPositiveEffectsInfos()
|
|
: FixtureLoader.LoadNegativeEffectsInfos();
|
|
uint expectedRoot = positive
|
|
? EffectsUiController.PositiveRootId
|
|
: EffectsUiController.NegativeRootId;
|
|
Assert.Equal(expectedRoot, info.Id);
|
|
Assert.Equal(0x1000001Bu, info.Type);
|
|
Assert.Equal(300f, info.Width);
|
|
Assert.Equal(362f, info.Height);
|
|
Assert.True(info.TryGetEffectiveProperty(0x1000000Cu, out UiPropertyValue effectType));
|
|
Assert.Equal(UiPropertyKind.Enum, effectType.Kind);
|
|
Assert.Equal(positive ? 1u : 2u, effectType.UnsignedValue);
|
|
Assert.Equal(
|
|
positive,
|
|
info.TryGetEffectiveBool(0x10000049u, out bool restorePrevious)
|
|
&& restorePrevious);
|
|
|
|
ElementInfo[] children = info.Children.OrderBy(child => child.ReadOrder).ToArray();
|
|
Assert.Equal(
|
|
[0x100000FCu, 0x10000120u, 0x10000123u, 0x10000124u, 0x10000125u],
|
|
children.Select(child => child.Id));
|
|
Assert.Equal([1u, 2u, 3u, 4u, 5u], children.Select(child => child.ReadOrder));
|
|
Assert.Equal(children.Length, children.Select(child => child.Id).Distinct().Count());
|
|
ElementInfo listInfo = Assert.Single(children, child => child.Id == EffectsUiController.ListId);
|
|
Assert.Equal(5u, listInfo.Type);
|
|
Assert.Equal(300f, listInfo.Width);
|
|
Assert.Equal(249f, listInfo.Height);
|
|
Assert.Equal(12u, FindInfo(info, EffectsUiController.InfoTextId)?.Type);
|
|
|
|
ImportedLayout layout = LayoutImporter.Build(info, NoTex, datFont: null);
|
|
var spellbook = new Spellbook();
|
|
int closes = 0;
|
|
|
|
using EffectsUiController? controller = EffectsUiController.Bind(
|
|
layout, spellbook, positive, () => 0d, NoTex, id => id,
|
|
Templates(), "SELECT A SPELL", () => closes++);
|
|
|
|
Assert.NotNull(controller);
|
|
Assert.NotNull(layout.FindElement(EffectsUiController.ListId));
|
|
Assert.IsType<UiText>(layout.FindElement(EffectsUiController.InfoTextId));
|
|
Assert.IsType<UiScrollbar>(layout.FindElement(EffectsUiController.ListScrollbarId));
|
|
Assert.IsType<UiScrollbar>(layout.FindElement(EffectsUiController.InfoScrollbarId));
|
|
Assert.Equal(expectedRoot, layout.Root.DatElementId);
|
|
UiButton close = Assert.IsType<UiButton>(layout.FindElement(EffectsUiController.CloseId));
|
|
close.OnEvent(new UiEvent(0, close, UiEventType.Click));
|
|
Assert.Equal(1, closes);
|
|
|
|
uint panelId = positive
|
|
? RetailPanelCatalog.PositiveEffects
|
|
: RetailPanelCatalog.NegativeEffects;
|
|
Assert.True(RetailPanelCatalog.TryGetWindowName(panelId, out string windowName));
|
|
Assert.Equal(
|
|
positive ? WindowNames.PositiveEffects : WindowNames.NegativeEffects,
|
|
windowName);
|
|
Assert.DoesNotContain(
|
|
RetailPanelCatalog.ToolbarPanels,
|
|
entry => entry.PanelId == panelId);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void AuthoredRestorePreviousProperty_DrivesRetailPanelLifecycle(bool positive)
|
|
{
|
|
ElementInfo info = positive
|
|
? FixtureLoader.LoadPositiveEffectsInfos()
|
|
: FixtureLoader.LoadNegativeEffectsInfos();
|
|
var visible = new Dictionary<string, bool>(StringComparer.Ordinal)
|
|
{
|
|
[WindowNames.Inventory] = false,
|
|
[positive ? WindowNames.PositiveEffects : WindowNames.NegativeEffects] = false,
|
|
};
|
|
var panelUi = new RetailPanelUiController(
|
|
name => visible[name],
|
|
name =>
|
|
{
|
|
visible[name] = true;
|
|
return true;
|
|
},
|
|
name =>
|
|
{
|
|
visible[name] = false;
|
|
return true;
|
|
});
|
|
uint effectsPanel = positive
|
|
? RetailPanelCatalog.PositiveEffects
|
|
: RetailPanelCatalog.NegativeEffects;
|
|
string effectsWindow = positive
|
|
? WindowNames.PositiveEffects
|
|
: WindowNames.NegativeEffects;
|
|
panelUi.Register(RetailPanelCatalog.Inventory, WindowNames.Inventory);
|
|
panelUi.Register(
|
|
effectsPanel,
|
|
effectsWindow,
|
|
info);
|
|
|
|
panelUi.SetPanelVisibility(RetailPanelCatalog.Inventory, visible: true);
|
|
panelUi.SetPanelVisibility(effectsPanel, visible: true);
|
|
panelUi.SetPanelVisibility(effectsPanel, visible: false);
|
|
|
|
Assert.Equal(positive, visible[WindowNames.Inventory]);
|
|
Assert.False(visible[effectsWindow]);
|
|
Assert.Equal(
|
|
positive ? RetailPanelCatalog.Inventory : null,
|
|
panelUi.ActivePanelId);
|
|
}
|
|
|
|
private static ElementInfo? FindInfo(ElementInfo root, uint id)
|
|
{
|
|
if (root.Id == id) return root;
|
|
foreach (ElementInfo child in root.Children)
|
|
if (FindInfo(child, id) is { } found)
|
|
return found;
|
|
return null;
|
|
}
|
|
}
|