1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Merge pull request #14991 from peppy/intro-tests-no-menu-load

Allow intro screens to be created without loading a `MainMenu`
This commit is contained in:
Dan Balasescu 2021-10-07 20:48:54 +09:00 committed by GitHub
commit f8e50731b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 61 additions and 18 deletions

View File

@ -5,7 +5,6 @@ using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Screens;
using osu.Game.Screens;
using osu.Game.Screens.Menu;
using osuTK;
@ -21,6 +20,8 @@ namespace osu.Game.Tests.Visual.Menus
protected OsuScreenStack IntroStack;
private IntroScreen intro;
protected IntroTestScene()
{
Children = new Drawable[]
@ -39,7 +40,11 @@ namespace osu.Game.Tests.Visual.Menus
Position = new Vector2(0.5f),
}
};
}
[Test]
public virtual void TestPlayIntro()
{
AddStep("restart sequence", () =>
{
logo.FinishTransforms();
@ -52,12 +57,12 @@ namespace osu.Game.Tests.Visual.Menus
RelativeSizeAxes = Axes.Both,
});
IntroStack.Push(CreateScreen());
IntroStack.Push(intro = CreateScreen());
});
AddUntilStep("wait for menu", () => IntroStack.CurrentScreen is MainMenu);
AddUntilStep("wait for menu", () => intro.DidLoadMenu);
}
protected abstract IScreen CreateScreen();
protected abstract IntroScreen CreateScreen();
}
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Screens;
using osu.Game.Screens.Menu;
namespace osu.Game.Tests.Visual.Menus
@ -10,6 +9,6 @@ namespace osu.Game.Tests.Visual.Menus
[TestFixture]
public class TestSceneIntroCircles : IntroTestScene
{
protected override IScreen CreateScreen() => new IntroCircles();
protected override IntroScreen CreateScreen() => new IntroCircles();
}
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Screens;
using osu.Game.Screens.Menu;
namespace osu.Game.Tests.Visual.Menus
@ -10,6 +9,6 @@ namespace osu.Game.Tests.Visual.Menus
[TestFixture]
public class TestSceneIntroTriangles : IntroTestScene
{
protected override IScreen CreateScreen() => new IntroTriangles();
protected override IntroScreen CreateScreen() => new IntroTriangles();
}
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Screens;
using osu.Framework.Utils;
using osu.Game.Screens.Menu;
@ -11,10 +10,12 @@ namespace osu.Game.Tests.Visual.Menus
[TestFixture]
public class TestSceneIntroWelcome : IntroTestScene
{
protected override IScreen CreateScreen() => new IntroWelcome();
protected override IntroScreen CreateScreen() => new IntroWelcome();
public TestSceneIntroWelcome()
public override void TestPlayIntro()
{
base.TestPlayIntro();
AddUntilStep("wait for load", () => MusicController.TrackLoaded);
AddAssert("correct track", () => Precision.AlmostEquals(MusicController.CurrentTrack.Length, 48000, 1));
AddAssert("check if menu music loops", () => MusicController.CurrentTrack.Looping);

View File

@ -49,14 +49,16 @@ namespace osu.Game.Screens
switch (introSequence)
{
case IntroSequence.Circles:
return new IntroCircles();
return new IntroCircles(createMainMenu);
case IntroSequence.Welcome:
return new IntroWelcome();
return new IntroWelcome(createMainMenu);
default:
return new IntroTriangles();
return new IntroTriangles(createMainMenu);
}
MainMenu createMainMenu() => new MainMenu();
}
protected virtual ShaderPrecompiler CreateShaderPrecompiler() => new ShaderPrecompiler();

View File

@ -1,6 +1,8 @@
// 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 System;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
@ -20,6 +22,11 @@ namespace osu.Game.Screens.Menu
private Sample welcome;
public IntroCircles([CanBeNull] Func<MainMenu> createNextScreen = null)
: base(createNextScreen)
{
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{

View File

@ -1,15 +1,17 @@
// 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 System;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Framework.Screens;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.IO.Archives;
@ -55,7 +57,7 @@ namespace osu.Game.Screens.Menu
private LeasedBindable<WorkingBeatmap> beatmap;
private MainMenu mainMenu;
private OsuScreen nextScreen;
[Resolved]
private AudioManager audio { get; set; }
@ -63,12 +65,20 @@ namespace osu.Game.Screens.Menu
[Resolved]
private MusicController musicController { get; set; }
[CanBeNull]
private readonly Func<OsuScreen> createNextScreen;
/// <summary>
/// Whether the <see cref="Track"/> is provided by osu! resources, rather than a user beatmap.
/// Only valid during or after <see cref="LogoArriving"/>.
/// </summary>
protected bool UsingThemedIntro { get; private set; }
protected IntroScreen([CanBeNull] Func<MainMenu> createNextScreen = null)
{
this.createNextScreen = createNextScreen;
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game)
{
@ -214,14 +224,21 @@ namespace osu.Game.Screens.Menu
}
}
protected void PrepareMenuLoad() => LoadComponentAsync(mainMenu = new MainMenu());
protected void PrepareMenuLoad()
{
nextScreen = createNextScreen?.Invoke();
if (nextScreen != null)
LoadComponentAsync(nextScreen);
}
protected void LoadMenu()
{
beatmap.Return();
DidLoadMenu = true;
this.Push(mainMenu);
if (nextScreen != null)
this.Push(nextScreen);
}
}
}

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
@ -44,6 +45,11 @@ namespace osu.Game.Screens.Menu
private DecoupleableInterpolatingFramedClock decoupledClock;
private TrianglesIntroSequence intro;
public IntroTriangles([CanBeNull] Func<MainMenu> createNextScreen = null)
: base(createNextScreen)
{
}
[BackgroundDependencyLoader]
private void load()
{

View File

@ -1,6 +1,8 @@
// 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 System;
using JetBrains.Annotations;
using osuTK;
using osu.Framework.Allocation;
using osu.Framework.Audio;
@ -32,6 +34,11 @@ namespace osu.Game.Screens.Menu
private BackgroundScreenDefault background;
public IntroWelcome([CanBeNull] Func<MainMenu> createNextScreen = null)
: base(createNextScreen)
{
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{