1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 20:22:55 +08:00

Add loading spinner while tournament bracket is loading / retrieving data

This commit is contained in:
Dean Herbert 2021-02-12 16:55:34 +09:00
parent 267869bd0b
commit 725db56837
4 changed files with 48 additions and 21 deletions

View File

@ -13,6 +13,8 @@ namespace osu.Game.Tournament.Tests
{ {
base.LoadComplete(); base.LoadComplete();
BracketLoadTask.Wait();
LoadComponentAsync(new Background("Menu/menu-background-0") LoadComponentAsync(new Background("Menu/menu-background-0")
{ {
Colour = OsuColour.Gray(0.5f), Colour = OsuColour.Gray(0.5f),

View File

@ -154,6 +154,8 @@ namespace osu.Game.Tournament.Tests
protected override void LoadAsyncComplete() protected override void LoadAsyncComplete()
{ {
BracketLoadTask.Wait();
// this has to be run here rather than LoadComplete because // this has to be run here rather than LoadComplete because
// TestScene.cs is checking the IsLoaded state (on another thread) and expects // TestScene.cs is checking the IsLoaded state (on another thread) and expects
// the runner to be loaded at that point. // the runner to be loaded at that point.

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics.Colour;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Tournament.Models; using osu.Game.Tournament.Models;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -32,25 +33,24 @@ namespace osu.Game.Tournament
private Drawable heightWarning; private Drawable heightWarning;
private Bindable<Size> windowSize; private Bindable<Size> windowSize;
private Bindable<WindowMode> windowMode; private Bindable<WindowMode> windowMode;
private LoadingSpinner loadingSpinner;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(FrameworkConfigManager frameworkConfig) private void load(FrameworkConfigManager frameworkConfig)
{ {
windowSize = frameworkConfig.GetBindable<Size>(FrameworkSetting.WindowedSize); 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 = 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 new Container
{ {
@ -93,7 +93,24 @@ namespace osu.Game.Tournament
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = new TournamentSceneManager() 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,8 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
@ -29,6 +31,8 @@ namespace osu.Game.Tournament
private DependencyContainer dependencies; private DependencyContainer dependencies;
private FileBasedIPC ipc; private FileBasedIPC ipc;
protected Task BracketLoadTask { get; private set; }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
return dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); return dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
@ -46,14 +50,9 @@ namespace osu.Game.Tournament
Textures.AddStore(new TextureLoaderStore(new StorageBackedResourceStore(storage))); Textures.AddStore(new TextureLoaderStore(new StorageBackedResourceStore(storage)));
readBracket(); BracketLoadTask = Task.Run(readBracket);
ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
dependencies.CacheAs(new StableInfo(storage)); dependencies.CacheAs(new StableInfo(storage));
dependencies.CacheAs<MatchIPCInfo>(ipc = new FileBasedIPC());
Add(ipc);
} }
private void readBracket() private void readBracket()
@ -70,8 +69,6 @@ namespace osu.Game.Tournament
Ruleset.BindTo(ladder.Ruleset); Ruleset.BindTo(ladder.Ruleset);
dependencies.Cache(ladder);
bool addedInfo = false; bool addedInfo = false;
// assign teams // assign teams
@ -127,6 +124,15 @@ namespace osu.Game.Tournament
if (addedInfo) if (addedInfo)
SaveChanges(); SaveChanges();
ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
Schedule(() =>
{
dependencies.Cache(ladder);
dependencies.CacheAs<MatchIPCInfo>(ipc = new FileBasedIPC());
Add(ipc);
});
} }
/// <summary> /// <summary>