fix(combat): resolve power spans after layout
Derive the dark middle range from live post-anchor sibling geometry instead of freezing the inherited 800-pixel prototype during controller binding. Render the user-directed bright desired-power band independently from the absolute bar-left edge to the green thumb center. Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
parent
707add8539
commit
f8c174d707
8 changed files with 129 additions and 24 deletions
|
|
@ -50,9 +50,9 @@ public sealed class CombatUiControllerTests
|
|||
|
||||
high.OnEvent(new UiEvent(0, high, UiEventType.MouseDown, Data1: 2, Data2: 2));
|
||||
now = 4.5d;
|
||||
Assert.Equal(0.5f, power.ScalarFill()!.Value, 3);
|
||||
Assert.Equal(104f, power.ScalarRangeLeft, 3);
|
||||
Assert.Equal(299f, power.ScalarRangeWidth, 3);
|
||||
Assert.True(power.ScalarFillFollowsThumb);
|
||||
var range = Assert.IsType<Func<(float Left, float Width)>>(power.ScalarRangeProvider);
|
||||
Assert.Equal((104f, 299f), range());
|
||||
high.OnEvent(new UiEvent(0, high, UiEventType.MouseUp, Data1: 2, Data2: 2));
|
||||
|
||||
var attack = Assert.Single(sent);
|
||||
|
|
@ -98,9 +98,30 @@ public sealed class CombatUiControllerTests
|
|||
Assert.False(speed.RightAligned);
|
||||
Assert.False(powerLabel.Centered);
|
||||
Assert.True(powerLabel.RightAligned);
|
||||
Assert.Equal(speed.Left + speed.Width - power.Left, power.ScalarRangeLeft, 3);
|
||||
Assert.Equal(powerLabel.Left - power.Left - power.ScalarRangeLeft,
|
||||
power.ScalarRangeWidth, 3);
|
||||
var range = Assert.IsType<Func<(float Left, float Width)>>(power.ScalarRangeProvider);
|
||||
var (left, width) = range();
|
||||
Assert.Equal(speed.Left + speed.Width - power.Left, left, 3);
|
||||
Assert.Equal(powerLabel.Left - power.Left - left, width, 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ImportedFixture_ReflowUpdatesCenteredDarkRange()
|
||||
{
|
||||
ElementInfo info = FixtureLoader.LoadCombatInfos();
|
||||
ImportedLayout layout = LayoutImporter.Build(info, NoTex, datFont: null);
|
||||
var combat = new CombatState();
|
||||
using var attacks = CreateAttacks(combat, () => 0d, []);
|
||||
GameplaySettings gameplay = GameplaySettings.Default;
|
||||
using var controller = CombatUiController.Bind(
|
||||
layout, combat, attacks, () => gameplay, value => gameplay = value,
|
||||
Labels, _ => { })!;
|
||||
|
||||
ApplyAnchors(layout.Root);
|
||||
|
||||
var power = Assert.IsType<UiScrollbar>(
|
||||
layout.FindElement(CombatUiController.PowerControlId));
|
||||
var range = Assert.IsType<Func<(float Left, float Width)>>(power.ScalarRangeProvider);
|
||||
Assert.Equal((104f, 299f), range());
|
||||
}
|
||||
|
||||
private static readonly CombatUiLabels Labels = new(
|
||||
|
|
@ -181,4 +202,13 @@ public sealed class CombatUiControllerTests
|
|||
};
|
||||
return (new ImportedLayout(root, byId), basic, advanced, power, high, medium, low);
|
||||
}
|
||||
|
||||
private static void ApplyAnchors(UiElement parent)
|
||||
{
|
||||
foreach (UiElement child in parent.Children)
|
||||
{
|
||||
child.ApplyAnchor(parent.Width, parent.Height);
|
||||
ApplyAnchors(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue