Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards;
using osu.Game.Overlays;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mods;
Expand Down Expand Up @@ -67,16 +68,16 @@ public void TestSheared()

foreach (var scoreInfo in getTestScores())
{
BeatmapLeaderboardScore.HighlightType? highlightType = null;
LeaderboardRankDisplay.HighlightType? highlightType = null;

switch (scoreInfo.User.Id)
{
case 2:
highlightType = BeatmapLeaderboardScore.HighlightType.Own;
highlightType = LeaderboardRankDisplay.HighlightType.Own;
break;

case 1541390:
highlightType = BeatmapLeaderboardScore.HighlightType.Friend;
highlightType = LeaderboardRankDisplay.HighlightType.Friend;
break;
}

Expand Down Expand Up @@ -118,16 +119,16 @@ public void TestNonSheared()

foreach (var scoreInfo in getTestScores())
{
BeatmapLeaderboardScore.HighlightType? highlightType = null;
LeaderboardRankDisplay.HighlightType? highlightType = null;

switch (scoreInfo.User.Id)
{
case 2:
highlightType = BeatmapLeaderboardScore.HighlightType.Own;
highlightType = LeaderboardRankDisplay.HighlightType.Own;
break;

case 1541390:
highlightType = BeatmapLeaderboardScore.HighlightType.Friend;
highlightType = LeaderboardRankDisplay.HighlightType.Friend;
break;
}

Expand Down
98 changes: 98 additions & 0 deletions osu.Game/Online/Leaderboards/LeaderboardRankDisplay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osuTK.Graphics;

namespace osu.Game.Online.Leaderboards
{
public partial class LeaderboardRankDisplay : Container
{
public const int WIDTH = 40;

public readonly int? Rank;
public readonly HighlightType? Highlight;

[Resolved]
private OsuColour colours { get; set; } = null!;

private static readonly Color4 personal_best_gradient_left = Color4Extensions.FromHex("#66FFCC");
private static readonly Color4 personal_best_gradient_right = Color4Extensions.FromHex("#51A388");

private Container highlightGradient = null!;

private readonly bool sheared;

public LeaderboardRankDisplay(int? rank, bool sheared = false, HighlightType? highlight = null)
{
Rank = rank;
Highlight = highlight;

this.sheared = sheared;
}

[BackgroundDependencyLoader]
private void load()
{
Width = WIDTH;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
highlightGradient = new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = -10f },
Alpha = Highlight != null ? 1 : 0,
Colour = getHighlightColour(Highlight),
Child = new Box { RelativeSizeAxes = Axes.Both },
},
new LeaderboardRankLabel(Rank, sheared, darkText: Highlight == HighlightType.Own)
{
RelativeSizeAxes = Axes.Both,
},
};
}

private ColourInfo getHighlightColour(HighlightType? highlightType, float lightenAmount = 0)
{
switch (highlightType)
{
case HighlightType.Own:
return ColourInfo.GradientHorizontal(personal_best_gradient_left.Lighten(lightenAmount), personal_best_gradient_right.Lighten(lightenAmount));

case HighlightType.Friend:
return ColourInfo.GradientHorizontal(colours.Pink1.Lighten(lightenAmount), colours.Pink3.Lighten(lightenAmount));

default:
return Colour4.White;
}
}

public void UpdateHighlightState(bool isHovered, double duration)
{
highlightGradient.FadeColour(getHighlightColour(Highlight, isHovered ? 0.2f : 0), duration, Easing.OutQuint);
}

public void Appear(double duration)
{
this.FadeIn(duration, Easing.OutQuint).ResizeWidthTo(WIDTH, duration, Easing.OutQuint);
}

public void Disappear(double duration)
{
this.FadeOut(duration, Easing.OutQuint).ResizeWidthTo(0, duration, Easing.OutQuint);
}

public enum HighlightType
{
Own,
Friend,
}
}
}
47 changes: 47 additions & 0 deletions osu.Game/Online/Leaderboards/LeaderboardRankLabel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Utils;
using osuTK;

namespace osu.Game.Online.Leaderboards
{
public partial class LeaderboardRankLabel : Container, IHasTooltip
{
private readonly bool darkText;
private readonly OsuSpriteText text;

public LeaderboardRankLabel(int? rank, bool sheared, bool darkText)
{
this.darkText = darkText;
if (rank >= 1000)
TooltipText = $"#{rank:N0}";

Child = text = new OsuSpriteText
{
Shear = sheared ? -OsuGame.SHEAR : Vector2.Zero,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Style.Heading2,
Text = rank?.FormatRank().Insert(0, "#") ?? "-",
Shadow = !darkText,
};
}

[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
text.Colour = darkText ? colourProvider.Background3 : colourProvider.Content1;
}

public LocalisableString TooltipText { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.Leaderboards;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
Expand Down Expand Up @@ -160,12 +161,12 @@ public void RefetchScores()
{
LoadComponentsAsync(best.Select((s, index) =>
{
BeatmapLeaderboardScore.HighlightType? highlightType = null;
LeaderboardRankDisplay.HighlightType? highlightType = null;

if (s.UserID == api.LocalUser.Value.Id)
highlightType = BeatmapLeaderboardScore.HighlightType.Own;
highlightType = LeaderboardRankDisplay.HighlightType.Own;
else if (api.LocalUserState.Friends.Any(r => r.TargetID == s.UserID))
highlightType = BeatmapLeaderboardScore.HighlightType.Friend;
highlightType = LeaderboardRankDisplay.HighlightType.Friend;

return new BeatmapLeaderboardScore(s, sheared: false)
{
Expand All @@ -191,7 +192,7 @@ public void RefetchScores()
userBestContainer.Add(new BeatmapLeaderboardScore(userBest, sheared: false)
{
Rank = userBest.Position,
Highlight = BeatmapLeaderboardScore.HighlightType.Own,
Highlight = LeaderboardRankDisplay.HighlightType.Own,
Action = () => PresentScore?.Invoke(userBest.OnlineID),
SelectedMods = { BindTarget = SelectedMods },
IsValidMod = IsValidMod,
Expand Down
Loading
Loading