2019-03-22 05:10:38 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2019-03-22 05:10:38 +00:00
|
|
|
using NUnit.Framework;
|
2019-03-22 06:08:47 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-03-22 05:10:38 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Screens;
|
2019-05-21 05:13:52 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-09-15 22:21:29 +00:00
|
|
|
using osu.Game.Overlays;
|
2019-03-22 05:10:38 +00:00
|
|
|
using osu.Game.Screens;
|
|
|
|
using osu.Game.Screens.Play;
|
2019-03-22 06:08:47 +00:00
|
|
|
using osuTK.Graphics;
|
2019-03-22 05:10:38 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2019-05-14 19:37:25 +00:00
|
|
|
public partial class TestSceneOsuScreenStack : OsuTestScene
|
2019-03-22 05:10:38 +00:00
|
|
|
{
|
|
|
|
private TestOsuScreenStack stack;
|
|
|
|
|
2021-09-15 22:21:29 +00:00
|
|
|
[Cached]
|
|
|
|
private MusicController musicController = new MusicController();
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2019-03-22 05:10:38 +00:00
|
|
|
{
|
2021-09-15 22:21:29 +00:00
|
|
|
stack = new TestOsuScreenStack { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
|
|
|
Add(musicController);
|
|
|
|
Add(stack);
|
|
|
|
|
|
|
|
LoadComponent(stack);
|
2019-03-22 05:10:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void ParallaxAssignmentTest()
|
|
|
|
{
|
2019-03-22 07:03:08 +00:00
|
|
|
NoParallaxTestScreen noParallaxScreen = null;
|
|
|
|
TestScreen parallaxScreen = null;
|
|
|
|
|
|
|
|
AddStep("Push no parallax", () => stack.Push(noParallaxScreen = new NoParallaxTestScreen("NO PARALLAX")));
|
|
|
|
AddUntilStep("Wait for current", () => noParallaxScreen.IsLoaded);
|
|
|
|
AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);
|
|
|
|
|
|
|
|
AddStep("Push parallax", () => noParallaxScreen.Push(parallaxScreen = new TestScreen("PARALLAX")));
|
|
|
|
AddUntilStep("Wait for current", () => parallaxScreen.IsLoaded);
|
|
|
|
AddAssert("Parallax is on", () => stack.ParallaxAmount > 0);
|
|
|
|
|
|
|
|
AddStep("Exit from new screen", () => { noParallaxScreen.MakeCurrent(); });
|
|
|
|
AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);
|
2019-03-22 05:10:38 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 22:21:29 +00:00
|
|
|
[Test]
|
|
|
|
public void AllowTrackAdjustmentsTest()
|
|
|
|
{
|
|
|
|
AddStep("push allowing screen", () => stack.Push(loadNewScreen<AllowScreen>()));
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("allows adjustments 1", () => musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
AddStep("push inheriting screen", () => stack.Push(loadNewScreen<InheritScreen>()));
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("allows adjustments 2", () => musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
AddStep("push disallowing screen", () => stack.Push(loadNewScreen<DisallowScreen>()));
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("disallows adjustments 3", () => !musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
AddStep("push inheriting screen", () => stack.Push(loadNewScreen<InheritScreen>()));
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("disallows adjustments 4", () => !musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
AddStep("push inheriting screen", () => stack.Push(loadNewScreen<InheritScreen>()));
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("disallows adjustments 5", () => !musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
AddStep("push allowing screen", () => stack.Push(loadNewScreen<AllowScreen>()));
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("allows adjustments 6", () => musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
// Now start exiting from screens
|
|
|
|
AddStep("exit screen", () => stack.Exit());
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("disallows adjustments 7", () => !musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
AddStep("exit screen", () => stack.Exit());
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("disallows adjustments 8", () => !musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
AddStep("exit screen", () => stack.Exit());
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("disallows adjustments 9", () => !musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
AddStep("exit screen", () => stack.Exit());
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("allows adjustments 10", () => musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
AddStep("exit screen", () => stack.Exit());
|
2023-07-25 10:58:23 +00:00
|
|
|
AddAssert("allows adjustments 11", () => musicController.ApplyModTrackAdjustments);
|
2021-09-15 22:21:29 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:30:23 +00:00
|
|
|
public partial class TestScreen : ScreenWithBeatmapBackground
|
2019-03-22 05:10:38 +00:00
|
|
|
{
|
2019-03-22 06:08:47 +00:00
|
|
|
private readonly string screenText;
|
|
|
|
|
|
|
|
public TestScreen(string screenText)
|
|
|
|
{
|
|
|
|
this.screenText = screenText;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2019-05-21 05:13:52 +00:00
|
|
|
AddInternal(new OsuSpriteText
|
2019-03-22 06:08:47 +00:00
|
|
|
{
|
|
|
|
Text = screenText,
|
2019-03-22 07:03:08 +00:00
|
|
|
Colour = Color4.White,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2019-03-22 06:08:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private partial class NoParallaxTestScreen : TestScreen
|
|
|
|
{
|
|
|
|
public NoParallaxTestScreen(string screenText)
|
|
|
|
: base(screenText)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override float BackgroundParallaxAmount => 0.0f;
|
2019-03-22 05:10:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private partial class TestOsuScreenStack : OsuScreenStack
|
|
|
|
{
|
2019-03-22 07:03:08 +00:00
|
|
|
public new float ParallaxAmount => base.ParallaxAmount;
|
2019-03-22 05:10:38 +00:00
|
|
|
}
|
2021-09-15 22:21:29 +00:00
|
|
|
|
|
|
|
private partial class AllowScreen : OsuScreen
|
|
|
|
{
|
2023-07-25 10:58:23 +00:00
|
|
|
public override bool? ApplyModTrackAdjustments => true;
|
2021-09-15 22:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public partial class DisallowScreen : OsuScreen
|
|
|
|
{
|
2023-07-25 10:58:23 +00:00
|
|
|
public override bool? ApplyModTrackAdjustments => false;
|
2021-09-15 22:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private partial class InheritScreen : OsuScreen
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private OsuScreen loadNewScreen<T>() where T : OsuScreen, new()
|
|
|
|
{
|
|
|
|
OsuScreen screen = new T();
|
|
|
|
LoadComponent(screen);
|
|
|
|
return screen;
|
|
|
|
}
|
2019-03-22 05:10:38 +00:00
|
|
|
}
|
|
|
|
}
|