mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 21:02:55 +08:00
Add a new test for OsuScreenStack, fix parallax
This commit is contained in:
parent
ee0d7b6c6d
commit
dcae86e39a
45
osu.Game.Tests/Visual/TestCaseOsuScreenStack.cs
Normal file
45
osu.Game.Tests/Visual/TestCaseOsuScreenStack.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// 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.Graphics;
|
||||||
|
using osu.Framework.Screens;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Screens;
|
||||||
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class TestCaseOsuScreenStack : OsuTestCase
|
||||||
|
{
|
||||||
|
private TestScreen baseScreen;
|
||||||
|
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 TestScreen()));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ParallaxAssignmentTest()
|
||||||
|
{
|
||||||
|
AddStep("Push new screen to base screen", () => baseScreen.Push(new TestScreen()));
|
||||||
|
AddAssert("Parallax is correct", () => stack.IsParallaxSet);
|
||||||
|
AddStep("Exit from new screen", () => { baseScreen.MakeCurrent(); });
|
||||||
|
AddAssert("Parallax is correct", () => stack.IsParallaxSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestScreen : ScreenWithBeatmapBackground
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestOsuScreenStack : OsuScreenStack
|
||||||
|
{
|
||||||
|
public bool IsParallaxSet => ParallaxAmount == ((TestScreen)CurrentScreen).BackgroundParallaxAmount * ParallaxContainer.DEFAULT_PARALLAX_AMOUNT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -406,6 +406,8 @@ namespace osu.Game
|
|||||||
loadComponentSingleFile(osuLogo, logo =>
|
loadComponentSingleFile(osuLogo, logo =>
|
||||||
{
|
{
|
||||||
logoContainer.Add(logo);
|
logoContainer.Add(logo);
|
||||||
|
|
||||||
|
// Loader has to be created synchronously in order for DI to be successful for its background screen stack.
|
||||||
screenStack.Push(new Loader
|
screenStack.Push(new Loader
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both
|
||||||
|
@ -15,6 +15,8 @@ namespace osu.Game.Screens
|
|||||||
|
|
||||||
private ParallaxContainer parallaxContainer;
|
private ParallaxContainer parallaxContainer;
|
||||||
|
|
||||||
|
protected float ParallaxAmount => parallaxContainer.ParallaxAmount;
|
||||||
|
|
||||||
public OsuScreenStack()
|
public OsuScreenStack()
|
||||||
{
|
{
|
||||||
initializeStack();
|
initializeStack();
|
||||||
@ -35,11 +37,15 @@ namespace osu.Game.Screens
|
|||||||
};
|
};
|
||||||
|
|
||||||
ScreenPushed += setParallax;
|
ScreenPushed += setParallax;
|
||||||
|
ScreenExited += setParallax;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setParallax(IScreen prev, IScreen next)
|
private void setParallax(IScreen prev, IScreen next)
|
||||||
{
|
{
|
||||||
parallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * ((IOsuScreen)next).BackgroundParallaxAmount;
|
if (next != null)
|
||||||
|
{
|
||||||
|
parallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * ((IOsuScreen)next).BackgroundParallaxAmount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,15 +73,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
Player?.Exit();
|
Player?.Exit();
|
||||||
Player = null;
|
Player = null;
|
||||||
|
|
||||||
var player = CreatePlayer(r);
|
Player = CreatePlayer(r);
|
||||||
|
|
||||||
LoadComponentAsync(player, p =>
|
LoadScreen(Player);
|
||||||
{
|
|
||||||
Player = p;
|
|
||||||
LoadScreen(p);
|
|
||||||
});
|
|
||||||
|
|
||||||
return player;
|
return Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
|
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
|
||||||
|
@ -52,11 +52,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
if (!AllowFail)
|
if (!AllowFail)
|
||||||
Beatmap.Value.Mods.Value = new[] { ruleset.GetAllMods().First(m => m is ModNoFail) };
|
Beatmap.Value.Mods.Value = new[] { ruleset.GetAllMods().First(m => m is ModNoFail) };
|
||||||
|
|
||||||
LoadComponentAsync(Player = CreatePlayer(ruleset), p =>
|
Player = CreatePlayer(ruleset);
|
||||||
{
|
LoadScreen(Player);
|
||||||
Player = p;
|
|
||||||
LoadScreen(p);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
|
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
|
||||||
|
Loading…
Reference in New Issue
Block a user