1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-21 17:17:20 +08:00

Merge pull request #11762 from peppy/add-tournament-mode-loading-screen

Add loading spinner while tournament bracket is loading / retrieving data
This commit is contained in:
Dan Balasescu 2021-02-15 13:41:10 +09:00 committed by GitHub
commit cb5f49f227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 34 deletions

View File

@ -13,15 +13,18 @@ namespace osu.Game.Tournament.Tests
{
base.LoadComplete();
LoadComponentAsync(new Background("Menu/menu-background-0")
BracketLoadTask.ContinueWith(_ => Schedule(() =>
{
Colour = OsuColour.Gray(0.5f),
Depth = 10
}, AddInternal);
LoadComponentAsync(new Background("Menu/menu-background-0")
{
Colour = OsuColour.Gray(0.5f),
Depth = 10
}, AddInternal);
// Have to construct this here, rather than in the constructor, because
// we depend on some dependencies to be loaded within OsuGameBase.load().
Add(new TestBrowser());
// Have to construct this here, rather than in the constructor, because
// we depend on some dependencies to be loaded within OsuGameBase.load().
Add(new TestBrowser());
}));
}
}
}

View File

@ -154,10 +154,13 @@ namespace osu.Game.Tournament.Tests
protected override void LoadAsyncComplete()
{
// this has to be run here rather than LoadComplete because
// TestScene.cs is checking the IsLoaded state (on another thread) and expects
// the runner to be loaded at that point.
Add(runner = new TestSceneTestRunner.TestRunner());
BracketLoadTask.ContinueWith(_ => Schedule(() =>
{
// this has to be run here rather than LoadComplete because
// TestScene.cs is checking the IsLoaded state (on another thread) and expects
// the runner to be loaded at that point.
Add(runner = new TestSceneTestRunner.TestRunner());
}));
}
public void RunTestBlocking(TestScene test) => runner.RunTestBlocking(test);

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics.Colour;
using osu.Game.Graphics.Cursor;
using osu.Game.Tournament.Models;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;
@ -32,25 +33,24 @@ namespace osu.Game.Tournament
private Drawable heightWarning;
private Bindable<Size> windowSize;
private Bindable<WindowMode> windowMode;
private LoadingSpinner loadingSpinner;
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager frameworkConfig)
{
windowSize = frameworkConfig.GetBindable<Size>(FrameworkSetting.WindowedSize);
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
{
var minWidth = (int)(size.NewValue.Height / 768f * TournamentSceneManager.REQUIRED_WIDTH) - 1;
heightWarning.Alpha = size.NewValue.Width < minWidth ? 1 : 0;
}), true);
windowMode = frameworkConfig.GetBindable<WindowMode>(FrameworkSetting.WindowMode);
windowMode.BindValueChanged(mode => ScheduleAfterChildren(() =>
{
windowMode.Value = WindowMode.Windowed;
}), true);
AddRange(new[]
Add(loadingSpinner = new LoadingSpinner(true, true)
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding(40),
});
loadingSpinner.Show();
BracketLoadTask.ContinueWith(_ => LoadComponentsAsync(new[]
{
new Container
{
@ -93,7 +93,24 @@ namespace osu.Game.Tournament
RelativeSizeAxes = Axes.Both,
Child = new TournamentSceneManager()
}
});
}, drawables =>
{
loadingSpinner.Hide();
loadingSpinner.Expire();
AddRange(drawables);
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
{
var minWidth = (int)(size.NewValue.Height / 768f * TournamentSceneManager.REQUIRED_WIDTH) - 1;
heightWarning.Alpha = size.NewValue.Width < minWidth ? 1 : 0;
}), true);
windowMode.BindValueChanged(mode => ScheduleAfterChildren(() =>
{
windowMode.Value = WindowMode.Windowed;
}), true);
}));
}
}
}

View File

@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Textures;
@ -29,6 +30,10 @@ namespace osu.Game.Tournament
private DependencyContainer dependencies;
private FileBasedIPC ipc;
protected Task BracketLoadTask => taskCompletionSource.Task;
private readonly TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>();
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
return dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
@ -46,14 +51,9 @@ namespace osu.Game.Tournament
Textures.AddStore(new TextureLoaderStore(new StorageBackedResourceStore(storage)));
readBracket();
ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
dependencies.CacheAs(new StableInfo(storage));
dependencies.CacheAs<MatchIPCInfo>(ipc = new FileBasedIPC());
Add(ipc);
Task.Run(readBracket);
}
private void readBracket()
@ -68,10 +68,6 @@ namespace osu.Game.Tournament
ladder ??= new LadderInfo();
ladder.Ruleset.Value ??= RulesetStore.AvailableRulesets.First();
Ruleset.BindTo(ladder.Ruleset);
dependencies.Cache(ladder);
bool addedInfo = false;
// assign teams
@ -127,6 +123,19 @@ namespace osu.Game.Tournament
if (addedInfo)
SaveChanges();
ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
Schedule(() =>
{
Ruleset.BindTo(ladder.Ruleset);
dependencies.Cache(ladder);
dependencies.CacheAs<MatchIPCInfo>(ipc = new FileBasedIPC());
Add(ipc);
taskCompletionSource.SetResult(true);
});
}
/// <summary>