2021-06-07 16:22:30 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-06-09 04:25:29 +08:00
|
|
|
using System;
|
2021-06-07 16:22:30 +08:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2021-12-14 15:10:53 +08:00
|
|
|
using osu.Framework.Audio;
|
2021-12-27 17:59:05 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
|
|
|
using osu.Framework.Graphics;
|
2022-08-02 18:50:57 +08:00
|
|
|
using osu.Framework.Graphics.Rendering;
|
2021-12-14 15:10:53 +08:00
|
|
|
using osu.Framework.Graphics.Textures;
|
2021-06-07 16:22:30 +08:00
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Testing;
|
2021-12-14 15:10:53 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-06-07 16:22:30 +08:00
|
|
|
using osu.Game.Configuration;
|
2021-11-29 16:57:17 +08:00
|
|
|
using osu.Game.Database;
|
2021-12-27 17:59:05 +08:00
|
|
|
using osu.Game.Graphics;
|
2021-06-07 16:22:30 +08:00
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2021-12-27 17:59:05 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-06-07 16:22:30 +08:00
|
|
|
using osu.Game.Online.API;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-06-07 16:22:30 +08:00
|
|
|
using osu.Game.Screens;
|
|
|
|
using osu.Game.Screens.Backgrounds;
|
2021-06-09 13:48:16 +08:00
|
|
|
using osu.Game.Skinning;
|
2021-12-27 17:59:05 +08:00
|
|
|
using osu.Game.Storyboards;
|
|
|
|
using osu.Game.Storyboards.Drawables;
|
2021-12-14 15:10:53 +08:00
|
|
|
using osu.Game.Tests.Beatmaps;
|
2021-06-07 16:22:30 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Background
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public partial class TestSceneBackgroundScreenDefault : OsuTestScene
|
|
|
|
{
|
|
|
|
private BackgroundScreenStack stack;
|
2021-12-14 15:10:53 +08:00
|
|
|
private TestBackgroundScreenDefault screen;
|
2021-06-07 16:22:30 +08:00
|
|
|
private Graphics.Backgrounds.Background getCurrentBackground() => screen.ChildrenOfType<Graphics.Backgrounds.Background>().FirstOrDefault();
|
|
|
|
|
2021-06-09 13:48:16 +08:00
|
|
|
[Resolved]
|
|
|
|
private SkinManager skins { get; set; }
|
|
|
|
|
2021-06-07 16:22:30 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
|
2022-08-02 18:50:57 +08:00
|
|
|
[Resolved]
|
|
|
|
private IRenderer renderer { get; set; }
|
|
|
|
|
2021-06-07 16:22:30 +08:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("create background stack", () => Child = stack = new BackgroundScreenStack());
|
2021-12-14 15:10:53 +08:00
|
|
|
AddStep("push default screen", () => stack.Push(screen = new TestBackgroundScreenDefault()));
|
2021-06-07 16:22:30 +08:00
|
|
|
AddUntilStep("wait for screen to load", () => screen.IsCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:10:53 +08:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmapBackgroundTracksBeatmap()
|
|
|
|
{
|
|
|
|
setSupporter(true);
|
|
|
|
setSourceMode(BackgroundSource.Beatmap);
|
|
|
|
|
|
|
|
AddStep("change beatmap", () => Beatmap.Value = createTestWorkingBeatmapWithUniqueBackground());
|
|
|
|
AddAssert("background changed", () => screen.CheckLastLoadChange() == true);
|
|
|
|
|
|
|
|
Graphics.Backgrounds.Background last = null;
|
|
|
|
|
|
|
|
AddUntilStep("wait for beatmap background to be loaded", () => getCurrentBackground()?.GetType() == typeof(BeatmapBackground));
|
|
|
|
AddStep("store background", () => last = getCurrentBackground());
|
|
|
|
|
|
|
|
AddStep("change beatmap", () => Beatmap.Value = createTestWorkingBeatmapWithUniqueBackground());
|
|
|
|
|
|
|
|
AddUntilStep("wait for beatmap background to change", () => screen.CheckLastLoadChange() == true);
|
|
|
|
|
|
|
|
AddUntilStep("background is new beatmap background", () => last != getCurrentBackground());
|
|
|
|
AddStep("store background", () => last = getCurrentBackground());
|
|
|
|
|
|
|
|
AddStep("change beatmap", () => Beatmap.Value = createTestWorkingBeatmapWithUniqueBackground());
|
|
|
|
|
|
|
|
AddUntilStep("wait for beatmap background to change", () => screen.CheckLastLoadChange() == true);
|
|
|
|
AddUntilStep("background is new beatmap background", () => last != getCurrentBackground());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBeatmapBackgroundTracksBeatmapWhenSuspended()
|
|
|
|
{
|
|
|
|
setSupporter(true);
|
|
|
|
setSourceMode(BackgroundSource.Beatmap);
|
|
|
|
|
|
|
|
AddStep("change beatmap", () => Beatmap.Value = createTestWorkingBeatmapWithUniqueBackground());
|
|
|
|
AddAssert("background changed", () => screen.CheckLastLoadChange() == true);
|
|
|
|
AddUntilStep("wait for beatmap background to be loaded", () => getCurrentBackground()?.GetType() == typeof(BeatmapBackground));
|
|
|
|
|
|
|
|
BackgroundScreenBeatmap nestedScreen = null;
|
|
|
|
|
|
|
|
// of note, this needs to be a type that doesn't match BackgroundScreenDefault else it is silently not pushed by the background stack.
|
|
|
|
AddStep("push new background to stack", () => stack.Push(nestedScreen = new BackgroundScreenBeatmap(Beatmap.Value)));
|
|
|
|
AddUntilStep("wait for screen to load", () => nestedScreen.IsLoaded && nestedScreen.IsCurrentScreen());
|
2021-12-20 11:44:22 +08:00
|
|
|
AddUntilStep("previous background hidden", () => !screen.IsAlive);
|
2021-12-14 15:10:53 +08:00
|
|
|
|
|
|
|
AddAssert("top level background hasn't changed yet", () => screen.CheckLastLoadChange() == null);
|
|
|
|
|
|
|
|
AddStep("change beatmap", () => Beatmap.Value = createTestWorkingBeatmapWithUniqueBackground());
|
|
|
|
|
|
|
|
AddAssert("top level background hasn't changed yet", () => screen.CheckLastLoadChange() == null);
|
|
|
|
|
|
|
|
AddStep("pop screen back to top level", () => screen.MakeCurrent());
|
|
|
|
|
|
|
|
AddAssert("top level background changed", () => screen.CheckLastLoadChange() == true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBeatmapBackgroundIgnoresNoChangeWhenSuspended()
|
|
|
|
{
|
|
|
|
BackgroundScreenBeatmap nestedScreen = null;
|
|
|
|
WorkingBeatmap originalWorking = null;
|
|
|
|
|
|
|
|
setSupporter(true);
|
|
|
|
setSourceMode(BackgroundSource.Beatmap);
|
|
|
|
|
|
|
|
AddStep("change beatmap", () => originalWorking = Beatmap.Value = createTestWorkingBeatmapWithUniqueBackground());
|
|
|
|
AddAssert("background changed", () => screen.CheckLastLoadChange() == true);
|
|
|
|
AddUntilStep("wait for beatmap background to be loaded", () => getCurrentBackground()?.GetType() == typeof(BeatmapBackground));
|
|
|
|
|
|
|
|
// of note, this needs to be a type that doesn't match BackgroundScreenDefault else it is silently not pushed by the background stack.
|
|
|
|
AddStep("push new background to stack", () => stack.Push(nestedScreen = new BackgroundScreenBeatmap(Beatmap.Value)));
|
|
|
|
AddUntilStep("wait for screen to load", () => nestedScreen.IsLoaded && nestedScreen.IsCurrentScreen());
|
|
|
|
|
|
|
|
// we're testing a case where scheduling may be used to avoid issues, so ensure the scheduler is no longer running.
|
|
|
|
AddUntilStep("wait for top level not alive", () => !screen.IsAlive);
|
|
|
|
|
|
|
|
AddStep("change beatmap", () => Beatmap.Value = createTestWorkingBeatmapWithUniqueBackground());
|
|
|
|
AddStep("change beatmap back", () => Beatmap.Value = originalWorking);
|
|
|
|
|
|
|
|
AddAssert("top level background hasn't changed yet", () => screen.CheckLastLoadChange() == null);
|
|
|
|
|
|
|
|
AddStep("pop screen back to top level", () => screen.MakeCurrent());
|
|
|
|
|
|
|
|
AddStep("top level screen is current", () => screen.IsCurrentScreen());
|
|
|
|
AddAssert("top level background reused existing", () => screen.CheckLastLoadChange() == false);
|
|
|
|
}
|
|
|
|
|
2021-12-27 17:59:05 +08:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmapBackgroundWithStoryboardClockAlwaysUsesCurrentTrack()
|
|
|
|
{
|
|
|
|
BackgroundScreenBeatmap nestedScreen = null;
|
|
|
|
WorkingBeatmap originalWorking = null;
|
|
|
|
|
|
|
|
setSupporter(true);
|
|
|
|
setSourceMode(BackgroundSource.BeatmapWithStoryboard);
|
|
|
|
|
|
|
|
AddStep("change beatmap", () => originalWorking = Beatmap.Value = createTestWorkingBeatmapWithStoryboard());
|
|
|
|
AddAssert("background changed", () => screen.CheckLastLoadChange() == true);
|
|
|
|
AddUntilStep("wait for beatmap background to be loaded", () => getCurrentBackground()?.GetType() == typeof(BeatmapBackgroundWithStoryboard));
|
|
|
|
|
|
|
|
AddStep("start music", () => MusicController.Play());
|
|
|
|
AddUntilStep("storyboard clock running", () => screen.ChildrenOfType<DrawableStoryboard>().SingleOrDefault()?.Clock.IsRunning == true);
|
|
|
|
|
|
|
|
// of note, this needs to be a type that doesn't match BackgroundScreenDefault else it is silently not pushed by the background stack.
|
|
|
|
AddStep("push new background to stack", () => stack.Push(nestedScreen = new BackgroundScreenBeatmap(Beatmap.Value)));
|
|
|
|
AddUntilStep("wait for screen to load", () => nestedScreen.IsLoaded && nestedScreen.IsCurrentScreen());
|
|
|
|
|
|
|
|
// we're testing a case where scheduling may be used to avoid issues, so ensure the scheduler is no longer running.
|
|
|
|
AddUntilStep("wait for top level not alive", () => !screen.IsAlive);
|
|
|
|
|
|
|
|
AddStep("stop music", () => MusicController.Stop());
|
|
|
|
AddStep("change beatmap", () => Beatmap.Value = createTestWorkingBeatmapWithStoryboard());
|
|
|
|
AddStep("change beatmap back", () => Beatmap.Value = originalWorking);
|
|
|
|
AddStep("restart music", () => MusicController.Play());
|
|
|
|
|
|
|
|
AddAssert("top level background hasn't changed yet", () => screen.CheckLastLoadChange() == null);
|
|
|
|
|
|
|
|
AddStep("pop screen back to top level", () => screen.MakeCurrent());
|
|
|
|
|
|
|
|
AddStep("top level screen is current", () => screen.IsCurrentScreen());
|
|
|
|
AddAssert("top level background reused existing", () => screen.CheckLastLoadChange() == false);
|
|
|
|
AddUntilStep("storyboard clock running", () => screen.ChildrenOfType<DrawableStoryboard>().Single().Clock.IsRunning);
|
|
|
|
|
|
|
|
AddStep("stop music", () => MusicController.Stop());
|
|
|
|
AddStep("restore default beatmap", () => Beatmap.SetDefault());
|
|
|
|
}
|
|
|
|
|
2021-06-07 16:32:10 +08:00
|
|
|
[Test]
|
2021-06-09 03:58:44 +08:00
|
|
|
public void TestBackgroundTypeSwitch()
|
2021-06-07 16:32:10 +08:00
|
|
|
{
|
|
|
|
setSupporter(true);
|
|
|
|
|
|
|
|
setSourceMode(BackgroundSource.Beatmap);
|
|
|
|
AddUntilStep("is beatmap background", () => getCurrentBackground() is BeatmapBackground);
|
|
|
|
|
|
|
|
setSourceMode(BackgroundSource.BeatmapWithStoryboard);
|
|
|
|
AddUntilStep("is storyboard background", () => getCurrentBackground() is BeatmapBackgroundWithStoryboard);
|
2021-06-09 03:58:44 +08:00
|
|
|
|
|
|
|
setSourceMode(BackgroundSource.Skin);
|
2021-06-09 13:48:16 +08:00
|
|
|
AddUntilStep("is default background", () => getCurrentBackground().GetType() == typeof(Graphics.Backgrounds.Background));
|
|
|
|
|
|
|
|
setCustomSkin();
|
2021-06-09 03:58:44 +08:00
|
|
|
AddUntilStep("is skin background", () => getCurrentBackground() is SkinBackground);
|
2021-06-07 16:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestTogglingSupporterTogglesBeatmapBackground()
|
|
|
|
{
|
|
|
|
setSourceMode(BackgroundSource.Beatmap);
|
|
|
|
|
|
|
|
setSupporter(true);
|
|
|
|
AddUntilStep("is beatmap background", () => getCurrentBackground() is BeatmapBackground);
|
|
|
|
|
|
|
|
setSupporter(false);
|
|
|
|
AddUntilStep("is default background", () => !(getCurrentBackground() is BeatmapBackground));
|
|
|
|
|
|
|
|
setSupporter(true);
|
|
|
|
AddUntilStep("is beatmap background", () => getCurrentBackground() is BeatmapBackground);
|
|
|
|
}
|
|
|
|
|
2021-06-09 04:25:29 +08:00
|
|
|
[TestCase(BackgroundSource.Beatmap, typeof(BeatmapBackground))]
|
|
|
|
[TestCase(BackgroundSource.BeatmapWithStoryboard, typeof(BeatmapBackgroundWithStoryboard))]
|
|
|
|
[TestCase(BackgroundSource.Skin, typeof(SkinBackground))]
|
|
|
|
public void TestBackgroundDoesntReloadOnNoChange(BackgroundSource source, Type backgroundType)
|
2021-06-07 16:22:30 +08:00
|
|
|
{
|
2021-06-09 04:25:29 +08:00
|
|
|
setSourceMode(source);
|
2021-06-07 16:22:30 +08:00
|
|
|
setSupporter(true);
|
2021-06-09 13:48:16 +08:00
|
|
|
if (source == BackgroundSource.Skin)
|
|
|
|
setCustomSkin();
|
2021-06-07 16:22:30 +08:00
|
|
|
|
2021-12-14 15:35:18 +08:00
|
|
|
AddUntilStep("wait for beatmap background to be loaded", () => (getCurrentBackground())?.GetType() == backgroundType);
|
2021-06-07 16:22:30 +08:00
|
|
|
AddAssert("next doesn't load new background", () => screen.Next() == false);
|
|
|
|
}
|
|
|
|
|
2021-06-09 13:48:16 +08:00
|
|
|
[Test]
|
|
|
|
public void TestBackgroundCyclingOnDefaultSkin([Values] bool supporter)
|
|
|
|
{
|
|
|
|
setSourceMode(BackgroundSource.Skin);
|
|
|
|
setSupporter(supporter);
|
|
|
|
setDefaultSkin();
|
|
|
|
|
2021-12-14 15:10:53 +08:00
|
|
|
AddUntilStep("wait for beatmap background to be loaded", () => (getCurrentBackground())?.GetType() == typeof(Graphics.Backgrounds.Background));
|
2021-06-09 13:48:16 +08:00
|
|
|
AddAssert("next cycles background", () => screen.Next());
|
|
|
|
}
|
|
|
|
|
2021-06-07 16:22:30 +08:00
|
|
|
private void setSourceMode(BackgroundSource source) =>
|
2021-06-09 03:58:44 +08:00
|
|
|
AddStep($"set background mode to {source}", () => config.SetValue(OsuSetting.MenuBackgroundSource, source));
|
2021-06-07 16:22:30 +08:00
|
|
|
|
|
|
|
private void setSupporter(bool isSupporter) =>
|
2021-11-04 17:02:44 +08:00
|
|
|
AddStep($"set supporter {isSupporter}", () => ((DummyAPIAccess)API).LocalUser.Value = new APIUser
|
2021-06-07 16:32:10 +08:00
|
|
|
{
|
|
|
|
IsSupporter = isSupporter,
|
|
|
|
Id = API.LocalUser.Value.Id + 1,
|
|
|
|
});
|
2021-06-09 13:48:16 +08:00
|
|
|
|
2022-08-02 18:50:57 +08:00
|
|
|
private WorkingBeatmap createTestWorkingBeatmapWithUniqueBackground() => new UniqueBackgroundTestWorkingBeatmap(renderer, Audio);
|
2021-12-27 17:59:05 +08:00
|
|
|
private WorkingBeatmap createTestWorkingBeatmapWithStoryboard() => new TestWorkingBeatmapWithStoryboard(Audio);
|
2021-12-14 15:10:53 +08:00
|
|
|
|
|
|
|
private partial class TestBackgroundScreenDefault : BackgroundScreenDefault
|
|
|
|
{
|
|
|
|
private bool? lastLoadTriggerCausedChange;
|
|
|
|
|
|
|
|
public TestBackgroundScreenDefault()
|
|
|
|
: base(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Next()
|
|
|
|
{
|
|
|
|
bool didChange = base.Next();
|
|
|
|
lastLoadTriggerCausedChange = didChange;
|
|
|
|
return didChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool? CheckLastLoadChange()
|
|
|
|
{
|
|
|
|
bool? lastChange = lastLoadTriggerCausedChange;
|
|
|
|
lastLoadTriggerCausedChange = null;
|
|
|
|
return lastChange;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class UniqueBackgroundTestWorkingBeatmap : TestWorkingBeatmap
|
|
|
|
{
|
2022-08-02 18:50:57 +08:00
|
|
|
private readonly IRenderer renderer;
|
|
|
|
|
|
|
|
public UniqueBackgroundTestWorkingBeatmap(IRenderer renderer, AudioManager audioManager)
|
2021-12-14 15:10:53 +08:00
|
|
|
: base(new Beatmap(), null, audioManager)
|
|
|
|
{
|
2022-08-02 18:50:57 +08:00
|
|
|
this.renderer = renderer;
|
2021-12-14 15:10:53 +08:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:17:44 +08:00
|
|
|
public override Texture GetBackground() => renderer.CreateTexture(1, 1);
|
2021-12-14 15:10:53 +08:00
|
|
|
}
|
|
|
|
|
2021-12-27 17:59:05 +08:00
|
|
|
private partial class TestWorkingBeatmapWithStoryboard : TestWorkingBeatmap
|
|
|
|
{
|
|
|
|
public TestWorkingBeatmapWithStoryboard(AudioManager audioManager)
|
|
|
|
: base(new Beatmap(), createStoryboard(), audioManager)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Track GetBeatmapTrack() => new TrackVirtual(100000);
|
|
|
|
|
|
|
|
private static Storyboard createStoryboard()
|
|
|
|
{
|
|
|
|
var storyboard = new Storyboard();
|
|
|
|
storyboard.Layers.Last().Add(new TestStoryboardElement());
|
|
|
|
return storyboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestStoryboardElement : IStoryboardElementWithDuration
|
|
|
|
{
|
|
|
|
public string Path => string.Empty;
|
|
|
|
public bool IsDrawable => true;
|
|
|
|
public double StartTime => double.MinValue;
|
|
|
|
public double EndTime => double.MaxValue;
|
2023-04-25 14:22:11 +08:00
|
|
|
public double EndTimeForDisplay => double.MaxValue;
|
2021-12-27 17:59:05 +08:00
|
|
|
|
|
|
|
public Drawable CreateDrawable() => new DrawableTestStoryboardElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
private partial class DrawableTestStoryboardElement : OsuSpriteText
|
|
|
|
{
|
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
|
|
|
public DrawableTestStoryboardElement()
|
|
|
|
{
|
|
|
|
Anchor = Origin = Anchor.Centre;
|
|
|
|
Font = OsuFont.Default.With(size: 32);
|
|
|
|
Text = "(not started)";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
Text = Time.Current.ToString("N2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-09 13:48:16 +08:00
|
|
|
private void setCustomSkin()
|
|
|
|
{
|
|
|
|
// feign a skin switch. this doesn't do anything except force CurrentSkin to become a LegacySkin.
|
2021-12-14 13:21:23 +08:00
|
|
|
AddStep("set custom skin", () => skins.CurrentSkinInfo.Value = new SkinInfo().ToLiveUnmanaged());
|
2021-06-09 13:48:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setDefaultSkin() => AddStep("set default skin", () => skins.CurrentSkinInfo.SetDefault());
|
|
|
|
|
|
|
|
[TearDownSteps]
|
|
|
|
public void TearDown() => setDefaultSkin();
|
2021-06-07 16:22:30 +08:00
|
|
|
}
|
|
|
|
}
|