mirror of
https://github.com/ppy/osu
synced 2024-12-17 12:25:19 +00:00
79 lines
2.7 KiB
C#
79 lines
2.7 KiB
C#
// 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 NUnit.Framework;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Framework.Screens;
|
|
using osu.Framework.Testing;
|
|
using osu.Game.Graphics.Containers;
|
|
using osu.Game.Screens;
|
|
using osu.Game.Screens.Play;
|
|
using osuTK.Graphics;
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
{
|
|
[TestFixture]
|
|
public class TestCaseOsuScreenStack : OsuTestCase
|
|
{
|
|
private NoParallaxTestScreen baseScreen;
|
|
private TestScreen newScreen;
|
|
private TestOsuScreenStack stack;
|
|
|
|
[SetUpSteps]
|
|
public void Setup()
|
|
{
|
|
AddStep("Create new screen stack", () => { Child = stack = new TestOsuScreenStack { RelativeSizeAxes = Axes.Both }; });
|
|
AddStep("Push new base screen", () => stack.Push(baseScreen = new NoParallaxTestScreen("THIS IS SCREEN 1. THIS SCREEN SHOULD HAVE NO PARALLAX.")));
|
|
AddUntilStep("Wait for Screen 1 to be current", baseScreen.IsCurrentScreen);
|
|
}
|
|
|
|
[Test]
|
|
public void ParallaxAssignmentTest()
|
|
{
|
|
AddStep("Push new screen to base screen", () => baseScreen.Push(newScreen = new TestScreen("THIS IS SCREEN 2. THIS SCREEN SHOULD HAVE PARALLAX.")));
|
|
AddUntilStep("Wait for Screen 2 to be current", newScreen.IsCurrentScreen);
|
|
AddAssert("Parallax is correct", () => stack.IsParallaxSet);
|
|
AddStep("Exit from new screen", () => { baseScreen.MakeCurrent(); });
|
|
AddUntilStep("Wait for Screen 1 to be current", baseScreen.IsCurrentScreen);
|
|
AddAssert("Parallax is correct", () => stack.IsParallaxSet);
|
|
}
|
|
|
|
private class TestScreen : ScreenWithBeatmapBackground
|
|
{
|
|
private readonly string screenText;
|
|
|
|
public TestScreen(string screenText)
|
|
{
|
|
this.screenText = screenText;
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
AddInternal(new SpriteText
|
|
{
|
|
Text = screenText,
|
|
Colour = Color4.White
|
|
});
|
|
}
|
|
}
|
|
|
|
private class NoParallaxTestScreen : TestScreen
|
|
{
|
|
public NoParallaxTestScreen(string screenText)
|
|
: base(screenText)
|
|
{
|
|
}
|
|
|
|
public override float BackgroundParallaxAmount => 0.0f;
|
|
}
|
|
|
|
private class TestOsuScreenStack : OsuScreenStack
|
|
{
|
|
public bool IsParallaxSet => ParallaxAmount == ((TestScreen)CurrentScreen).BackgroundParallaxAmount * ParallaxContainer.DEFAULT_PARALLAX_AMOUNT;
|
|
}
|
|
}
|
|
}
|