mirror of
https://github.com/ppy/osu
synced 2024-12-27 17:32:56 +00:00
Create a custom background stack to fix various background issues
This commit is contained in:
parent
a7e281469b
commit
f0e0088f43
@ -85,8 +85,7 @@ namespace osu.Game
|
||||
|
||||
public readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
|
||||
|
||||
private ParallaxContainer backgroundParallax;
|
||||
private ScreenStack backgroundStack;
|
||||
private BackgroundScreenStack backgroundStack;
|
||||
private ScreenStack screenStack;
|
||||
private VolumeOverlay volume;
|
||||
private OnScreenDisplay onscreenDisplay;
|
||||
@ -356,12 +355,7 @@ namespace osu.Game
|
||||
ActionRequested = action => volume.Adjust(action),
|
||||
ScrollActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise),
|
||||
},
|
||||
backgroundParallax = new ParallaxContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Scale = new Vector2(1.06f),
|
||||
Child = backgroundStack = new ScreenStack { RelativeSizeAxes = Axes.Both }
|
||||
},
|
||||
backgroundStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both },
|
||||
screenContainer = new ScalingContainer(ScalingMode.ExcludeOverlays)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -376,6 +370,8 @@ namespace osu.Game
|
||||
idleTracker = new IdleTracker(6000)
|
||||
});
|
||||
|
||||
dependencies.Cache(backgroundStack);
|
||||
|
||||
screenStack.ScreenPushed += screenPushed;
|
||||
screenStack.ScreenExited += screenExited;
|
||||
|
||||
@ -742,9 +738,6 @@ namespace osu.Game
|
||||
|
||||
protected virtual void ScreenChanged(IScreen lastScreen, IScreen newScreen)
|
||||
{
|
||||
if (newScreen is IOsuScreen newOsuScreen)
|
||||
backgroundParallax.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * newOsuScreen.BackgroundParallaxAmount;
|
||||
|
||||
switch (newScreen)
|
||||
{
|
||||
case Intro intro:
|
||||
@ -758,18 +751,12 @@ namespace osu.Game
|
||||
|
||||
private void screenPushed(IScreen lastScreen, IScreen newScreen)
|
||||
{
|
||||
if (newScreen is IOsuScreen newOsuScreen && newOsuScreen.Background != null)
|
||||
backgroundStack.Push(newOsuScreen.Background);
|
||||
|
||||
ScreenChanged(lastScreen, newScreen);
|
||||
Logger.Log($"Screen changed → {newScreen}");
|
||||
}
|
||||
|
||||
private void screenExited(IScreen lastScreen, IScreen newScreen)
|
||||
{
|
||||
if (newScreen is IOsuScreen newOsuScreen)
|
||||
newOsuScreen.Background?.MakeCurrent();
|
||||
|
||||
ScreenChanged(lastScreen, newScreen);
|
||||
Logger.Log($"Screen changed ← {newScreen}");
|
||||
|
||||
|
52
osu.Game/Screens/BackgroundScreenStack.cs
Normal file
52
osu.Game/Screens/BackgroundScreenStack.cs
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2007-2019 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens
|
||||
{
|
||||
public class BackgroundScreenStack : CompositeDrawable
|
||||
{
|
||||
public BackgroundScreen Current => (BackgroundScreen)stack.CurrentScreen;
|
||||
|
||||
private readonly ParallaxContainer parallax;
|
||||
private readonly ScreenStack stack;
|
||||
|
||||
public BackgroundScreenStack()
|
||||
{
|
||||
InternalChild = parallax = new ParallaxContainer
|
||||
{
|
||||
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 void Push(BackgroundScreen screen)
|
||||
{
|
||||
if (screen == null)
|
||||
return;
|
||||
|
||||
if (EqualityComparer<BackgroundScreen>.Default.Equals(Current, screen))
|
||||
return;
|
||||
|
||||
stack.Push(screen);
|
||||
}
|
||||
|
||||
public void Exit(BackgroundScreen screen)
|
||||
{
|
||||
if (stack.CurrentScreen == screen)
|
||||
stack.Exit();
|
||||
}
|
||||
}
|
||||
}
|
@ -19,9 +19,5 @@ namespace osu.Game.Screens
|
||||
/// Whether this <see cref="OsuScreen"/> allows the cursor to be displayed.
|
||||
/// </summary>
|
||||
bool CursorVisible { get; }
|
||||
|
||||
BackgroundScreen Background { get; }
|
||||
|
||||
float BackgroundParallaxAmount { get; }
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ namespace osu.Game.Screens
|
||||
{
|
||||
public abstract class OsuScreen : Screen, IOsuScreen, IKeyBindingHandler<GlobalAction>, IHasDescription
|
||||
{
|
||||
public BackgroundScreen Background { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A user-facing title for this screen.
|
||||
/// </summary>
|
||||
@ -34,12 +32,6 @@ namespace osu.Game.Screens
|
||||
|
||||
public virtual bool AllowExternalScreenChange => false;
|
||||
|
||||
/// <summary>
|
||||
/// Override to create a BackgroundMode for the current screen.
|
||||
/// Note that the instance created may not be the used instance if it matches the BackgroundMode equality clause.
|
||||
/// </summary>
|
||||
protected virtual BackgroundScreen CreateBackground() => null;
|
||||
|
||||
private Action updateOverlayStates;
|
||||
|
||||
/// <summary>
|
||||
@ -58,9 +50,6 @@ namespace osu.Game.Screens
|
||||
|
||||
protected new OsuGameBase Game => base.Game as OsuGameBase;
|
||||
|
||||
[Resolved]
|
||||
private OsuLogo logo { get; set; }
|
||||
|
||||
public virtual bool AllowBeatmapRulesetChange => true;
|
||||
|
||||
protected readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
|
||||
@ -71,12 +60,20 @@ namespace osu.Game.Screens
|
||||
|
||||
private SampleChannel sampleExit;
|
||||
|
||||
protected BackgroundScreen Background => backgroundStack?.Current;
|
||||
|
||||
private BackgroundScreen localBackground;
|
||||
|
||||
[Resolved]
|
||||
private BackgroundScreenStack backgroundStack { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuLogo logo { get; set; }
|
||||
|
||||
protected OsuScreen()
|
||||
{
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
Background = CreateBackground();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
@ -134,6 +131,8 @@ namespace osu.Game.Screens
|
||||
{
|
||||
applyArrivingDefaults(false);
|
||||
|
||||
backgroundStack.Push(localBackground = CreateBackground());
|
||||
|
||||
base.OnEntering(last);
|
||||
}
|
||||
|
||||
@ -145,6 +144,8 @@ namespace osu.Game.Screens
|
||||
if (base.OnExiting(next))
|
||||
return true;
|
||||
|
||||
backgroundStack.Exit(localBackground);
|
||||
|
||||
Beatmap.UnbindAll();
|
||||
return false;
|
||||
}
|
||||
@ -171,6 +172,8 @@ namespace osu.Game.Screens
|
||||
if (this.IsCurrentScreen()) LogoArriving(logo, isResuming);
|
||||
}, true);
|
||||
|
||||
backgroundStack.ParallaxAmount = BackgroundParallaxAmount;
|
||||
|
||||
OverlayActivationMode.Value = InitialOverlayActivationMode;
|
||||
|
||||
updateOverlayStates?.Invoke();
|
||||
@ -199,5 +202,11 @@ namespace osu.Game.Screens
|
||||
protected virtual void LogoSuspending(OsuLogo logo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override to create a BackgroundMode for the current screen.
|
||||
/// Note that the instance created may not be the used instance if it matches the BackgroundMode equality clause.
|
||||
/// </summary>
|
||||
protected virtual BackgroundScreen CreateBackground() => null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user