mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 16:12:57 +08:00
Merge pull request #4451 from nyquillerium/multi-background-stack
Centralise BackgroundScreenStack handling Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
1155dba195
@ -9,7 +9,6 @@ using NUnit.Framework;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Input.States;
|
using osu.Framework.Input.States;
|
||||||
@ -54,8 +53,6 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
private BeatmapManager manager;
|
private BeatmapManager manager;
|
||||||
private RulesetStore rulesets;
|
private RulesetStore rulesets;
|
||||||
|
|
||||||
private ScreenStackCacheContainer screenStackContainer;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(GameHost host)
|
private void load(GameHost host)
|
||||||
{
|
{
|
||||||
@ -82,8 +79,10 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
[SetUp]
|
[SetUp]
|
||||||
public virtual void SetUp() => Schedule(() =>
|
public virtual void SetUp() => Schedule(() =>
|
||||||
{
|
{
|
||||||
Child = screenStackContainer = new ScreenStackCacheContainer { RelativeSizeAxes = Axes.Both };
|
Child = new OsuScreenStack(songSelect = new DummySongSelect())
|
||||||
screenStackContainer.ScreenStack.Push(songSelect = new DummySongSelect());
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -373,20 +372,6 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ScreenStackCacheContainer : Container
|
|
||||||
{
|
|
||||||
[Cached]
|
|
||||||
private BackgroundScreenStack backgroundScreenStack;
|
|
||||||
|
|
||||||
public readonly ScreenStack ScreenStack;
|
|
||||||
|
|
||||||
public ScreenStackCacheContainer()
|
|
||||||
{
|
|
||||||
Add(backgroundScreenStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both });
|
|
||||||
Add(ScreenStack = new ScreenStack { RelativeSizeAxes = Axes.Both });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TestPlayerLoader : PlayerLoader
|
private class TestPlayerLoader : PlayerLoader
|
||||||
{
|
{
|
||||||
public VisualSettings VisualSettingsPos => VisualSettings;
|
public VisualSettings VisualSettingsPos => VisualSettings;
|
||||||
|
@ -14,15 +14,11 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
public class TestCasePlayerLoader : ManualInputManagerTestCase
|
public class TestCasePlayerLoader : ManualInputManagerTestCase
|
||||||
{
|
{
|
||||||
private PlayerLoader loader;
|
private PlayerLoader loader;
|
||||||
private readonly ScreenStack stack;
|
private readonly OsuScreenStack stack;
|
||||||
|
|
||||||
[Cached]
|
|
||||||
private BackgroundScreenStack backgroundStack;
|
|
||||||
|
|
||||||
public TestCasePlayerLoader()
|
public TestCasePlayerLoader()
|
||||||
{
|
{
|
||||||
InputManager.Add(backgroundStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both });
|
InputManager.Add(stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both });
|
||||||
InputManager.Add(stack = new ScreenStack { RelativeSizeAxes = Axes.Both });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
@ -16,7 +16,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
ScreenStack screenStack = new ScreenStack(new TestMultiplayerSubScreen(index)) { RelativeSizeAxes = Axes.Both };
|
OsuScreenStack screenStack = new OsuScreenStack(new TestMultiplayerSubScreen(index)) { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
82
osu.Game.Tests/Visual/TestCaseOsuScreenStack.cs
Normal file
82
osu.Game.Tests/Visual/TestCaseOsuScreenStack.cs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Screens;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Screens;
|
||||||
|
using osu.Game.Screens.Play;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class TestCaseOsuScreenStack : OsuTestCase
|
||||||
|
{
|
||||||
|
private TestOsuScreenStack stack;
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
|
AddStep("Create new screen stack", () => { Child = stack = new TestOsuScreenStack { RelativeSizeAxes = Axes.Both }; });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ParallaxAssignmentTest()
|
||||||
|
{
|
||||||
|
NoParallaxTestScreen noParallaxScreen = null;
|
||||||
|
TestScreen parallaxScreen = null;
|
||||||
|
|
||||||
|
AddStep("Push no parallax", () => stack.Push(noParallaxScreen = new NoParallaxTestScreen("NO PARALLAX")));
|
||||||
|
AddUntilStep("Wait for current", () => noParallaxScreen.IsLoaded);
|
||||||
|
AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);
|
||||||
|
|
||||||
|
AddStep("Push parallax", () => noParallaxScreen.Push(parallaxScreen = new TestScreen("PARALLAX")));
|
||||||
|
AddUntilStep("Wait for current", () => parallaxScreen.IsLoaded);
|
||||||
|
AddAssert("Parallax is on", () => stack.ParallaxAmount > 0);
|
||||||
|
|
||||||
|
AddStep("Exit from new screen", () => { noParallaxScreen.MakeCurrent(); });
|
||||||
|
AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestScreen : ScreenWithBeatmapBackground
|
||||||
|
{
|
||||||
|
private readonly string screenText;
|
||||||
|
|
||||||
|
public TestScreen(string screenText)
|
||||||
|
{
|
||||||
|
this.screenText = screenText;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
AddInternal(new SpriteText
|
||||||
|
{
|
||||||
|
Text = screenText,
|
||||||
|
Colour = Color4.White,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NoParallaxTestScreen : TestScreen
|
||||||
|
{
|
||||||
|
public NoParallaxTestScreen(string screenText)
|
||||||
|
: base(screenText)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override float BackgroundParallaxAmount => 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestOsuScreenStack : OsuScreenStack
|
||||||
|
{
|
||||||
|
public new float ParallaxAmount => base.ParallaxAmount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,14 +19,14 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
public class TestCaseScreenBreadcrumbControl : OsuTestCase
|
public class TestCaseScreenBreadcrumbControl : OsuTestCase
|
||||||
{
|
{
|
||||||
private readonly ScreenBreadcrumbControl breadcrumbs;
|
private readonly ScreenBreadcrumbControl breadcrumbs;
|
||||||
private readonly ScreenStack screenStack;
|
private readonly OsuScreenStack screenStack;
|
||||||
|
|
||||||
public TestCaseScreenBreadcrumbControl()
|
public TestCaseScreenBreadcrumbControl()
|
||||||
{
|
{
|
||||||
OsuSpriteText titleText;
|
OsuSpriteText titleText;
|
||||||
|
|
||||||
IScreen startScreen = new TestScreenOne();
|
IScreen startScreen = new TestScreenOne();
|
||||||
screenStack = new ScreenStack(startScreen) { RelativeSizeAxes = Axes.Both };
|
screenStack = new OsuScreenStack(startScreen) { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
@ -87,11 +87,7 @@ namespace osu.Game
|
|||||||
|
|
||||||
public readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
|
public readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
|
||||||
|
|
||||||
private BackgroundScreenStack backgroundStack;
|
private OsuScreenStack screenStack;
|
||||||
|
|
||||||
private ParallaxContainer backgroundParallax;
|
|
||||||
|
|
||||||
private ScreenStack screenStack;
|
|
||||||
private VolumeOverlay volume;
|
private VolumeOverlay volume;
|
||||||
private OnScreenDisplay onscreenDisplay;
|
private OnScreenDisplay onscreenDisplay;
|
||||||
private OsuLogo osuLogo;
|
private OsuLogo osuLogo;
|
||||||
@ -390,12 +386,7 @@ namespace osu.Game
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
backgroundParallax = new ParallaxContainer
|
screenStack = new OsuScreenStack { RelativeSizeAxes = Axes.Both },
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Child = backgroundStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both },
|
|
||||||
},
|
|
||||||
screenStack = new ScreenStack { RelativeSizeAxes = Axes.Both },
|
|
||||||
logoContainer = new Container { RelativeSizeAxes = Axes.Both },
|
logoContainer = new Container { RelativeSizeAxes = Axes.Both },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -407,17 +398,19 @@ namespace osu.Game
|
|||||||
idleTracker = new GameIdleTracker(6000)
|
idleTracker = new GameIdleTracker(6000)
|
||||||
});
|
});
|
||||||
|
|
||||||
dependencies.Cache(backgroundStack);
|
|
||||||
|
|
||||||
screenStack.ScreenPushed += screenPushed;
|
screenStack.ScreenPushed += screenPushed;
|
||||||
screenStack.ScreenExited += screenExited;
|
screenStack.ScreenExited += screenExited;
|
||||||
|
|
||||||
loadComponentSingleFile(osuLogo, logoContainer.Add);
|
loadComponentSingleFile(osuLogo, logo =>
|
||||||
|
|
||||||
loadComponentSingleFile(new Loader
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both
|
logoContainer.Add(logo);
|
||||||
}, screenStack.Push);
|
|
||||||
|
// Loader has to be created after the logo has finished loading as Loader performs logo transformations on entering.
|
||||||
|
screenStack.Push(new Loader
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
loadComponentSingleFile(Toolbar = new Toolbar
|
loadComponentSingleFile(Toolbar = new Toolbar
|
||||||
{
|
{
|
||||||
@ -777,8 +770,6 @@ 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)
|
||||||
|
@ -95,7 +95,7 @@ namespace osu.Game.Screens.Multi
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Padding = new MarginPadding { Top = Header.HEIGHT },
|
Padding = new MarginPadding { Top = Header.HEIGHT },
|
||||||
Child = screenStack = new ScreenStack(loungeSubScreen = new LoungeSubScreen()) { RelativeSizeAxes = Axes.Both }
|
Child = screenStack = new OsuScreenStack(loungeSubScreen = new LoungeSubScreen()) { RelativeSizeAxes = Axes.Both }
|
||||||
},
|
},
|
||||||
new Header(screenStack),
|
new Header(screenStack),
|
||||||
createButton = new HeaderButton
|
createButton = new HeaderButton
|
||||||
|
48
osu.Game/Screens/OsuScreenStack.cs
Normal file
48
osu.Game/Screens/OsuScreenStack.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
private ParallaxContainer parallaxContainer;
|
||||||
|
|
||||||
|
protected float ParallaxAmount => parallaxContainer.ParallaxAmount;
|
||||||
|
|
||||||
|
public OsuScreenStack()
|
||||||
|
{
|
||||||
|
initializeStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsuScreenStack(IScreen baseScreen)
|
||||||
|
: base(baseScreen)
|
||||||
|
{
|
||||||
|
initializeStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeStack()
|
||||||
|
{
|
||||||
|
InternalChild = parallaxContainer = new ParallaxContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Child = backgroundScreenStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both },
|
||||||
|
};
|
||||||
|
|
||||||
|
ScreenPushed += onScreenChange;
|
||||||
|
ScreenExited += onScreenChange;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onScreenChange(IScreen prev, IScreen next)
|
||||||
|
{
|
||||||
|
parallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * ((IOsuScreen)next)?.BackgroundParallaxAmount ?? 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -73,15 +73,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
Player?.Exit();
|
Player?.Exit();
|
||||||
Player = null;
|
Player = null;
|
||||||
|
|
||||||
var player = CreatePlayer(r);
|
Player = CreatePlayer(r);
|
||||||
|
|
||||||
LoadComponentAsync(player, p =>
|
LoadScreen(Player);
|
||||||
{
|
|
||||||
Player = p;
|
|
||||||
LoadScreen(p);
|
|
||||||
});
|
|
||||||
|
|
||||||
return player;
|
return Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
|
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
|
||||||
|
@ -26,7 +26,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
Beatmap.Value = new TestWorkingBeatmap(ruleset.RulesetInfo, null);
|
Beatmap.Value = new TestWorkingBeatmap(ruleset.RulesetInfo, null);
|
||||||
|
|
||||||
LoadComponentAsync(new Editor(), LoadScreen);
|
LoadScreen(new Editor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
if (!AllowFail)
|
if (!AllowFail)
|
||||||
Beatmap.Value.Mods.Value = new[] { ruleset.GetAllMods().First(m => m is ModNoFail) };
|
Beatmap.Value.Mods.Value = new[] { ruleset.GetAllMods().First(m => m is ModNoFail) };
|
||||||
|
|
||||||
LoadComponentAsync(Player = CreatePlayer(ruleset), p =>
|
Player = CreatePlayer(ruleset);
|
||||||
{
|
LoadScreen(Player);
|
||||||
Player = p;
|
|
||||||
LoadScreen(p);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
|
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Screens;
|
|
||||||
using osu.Game.Screens;
|
using osu.Game.Screens;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual
|
namespace osu.Game.Tests.Visual
|
||||||
@ -13,18 +11,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ScreenTestCase : OsuTestCase
|
public abstract class ScreenTestCase : OsuTestCase
|
||||||
{
|
{
|
||||||
private readonly ScreenStack stack;
|
private readonly OsuScreenStack stack;
|
||||||
|
|
||||||
[Cached]
|
|
||||||
private BackgroundScreenStack backgroundStack;
|
|
||||||
|
|
||||||
protected ScreenTestCase()
|
protected ScreenTestCase()
|
||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Child = stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both };
|
||||||
{
|
|
||||||
backgroundStack = new BackgroundScreenStack { RelativeSizeAxes = Axes.Both },
|
|
||||||
stack = new ScreenStack { RelativeSizeAxes = Axes.Both }
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void LoadScreen(OsuScreen screen)
|
protected void LoadScreen(OsuScreen screen)
|
||||||
|
Loading…
Reference in New Issue
Block a user