2020-06-15 21:45:18 +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
|
|
|
|
|
2020-11-12 03:20:29 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2024-09-24 23:51:54 +08:00
|
|
|
using System.Linq;
|
2022-05-28 19:59:10 +08:00
|
|
|
using System.Threading;
|
2020-06-15 21:45:18 +08:00
|
|
|
using NUnit.Framework;
|
2024-09-24 23:51:54 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-06-18 21:21:30 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-02-03 17:00:40 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2024-09-24 23:51:54 +08:00
|
|
|
using osu.Framework.Testing;
|
2022-02-03 17:00:40 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2024-09-24 23:51:54 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2024-02-29 06:13:31 +08:00
|
|
|
using osu.Game.Online;
|
2022-02-03 17:00:40 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Difficulty;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2022-05-28 19:59:10 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-06-15 21:45:18 +08:00
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Screens.Ranking.Statistics;
|
2020-11-12 03:20:29 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2022-02-03 17:00:40 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
2024-09-24 23:51:54 +08:00
|
|
|
using osu.Game.Screens.Ranking.Statistics.User;
|
2021-12-13 15:34:48 +08:00
|
|
|
using osu.Game.Tests.Resources;
|
2023-06-28 18:06:48 +08:00
|
|
|
using osu.Game.Users;
|
2020-11-12 03:20:29 +08:00
|
|
|
using osuTK;
|
2020-06-15 21:45:18 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Ranking
|
|
|
|
{
|
2020-06-16 15:08:41 +08:00
|
|
|
public partial class TestSceneStatisticsPanel : OsuTestScene
|
2020-06-15 21:45:18 +08:00
|
|
|
{
|
|
|
|
[Test]
|
2023-06-28 17:17:46 +08:00
|
|
|
public void TestScoreWithPositionStatistics()
|
2020-06-15 21:45:18 +08:00
|
|
|
{
|
2021-12-13 15:34:48 +08:00
|
|
|
var score = TestResources.CreateTestScoreInfo();
|
2023-06-28 18:06:48 +08:00
|
|
|
score.OnlineID = 1234;
|
2023-07-13 00:06:26 +08:00
|
|
|
score.HitEvents = CreatePositionDistributedHitEvents();
|
2020-06-16 16:49:37 +08:00
|
|
|
|
|
|
|
loadPanel(score);
|
2020-06-15 21:45:18 +08:00
|
|
|
}
|
|
|
|
|
2020-11-12 03:20:29 +08:00
|
|
|
[Test]
|
2023-06-28 17:17:46 +08:00
|
|
|
public void TestScoreWithTimeStatistics()
|
2020-11-12 03:20:29 +08:00
|
|
|
{
|
2021-12-13 15:34:48 +08:00
|
|
|
var score = TestResources.CreateTestScoreInfo();
|
2023-06-28 17:17:46 +08:00
|
|
|
score.HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents();
|
2020-11-12 03:20:29 +08:00
|
|
|
|
|
|
|
loadPanel(score);
|
|
|
|
}
|
|
|
|
|
2020-06-18 21:21:30 +08:00
|
|
|
[Test]
|
|
|
|
public void TestScoreWithoutStatistics()
|
|
|
|
{
|
2021-12-13 15:37:20 +08:00
|
|
|
loadPanel(TestResources.CreateTestScoreInfo());
|
2020-06-18 21:21:30 +08:00
|
|
|
}
|
|
|
|
|
2022-02-03 17:00:40 +08:00
|
|
|
[Test]
|
|
|
|
public void TestScoreInRulesetWhereAllStatsRequireHitEvents()
|
|
|
|
{
|
|
|
|
loadPanel(TestResources.CreateTestScoreInfo(new TestRulesetAllStatsRequireHitEvents().RulesetInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestScoreInRulesetWhereNoStatsRequireHitEvents()
|
|
|
|
{
|
|
|
|
loadPanel(TestResources.CreateTestScoreInfo(new TestRulesetNoStatsRequireHitEvents().RulesetInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestScoreInMixedRuleset()
|
|
|
|
{
|
|
|
|
loadPanel(TestResources.CreateTestScoreInfo(new TestRulesetMixed().RulesetInfo));
|
|
|
|
}
|
|
|
|
|
2020-06-19 21:47:55 +08:00
|
|
|
[Test]
|
|
|
|
public void TestNullScore()
|
|
|
|
{
|
|
|
|
loadPanel(null);
|
|
|
|
}
|
|
|
|
|
2024-09-24 23:51:54 +08:00
|
|
|
[Test]
|
|
|
|
public void TestStatisticsShownCorrectlyIfUpdateDeliveredBeforeLoad()
|
|
|
|
{
|
|
|
|
UserStatisticsWatcher userStatisticsWatcher = null!;
|
|
|
|
ScoreInfo score = null!;
|
|
|
|
|
|
|
|
AddStep("create user statistics watcher", () => Add(userStatisticsWatcher = new UserStatisticsWatcher()));
|
|
|
|
AddStep("set user statistics update", () =>
|
|
|
|
{
|
|
|
|
score = TestResources.CreateTestScoreInfo();
|
|
|
|
score.OnlineID = 1234;
|
|
|
|
((Bindable<UserStatisticsUpdate>)userStatisticsWatcher.LatestUpdate).Value = new UserStatisticsUpdate(score,
|
|
|
|
new UserStatistics
|
|
|
|
{
|
|
|
|
Level = new UserStatistics.LevelInfo
|
|
|
|
{
|
|
|
|
Current = 5,
|
|
|
|
Progress = 20,
|
|
|
|
},
|
|
|
|
GlobalRank = 38000,
|
|
|
|
CountryRank = 12006,
|
|
|
|
PP = 2134,
|
|
|
|
RankedScore = 21123849,
|
|
|
|
Accuracy = 0.985,
|
|
|
|
PlayCount = 13375,
|
|
|
|
PlayTime = 354490,
|
|
|
|
TotalScore = 128749597,
|
|
|
|
TotalHits = 0,
|
|
|
|
MaxCombo = 1233,
|
|
|
|
}, new UserStatistics
|
|
|
|
{
|
|
|
|
Level = new UserStatistics.LevelInfo
|
|
|
|
{
|
|
|
|
Current = 5,
|
|
|
|
Progress = 30,
|
|
|
|
},
|
|
|
|
GlobalRank = 36000,
|
|
|
|
CountryRank = 12000,
|
|
|
|
PP = (decimal)2134.5,
|
|
|
|
RankedScore = 23897015,
|
|
|
|
Accuracy = 0.984,
|
|
|
|
PlayCount = 13376,
|
|
|
|
PlayTime = 35789,
|
|
|
|
TotalScore = 132218497,
|
|
|
|
TotalHits = 0,
|
|
|
|
MaxCombo = 1233,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
AddStep("load user statistics panel", () => Child = new DependencyProvidingContainer
|
|
|
|
{
|
|
|
|
CachedDependencies = [(typeof(UserStatisticsWatcher), userStatisticsWatcher)],
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = new UserStatisticsPanel(score)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
State = { Value = Visibility.Visible },
|
|
|
|
Score = { Value = score, }
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AddUntilStep("overall ranking present", () => this.ChildrenOfType<OverallRanking>().Any());
|
|
|
|
AddUntilStep("loading spinner not visible", () => this.ChildrenOfType<LoadingLayer>().All(l => l.State.Value == Visibility.Hidden));
|
|
|
|
}
|
|
|
|
|
2020-06-15 21:45:18 +08:00
|
|
|
private void loadPanel(ScoreInfo score) => AddStep("load panel", () =>
|
|
|
|
{
|
2024-02-23 02:49:14 +08:00
|
|
|
Child = new UserStatisticsPanel(score)
|
2020-06-18 21:21:30 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
State = { Value = Visibility.Visible },
|
2023-06-28 18:06:48 +08:00
|
|
|
Score = { Value = score },
|
2024-02-23 02:49:14 +08:00
|
|
|
DisplayedUserStatisticsUpdate =
|
2023-07-13 00:29:58 +08:00
|
|
|
{
|
2024-02-23 02:50:46 +08:00
|
|
|
Value = new UserStatisticsUpdate(score, new UserStatistics
|
2023-07-13 00:29:58 +08:00
|
|
|
{
|
|
|
|
Level = new UserStatistics.LevelInfo
|
|
|
|
{
|
|
|
|
Current = 5,
|
|
|
|
Progress = 20,
|
|
|
|
},
|
|
|
|
GlobalRank = 38000,
|
|
|
|
CountryRank = 12006,
|
|
|
|
PP = 2134,
|
|
|
|
RankedScore = 21123849,
|
|
|
|
Accuracy = 0.985,
|
|
|
|
PlayCount = 13375,
|
|
|
|
PlayTime = 354490,
|
|
|
|
TotalScore = 128749597,
|
|
|
|
TotalHits = 0,
|
|
|
|
MaxCombo = 1233,
|
|
|
|
}, new UserStatistics
|
|
|
|
{
|
|
|
|
Level = new UserStatistics.LevelInfo
|
|
|
|
{
|
|
|
|
Current = 5,
|
|
|
|
Progress = 30,
|
|
|
|
},
|
|
|
|
GlobalRank = 36000,
|
|
|
|
CountryRank = 12000,
|
|
|
|
PP = (decimal)2134.5,
|
|
|
|
RankedScore = 23897015,
|
|
|
|
Accuracy = 0.984,
|
|
|
|
PlayCount = 13376,
|
|
|
|
PlayTime = 35789,
|
|
|
|
TotalScore = 132218497,
|
|
|
|
TotalHits = 0,
|
|
|
|
MaxCombo = 1233,
|
|
|
|
})
|
|
|
|
}
|
2020-06-18 21:21:30 +08:00
|
|
|
};
|
2020-06-15 21:45:18 +08:00
|
|
|
});
|
2020-11-12 03:20:29 +08:00
|
|
|
|
2023-07-13 00:06:26 +08:00
|
|
|
public static List<HitEvent> CreatePositionDistributedHitEvents()
|
2020-11-12 03:20:29 +08:00
|
|
|
{
|
2023-06-28 17:17:46 +08:00
|
|
|
var hitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents();
|
|
|
|
|
2020-11-12 03:20:29 +08:00
|
|
|
// Use constant seed for reproducibility
|
|
|
|
var random = new Random(0);
|
|
|
|
|
2023-06-28 17:17:46 +08:00
|
|
|
for (int i = 0; i < hitEvents.Count; i++)
|
2020-11-12 03:20:29 +08:00
|
|
|
{
|
2020-11-12 05:40:52 +08:00
|
|
|
double angle = random.NextDouble() * 2 * Math.PI;
|
|
|
|
double radius = random.NextDouble() * 0.5f * OsuHitObject.OBJECT_RADIUS;
|
2020-11-12 03:20:29 +08:00
|
|
|
|
2020-11-12 05:40:52 +08:00
|
|
|
var position = new Vector2((float)(radius * Math.Cos(angle)), (float)(radius * Math.Sin(angle)));
|
2020-11-12 03:20:29 +08:00
|
|
|
|
2023-06-28 17:17:46 +08:00
|
|
|
hitEvents[i] = hitEvents[i].With(position);
|
2020-11-12 03:20:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return hitEvents;
|
|
|
|
}
|
2022-02-03 17:00:40 +08:00
|
|
|
|
|
|
|
private class TestRuleset : Ruleset
|
|
|
|
{
|
|
|
|
public override IEnumerable<Mod> GetModsFor(ModType type)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2022-05-28 19:59:10 +08:00
|
|
|
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new TestBeatmapConverter(beatmap);
|
2022-02-03 17:00:40 +08:00
|
|
|
|
|
|
|
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string Description => string.Empty;
|
|
|
|
|
|
|
|
public override string ShortName => string.Empty;
|
|
|
|
|
|
|
|
protected static Drawable CreatePlaceholderStatistic(string message) => new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 20,
|
|
|
|
Height = 250,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.Gray(0.5f),
|
|
|
|
Alpha = 0.5f
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Text = message,
|
|
|
|
Margin = new MarginPadding { Left = 20 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-05-28 19:59:10 +08:00
|
|
|
|
|
|
|
private class TestBeatmapConverter : IBeatmapConverter
|
|
|
|
{
|
|
|
|
#pragma warning disable CS0067 // The event is never used
|
|
|
|
public event Action<HitObject, IEnumerable<HitObject>> ObjectConverted;
|
|
|
|
#pragma warning restore CS0067
|
|
|
|
|
|
|
|
public IBeatmap Beatmap { get; }
|
|
|
|
|
2023-11-12 16:21:17 +08:00
|
|
|
// ReSharper disable once NotNullOrRequiredMemberIsNotInitialized
|
2022-05-28 19:59:10 +08:00
|
|
|
public TestBeatmapConverter(IBeatmap beatmap)
|
|
|
|
{
|
|
|
|
Beatmap = beatmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CanConvert() => true;
|
|
|
|
|
|
|
|
public IBeatmap Convert(CancellationToken cancellationToken = default) => Beatmap.Clone();
|
|
|
|
}
|
2022-02-03 17:00:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestRulesetAllStatsRequireHitEvents : TestRuleset
|
|
|
|
{
|
2023-06-01 13:35:14 +08:00
|
|
|
public override StatisticItem[] CreateStatisticsForScore(ScoreInfo score, IBeatmap playableBeatmap) => new[]
|
2022-02-03 17:00:40 +08:00
|
|
|
{
|
2023-06-01 13:35:14 +08:00
|
|
|
new StatisticItem("Statistic Requiring Hit Events 1", () => CreatePlaceholderStatistic("Placeholder statistic. Requires hit events"), true),
|
|
|
|
new StatisticItem("Statistic Requiring Hit Events 2", () => CreatePlaceholderStatistic("Placeholder statistic. Requires hit events"), true)
|
|
|
|
};
|
2022-02-03 17:00:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestRulesetNoStatsRequireHitEvents : TestRuleset
|
|
|
|
{
|
2023-06-01 13:35:14 +08:00
|
|
|
public override StatisticItem[] CreateStatisticsForScore(ScoreInfo score, IBeatmap playableBeatmap)
|
2022-02-03 17:00:40 +08:00
|
|
|
{
|
|
|
|
return new[]
|
|
|
|
{
|
2023-06-01 13:35:14 +08:00
|
|
|
new StatisticItem("Statistic Not Requiring Hit Events 1", () => CreatePlaceholderStatistic("Placeholder statistic. Does not require hit events")),
|
|
|
|
new StatisticItem("Statistic Not Requiring Hit Events 2", () => CreatePlaceholderStatistic("Placeholder statistic. Does not require hit events"))
|
2022-02-03 17:00:40 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestRulesetMixed : TestRuleset
|
|
|
|
{
|
2023-06-01 13:35:14 +08:00
|
|
|
public override StatisticItem[] CreateStatisticsForScore(ScoreInfo score, IBeatmap playableBeatmap)
|
2022-02-03 17:00:40 +08:00
|
|
|
{
|
|
|
|
return new[]
|
|
|
|
{
|
2023-06-01 13:35:14 +08:00
|
|
|
new StatisticItem("Statistic Requiring Hit Events", () => CreatePlaceholderStatistic("Placeholder statistic. Requires hit events"), true),
|
|
|
|
new StatisticItem("Statistic Not Requiring Hit Events", () => CreatePlaceholderStatistic("Placeholder statistic. Does not require hit events"))
|
2022-02-03 17:00:40 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 21:45:18 +08:00
|
|
|
}
|
|
|
|
}
|