diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs index c3894471ee..91446bddcf 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs @@ -216,13 +216,13 @@ namespace osu.Game.Tests.Visual.UserInterface private void testRankedText(Mod mod) { - AddWaitStep("wait for fade", 1); + waitForLoad(); AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0); selectNext(mod); - AddWaitStep("wait for fade", 1); + waitForLoad(); AddAssert("check for unranked", () => modSelect.UnrankedLabel.Alpha != 0); selectPrevious(mod); - AddWaitStep("wait for fade", 1); + waitForLoad(); AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0); } @@ -232,15 +232,22 @@ namespace osu.Game.Tests.Visual.UserInterface private void checkSelected(Mod mod) { - AddUntilStep($"check {mod.Name} is selected", () => + waitForLoad(); + AddAssert($"check {mod.Name} is selected", () => { var button = modSelect.GetModButton(mod); - return modSelect.SelectedMods.Value.SingleOrDefault(m => m.Name == mod.Name) != null && button.SelectedMod.GetType() == mod.GetType() && button.Selected; + return modSelect.SelectedMods.Value.Single(m => m.Name == mod.Name) != null && button.SelectedMod.GetType() == mod.GetType() && button.Selected; }); } + private void waitForLoad() + { + AddAssert("wait for icons to load", () => modSelect.AllLoaded); + } + private void checkNotSelected(Mod mod) { + waitForLoad(); AddAssert($"check {mod.Name} is not selected", () => { var button = modSelect.GetModButton(mod); @@ -254,6 +261,8 @@ namespace osu.Game.Tests.Visual.UserInterface { public new Bindable> SelectedMods => base.SelectedMods; + public bool AllLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded); + public ModButton GetModButton(Mod mod) { var section = ModSectionsContainer.Children.Single(s => s.ModType == mod.Type); diff --git a/osu.Game/Overlays/Mods/ModSection.cs b/osu.Game/Overlays/Mods/ModSection.cs index ba83af9f28..dedd397fa5 100644 --- a/osu.Game/Overlays/Mods/ModSection.cs +++ b/osu.Game/Overlays/Mods/ModSection.cs @@ -36,6 +36,11 @@ namespace osu.Game.Overlays.Mods private CancellationTokenSource modsLoadCts; + /// + /// True when all mod icons have completed loading. + /// + public bool ModIconsLoaded { get; private set; } = true; + public IEnumerable Mods { set @@ -52,7 +57,13 @@ namespace osu.Game.Overlays.Mods }).ToArray(); modsLoadCts?.Cancel(); - LoadComponentsAsync(modContainers, c => ButtonsContainer.ChildrenEnumerable = c, (modsLoadCts = new CancellationTokenSource()).Token); + ModIconsLoaded = false; + + LoadComponentsAsync(modContainers, c => + { + ModIconsLoaded = true; + ButtonsContainer.ChildrenEnumerable = c; + }, (modsLoadCts = new CancellationTokenSource()).Token); buttons = modContainers.OfType().ToArray();