mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 09:32:55 +08:00
Merge pull request #5083 from peppy/modselect-async-improvements
Fix mod icons in ModSelect being loaded in a blocking fashion
This commit is contained in:
commit
daad16b5e7
@ -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,6 +232,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
private void checkSelected(Mod mod)
|
||||
{
|
||||
waitForLoad();
|
||||
AddAssert($"check {mod.Name} is selected", () =>
|
||||
{
|
||||
var button = modSelect.GetModButton(mod);
|
||||
@ -239,8 +240,14 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
});
|
||||
}
|
||||
|
||||
private void waitForLoad()
|
||||
{
|
||||
AddUntilStep("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<IReadOnlyList<Mod>> 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);
|
||||
|
@ -10,6 +10,7 @@ using osu.Game.Rulesets.Mods;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
|
||||
@ -33,6 +34,13 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
public IEnumerable<Mod> SelectedMods => buttons.Select(b => b.SelectedMod).Where(m => m != null);
|
||||
|
||||
private CancellationTokenSource modsLoadCts;
|
||||
|
||||
/// <summary>
|
||||
/// True when all mod icons have completed loading.
|
||||
/// </summary>
|
||||
public bool ModIconsLoaded { get; private set; } = true;
|
||||
|
||||
public IEnumerable<Mod> Mods
|
||||
{
|
||||
set
|
||||
@ -48,7 +56,15 @@ namespace osu.Game.Overlays.Mods
|
||||
};
|
||||
}).ToArray();
|
||||
|
||||
ButtonsContainer.Children = modContainers;
|
||||
modsLoadCts?.Cancel();
|
||||
ModIconsLoaded = false;
|
||||
|
||||
LoadComponentsAsync(modContainers, c =>
|
||||
{
|
||||
ModIconsLoaded = true;
|
||||
ButtonsContainer.ChildrenEnumerable = c;
|
||||
}, (modsLoadCts = new CancellationTokenSource()).Token);
|
||||
|
||||
buttons = modContainers.OfType<ModButton>().ToArray();
|
||||
|
||||
if (value.Any())
|
||||
|
Loading…
Reference in New Issue
Block a user