1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 20:07:25 +08:00
osu-lazer/osu.Game.Tests/Visual/Menus/TestCaseLoaderAnimation.cs

123 lines
3.9 KiB
C#
Raw Normal View History

// 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.
2018-05-31 16:29:59 +08:00
using NUnit.Framework;
2019-03-27 21:27:53 +08:00
using osu.Framework.Allocation;
2018-05-31 16:29:59 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
2019-01-23 19:52:00 +08:00
using osu.Framework.Screens;
2018-05-31 16:29:59 +08:00
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
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Menus
2018-05-31 16:29:59 +08:00
{
[TestFixture]
2019-03-27 21:27:53 +08:00
public class TestCaseLoaderAnimation : ScreenTestCase
2018-05-31 16:29:59 +08:00
{
private TestLoader loader;
2019-03-27 21:27:53 +08:00
[Cached]
private OsuLogo logo;
public TestCaseLoaderAnimation()
{
Add(logo = new OsuLogo { Depth = float.MinValue });
}
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();
bool logoVisible = false;
2019-03-27 21:27:53 +08:00
AddStep("almost instant display", () => LoadScreen(loader = new TestLoader(250)));
2019-03-19 16:24:26 +08:00
AddUntilStep("loaded", () =>
2018-05-31 16:29:59 +08:00
{
2018-05-31 19:07:55 +08:00
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
2019-03-19 16:24:26 +08:00
});
2018-05-31 16:29:59 +08:00
AddAssert("logo not visible", () => !logoVisible);
2019-03-27 21:27:53 +08:00
AddStep("short load", () => LoadScreen(loader = new TestLoader(800)));
2019-03-19 16:24:26 +08:00
AddUntilStep("loaded", () =>
2018-05-31 16:29:59 +08:00
{
2018-05-31 19:07:55 +08:00
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
2019-03-19 16:24:26 +08:00
});
2018-05-31 16:29:59 +08:00
AddAssert("logo visible", () => logoVisible);
2019-03-19 16:24:26 +08:00
AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0);
2018-05-31 16:29:59 +08:00
2019-03-27 21:27:53 +08:00
AddStep("longer load", () => LoadScreen(loader = new TestLoader(1400)));
2019-03-19 16:24:26 +08:00
AddUntilStep("loaded", () =>
2018-05-31 16:29:59 +08:00
{
2018-05-31 19:07:55 +08:00
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
2019-03-19 16:24:26 +08:00
});
2018-05-31 16:29:59 +08:00
AddAssert("logo visible", () => logoVisible);
2019-03-19 16:24:26 +08:00
AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0);
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
2019-01-23 19:52:00 +08:00
public bool ScreenLoaded => screen.IsCurrentScreen();
2018-05-31 19:07:55 +08:00
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()
{
2019-01-23 19:52:00 +08:00
InternalChild = new Box
2018-05-31 16:29:59 +08:00
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.DarkSlateGray,
Alpha = 0,
};
}
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
2019-01-23 19:52:00 +08:00
InternalChild.FadeInFromZero(200);
2018-05-31 16:29:59 +08:00
}
}
}
}
}