1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-21 06:02:56 +08:00

Merge pull request #8212 from peppy/update-loader-animation

Update loader animation
This commit is contained in:
Dan Balasescu 2020-03-18 12:07:50 +09:00 committed by GitHub
commit 9b029fa9e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 38 deletions

View File

@ -1,12 +1,15 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using System.Threading;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens;
using osu.Game.Screens.Menu;
using osuTK.Graphics;
@ -14,14 +17,14 @@ using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Menus
{
[TestFixture]
public class TestSceneLoaderAnimation : ScreenTestScene
public class TestSceneLoader : ScreenTestScene
{
private TestLoader loader;
[Cached]
private OsuLogo logo;
public TestSceneLoaderAnimation()
public TestSceneLoader()
{
Child = logo = new OsuLogo
{
@ -42,33 +45,33 @@ namespace osu.Game.Tests.Visual.Menus
LoadScreen(loader);
});
AddAssert("spinner did not display", () => loader.LoadingSpinner?.Alpha == 0);
AddUntilStep("loaded", () => loader.ScreenLoaded);
AddUntilStep("not current", () => !loader.IsCurrentScreen());
}
[Test]
public void TestDelayedLoad()
{
AddStep("begin loading", () => LoadScreen(loader = new TestLoader()));
AddUntilStep("wait for logo visible", () => loader.Logo?.Alpha > 0);
AddUntilStep("wait for spinner visible", () => loader.LoadingSpinner?.Alpha > 0);
AddStep("finish loading", () => loader.AllowLoad.Set());
AddUntilStep("loaded", () => loader.Logo != null && loader.ScreenLoaded);
AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0);
AddUntilStep("spinner gone", () => loader.LoadingSpinner?.Alpha == 0);
AddUntilStep("loaded", () => loader.ScreenLoaded);
AddUntilStep("not current", () => !loader.IsCurrentScreen());
}
private class TestLoader : Loader
{
public readonly ManualResetEventSlim AllowLoad = new ManualResetEventSlim();
public OsuLogo Logo;
public LoadingSpinner LoadingSpinner => this.ChildrenOfType<LoadingSpinner>().FirstOrDefault();
private TestScreen screen;
public bool ScreenLoaded => screen.IsCurrentScreen();
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
Logo = logo;
base.LogoArriving(logo, resuming);
}
protected override OsuScreen CreateLoadableScreen() => screen = new TestScreen();
protected override ShaderPrecompiler CreateShaderPrecompiler() => new TestShaderPrecompiler(AllowLoad);

View File

@ -19,7 +19,7 @@ namespace osu.Game.Graphics.UserInterface
protected Container MainContents;
protected const float TRANSITION_DURATION = 500;
public const float TRANSITION_DURATION = 500;
private const float spin_duration = 900;
@ -27,7 +27,8 @@ namespace osu.Game.Graphics.UserInterface
/// Constuct a new loading spinner.
/// </summary>
/// <param name="withBox">Whether the spinner should have a surrounding black box for visibility.</param>
public LoadingSpinner(bool withBox = false)
/// <param name="inverted">Whether colours should be inverted (black spinner instead of white).</param>
public LoadingSpinner(bool withBox = false, bool inverted = false)
{
Size = new Vector2(60);
@ -45,7 +46,7 @@ namespace osu.Game.Graphics.UserInterface
{
new Box
{
Colour = Color4.Black,
Colour = inverted ? Color4.White : Color4.Black,
RelativeSizeAxes = Axes.Both,
Alpha = withBox ? 0.7f : 0
},
@ -53,6 +54,7 @@ namespace osu.Game.Graphics.UserInterface
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = inverted ? Color4.Black : Color4.White,
Scale = new Vector2(withBox ? 0.6f : 1),
RelativeSizeAxes = Axes.Both,
Icon = FontAwesome.Solid.CircleNotch

View File

@ -5,12 +5,14 @@ using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Utils;
using osu.Game.Screens.Menu;
using osuTK;
using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using IntroSequence = osu.Game.Configuration.IntroSequence;
namespace osu.Game.Screens
@ -24,31 +26,12 @@ namespace osu.Game.Screens
ValidForResume = false;
}
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
logo.BeatMatching = false;
logo.Triangles = false;
logo.RelativePositionAxes = Axes.None;
logo.Origin = Anchor.BottomRight;
logo.Anchor = Anchor.BottomRight;
logo.Position = new Vector2(-40);
logo.Scale = new Vector2(0.2f);
logo.Delay(500).FadeInFromZero(1000, Easing.OutQuint);
}
protected override void LogoSuspending(OsuLogo logo)
{
base.LogoSuspending(logo);
logo.FadeOut(logo.Alpha * 400);
}
private OsuScreen loadableScreen;
private ShaderPrecompiler precompiler;
private IntroSequence introSequence;
private LoadingSpinner spinner;
private ScheduledDelegate spinnerShow;
protected virtual OsuScreen CreateLoadableScreen()
{
@ -82,6 +65,17 @@ namespace osu.Game.Screens
LoadComponentAsync(precompiler = CreateShaderPrecompiler(), AddInternal);
LoadComponentAsync(loadableScreen = CreateLoadableScreen());
LoadComponentAsync(spinner = new LoadingSpinner(true, true)
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding(40),
}, _ =>
{
AddInternal(spinner);
spinnerShow = Scheduler.AddDelayed(spinner.Show, 200);
});
checkIfLoaded();
}
@ -93,7 +87,15 @@ namespace osu.Game.Screens
return;
}
this.Push(loadableScreen);
spinnerShow?.Cancel();
if (spinner.State.Value == Visibility.Visible)
{
spinner.Hide();
Scheduler.AddDelayed(() => this.Push(loadableScreen), LoadingSpinner.TRANSITION_DURATION);
}
else
this.Push(loadableScreen);
}
[BackgroundDependencyLoader]