2022-09-10 06:12:57 +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.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2022-09-13 16:49:53 +08:00
|
|
|
using osu.Framework.Bindables;
|
2022-09-10 06:12:57 +08:00
|
|
|
using osu.Framework.Graphics;
|
2022-09-13 16:49:53 +08:00
|
|
|
using osu.Framework.Testing;
|
2022-09-10 06:12:57 +08:00
|
|
|
using osu.Framework.Utils;
|
2022-09-26 21:11:48 +08:00
|
|
|
using osu.Game.Configuration;
|
2022-09-10 06:12:57 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
2022-09-26 21:11:48 +08:00
|
|
|
using osu.Game.Users;
|
2022-09-10 06:12:57 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
2022-09-16 17:15:17 +08:00
|
|
|
public class TestSceneSoloGameplayLeaderboard : OsuTestScene
|
2022-09-10 06:12:57 +08:00
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
private readonly ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
|
|
|
|
|
2022-09-13 16:49:53 +08:00
|
|
|
private readonly BindableList<ScoreInfo> scores = new BindableList<ScoreInfo>();
|
2022-09-10 06:12:57 +08:00
|
|
|
|
2022-09-26 21:26:13 +08:00
|
|
|
private readonly Bindable<bool> configVisibility = new Bindable<bool>();
|
2022-09-26 21:11:48 +08:00
|
|
|
|
|
|
|
private TestSoloGameplayLeaderboard? testSoloGameplayLeaderboard;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
|
|
|
config.BindWith(OsuSetting.GameplayLeaderboard, configVisibility);
|
|
|
|
}
|
|
|
|
|
2022-09-13 16:49:53 +08:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
2022-09-10 06:12:57 +08:00
|
|
|
{
|
2022-09-13 16:49:53 +08:00
|
|
|
AddStep("clear scores", () => scores.Clear());
|
2022-09-10 06:12:57 +08:00
|
|
|
|
2022-09-13 16:49:53 +08:00
|
|
|
AddStep("create component", () =>
|
2022-09-10 06:12:57 +08:00
|
|
|
{
|
2022-09-13 16:49:53 +08:00
|
|
|
var trackingUser = new APIUser
|
|
|
|
{
|
|
|
|
Username = "local user",
|
|
|
|
Id = 2,
|
|
|
|
};
|
|
|
|
|
2022-09-26 21:11:48 +08:00
|
|
|
Child = testSoloGameplayLeaderboard = new TestSoloGameplayLeaderboard(trackingUser)
|
2022-09-13 16:49:53 +08:00
|
|
|
{
|
2022-09-16 17:15:17 +08:00
|
|
|
Scores = { BindTarget = scores },
|
2022-09-13 16:49:53 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Expanded = { Value = true },
|
|
|
|
};
|
|
|
|
});
|
2022-09-10 06:12:57 +08:00
|
|
|
|
2022-09-13 16:49:53 +08:00
|
|
|
AddStep("add scores", () => scores.AddRange(createSampleScores()));
|
|
|
|
}
|
2022-09-10 06:12:57 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLocalUser()
|
|
|
|
{
|
|
|
|
AddSliderStep("score", 0, 1000000, 500000, v => scoreProcessor.TotalScore.Value = v);
|
|
|
|
AddSliderStep("accuracy", 0f, 1f, 0.5f, v => scoreProcessor.Accuracy.Value = v);
|
|
|
|
AddSliderStep("combo", 0, 1000, 0, v => scoreProcessor.Combo.Value = v);
|
|
|
|
}
|
|
|
|
|
2022-09-26 21:11:48 +08:00
|
|
|
[Test]
|
|
|
|
public void TestVisibility()
|
|
|
|
{
|
|
|
|
AddStep("set visible true", () => configVisibility.Value = true);
|
|
|
|
AddWaitStep("wait", 1);
|
|
|
|
AddAssert("is leaderboard fully visible", () => testSoloGameplayLeaderboard?.FlowAlpha == 1);
|
|
|
|
|
|
|
|
AddStep("set visible false", () => configVisibility.Value = false);
|
|
|
|
AddWaitStep("wait", 1);
|
|
|
|
AddAssert("is leaderboard fully invisible", () => testSoloGameplayLeaderboard?.FlowAlpha == 0);
|
|
|
|
}
|
|
|
|
|
2022-09-10 06:12:57 +08:00
|
|
|
private static List<ScoreInfo> createSampleScores()
|
|
|
|
{
|
|
|
|
return new[]
|
|
|
|
{
|
|
|
|
new ScoreInfo { User = new APIUser { Username = @"peppy" }, TotalScore = RNG.Next(500000, 1000000) },
|
|
|
|
new ScoreInfo { User = new APIUser { Username = @"smoogipoo" }, TotalScore = RNG.Next(500000, 1000000) },
|
|
|
|
new ScoreInfo { User = new APIUser { Username = @"spaceman_atlas" }, TotalScore = RNG.Next(500000, 1000000) },
|
|
|
|
new ScoreInfo { User = new APIUser { Username = @"frenzibyte" }, TotalScore = RNG.Next(500000, 1000000) },
|
|
|
|
new ScoreInfo { User = new APIUser { Username = @"Susko3" }, TotalScore = RNG.Next(500000, 1000000) },
|
2022-09-21 14:03:06 +08:00
|
|
|
}.Concat(Enumerable.Range(0, 50).Select(i => new ScoreInfo { User = new APIUser { Username = $"User {i + 1}" }, TotalScore = 1000000 - i * 10000 })).ToList();
|
2022-09-10 06:12:57 +08:00
|
|
|
}
|
2022-09-26 21:11:48 +08:00
|
|
|
|
|
|
|
private class TestSoloGameplayLeaderboard : SoloGameplayLeaderboard
|
|
|
|
{
|
|
|
|
public float FlowAlpha => Flow.Alpha;
|
2022-09-26 21:26:13 +08:00
|
|
|
|
2022-09-26 21:11:48 +08:00
|
|
|
public TestSoloGameplayLeaderboard(IUser trackingUser)
|
2022-09-26 21:26:13 +08:00
|
|
|
: base(trackingUser)
|
|
|
|
{
|
|
|
|
}
|
2022-09-26 21:11:48 +08:00
|
|
|
}
|
2022-09-10 06:12:57 +08:00
|
|
|
}
|
|
|
|
}
|