fix(studio): switch character skills tab on visible list

This commit is contained in:
Erik 2026-06-26 17:08:24 +02:00
parent e7e943a580
commit 5f92493742
2 changed files with 94 additions and 1 deletions

View file

@ -678,6 +678,46 @@ public class CharacterStatControllerTests
Assert.Equal("Strength", rows[0].Children.OfType<UiText>().ToList()[1].LinesProvider()[0].Text);
}
[Fact]
public void SkillsTab_MouseClick_RebuildsVisibleListWhenListIdIsDuplicated()
{
var root = new UiPanel { Width = 300, Height = 600 };
var attrPage = new UiPanel { Top = 25, Width = 300, Height = 575 };
var hiddenPage = new UiPanel { Top = 25, Width = 300, Height = 575 };
var name = new UiText();
var visibleList = MakeDatElement(CharacterStatController.ListBoxId, top: 112, width: 300, height: 398);
var hiddenDuplicateList = MakeDatElement(CharacterStatController.ListBoxId, top: 112, width: 300, height: 398);
attrPage.AddChild(name);
attrPage.AddChild(visibleList);
hiddenPage.AddChild(hiddenDuplicateList);
root.AddChild(attrPage);
root.AddChild(hiddenPage);
var layout = new ImportedLayout(root, new Dictionary<uint, UiElement>
{
[CharacterStatController.NameId] = name,
// Mirrors the real import: the id dictionary can point at a hidden duplicate.
[CharacterStatController.ListBoxId] = hiddenDuplicateList,
});
CharacterStatController.Bind(layout, SampleData.SampleCharacter,
spriteResolve: id => (id, 16, 16));
Assert.Equal("Strength", FirstRowName(visibleList));
Assert.Equal("<no row>", FirstRowName(hiddenDuplicateList));
var ui = new UiRoot { Width = 300, Height = 600 };
ui.AddChild(root);
Assert.IsType<UiClickablePanel>(ui.Pick(132, 12));
ui.OnMouseDown(UiMouseButton.Left, 132, 12);
ui.OnMouseUp(UiMouseButton.Left, 132, 12);
Assert.Equal("Melee Defense", FirstRowName(visibleList));
Assert.Equal("<no row>", FirstRowName(hiddenDuplicateList));
}
[Fact]
public void SkillsTab_SelectWarMagic_ShowsTrainedSkillFooter()
{
@ -1027,6 +1067,32 @@ public class CharacterStatControllerTests
tab.OnClick!();
}
private static string FirstRowName(UiElement list)
{
var row = list.Children.OfType<UiClickablePanel>().FirstOrDefault();
if (row is null) return "<no row>";
var texts = row.Children.OfType<UiText>().ToList();
return texts.Count > 1 ? texts[1].LinesProvider()[0].Text : "<no text>";
}
private static UiDatElement MakeDatElement(uint id, float top, float width, float height)
{
var info = new ElementInfo
{
Id = id,
Type = 3,
Y = top,
Width = width,
Height = height,
};
return new UiDatElement(info, static _ => (0u, 0, 0))
{
Top = top,
Width = width,
Height = height,
};
}
/// <summary>Manufacture a minimal UiButton with a fake ElementInfo (no dat sprites).</summary>
private static UiButton MakeButton()
{