1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 22:22:55 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneUpdateableBeatmapBackgroundSprite.cs

149 lines
5.0 KiB
C#
Raw Normal View History

// 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.
2018-12-25 18:17:32 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
2018-12-25 18:17:32 +08:00
using System.Linq;
2019-05-07 16:23:44 +08:00
using NUnit.Framework;
2018-12-25 18:17:32 +08:00
using osu.Framework.Allocation;
using osu.Framework.Extensions;
2018-12-25 18:17:32 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-12-25 18:17:32 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics.Containers;
2018-12-25 18:17:32 +08:00
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
2018-12-25 18:17:32 +08:00
using osu.Game.Tests.Beatmaps.IO;
2019-05-07 16:23:44 +08:00
using osuTK;
2018-12-25 18:17:32 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.UserInterface
2018-12-25 18:17:32 +08:00
{
2022-11-24 13:32:20 +08:00
public partial class TestSceneUpdateableBeatmapBackgroundSprite : OsuTestScene
2018-12-25 18:17:32 +08:00
{
protected override bool UseOnlineAPI => true;
2019-08-01 03:44:44 +08:00
2019-05-07 16:23:44 +08:00
private BeatmapSetInfo testBeatmap;
private IAPIProvider api;
2018-12-25 18:17:32 +08:00
[BackgroundDependencyLoader]
2022-01-15 08:06:39 +08:00
private void load(OsuGameBase osu, IAPIProvider api)
2018-12-25 18:17:32 +08:00
{
2019-09-13 16:38:04 +08:00
this.api = api;
2018-12-25 18:17:32 +08:00
2021-12-17 17:26:12 +08:00
testBeatmap = BeatmapImportHelper.LoadOszIntoOsu(osu).GetResultSafely();
2019-05-07 16:23:44 +08:00
}
[Test]
public void TestNullBeatmap()
{
TestUpdateableBeatmapBackgroundSprite background = null;
2018-12-25 18:17:32 +08:00
2019-05-07 16:23:44 +08:00
AddStep("load null beatmap", () => Child = background = new TestUpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both });
2019-06-04 18:25:34 +08:00
AddUntilStep("content loaded", () => background.ContentLoaded);
2019-05-07 16:23:44 +08:00
}
2018-12-25 18:17:32 +08:00
2019-05-07 16:23:44 +08:00
[Test]
public void TestLocalBeatmap()
{
TestUpdateableBeatmapBackgroundSprite background = null;
2018-12-25 18:17:32 +08:00
2019-05-07 16:23:44 +08:00
AddStep("load local beatmap", () =>
{
Child = background = new TestUpdateableBeatmapBackgroundSprite
{
RelativeSizeAxes = Axes.Both,
Beatmap = { Value = testBeatmap.Beatmaps.First() }
};
});
2018-12-25 18:17:32 +08:00
2019-05-07 16:23:44 +08:00
AddUntilStep("wait for load", () => background.ContentLoaded);
}
2018-12-25 18:17:32 +08:00
2019-05-07 16:23:44 +08:00
[Test]
public void TestOnlineBeatmap()
{
2018-12-25 18:17:32 +08:00
if (api.IsLoggedIn)
{
2019-05-07 16:23:44 +08:00
var req = new GetBeatmapSetRequest(1);
api.Queue(req);
AddUntilStep("wait for api response", () => req.Response != null);
2019-05-07 16:23:44 +08:00
TestUpdateableBeatmapBackgroundSprite background = null;
AddStep("load online beatmap", () =>
{
2019-05-07 16:23:44 +08:00
Child = background = new TestUpdateableBeatmapBackgroundSprite
{
RelativeSizeAxes = Axes.Both,
Beatmap = { Value = new APIBeatmap { BeatmapSet = req.Response } }
2019-05-07 16:23:44 +08:00
};
});
2019-05-07 16:23:44 +08:00
AddUntilStep("wait for load", () => background.ContentLoaded);
}
else
AddStep("online (login first)", () => { });
2018-12-25 18:17:32 +08:00
}
[Test]
public void TestUnloadAndReload()
{
var backgrounds = new List<TestUpdateableBeatmapBackgroundSprite>();
OsuScrollContainer scrollContainer = null;
AddStep("create backgrounds hierarchy", () =>
{
FillFlowContainer backgroundFlow;
Child = scrollContainer = new OsuScrollContainer
{
Size = new Vector2(500),
Child = backgroundFlow = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Padding = new MarginPadding { Bottom = 550 }
}
};
for (int i = 0; i < 25; i++)
{
var background = new TestUpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both };
if (i % 2 == 0)
background.Beatmap.Value = testBeatmap.Beatmaps.First();
backgroundFlow.Add(new Container
{
RelativeSizeAxes = Axes.X,
Height = 100,
Masking = true,
Child = background
});
backgrounds.Add(background);
}
});
var loadedBackgrounds = backgrounds.Where(b => b.ContentLoaded);
AddUntilStep("some loaded", () => loadedBackgrounds.Any());
AddStep("scroll to bottom", () => scrollContainer.ScrollToEnd());
AddUntilStep("all unloaded", () => !loadedBackgrounds.Any());
}
2022-11-24 13:32:20 +08:00
private partial class TestUpdateableBeatmapBackgroundSprite : UpdateableBeatmapBackgroundSprite
{
protected override double UnloadDelay => 2000;
2019-05-07 16:23:44 +08:00
public bool ContentLoaded => ((DelayedLoadUnloadWrapper)InternalChildren.LastOrDefault())?.Content?.IsLoaded ?? false;
}
2018-12-25 18:17:32 +08:00
}
}