2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-03-11 18:48:07 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
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
|
2019-03-11 18:48:07 +08:00
|
|
|
|
{
|
|
|
|
|
[Cached]
|
|
|
|
|
private BackgroundScreenStack backgroundScreenStack;
|
|
|
|
|
|
2020-01-31 20:36:19 +08:00
|
|
|
|
private readonly ParallaxContainer parallaxContainer;
|
2019-03-12 15:03:25 +08:00
|
|
|
|
|
2019-03-22 13:10:38 +08:00
|
|
|
|
protected float ParallaxAmount => parallaxContainer.ParallaxAmount;
|
|
|
|
|
|
2024-05-16 12:20:55 +08:00
|
|
|
|
public new MarginPadding Padding
|
|
|
|
|
{
|
|
|
|
|
get => base.Padding;
|
|
|
|
|
set => base.Padding = value;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 15:03:25 +08:00
|
|
|
|
public OsuScreenStack()
|
|
|
|
|
{
|
|
|
|
|
InternalChild = parallaxContainer = new ParallaxContainer
|
2019-03-11 18:48:07 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-03-12 15:03:25 +08:00
|
|
|
|
Child = backgroundScreenStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both },
|
2019-03-11 18:48:07 +08:00
|
|
|
|
};
|
2019-03-12 15:03:25 +08:00
|
|
|
|
|
2020-01-31 18:10:44 +08:00
|
|
|
|
ScreenPushed += screenPushed;
|
2020-02-06 13:22:01 +08:00
|
|
|
|
ScreenExited += ScreenChanged;
|
2019-03-12 15:03:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 17:08:17 +08:00
|
|
|
|
public void PushSynchronously(OsuScreen screen)
|
|
|
|
|
{
|
|
|
|
|
LoadComponent(screen);
|
|
|
|
|
|
|
|
|
|
Push(screen);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-31 18:10:44 +08:00
|
|
|
|
private void screenPushed(IScreen prev, IScreen next)
|
2019-03-12 15:03:25 +08:00
|
|
|
|
{
|
2020-01-31 18:10:44 +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);
|
|
|
|
|
|
2020-02-06 13:22:01 +08:00
|
|
|
|
ScreenChanged(prev, next);
|
2019-03-11 18:48:07 +08:00
|
|
|
|
}
|
2020-01-31 18:10:44 +08:00
|
|
|
|
|
2023-06-23 23:59:36 +08:00
|
|
|
|
protected virtual void ScreenChanged(IScreen prev, IScreen? next)
|
2020-01-31 18:10:44 +08:00
|
|
|
|
{
|
|
|
|
|
setParallax(next);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-23 23:59:36 +08:00
|
|
|
|
private void setParallax(IScreen? next) =>
|
|
|
|
|
parallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * ((next as IOsuScreen)?.BackgroundParallaxAmount ?? 1.0f);
|
2019-03-11 18:48:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|