1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 05:53:21 +08:00
osu-lazer/osu.Game/Screens/OsuScreenStack.cs

66 lines
2.0 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens
{
2022-11-24 13:32:20 +08:00
public partial class OsuScreenStack : ScreenStack
{
[Cached]
private BackgroundScreenStack backgroundScreenStack;
2020-01-31 20:36:19 +08:00
private readonly ParallaxContainer parallaxContainer;
2019-03-12 15:03:25 +08:00
protected float ParallaxAmount => parallaxContainer.ParallaxAmount;
2019-03-12 15:03:25 +08:00
public OsuScreenStack()
{
InternalChild = parallaxContainer = new ParallaxContainer
{
RelativeSizeAxes = Axes.Both,
2019-03-12 15:03:25 +08:00
Child = backgroundScreenStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both },
};
2019-03-12 15:03:25 +08:00
ScreenPushed += screenPushed;
ScreenExited += ScreenChanged;
2019-03-12 15:03:25 +08:00
}
public void PushSynchronously(OsuScreen screen)
{
LoadComponent(screen);
Push(screen);
}
private void screenPushed(IScreen prev, IScreen next)
2019-03-12 15:03:25 +08:00
{
if (LoadState < LoadState.Ready)
{
// dependencies must be present to stay in a sane state.
// this is generally only ever hit by test scenes.
Schedule(() => screenPushed(prev, next));
return;
}
// create dependencies synchronously to ensure leases are in a sane state.
((OsuScreen)next).CreateLeasedDependencies((prev as OsuScreen)?.Dependencies ?? Dependencies);
ScreenChanged(prev, next);
}
protected virtual void ScreenChanged(IScreen prev, IScreen next)
{
setParallax(next);
}
private void setParallax(IScreen next) =>
parallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * (((IOsuScreen)next)?.BackgroundParallaxAmount ?? 1.0f);
}
}