1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 19:37:51 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCaseLoaderAnimation.cs

116 lines
3.7 KiB
C#
Raw Normal View History

2018-05-31 16:29:59 +08:00
// 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;
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
2018-05-31 16:29:59 +08:00
namespace osu.Game.Tests.Visual
{
[TestFixture]
public class TestCaseLoaderAnimation : OsuTestCase
{
private TestLoader loader;
2018-05-31 19:07:55 +08:00
protected override void LoadComplete()
2018-05-31 16:29:59 +08:00
{
2018-05-31 19:07:55 +08:00
base.LoadComplete();
// required to preload the logo in a headless run (so it doesn't delay the loading itself).
Add(new OsuLogo());
2018-05-31 16:29:59 +08:00
2018-05-31 19:07:55 +08:00
bool logoVisible = false;
AddStep("almost instant display", () => Child = loader = new TestLoader(250));
2018-05-31 16:29:59 +08:00
AddUntilStep(() =>
{
2018-05-31 19:07:55 +08:00
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
2018-05-31 16:29:59 +08:00
}, "loaded");
AddAssert("logo not visible", () => !logoVisible);
2018-05-31 19:07:55 +08:00
AddStep("short load", () => Child = loader = new TestLoader(800));
2018-05-31 16:29:59 +08:00
AddUntilStep(() =>
{
2018-05-31 19:07:55 +08:00
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
2018-05-31 16:29:59 +08:00
}, "loaded");
AddAssert("logo visible", () => logoVisible);
2018-05-31 19:07:55 +08:00
AddUntilStep(() => loader.Logo?.Alpha == 0, "logo gone");
2018-05-31 16:29:59 +08:00
2018-05-31 19:07:55 +08:00
AddStep("longer load", () => Child = loader = new TestLoader(1400));
2018-05-31 16:29:59 +08:00
AddUntilStep(() =>
{
2018-05-31 19:07:55 +08:00
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
2018-05-31 16:29:59 +08:00
}, "loaded");
AddAssert("logo visible", () => logoVisible);
2018-05-31 19:07:55 +08:00
AddUntilStep(() => loader.Logo?.Alpha == 0, "logo gone");
2018-05-31 16:29:59 +08:00
}
private class TestLoader : Loader
{
2018-05-31 19:07:55 +08:00
private readonly double delay;
2018-05-31 16:29:59 +08:00
public OsuLogo Logo;
2018-05-31 19:07:55 +08:00
private TestScreen screen;
2018-05-31 16:29:59 +08:00
2018-05-31 19:07:55 +08:00
public bool ScreenLoaded => screen.IsCurrentScreen;
public TestLoader(double delay)
2018-05-31 16:29:59 +08:00
{
2018-05-31 19:07:55 +08:00
this.delay = delay;
2018-05-31 16:29:59 +08:00
}
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
Logo = logo;
base.LogoArriving(logo, resuming);
}
2018-05-31 19:07:55 +08:00
protected override OsuScreen CreateLoadableScreen() => screen = new TestScreen();
protected override ShaderPrecompiler CreateShaderPrecompiler() => new TestShaderPrecompiler(delay);
2018-05-31 16:29:59 +08:00
2018-05-31 19:07:55 +08:00
private class TestShaderPrecompiler : ShaderPrecompiler
2018-05-31 16:29:59 +08:00
{
2018-05-31 19:07:55 +08:00
private readonly double delay;
private double startTime;
2018-05-31 16:29:59 +08:00
2018-05-31 19:07:55 +08:00
public TestShaderPrecompiler(double delay)
2018-05-31 16:29:59 +08:00
{
2018-05-31 19:07:55 +08:00
this.delay = delay;
}
protected override void LoadComplete()
{
base.LoadComplete();
startTime = Time.Current;
}
2018-05-31 16:29:59 +08:00
2018-05-31 19:07:55 +08:00
protected override bool AllLoaded => Time.Current > startTime + delay;
}
private class TestScreen : OsuScreen
{
public TestScreen()
{
2018-05-31 16:29:59 +08:00
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);
}
}
}
}
}