1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 16:03:01 +08:00

setup up rank and score logic flow

This commit is contained in:
mk56-spn 2023-01-16 17:35:27 +01:00
parent b7584b4a02
commit 9ea1515396
2 changed files with 100 additions and 5 deletions

View File

@ -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)
}
};
}

View File

@ -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; }
}
}
}