|
| 1 | +// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. |
| 2 | +// See the LICENCE file in the repository root for full licence text. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Linq; |
| 6 | +using NUnit.Framework; |
| 7 | +using osu.Framework.Allocation; |
| 8 | +using osu.Framework.Graphics; |
| 9 | +using osu.Framework.Graphics.Containers; |
| 10 | +using osu.Framework.Testing; |
| 11 | +using osu.Framework.Utils; |
| 12 | +using osu.Game.Configuration; |
| 13 | +using osu.Game.Graphics.Sprites; |
| 14 | +using osu.Game.Online.API.Requests.Responses; |
| 15 | +using osu.Game.Overlays; |
| 16 | +using osu.Game.Rulesets.Mania; |
| 17 | +using osu.Game.Rulesets.Mods; |
| 18 | +using osu.Game.Rulesets.Osu; |
| 19 | +using osu.Game.Rulesets.Osu.Mods; |
| 20 | +using osu.Game.Rulesets.Scoring; |
| 21 | +using osu.Game.Scoring; |
| 22 | +using osu.Game.Screens.SelectV2.Leaderboards; |
| 23 | +using osu.Game.Tests.Resources; |
| 24 | +using osu.Game.Users; |
| 25 | +using osuTK; |
| 26 | + |
| 27 | +namespace osu.Game.Tests.Visual.SongSelect |
| 28 | +{ |
| 29 | + public partial class TestSceneLeaderboardScoreV2 : OsuTestScene |
| 30 | + { |
| 31 | + [Cached] |
| 32 | + private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Aquamarine); |
| 33 | + |
| 34 | + [Resolved] |
| 35 | + private OsuConfigManager config { get; set; } = null!; |
| 36 | + |
| 37 | + private FillFlowContainer? fillFlow; |
| 38 | + private OsuSpriteText? drawWidthText; |
| 39 | + private float relativeWidth; |
| 40 | + |
| 41 | + [BackgroundDependencyLoader] |
| 42 | + private void load() |
| 43 | + { |
| 44 | + // TODO: invalidation seems to be one-off when clicking slider to a certain value, so drag for now |
| 45 | + // doesn't seem to happen in-game (when toggling window mode) |
| 46 | + AddSliderStep("change relative width", 0, 1f, 0.6f, v => |
| 47 | + { |
| 48 | + relativeWidth = v; |
| 49 | + if (fillFlow != null) fillFlow.Width = v; |
| 50 | + }); |
| 51 | + } |
| 52 | + |
| 53 | + [SetUp] |
| 54 | + public void Setup() => Schedule(() => |
| 55 | + { |
| 56 | + Children = new Drawable[] |
| 57 | + { |
| 58 | + fillFlow = new FillFlowContainer |
| 59 | + { |
| 60 | + Width = relativeWidth, |
| 61 | + Anchor = Anchor.Centre, |
| 62 | + Origin = Anchor.Centre, |
| 63 | + RelativeSizeAxes = Axes.X, |
| 64 | + AutoSizeAxes = Axes.Y, |
| 65 | + Spacing = new Vector2(0f, 2f), |
| 66 | + Shear = new Vector2(OsuGame.SHEAR, 0) |
| 67 | + }, |
| 68 | + drawWidthText = new OsuSpriteText(), |
| 69 | + }; |
| 70 | + |
| 71 | + foreach (var scoreInfo in getTestScores()) |
| 72 | + { |
| 73 | + fillFlow.Add(new LeaderboardScoreV2(scoreInfo, scoreInfo.Position, scoreInfo.User.Id == 2) |
| 74 | + { |
| 75 | + Shear = Vector2.Zero, |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + foreach (var score in fillFlow.Children) |
| 80 | + score.Show(); |
| 81 | + }); |
| 82 | + |
| 83 | + [SetUpSteps] |
| 84 | + public void SetUpSteps() |
| 85 | + { |
| 86 | + AddToggleStep("toggle scoring mode", v => config.SetValue(OsuSetting.ScoreDisplayMode, v ? ScoringMode.Classic : ScoringMode.Standardised)); |
| 87 | + } |
| 88 | + |
| 89 | + protected override void UpdateAfterChildren() |
| 90 | + { |
| 91 | + base.UpdateAfterChildren(); |
| 92 | + |
| 93 | + if (drawWidthText != null) drawWidthText.Text = $"DrawWidth: {fillFlow?.DrawWidth}"; |
| 94 | + } |
| 95 | + |
| 96 | + private static ScoreInfo[] getTestScores() |
| 97 | + { |
| 98 | + var scores = new[] |
| 99 | + { |
| 100 | + new ScoreInfo |
| 101 | + { |
| 102 | + Position = 999, |
| 103 | + Rank = ScoreRank.X, |
| 104 | + Accuracy = 1, |
| 105 | + MaxCombo = 244, |
| 106 | + TotalScore = RNG.Next(1_800_000, 2_000_000), |
| 107 | + MaximumStatistics = { { HitResult.Great, 3000 } }, |
| 108 | + Ruleset = new OsuRuleset().RulesetInfo, |
| 109 | + User = new APIUser |
| 110 | + { |
| 111 | + Id = 6602580, |
| 112 | + Username = @"waaiiru", |
| 113 | + CountryCode = CountryCode.ES, |
| 114 | + CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c1.jpg", |
| 115 | + }, |
| 116 | + Date = DateTimeOffset.Now.AddYears(-2), |
| 117 | + }, |
| 118 | + new ScoreInfo |
| 119 | + { |
| 120 | + Position = 22333, |
| 121 | + Rank = ScoreRank.S, |
| 122 | + Accuracy = 0.1f, |
| 123 | + MaxCombo = 32040, |
| 124 | + TotalScore = RNG.Next(1_200_000, 1_500_000), |
| 125 | + MaximumStatistics = { { HitResult.Great, 3000 } }, |
| 126 | + Ruleset = new OsuRuleset().RulesetInfo, |
| 127 | + User = new APIUser |
| 128 | + { |
| 129 | + Id = 1541390, |
| 130 | + Username = @"Toukai", |
| 131 | + CountryCode = CountryCode.CA, |
| 132 | + CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c2.jpg", |
| 133 | + }, |
| 134 | + Date = DateTimeOffset.Now.AddMonths(-6), |
| 135 | + }, |
| 136 | + TestResources.CreateTestScoreInfo(), |
| 137 | + new ScoreInfo |
| 138 | + { |
| 139 | + Position = 110000, |
| 140 | + Rank = ScoreRank.B, |
| 141 | + Accuracy = 1, |
| 142 | + MaxCombo = 244, |
| 143 | + TotalScore = RNG.Next(1_000_000, 1_200_000), |
| 144 | + MaximumStatistics = { { HitResult.Great, 3000 } }, |
| 145 | + Ruleset = new ManiaRuleset().RulesetInfo, |
| 146 | + User = new APIUser |
| 147 | + { |
| 148 | + Username = @"No cover", |
| 149 | + CountryCode = CountryCode.BR, |
| 150 | + }, |
| 151 | + Date = DateTimeOffset.Now, |
| 152 | + }, |
| 153 | + new ScoreInfo |
| 154 | + { |
| 155 | + Position = 110000, |
| 156 | + Rank = ScoreRank.D, |
| 157 | + Accuracy = 1, |
| 158 | + MaxCombo = 244, |
| 159 | + TotalScore = RNG.Next(500_000, 1_000_000), |
| 160 | + MaximumStatistics = { { HitResult.Great, 3000 } }, |
| 161 | + Ruleset = new ManiaRuleset().RulesetInfo, |
| 162 | + User = new APIUser |
| 163 | + { |
| 164 | + Id = 226597, |
| 165 | + Username = @"WWWWWWWWWWWWWWWWWWWW", |
| 166 | + CountryCode = CountryCode.US, |
| 167 | + }, |
| 168 | + Date = DateTimeOffset.Now, |
| 169 | + }, |
| 170 | + }; |
| 171 | + |
| 172 | + scores[2].Rank = ScoreRank.A; |
| 173 | + scores[2].TotalScore = RNG.Next(120_000, 400_000); |
| 174 | + scores[2].MaximumStatistics[HitResult.Great] = 3000; |
| 175 | + |
| 176 | + scores[1].Mods = new Mod[] { new OsuModHidden(), new OsuModDoubleTime(), new OsuModHardRock(), new OsuModFlashlight() }; |
| 177 | + scores[2].Mods = new Mod[] { new OsuModHidden(), new OsuModDoubleTime(), new OsuModHardRock(), new OsuModFlashlight(), new OsuModClassic() }; |
| 178 | + scores[3].Mods = new Mod[] { new OsuModHidden(), new OsuModDoubleTime(), new OsuModHardRock(), new OsuModFlashlight(), new OsuModClassic(), new OsuModDifficultyAdjust() }; |
| 179 | + scores[4].Mods = new ManiaRuleset().CreateAllMods().ToArray(); |
| 180 | + |
| 181 | + return scores; |
| 182 | + } |
| 183 | + } |
| 184 | +} |
0 commit comments