Move parallax logic out of BackgroundScreenStack

This commit is contained in:
Dean Herbert 2019-01-31 18:10:21 +09:00
parent bdaff27575
commit b48bb5b792
6 changed files with 29 additions and 33 deletions

View File

@ -86,6 +86,9 @@ namespace osu.Game
public readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>(); public readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
private BackgroundScreenStack backgroundStack; private BackgroundScreenStack backgroundStack;
private ParallaxContainer backgroundParallax;
private ScreenStack screenStack; private ScreenStack screenStack;
private VolumeOverlay volume; private VolumeOverlay volume;
private OnScreenDisplay onscreenDisplay; private OnScreenDisplay onscreenDisplay;
@ -353,7 +356,11 @@ namespace osu.Game
ActionRequested = action => volume.Adjust(action), ActionRequested = action => volume.Adjust(action),
ScrollActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise), ScrollActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise),
}, },
backgroundStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both }, backgroundParallax = new ParallaxContainer
{
RelativeSizeAxes = Axes.Both,
Child = backgroundStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both },
},
screenContainer = new ScalingContainer(ScalingMode.ExcludeOverlays) screenContainer = new ScalingContainer(ScalingMode.ExcludeOverlays)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -766,6 +773,8 @@ namespace osu.Game
if (newScreen is IOsuScreen newOsuScreen) if (newScreen is IOsuScreen newOsuScreen)
{ {
backgroundParallax.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * newOsuScreen.BackgroundParallaxAmount;
OverlayActivationMode.Value = newOsuScreen.InitialOverlayActivationMode; OverlayActivationMode.Value = newOsuScreen.InitialOverlayActivationMode;
if (newOsuScreen.HideOverlaysOnEnter) if (newOsuScreen.HideOverlaysOnEnter)

View File

@ -3,50 +3,30 @@
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Graphics.Containers;
using osuTK; using osuTK;
namespace osu.Game.Screens namespace osu.Game.Screens
{ {
public class BackgroundScreenStack : CompositeDrawable public class BackgroundScreenStack : ScreenStack
{ {
public BackgroundScreen Current => (BackgroundScreen)stack.CurrentScreen;
private readonly ParallaxContainer parallax;
private readonly ScreenStack stack;
public BackgroundScreenStack() public BackgroundScreenStack()
{ {
InternalChild = parallax = new ParallaxContainer Scale = new Vector2(1.06f);
{ RelativeSizeAxes = Axes.Both;
RelativeSizeAxes = Axes.Both,
Child = stack = new ScreenStack
{
RelativeSizeAxes = Axes.Both,
Scale = new Vector2(1.06f)
}
};
} }
public float ParallaxAmount { set => parallax.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * value; } //public float ParallaxAmount { set => parallax.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * value; }
public void Push(BackgroundScreen screen) public new void Push(BackgroundScreen screen)
{ {
if (screen == null) if (screen == null)
return; return;
if (EqualityComparer<BackgroundScreen>.Default.Equals(Current, screen)) if (EqualityComparer<BackgroundScreen>.Default.Equals((BackgroundScreen)CurrentScreen, screen))
return; return;
stack.Push(screen); base.Push(screen);
}
public void Exit(BackgroundScreen screen)
{
if (stack.CurrentScreen == screen)
stack.Exit();
} }
} }
} }

View File

@ -30,5 +30,10 @@ namespace osu.Game.Screens
/// Whether overlays should be able to be opened once this screen is entered or resumed. /// Whether overlays should be able to be opened once this screen is entered or resumed.
/// </summary> /// </summary>
OverlayActivation InitialOverlayActivationMode { get; } OverlayActivation InitialOverlayActivationMode { get; }
/// <summary>
/// The amount of parallax to be applied while this screen is displayed.
/// </summary>
float BackgroundParallaxAmount { get; }
} }
} }

View File

@ -35,6 +35,8 @@ namespace osu.Game.Screens.Multi
public bool HideOverlaysOnEnter => false; public bool HideOverlaysOnEnter => false;
public OverlayActivation InitialOverlayActivationMode => OverlayActivation.All; public OverlayActivation InitialOverlayActivationMode => OverlayActivation.All;
public float BackgroundParallaxAmount => 1;
public bool ValidForResume { get; set; } = true; public bool ValidForResume { get; set; } = true;
public bool ValidForPush { get; set; } = true; public bool ValidForPush { get; set; } = true;

View File

@ -22,6 +22,8 @@ namespace osu.Game.Screens.Multi
public bool HideOverlaysOnEnter => false; public bool HideOverlaysOnEnter => false;
public OverlayActivation InitialOverlayActivationMode => OverlayActivation.All; public OverlayActivation InitialOverlayActivationMode => OverlayActivation.All;
public float BackgroundParallaxAmount => 1;
public bool ValidForResume { get; set; } = true; public bool ValidForResume { get; set; } = true;
public bool ValidForPush { get; set; } = true; public bool ValidForPush { get; set; } = true;

View File

@ -60,7 +60,7 @@ namespace osu.Game.Screens
private SampleChannel sampleExit; private SampleChannel sampleExit;
protected BackgroundScreen Background => backgroundStack?.Current; protected BackgroundScreen Background => backgroundStack?.CurrentScreen as BackgroundScreen;
private BackgroundScreen localBackground; private BackgroundScreen localBackground;
@ -137,7 +137,8 @@ namespace osu.Game.Screens
if (base.OnExiting(next)) if (base.OnExiting(next))
return true; return true;
backgroundStack?.Exit(localBackground); if (localBackground != null && backgroundStack?.CurrentScreen == localBackground)
backgroundStack?.Exit();
Beatmap.UnbindAll(); Beatmap.UnbindAll();
return false; return false;
@ -157,9 +158,6 @@ namespace osu.Game.Screens
{ {
if (this.IsCurrentScreen()) LogoArriving(logo, isResuming); if (this.IsCurrentScreen()) LogoArriving(logo, isResuming);
}, true); }, true);
if (backgroundStack != null)
backgroundStack.ParallaxAmount = BackgroundParallaxAmount;
} }
/// <summary> /// <summary>