From 9ea151539670ad5bb8175026c8fcaeba6059e695 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Mon, 16 Jan 2023 17:35:27 +0100 Subject: [PATCH] setup up rank and score logic flow --- .../SongSelect/TestSceneLeaderboardScoreV2.cs | 60 ++++++++++++++++++- .../Online/Leaderboards/LeaderBoardScoreV2.cs | 45 +++++++++++++- 2 files changed, 100 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneLeaderboardScoreV2.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneLeaderboardScoreV2.cs index 377bc79605..13eaf5417d 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneLeaderboardScoreV2.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneLeaderboardScoreV2.cs @@ -4,7 +4,13 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Leaderboards; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Osu; +using osu.Game.Rulesets.Osu.Mods; +using osu.Game.Scoring; +using osu.Game.Users; using osuTK; namespace osu.Game.Tests.Visual.SongSelect @@ -14,6 +20,56 @@ namespace osu.Game.Tests.Visual.SongSelect [BackgroundDependencyLoader] private void load() { + var scores = new[] + { + new ScoreInfo + { + Position = 999, + Rank = ScoreRank.XH, + Accuracy = 1, + MaxCombo = 244, + TotalScore = 1707827, + Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), }, + Ruleset = new OsuRuleset().RulesetInfo, + User = new APIUser + { + Id = 6602580, + Username = @"waaiiru", + CountryCode = CountryCode.ES, + }, + }, + new ScoreInfo + { + Position = 110000, + Rank = ScoreRank.X, + Accuracy = 1, + MaxCombo = 244, + TotalScore = 1707827, + Ruleset = new OsuRuleset().RulesetInfo, + User = new APIUser + { + Id = 4608074, + Username = @"Skycries", + CountryCode = CountryCode.BR, + }, + }, + new ScoreInfo + { + Position = 22333, + Rank = ScoreRank.S, + Accuracy = 1, + MaxCombo = 244, + TotalScore = 1707827, + Ruleset = new OsuRuleset().RulesetInfo, + User = new APIUser + { + Id = 1541390, + Username = @"Toukai", + CountryCode = CountryCode.CA, + }, + } + }; + Child = new FillFlowContainer { Width = 900, @@ -23,8 +79,8 @@ namespace osu.Game.Tests.Visual.SongSelect AutoSizeAxes = Axes.Y, Children = new Drawable[] { - new LeaderBoardScoreV2(), - new LeaderBoardScoreV2(true) + new LeaderBoardScoreV2(scores[0], 1), + new LeaderBoardScoreV2(scores[2], 3, true) } }; } diff --git a/osu.Game/Online/Leaderboards/LeaderBoardScoreV2.cs b/osu.Game/Online/Leaderboards/LeaderBoardScoreV2.cs index 7a56657365..d526172861 100644 --- a/osu.Game/Online/Leaderboards/LeaderBoardScoreV2.cs +++ b/osu.Game/Online/Leaderboards/LeaderBoardScoreV2.cs @@ -4,21 +4,32 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; using osu.Framework.Input.Events; +using osu.Framework.Localisation; +using osu.Game.Graphics; using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; using osu.Game.Overlays; +using osu.Game.Scoring; +using osu.Game.Utils; using osuTK; namespace osu.Game.Online.Leaderboards { public partial class LeaderBoardScoreV2 : OsuClickableContainer { - private readonly bool isPersonalBest; + private readonly ScoreInfo score; + private const int HEIGHT = 60; private const int corner_radius = 10; private const int transition_duration = 200; + private readonly int? rank; + + private readonly bool isPersonalBest; + private Colour4 foregroundColour; private Colour4 backgroundColour; @@ -31,8 +42,10 @@ namespace osu.Game.Online.Leaderboards private Box background = null!; private Box foreground = null!; - public LeaderBoardScoreV2(bool isPersonalBest = false) + public LeaderBoardScoreV2(ScoreInfo score, int? rank, bool isPersonalBest = false) { + this.score = score; + this.rank = rank; this.isPersonalBest = isPersonalBest; } @@ -70,7 +83,14 @@ namespace osu.Game.Online.Leaderboards { new[] { - Empty(), + new RankLabel(rank) + { + Shear = -shear, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Y, + Width = 35 + }, createCentreContent(), Empty(), } @@ -115,5 +135,24 @@ namespace osu.Game.Online.Leaderboards foreground.FadeColour(IsHovered ? foregroundColour.Lighten(0.2f) : foregroundColour, transition_duration, Easing.OutQuint); background.FadeColour(IsHovered ? backgroundColour.Lighten(0.2f) : backgroundColour, transition_duration, Easing.OutQuint); } + + private partial class RankLabel : Container, IHasTooltip + { + public RankLabel(int? rank) + { + if (rank >= 1000) + TooltipText = $"#{rank:N0}"; + + Child = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 20, weight: FontWeight.SemiBold, italics: true), + Text = rank == null ? "-" : rank.Value.FormatRank().Insert(0, "#") + }; + } + + public LocalisableString TooltipText { get; } + } } }