Give flow container a type to avoid locally casting in every location

This commit is contained in:
Dean Herbert 2023-01-17 18:27:33 +09:00
parent 09c7ab3af6
commit 35ad66eef9
2 changed files with 10 additions and 13 deletions

View File

@ -103,10 +103,10 @@ public void TestToggleJudgementNames()
{
AddStep("Hide judgement names", () => counterDisplay.ShowJudgementNames.Value = false);
AddWaitStep("wait some", 2);
AddAssert("Assert hidden", () => counterDisplay.JudgementContainer.Children.OfType<JudgementCounter>().First().ResultName.Alpha == 0);
AddAssert("Assert hidden", () => counterDisplay.JudgementContainer.Children.First().ResultName.Alpha == 0);
AddStep("Hide judgement names", () => counterDisplay.ShowJudgementNames.Value = true);
AddWaitStep("wait some", 2);
AddAssert("Assert shown", () => counterDisplay.JudgementContainer.Children.OfType<JudgementCounter>().First().ResultName.Alpha == 1);
AddAssert("Assert shown", () => counterDisplay.JudgementContainer.Children.First().ResultName.Alpha == 1);
}
[Test]
@ -132,13 +132,13 @@ public void TestCycleDisplayModes()
private int hiddenCount()
{
var num = counterDisplay.JudgementContainer.Children.OfType<JudgementCounter>().First(child => child.Result.Type == HitResult.LargeTickHit);
var num = counterDisplay.JudgementContainer.Children.First(child => child.Result.Type == HitResult.LargeTickHit);
return num.Result.ResultCount.Value;
}
private partial class TestJudgementCounterDisplay : JudgementCounterDisplay
{
public new FillFlowContainer JudgementContainer => base.JudgementContainer;
public new FillFlowContainer<JudgementCounter> JudgementContainer => base.JudgementContainer;
}
}
}

View File

@ -34,13 +34,13 @@ public partial class JudgementCounterDisplay : CompositeDrawable, ISkinnableDraw
[Resolved]
private JudgementTally tally { get; set; } = null!;
protected FillFlowContainer JudgementContainer = null!;
protected FillFlowContainer<JudgementCounter> JudgementContainer = null!;
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
InternalChild = JudgementContainer = new FillFlowContainer
InternalChild = JudgementContainer = new FillFlowContainer<JudgementCounter>
{
Direction = getFillDirection(FlowDirection.Value),
Spacing = new Vector2(10),
@ -60,7 +60,7 @@ protected override void LoadComplete()
JudgementContainer.Direction = getFillDirection(direction.NewValue);
//Can't pass directly due to Enum conversion
foreach (var counter in JudgementContainer.Children.OfType<JudgementCounter>())
foreach (var counter in JudgementContainer.Children)
counter.Direction.Value = getFillDirection(direction.NewValue);
}, true);
Mode.BindValueChanged(_ => updateMode(), true);
@ -73,7 +73,7 @@ protected override void LoadComplete()
private void updateMode()
{
foreach (var counter in JudgementContainer.Children.OfType<JudgementCounter>().Where(counter => !counter.Result.Type.IsBasic()))
foreach (var counter in JudgementContainer.Children.Where(counter => !counter.Result.Type.IsBasic()))
{
switch (Mode.Value)
{
@ -110,15 +110,12 @@ private FillDirection getFillDirection(Direction flow)
}
}
private JudgementCounter createCounter(JudgementTally.JudgementCount info)
{
JudgementCounter counter = new JudgementCounter(info)
private JudgementCounter createCounter(JudgementTally.JudgementCount info) =>
new JudgementCounter(info)
{
State = { Value = Visibility.Visible },
ShowName = { BindTarget = ShowJudgementNames }
};
return counter;
}
public enum DisplayMode
{