2019-01-24 08:43:03 +00: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.
|
2018-12-25 10:17:32 +00:00
|
|
|
|
2019-05-07 08:24:05 +00:00
|
|
|
using System.Collections.Generic;
|
2018-12-25 10:17:32 +00:00
|
|
|
using System.Linq;
|
2019-05-07 08:23:44 +00:00
|
|
|
using NUnit.Framework;
|
2018-12-25 10:17:32 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2019-05-07 08:24:05 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-12-25 10:17:32 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2019-06-14 06:55:32 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2018-12-25 10:17:32 +00:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Tests.Beatmaps.IO;
|
2019-05-07 08:23:44 +00:00
|
|
|
using osuTK;
|
2018-12-25 10:17:32 +00:00
|
|
|
|
2019-03-24 16:02:36 +00:00
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
2018-12-25 10:17:32 +00:00
|
|
|
{
|
2019-05-14 19:37:25 +00:00
|
|
|
public class TestSceneUpdateableBeatmapBackgroundSprite : OsuTestScene
|
2018-12-25 10:17:32 +00:00
|
|
|
{
|
2019-09-13 08:15:33 +00:00
|
|
|
protected override bool UseOnlineAPI => true;
|
2019-07-31 19:44:44 +00:00
|
|
|
|
2019-05-07 08:23:44 +00:00
|
|
|
private BeatmapSetInfo testBeatmap;
|
|
|
|
private IAPIProvider api;
|
|
|
|
private RulesetStore rulesets;
|
2018-12-25 10:17:32 +00:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-03-13 03:56:47 +00:00
|
|
|
private void load(OsuGameBase osu, IAPIProvider api, RulesetStore rulesets)
|
2018-12-25 10:17:32 +00:00
|
|
|
{
|
2019-09-13 08:38:04 +00:00
|
|
|
this.api = api;
|
2019-05-07 08:23:44 +00:00
|
|
|
this.rulesets = rulesets;
|
2018-12-25 10:17:32 +00:00
|
|
|
|
2019-05-28 09:59:21 +00:00
|
|
|
testBeatmap = ImportBeatmapTest.LoadOszIntoOsu(osu).Result;
|
2019-05-07 08:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNullBeatmap()
|
|
|
|
{
|
|
|
|
TestUpdateableBeatmapBackgroundSprite background = null;
|
2018-12-25 10:17:32 +00:00
|
|
|
|
2019-05-07 08:23:44 +00:00
|
|
|
AddStep("load null beatmap", () => Child = background = new TestUpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both });
|
2019-06-04 10:25:34 +00:00
|
|
|
AddUntilStep("content loaded", () => background.ContentLoaded);
|
2019-05-07 08:23:44 +00:00
|
|
|
}
|
2018-12-25 10:17:32 +00:00
|
|
|
|
2019-05-07 08:23:44 +00:00
|
|
|
[Test]
|
|
|
|
public void TestLocalBeatmap()
|
|
|
|
{
|
|
|
|
TestUpdateableBeatmapBackgroundSprite background = null;
|
2018-12-25 10:17:32 +00:00
|
|
|
|
2019-05-07 08:23:44 +00:00
|
|
|
AddStep("load local beatmap", () =>
|
|
|
|
{
|
|
|
|
Child = background = new TestUpdateableBeatmapBackgroundSprite
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Beatmap = { Value = testBeatmap.Beatmaps.First() }
|
|
|
|
};
|
|
|
|
});
|
2018-12-25 10:17:32 +00:00
|
|
|
|
2019-05-07 08:23:44 +00:00
|
|
|
AddUntilStep("wait for load", () => background.ContentLoaded);
|
|
|
|
}
|
2018-12-25 10:17:32 +00:00
|
|
|
|
2019-05-07 08:23:44 +00:00
|
|
|
[Test]
|
|
|
|
public void TestOnlineBeatmap()
|
|
|
|
{
|
2018-12-25 10:17:32 +00:00
|
|
|
if (api.IsLoggedIn)
|
2018-12-26 11:42:47 +00:00
|
|
|
{
|
2019-05-07 08:23:44 +00:00
|
|
|
var req = new GetBeatmapSetRequest(1);
|
|
|
|
api.Queue(req);
|
|
|
|
|
2019-03-19 08:24:26 +00:00
|
|
|
AddUntilStep("wait for api response", () => req.Result != null);
|
2019-05-07 08:23:44 +00:00
|
|
|
|
|
|
|
TestUpdateableBeatmapBackgroundSprite background = null;
|
|
|
|
|
|
|
|
AddStep("load online beatmap", () =>
|
2018-12-26 11:42:47 +00:00
|
|
|
{
|
2019-05-07 08:23:44 +00:00
|
|
|
Child = background = new TestUpdateableBeatmapBackgroundSprite
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Beatmap = { Value = new BeatmapInfo { BeatmapSet = req.Result?.ToBeatmapSet(rulesets) } }
|
|
|
|
};
|
2018-12-26 11:42:47 +00:00
|
|
|
});
|
2019-05-07 08:23:44 +00:00
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => background.ContentLoaded);
|
2018-12-26 11:42:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
AddStep("online (login first)", () => { });
|
2018-12-25 10:17:32 +00:00
|
|
|
}
|
2019-03-06 09:55:01 +00:00
|
|
|
|
2019-05-07 08:24:05 +00:00
|
|
|
[Test]
|
|
|
|
public void TestUnloadAndReload()
|
|
|
|
{
|
|
|
|
var backgrounds = new List<TestUpdateableBeatmapBackgroundSprite>();
|
2019-06-14 06:55:32 +00:00
|
|
|
OsuScrollContainer scrollContainer = null;
|
2019-05-07 08:24:05 +00:00
|
|
|
|
|
|
|
AddStep("create backgrounds hierarchy", () =>
|
|
|
|
{
|
|
|
|
FillFlowContainer backgroundFlow;
|
|
|
|
|
2019-06-14 06:55:32 +00:00
|
|
|
Child = scrollContainer = new OsuScrollContainer
|
2019-05-07 08:24:05 +00:00
|
|
|
{
|
|
|
|
Size = new Vector2(500),
|
|
|
|
Child = backgroundFlow = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(10),
|
2019-05-08 14:38:57 +00:00
|
|
|
Padding = new MarginPadding { Bottom = 550 }
|
2019-05-07 08:24:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-05-09 01:38:22 +00:00
|
|
|
AddUntilStep("some loaded", () => loadedBackgrounds.Any());
|
2019-05-07 08:24:05 +00:00
|
|
|
AddStep("scroll to bottom", () => scrollContainer.ScrollToEnd());
|
2019-05-08 14:38:57 +00:00
|
|
|
AddUntilStep("all unloaded", () => !loadedBackgrounds.Any());
|
2019-05-07 08:24:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-06 09:55:01 +00:00
|
|
|
private class TestUpdateableBeatmapBackgroundSprite : UpdateableBeatmapBackgroundSprite
|
|
|
|
{
|
2019-05-07 08:24:05 +00:00
|
|
|
protected override double UnloadDelay => 2000;
|
|
|
|
|
2019-05-07 08:23:44 +00:00
|
|
|
public bool ContentLoaded => ((DelayedLoadUnloadWrapper)InternalChildren.LastOrDefault())?.Content?.IsLoaded ?? false;
|
2019-03-06 09:55:01 +00:00
|
|
|
}
|
2018-12-25 10:17:32 +00:00
|
|
|
}
|
|
|
|
}
|