mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:37:28 +08:00
Add loading animation to player loader to make it more obvious when loading is complete
This commit is contained in:
parent
1ed6b23306
commit
b1afcf0e5d
@ -1,25 +1,61 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,9 +12,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
|
||||
{
|
||||
@ -65,21 +67,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);
|
||||
}
|
||||
@ -230,6 +236,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)
|
||||
{
|
||||
@ -276,9 +301,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,
|
||||
@ -286,6 +311,7 @@ namespace osu.Game.Screens.Play
|
||||
Anchor = Anchor.Centre,
|
||||
FillMode = FillMode.Fill,
|
||||
},
|
||||
loading = new LoadingAnimation { Scale = new Vector2(1.3f) }
|
||||
}
|
||||
},
|
||||
new OsuSpriteText
|
||||
@ -313,6 +339,8 @@ namespace osu.Game.Screens.Play
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
Loading = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user