Merge pull request #2683 from peppy/better-loading-logo

Improve feel of initial loading osu! logo
This commit is contained in:
Dan Balasescu 2018-06-04 20:29:18 +09:00 committed by GitHub
commit 877bc3ce5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 177 additions and 60 deletions

View File

@ -0,0 +1,115 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Screens;
using osu.Game.Screens.Menu;
using OpenTK.Graphics;
namespace osu.Game.Tests.Visual
{
[TestFixture]
public class TestCaseLoaderAnimation : OsuTestCase
{
private TestLoader loader;
protected override void LoadComplete()
{
base.LoadComplete();
// required to preload the logo in a headless run (so it doesn't delay the loading itself).
Add(new OsuLogo());
bool logoVisible = false;
AddStep("almost instant display", () => Child = loader = new TestLoader(250));
AddUntilStep(() =>
{
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
}, "loaded");
AddAssert("logo not visible", () => !logoVisible);
AddStep("short load", () => Child = loader = new TestLoader(800));
AddUntilStep(() =>
{
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
}, "loaded");
AddAssert("logo visible", () => logoVisible);
AddUntilStep(() => loader.Logo?.Alpha == 0, "logo gone");
AddStep("longer load", () => Child = loader = new TestLoader(1400));
AddUntilStep(() =>
{
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
}, "loaded");
AddAssert("logo visible", () => logoVisible);
AddUntilStep(() => loader.Logo?.Alpha == 0, "logo gone");
}
private class TestLoader : Loader
{
private readonly double delay;
public OsuLogo Logo;
private TestScreen screen;
public bool ScreenLoaded => screen.IsCurrentScreen;
public TestLoader(double delay)
{
this.delay = delay;
}
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(delay);
private class TestShaderPrecompiler : ShaderPrecompiler
{
private readonly double delay;
private double startTime;
public TestShaderPrecompiler(double delay)
{
this.delay = delay;
}
protected override void LoadComplete()
{
base.LoadComplete();
startTime = Time.Current;
}
protected override bool AllLoaded => Time.Current > startTime + delay;
}
private class TestScreen : OsuScreen
{
public TestScreen()
{
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.DarkSlateGray,
Alpha = 0,
};
}
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
Child.FadeInFromZero(200);
}
}
}
}
}

View File

@ -1,7 +1,6 @@
// 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;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
@ -30,43 +29,48 @@ namespace osu.Game.Screens
{
base.LogoArriving(logo, resuming);
logo.BeatMatching = false;
logo.Triangles = false;
logo.Origin = Anchor.BottomRight;
logo.Anchor = Anchor.BottomRight;
logo.Position = new Vector2(-40);
logo.Scale = new Vector2(0.2f);
logo.FadeInFromZero(5000, Easing.OutQuint);
}
private OsuScreen loadScreen;
private ShaderPrecompiler precompiler;
protected override void OnEntering(Screen last)
{
base.OnEntering(last);
LoadComponentAsync(precompiler = new ShaderPrecompiler(loadIfReady), Add);
LoadComponentAsync(loadScreen = showDisclaimer ? (OsuScreen)new Disclaimer() : new Intro(), s => loadIfReady());
}
private void loadIfReady()
{
if (ChildScreen == loadScreen) return;
if (loadScreen.LoadState != LoadState.Ready)
return;
if (!precompiler.FinishedCompiling)
return;
Push(loadScreen);
logo.Delay(500).FadeInFromZero(1000, Easing.OutQuint);
}
protected override void LogoSuspending(OsuLogo logo)
{
base.LogoSuspending(logo);
logo.FadeOut(100);
logo.FadeOut(logo.Alpha * 400);
}
private OsuScreen loadableScreen;
private ShaderPrecompiler precompiler;
protected virtual OsuScreen CreateLoadableScreen() => showDisclaimer ? (OsuScreen)new Disclaimer() : new Intro();
protected virtual ShaderPrecompiler CreateShaderPrecompiler() => new ShaderPrecompiler();
protected override void OnEntering(Screen last)
{
base.OnEntering(last);
LoadComponentAsync(precompiler = CreateShaderPrecompiler(), Add);
LoadComponentAsync(loadableScreen = CreateLoadableScreen());
checkIfLoaded();
}
private void checkIfLoaded()
{
if (loadableScreen.LoadState != LoadState.Ready || !precompiler.FinishedCompiling)
{
Schedule(checkIfLoaded);
return;
}
Push(loadableScreen);
}
[BackgroundDependencyLoader]
@ -80,16 +84,10 @@ namespace osu.Game.Screens
/// </summary>
public class ShaderPrecompiler : Drawable
{
private readonly Action onLoaded;
private readonly List<Shader> loadTargets = new List<Shader>();
public bool FinishedCompiling { get; private set; }
public ShaderPrecompiler(Action onLoaded)
{
this.onLoaded = onLoaded;
}
[BackgroundDependencyLoader]
private void load(ShaderManager manager)
{
@ -103,16 +101,17 @@ namespace osu.Game.Screens
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_3, FragmentShaderDescriptor.TEXTURE));
}
protected virtual bool AllLoaded => loadTargets.All(s => s.Loaded);
protected override void Update()
{
base.Update();
// if our target is null we are done.
if (loadTargets.All(s => s.Loaded))
if (AllLoaded)
{
FinishedCompiling = true;
Expire();
onLoaded?.Invoke();
}
}
}

View File

@ -79,31 +79,6 @@ namespace osu.Game.Screens.Menu
seeya = audio.Sample.Get(@"seeya");
}
protected override void OnEntering(Screen last)
{
base.OnEntering(last);
Game.Beatmap.Value = beatmap;
if (menuVoice)
welcome.Play();
Scheduler.AddDelayed(delegate
{
// Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Manu.
if (menuMusic)
track.Start();
LoadComponentAsync(mainMenu = new MainMenu());
Scheduler.AddDelayed(delegate
{
DidLoadMenu = true;
Push(mainMenu);
}, delay_step_one);
}, delay_step_two);
}
private const double delay_step_one = 2300;
private const double delay_step_two = 600;
@ -113,6 +88,29 @@ namespace osu.Game.Screens.Menu
{
base.LogoArriving(logo, resuming);
if (!resuming)
{
Game.Beatmap.Value = beatmap;
if (menuVoice)
welcome.Play();
Scheduler.AddDelayed(delegate
{
// Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Manu.
if (menuMusic)
track.Start();
LoadComponentAsync(mainMenu = new MainMenu());
Scheduler.AddDelayed(delegate
{
DidLoadMenu = true;
Push(mainMenu);
}, delay_step_one);
}, delay_step_two);
}
logo.RelativePositionAxes = Axes.Both;
logo.Colour = Color4.White;
logo.Ripple = false;

View File

@ -64,6 +64,8 @@ namespace osu.Game.Screens.Menu
set { colourAndTriangles.FadeTo(value ? 1 : 0, transition_length, Easing.OutQuint); }
}
public bool BeatMatching = true;
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => logoContainer.ReceiveMouseInputAt(screenSpacePos);
public bool Ripple
@ -264,6 +266,8 @@ namespace osu.Game.Screens.Menu
{
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
if (!BeatMatching) return;
lastBeatIndex = beatIndex;
var beatLength = timingPoint.BeatLength;

View File

@ -225,6 +225,7 @@ namespace osu.Game.Screens
logo.Anchor = Anchor.TopLeft;
logo.Origin = Anchor.Centre;
logo.RelativePositionAxes = Axes.None;
logo.BeatMatching = true;
logo.Triangles = true;
logo.Ripple = true;
}