2021-01-24 04:29:32 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
|
|
|
using osu.Game.Graphics.Containers;
|
2021-10-20 17:43:48 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-01-24 04:29:32 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
public class TestSceneUpdateableBeatmapSetCover : OsuTestScene
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestLocal([Values] BeatmapSetCoverType coverType)
|
|
|
|
{
|
2021-10-21 15:53:50 +08:00
|
|
|
AddStep("setup cover", () => Child = new UpdateableOnlineBeatmapSetCover(coverType)
|
2021-01-24 04:29:32 +08:00
|
|
|
{
|
2021-11-01 15:43:39 +08:00
|
|
|
OnlineInfo = CreateAPIBeatmapSet(),
|
2021-01-24 04:29:32 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
});
|
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
AddUntilStep("wait for load", () => this.ChildrenOfType<OnlineBeatmapSetCover>().SingleOrDefault()?.IsLoaded ?? false);
|
2021-01-24 04:29:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestUnloadAndReload()
|
|
|
|
{
|
|
|
|
OsuScrollContainer scroll = null;
|
2021-10-21 15:53:50 +08:00
|
|
|
List<UpdateableOnlineBeatmapSetCover> covers = new List<UpdateableOnlineBeatmapSetCover>();
|
2021-01-24 04:29:32 +08:00
|
|
|
|
|
|
|
AddStep("setup covers", () =>
|
|
|
|
{
|
2021-11-01 15:43:39 +08:00
|
|
|
var beatmapSet = CreateAPIBeatmapSet();
|
2021-01-24 04:29:32 +08:00
|
|
|
|
|
|
|
FillFlowContainer fillFlow;
|
|
|
|
|
|
|
|
Child = scroll = new OsuScrollContainer
|
|
|
|
{
|
|
|
|
Size = new Vector2(500f),
|
|
|
|
Child = fillFlow = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
Padding = new MarginPadding { Bottom = 550 }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-03 21:57:57 +08:00
|
|
|
var coverTypes = Enum.GetValues(typeof(BeatmapSetCoverType))
|
|
|
|
.Cast<BeatmapSetCoverType>()
|
|
|
|
.ToList();
|
2021-01-24 04:29:32 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < 25; i++)
|
|
|
|
{
|
2021-05-03 21:57:57 +08:00
|
|
|
var coverType = coverTypes[i % coverTypes.Count];
|
2021-01-24 04:29:32 +08:00
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
var cover = new UpdateableOnlineBeatmapSetCover(coverType)
|
2021-01-24 04:29:32 +08:00
|
|
|
{
|
2021-11-01 14:42:12 +08:00
|
|
|
OnlineInfo = beatmapSet,
|
2021-01-24 04:29:32 +08:00
|
|
|
Height = 100,
|
|
|
|
Masking = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (coverType == BeatmapSetCoverType.Cover)
|
|
|
|
cover.Width = 500;
|
|
|
|
else if (coverType == BeatmapSetCoverType.Card)
|
|
|
|
cover.Width = 400;
|
|
|
|
else if (coverType == BeatmapSetCoverType.List)
|
|
|
|
cover.Size = new Vector2(100, 50);
|
|
|
|
|
|
|
|
fillFlow.Add(cover);
|
|
|
|
covers.Add(cover);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
var loadedCovers = covers.Where(c => c.ChildrenOfType<OnlineBeatmapSetCover>().SingleOrDefault()?.IsLoaded ?? false);
|
2021-01-24 04:29:32 +08:00
|
|
|
|
|
|
|
AddUntilStep("some loaded", () => loadedCovers.Any());
|
|
|
|
AddStep("scroll to end", () => scroll.ScrollToEnd());
|
|
|
|
AddUntilStep("all unloaded", () => !loadedCovers.Any());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSetNullBeatmapWhileLoading()
|
|
|
|
{
|
2021-10-21 15:53:50 +08:00
|
|
|
TestUpdateableOnlineBeatmapSetCover updateableCover = null;
|
2021-01-24 04:29:32 +08:00
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover
|
2021-01-24 04:29:32 +08:00
|
|
|
{
|
2021-11-01 15:43:39 +08:00
|
|
|
OnlineInfo = CreateAPIBeatmapSet(),
|
2021-01-24 04:29:32 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
});
|
|
|
|
|
2021-10-27 23:13:25 +08:00
|
|
|
AddStep("change model", () => updateableCover.OnlineInfo = null);
|
2021-01-24 04:29:32 +08:00
|
|
|
AddWaitStep("wait some", 5);
|
|
|
|
AddAssert("no cover added", () => !updateableCover.ChildrenOfType<DelayedLoadUnloadWrapper>().Any());
|
|
|
|
}
|
|
|
|
|
2021-05-05 03:00:12 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCoverChangeOnNewBeatmap()
|
|
|
|
{
|
2021-10-21 15:53:50 +08:00
|
|
|
TestUpdateableOnlineBeatmapSetCover updateableCover = null;
|
|
|
|
OnlineBeatmapSetCover initialCover = null;
|
2021-05-05 03:00:12 +08:00
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover(0)
|
2021-05-05 03:00:12 +08:00
|
|
|
{
|
2021-11-01 14:42:12 +08:00
|
|
|
OnlineInfo = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1189904/covers/cover.jpg"),
|
2021-05-05 03:00:12 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
Alpha = 0.4f
|
|
|
|
});
|
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
AddUntilStep("cover loaded", () => updateableCover.ChildrenOfType<OnlineBeatmapSetCover>().Any());
|
|
|
|
AddStep("store initial cover", () => initialCover = updateableCover.ChildrenOfType<OnlineBeatmapSetCover>().Single());
|
2021-05-05 03:00:12 +08:00
|
|
|
AddUntilStep("wait for fade complete", () => initialCover.Alpha == 1);
|
|
|
|
|
|
|
|
AddStep("switch beatmap",
|
2021-11-01 14:42:12 +08:00
|
|
|
() => updateableCover.OnlineInfo = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1079428/covers/cover.jpg"));
|
2021-10-21 15:53:50 +08:00
|
|
|
AddUntilStep("new cover loaded", () => updateableCover.ChildrenOfType<OnlineBeatmapSetCover>().Except(new[] { initialCover }).Any());
|
2021-05-05 03:00:12 +08:00
|
|
|
}
|
|
|
|
|
2021-11-01 14:42:12 +08:00
|
|
|
private static APIBeatmapSet createBeatmapWithCover(string coverUrl) => new APIBeatmapSet
|
2021-05-05 03:00:12 +08:00
|
|
|
{
|
2021-11-01 14:42:12 +08:00
|
|
|
Covers = new BeatmapSetOnlineCovers { Cover = coverUrl }
|
2021-05-05 03:00:12 +08:00
|
|
|
};
|
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
private class TestUpdateableOnlineBeatmapSetCover : UpdateableOnlineBeatmapSetCover
|
2021-01-24 04:29:32 +08:00
|
|
|
{
|
2021-05-05 03:00:12 +08:00
|
|
|
private readonly int loadDelay;
|
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
public TestUpdateableOnlineBeatmapSetCover(int loadDelay = 10000)
|
2021-05-05 03:00:12 +08:00
|
|
|
{
|
|
|
|
this.loadDelay = loadDelay;
|
|
|
|
}
|
|
|
|
|
2021-10-20 17:43:48 +08:00
|
|
|
protected override Drawable CreateDrawable(IBeatmapSetOnlineInfo model)
|
2021-01-24 04:28:46 +08:00
|
|
|
{
|
|
|
|
if (model == null)
|
|
|
|
return null;
|
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
return new TestOnlineBeatmapSetCover(model, loadDelay)
|
2021-01-24 04:28:46 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
};
|
|
|
|
}
|
2021-01-24 04:29:32 +08:00
|
|
|
}
|
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
private class TestOnlineBeatmapSetCover : OnlineBeatmapSetCover
|
2021-01-24 04:29:32 +08:00
|
|
|
{
|
2021-05-05 03:00:12 +08:00
|
|
|
private readonly int loadDelay;
|
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
public TestOnlineBeatmapSetCover(IBeatmapSetOnlineInfo set, int loadDelay)
|
2021-01-24 04:28:46 +08:00
|
|
|
: base(set)
|
2021-01-24 04:29:32 +08:00
|
|
|
{
|
2021-05-05 03:00:12 +08:00
|
|
|
this.loadDelay = loadDelay;
|
2021-01-24 04:29:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-05-05 03:00:12 +08:00
|
|
|
Thread.Sleep(loadDelay);
|
2021-01-24 04:29:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|