diff --git a/osu.Desktop/osu.Desktop.csproj b/osu.Desktop/osu.Desktop.csproj index 6ee9c3155e..180abd7fec 100644 --- a/osu.Desktop/osu.Desktop.csproj +++ b/osu.Desktop/osu.Desktop.csproj @@ -27,7 +27,7 @@ - + diff --git a/osu.Game.Tests/Visual/TestCasePlayerLoader.cs b/osu.Game.Tests/Visual/TestCasePlayerLoader.cs index 52a9db080d..de839a21af 100644 --- a/osu.Game.Tests/Visual/TestCasePlayerLoader.cs +++ b/osu.Game.Tests/Visual/TestCasePlayerLoader.cs @@ -1,25 +1,61 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Threading; using osu.Framework.Allocation; using osu.Game.Beatmaps; using osu.Game.Screens.Play; namespace osu.Game.Tests.Visual { - public class TestCasePlayerLoader : OsuTestCase + public class TestCasePlayerLoader : ManualInputManagerTestCase { + private PlayerLoader loader; + [BackgroundDependencyLoader] private void load(OsuGameBase game) { Beatmap.Value = new DummyWorkingBeatmap(game); - AddStep("load dummy beatmap", () => Add(new PlayerLoader(new Player + AddStep("load dummy beatmap", () => Add(loader = new PlayerLoader(new Player { AllowPause = false, AllowLeadIn = false, AllowResults = false, }))); + + AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre)); + + AddUntilStep(() => !loader.IsCurrentScreen, "wait for no longer current"); + + AddStep("load slow dummy beatmap", () => + { + SlowLoadPlayer slow; + + Add(loader = new PlayerLoader(slow = new SlowLoadPlayer + { + AllowPause = false, + AllowLeadIn = false, + AllowResults = false, + })); + + Scheduler.AddDelayed(() => slow.Ready = true, 5000); + }); + + AddUntilStep(() => !loader.IsCurrentScreen, "wait for no longer current"); + } + + protected class SlowLoadPlayer : Player + { + public bool Ready; + + [BackgroundDependencyLoader] + private void load() + { + while (!Ready) + Thread.Sleep(1); + } } } + } diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index e9aa012cd7..fd4322c268 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -14,9 +14,11 @@ using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; using osu.Game.Screens.Menu; using osu.Game.Screens.Play.PlayerSettings; using OpenTK; +using OpenTK.Graphics; namespace osu.Game.Screens.Play { @@ -69,21 +71,25 @@ namespace osu.Game.Screens.Play } }); - loadTask = LoadComponentAsync(player); + loadTask = LoadComponentAsync(player, playerLoaded); } + private void playerLoaded(Player player) => info.Loading = false; + protected override void OnResuming(Screen last) { base.OnResuming(last); contentIn(); + info.Loading = true; + //we will only be resumed if the player has requested a re-run (see ValidForResume setting above) loadTask = LoadComponentAsync(player = new Player { RestartCount = player.RestartCount + 1, RestartRequested = player.RestartRequested, - }); + }, playerLoaded); this.Delay(400).Schedule(pushWhenLoaded); } @@ -258,6 +264,25 @@ namespace osu.Game.Screens.Play } private readonly WorkingBeatmap beatmap; + private LoadingAnimation loading; + private Sprite backgroundSprite; + + public bool Loading + { + set + { + if (value) + { + loading.Show(); + backgroundSprite.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint); + } + else + { + loading.Hide(); + backgroundSprite.FadeColour(Color4.White, 400, Easing.OutQuint); + } + } + } public BeatmapMetadataDisplay(WorkingBeatmap beatmap) { @@ -304,9 +329,9 @@ namespace osu.Game.Screens.Play Anchor = Anchor.TopCentre, CornerRadius = 10, Masking = true, - Children = new[] + Children = new Drawable[] { - new Sprite + backgroundSprite = new Sprite { RelativeSizeAxes = Axes.Both, Texture = beatmap?.Background, @@ -314,6 +339,7 @@ namespace osu.Game.Screens.Play Anchor = Anchor.Centre, FillMode = FillMode.Fill, }, + loading = new LoadingAnimation { Scale = new Vector2(1.3f) } } }, new OsuSpriteText @@ -341,6 +367,8 @@ namespace osu.Game.Screens.Play }, } }; + + Loading = true; } } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 1fed7f46bc..e9fc51ee9b 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -18,7 +18,7 @@ - +