2019-03-11 10:48:07 +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-11 10:48:07 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens
|
|
|
|
{
|
|
|
|
public class OsuScreenStack : ScreenStack
|
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
private BackgroundScreenStack backgroundScreenStack;
|
|
|
|
|
2020-01-31 12:36:19 +00:00
|
|
|
private readonly ParallaxContainer parallaxContainer;
|
2019-03-12 07:03:25 +00:00
|
|
|
|
2019-03-22 05:10:38 +00:00
|
|
|
protected float ParallaxAmount => parallaxContainer.ParallaxAmount;
|
|
|
|
|
2019-03-12 07:03:25 +00:00
|
|
|
public OsuScreenStack()
|
|
|
|
{
|
|
|
|
InternalChild = parallaxContainer = new ParallaxContainer
|
2019-03-11 10:48:07 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-03-12 07:03:25 +00:00
|
|
|
Child = backgroundScreenStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both },
|
2019-03-11 10:48:07 +00:00
|
|
|
};
|
2019-03-12 07:03:25 +00:00
|
|
|
|
2020-01-31 10:10:44 +00:00
|
|
|
ScreenPushed += screenPushed;
|
2020-02-06 05:22:01 +00:00
|
|
|
ScreenExited += ScreenChanged;
|
2019-03-12 07:03:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 09:08:17 +00:00
|
|
|
public void PushSynchronously(OsuScreen screen)
|
|
|
|
{
|
|
|
|
LoadComponent(screen);
|
|
|
|
|
|
|
|
Push(screen);
|
|
|
|
}
|
|
|
|
|
2020-01-31 10:10:44 +00:00
|
|
|
private void screenPushed(IScreen prev, IScreen next)
|
2019-03-12 07:03:25 +00:00
|
|
|
{
|
2020-01-31 10:10:44 +00: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);
|
|
|
|
|
2020-02-06 05:22:01 +00:00
|
|
|
ScreenChanged(prev, next);
|
2019-03-11 10:48:07 +00:00
|
|
|
}
|
2020-01-31 10:10:44 +00:00
|
|
|
|
2020-02-06 05:22:01 +00:00
|
|
|
protected virtual void ScreenChanged(IScreen prev, IScreen next)
|
2020-01-31 10:10:44 +00:00
|
|
|
{
|
|
|
|
setParallax(next);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setParallax(IScreen next) =>
|
2021-09-17 09:14:39 +00:00
|
|
|
parallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * (((IOsuScreen)next)?.BackgroundParallaxAmount ?? 1.0f);
|
2019-03-11 10:48:07 +00:00
|
|
|
}
|
|
|
|
}
|