diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboardScore.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboardScore.cs index 856a4be67dcc..95c4de842171 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboardScore.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboardScore.cs @@ -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; @@ -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; } @@ -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; } diff --git a/osu.Game/Online/Leaderboards/LeaderboardCommonDisplay.cs b/osu.Game/Online/Leaderboards/LeaderboardCommonDisplay.cs new file mode 100644 index 000000000000..f78cf73db44c --- /dev/null +++ b/osu.Game/Online/Leaderboards/LeaderboardCommonDisplay.cs @@ -0,0 +1,180 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; +using osu.Game.Extensions; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Overlays; +using osu.Game.Screens.Select; +using osu.Game.Users.Drawables; +using osuTK; + +namespace osu.Game.Online.Leaderboards +{ + public partial class LeaderboardCommonDisplay : Container + { + public readonly APIUser User; + public readonly DateTimeOffset? Date; + public readonly int? Rank; + + private const int corner_radius = BeatmapLeaderboardScore.CORNER_RADIUS; + + private FillFlowContainer fillFlowContainer = null!; + private ClickableAvatar innerAvatar = null!; + private Container rankOverlay = null!; + + private readonly bool sheared; + + public LeaderboardCommonDisplay(APIUser user, DateTimeOffset? date, int? rank = null, bool sheared = false) + { + User = user; + Date = date; + Rank = rank; + + this.sheared = sheared; + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider) + { + RelativeSizeAxes = Axes.Both; + + Child = new GridContainer + { + RelativeSizeAxes = Axes.Both, + ColumnDimensions = new[] + { + new Dimension(GridSizeMode.AutoSize), + new Dimension(), + }, + Content = new[] + { + new Drawable[] + { + new Container + { + AutoSizeAxes = Axes.Both, + CornerRadius = corner_radius, + Masking = true, + Children = new Drawable[] + { + new DelayedLoadWrapper(innerAvatar = new ClickableAvatar(User) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(1.1f), + Shear = sheared ? -OsuGame.SHEAR : Vector2.Zero, + RelativeSizeAxes = Axes.Both, + }) + { + RelativeSizeAxes = Axes.None, + Size = new Vector2(BeatmapLeaderboardScore.HEIGHT) + }, + rankOverlay = new Container + { + RelativeSizeAxes = Axes.Both, + Alpha = 0, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Colour4.Black.Opacity(0.5f), + }, + new LeaderboardRankLabel(Rank, sheared, false) + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }, + } + } + }, + }, + new FillFlowContainer + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Padding = new MarginPadding { Horizontal = corner_radius }, + Children = new Drawable[] + { + fillFlowContainer = new FillFlowContainer + { + Shear = sheared ? -OsuGame.SHEAR : Vector2.Zero, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(5), + AutoSizeAxes = Axes.Both, + Masking = true, + Children = new Drawable[] + { + new UpdateableFlag(User.CountryCode) + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Size = new Vector2(20, 14), + }, + new UpdateableTeamFlag(User.Team) + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Size = new Vector2(30, 15), + }, + }, + }, + new TruncatingSpriteText + { + RelativeSizeAxes = Axes.X, + Shear = sheared ? -OsuGame.SHEAR : Vector2.Zero, + Text = User.Username, + Font = OsuFont.Style.Heading2, + } + } + }, + }, + } + }; + + innerAvatar.OnLoadComplete += d => d.FadeInFromZero(200); + + if (Date != null) + { + fillFlowContainer.Add(new DateLabel(Date.Value) + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Colour = colourProvider.Content2, + UseFullGlyphHeight = false, + }); + } + } + + public void UpdateRankOverlayState(bool shouldBeVisible, double duration) + { + if (shouldBeVisible) + rankOverlay.FadeIn(duration, Easing.OutQuint); + else + rankOverlay.FadeOut(duration, Easing.OutQuint); + } + + private partial class DateLabel : DrawableDate + { + public DateLabel(DateTimeOffset date) + : base(date) + { + Font = OsuFont.Style.Caption1.With(weight: FontWeight.SemiBold); + } + + protected override LocalisableString Format() => Date.ToShortRelativeTime(TimeSpan.FromSeconds(30)); + } + } +} diff --git a/osu.Game/Online/Leaderboards/LeaderboardRankDisplay.cs b/osu.Game/Online/Leaderboards/LeaderboardRankDisplay.cs new file mode 100644 index 000000000000..4d83589edece --- /dev/null +++ b/osu.Game/Online/Leaderboards/LeaderboardRankDisplay.cs @@ -0,0 +1,98 @@ +// Copyright (c) ppy Pty Ltd . 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, + } + } +} diff --git a/osu.Game/Online/Leaderboards/LeaderboardRankLabel.cs b/osu.Game/Online/Leaderboards/LeaderboardRankLabel.cs new file mode 100644 index 000000000000..67c6081fdcdb --- /dev/null +++ b/osu.Game/Online/Leaderboards/LeaderboardRankLabel.cs @@ -0,0 +1,47 @@ +// Copyright (c) ppy Pty Ltd . 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; } + } +} diff --git a/osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallengeLeaderboard.cs b/osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallengeLeaderboard.cs index 62c5c0c8dfb5..400a4b440a88 100644 --- a/osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallengeLeaderboard.cs +++ b/osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallengeLeaderboard.cs @@ -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; @@ -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) { @@ -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, diff --git a/osu.Game/Screens/Select/BeatmapLeaderboardScore.Tooltip.cs b/osu.Game/Screens/Select/BeatmapLeaderboardScore.Tooltip.cs index 64a5f4334ee8..7135604a061a 100644 --- a/osu.Game/Screens/Select/BeatmapLeaderboardScore.Tooltip.cs +++ b/osu.Game/Screens/Select/BeatmapLeaderboardScore.Tooltip.cs @@ -145,7 +145,7 @@ private void load(OsuConfigManager configManager) { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - CornerRadius = corner_radius; + CornerRadius = CORNER_RADIUS; Masking = true; EdgeEffect = new EdgeEffectParameters @@ -193,7 +193,7 @@ private void load(OsuConfigManager configManager) Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - CornerRadius = corner_radius, + CornerRadius = CORNER_RADIUS, Masking = true, Margin = new MarginPadding { Top = 4f }, Children = new Drawable[] @@ -357,7 +357,7 @@ private void load(OverlayColourProvider colourProvider) { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - CornerRadius = corner_radius; + CornerRadius = CORNER_RADIUS; Masking = true; EdgeEffect = new EdgeEffectParameters @@ -417,7 +417,7 @@ private void load() { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - CornerRadius = corner_radius; + CornerRadius = CORNER_RADIUS; Masking = true; EdgeEffect = new EdgeEffectParameters diff --git a/osu.Game/Screens/Select/BeatmapLeaderboardScore.cs b/osu.Game/Screens/Select/BeatmapLeaderboardScore.cs index bb96c97d520a..5a530b02aa24 100644 --- a/osu.Game/Screens/Select/BeatmapLeaderboardScore.cs +++ b/osu.Game/Screens/Select/BeatmapLeaderboardScore.cs @@ -17,7 +17,6 @@ using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Game.Configuration; -using osu.Game.Extensions; using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; @@ -33,8 +32,6 @@ using osu.Game.Rulesets.UI; using osu.Game.Scoring; using osu.Game.Users; -using osu.Game.Users.Drawables; -using osu.Game.Utils; using osuTK; using osuTK.Graphics; using CommonStrings = osu.Game.Localisation.CommonStrings; @@ -44,6 +41,7 @@ namespace osu.Game.Screens.Select public sealed partial class BeatmapLeaderboardScore : OsuClickableContainer, IHasContextMenu, IHasCustomTooltip { public const int HEIGHT = 50; + public const int CORNER_RADIUS = 10; public readonly ScoreInfo Score; @@ -57,15 +55,12 @@ public sealed partial class BeatmapLeaderboardScore : OsuClickableContainer, IHa public Func IsValidMod { get; set; } = _ => true; public int? Rank { get; init; } - public HighlightType? Highlight { get; init; } + public LeaderboardRankDisplay.HighlightType? Highlight { get; init; } public Action? ShowReplay { get; init; } [Resolved] private OverlayColourProvider colourProvider { get; set; } = null!; - [Resolved] - private OsuColour colours { get; set; } = null!; - [Resolved] private IDialogOverlay? dialogOverlay { get; set; } @@ -86,14 +81,9 @@ public sealed partial class BeatmapLeaderboardScore : OsuClickableContainer, IHa private const float username_min_width = 120; private const float statistics_regular_min_width = 165; private const float statistics_compact_min_width = 90; - private const float rank_label_width = 40; - private const int corner_radius = 10; private const int transition_duration = 200; - private static readonly Color4 personal_best_gradient_left = Color4Extensions.FromHex("#66FFCC"); - private static readonly Color4 personal_best_gradient_right = Color4Extensions.FromHex("#51A388"); - private Colour4 foregroundColour; private Colour4 backgroundColour; private ColourInfo totalScoreBackgroundGradient; @@ -103,8 +93,6 @@ public sealed partial class BeatmapLeaderboardScore : OsuClickableContainer, IHa private Box background = null!; private Box foreground = null!; - private ClickableAvatar innerAvatar = null!; - private Container centreContent = null!; private Container rightContent = null!; @@ -112,10 +100,9 @@ public sealed partial class BeatmapLeaderboardScore : OsuClickableContainer, IHa private Box totalScoreBackground = null!; + private LeaderboardCommonDisplay leaderboardCommonDisplay = null!; private FillFlowContainer statisticsContainer = null!; - private Container highlightGradient = null!; - private Container rankLabelStandalone = null!; - private Container rankLabelOverlay = null!; + private LeaderboardRankDisplay rankDisplay = null!; private readonly bool sheared; @@ -149,7 +136,7 @@ private void load() Child = new Container { Masking = true, - CornerRadius = corner_radius, + CornerRadius = CORNER_RADIUS, RelativeSizeAxes = Axes.Both, Children = new Drawable[] { @@ -159,26 +146,7 @@ private void load() RelativeSizeAxes = Axes.Both, Colour = backgroundColour }, - rankLabelStandalone = new Container - { - Width = rank_label_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 RankLabel(Rank, sheared, darkText: Highlight == HighlightType.Own) - { - RelativeSizeAxes = Axes.Both, - } - }, - }, + rankDisplay = new LeaderboardRankDisplay(Rank, sheared, Highlight), centreContent = new Container { Name = @"Centre container", @@ -186,7 +154,7 @@ private void load() Child = new Container { Masking = true, - CornerRadius = corner_radius, + CornerRadius = CORNER_RADIUS, RelativeSizeAxes = Axes.Both, Children = new Drawable[] { @@ -210,7 +178,6 @@ private void load() RelativeSizeAxes = Axes.Both, ColumnDimensions = new[] { - new Dimension(GridSizeMode.AutoSize), new Dimension(), new Dimension(GridSizeMode.AutoSize), }, @@ -218,95 +185,7 @@ private void load() { new Drawable[] { - new Container - { - AutoSizeAxes = Axes.Both, - CornerRadius = corner_radius, - Masking = true, - Children = new Drawable[] - { - new DelayedLoadWrapper(innerAvatar = new ClickableAvatar(Score.User) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(1.1f), - Shear = sheared ? -OsuGame.SHEAR : Vector2.Zero, - RelativeSizeAxes = Axes.Both, - }) - { - RelativeSizeAxes = Axes.None, - Size = new Vector2(HEIGHT) - }, - rankLabelOverlay = new Container - { - RelativeSizeAxes = Axes.Both, - Alpha = 0, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Colour4.Black.Opacity(0.5f), - }, - new RankLabel(Rank, sheared, false) - { - AutoSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }, - } - } - }, - }, - new FillFlowContainer - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Direction = FillDirection.Vertical, - Padding = new MarginPadding { Horizontal = corner_radius }, - Children = new Drawable[] - { - new FillFlowContainer - { - Shear = sheared ? -OsuGame.SHEAR : Vector2.Zero, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(5), - AutoSizeAxes = Axes.Both, - Masking = true, - Children = new Drawable[] - { - new UpdateableFlag(Score.User.CountryCode) - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Size = new Vector2(20, 14), - }, - new UpdateableTeamFlag(Score.User.Team) - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Size = new Vector2(30, 15), - }, - new DateLabel(Score.Date) - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Colour = colourProvider.Content2, - UseFullGlyphHeight = false, - } - } - }, - new TruncatingSpriteText - { - RelativeSizeAxes = Axes.X, - Shear = sheared ? -OsuGame.SHEAR : Vector2.Zero, - Text = Score.User.Username, - Font = OsuFont.Style.Heading2, - } - } - }, + leaderboardCommonDisplay = new LeaderboardCommonDisplay(Score.User, Score.Date, Rank, sheared), new Container { AutoSizeAxes = Axes.Both, @@ -410,7 +289,7 @@ private void load() { RelativeSizeAxes = Axes.Both, Masking = true, - CornerRadius = corner_radius, + CornerRadius = CORNER_RADIUS, Children = new Drawable[] { totalScoreBackground = new Box @@ -429,7 +308,7 @@ private void load() Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, Direction = FillDirection.Vertical, - Padding = new MarginPadding { Horizontal = corner_radius }, + Padding = new MarginPadding { Horizontal = CORNER_RADIUS }, Spacing = new Vector2(0f, -2f), Children = new Drawable[] { @@ -462,22 +341,6 @@ private void load() } } }; - innerAvatar.OnLoadComplete += d => d.FadeInFromZero(200); - } - - 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; - } } protected override void LoadComplete() @@ -541,12 +404,8 @@ private void updateState() foreground.FadeColour(IsHovered ? foregroundColour.Lighten(0.2f) : foregroundColour, transition_duration, Easing.OutQuint); background.FadeColour(IsHovered ? backgroundColour.Lighten(0.2f) : backgroundColour, transition_duration, Easing.OutQuint); totalScoreBackground.FadeColour(IsHovered ? lightenedGradient : totalScoreBackgroundGradient, transition_duration, Easing.OutQuint); - highlightGradient.FadeColour(getHighlightColour(Highlight, IsHovered ? 0.2f : 0), transition_duration, Easing.OutQuint); - - if (IsHovered && currentMode != DisplayMode.Full) - rankLabelOverlay.FadeIn(transition_duration, Easing.OutQuint); - else - rankLabelOverlay.FadeOut(transition_duration, Easing.OutQuint); + rankDisplay.UpdateHighlightState(IsHovered, transition_duration); + leaderboardCommonDisplay.UpdateRankOverlayState(IsHovered && currentMode != DisplayMode.Full, transition_duration); } private DisplayMode? currentMode; @@ -562,7 +421,7 @@ protected override void Update() centreContent.Padding = new MarginPadding { - Left = rankLabelStandalone.DrawWidth, + Left = rankDisplay.DrawWidth, Right = rightContent.DrawWidth, }; } @@ -570,10 +429,11 @@ protected override void Update() private void updateDisplayMode(DisplayMode mode) { double duration = currentMode == null ? 0 : transition_duration; + if (mode >= DisplayMode.Full) - rankLabelStandalone.FadeIn(duration, Easing.OutQuint).ResizeWidthTo(rank_label_width, duration, Easing.OutQuint); + rankDisplay.Appear(duration); else - rankLabelStandalone.FadeOut(duration, Easing.OutQuint).ResizeWidthTo(0, duration, Easing.OutQuint); + rankDisplay.Disappear(duration); if (mode >= DisplayMode.Regular) { @@ -595,7 +455,7 @@ private void updateDisplayMode(DisplayMode mode) private DisplayMode getCurrentDisplayMode() { - if (DrawWidth >= username_min_width + statistics_regular_min_width + expanded_right_content_width + rank_label_width) + if (DrawWidth >= username_min_width + statistics_regular_min_width + expanded_right_content_width + LeaderboardRankDisplay.WIDTH) return DisplayMode.Full; if (DrawWidth >= username_min_width + statistics_regular_min_width + expanded_right_content_width) @@ -648,17 +508,6 @@ private enum DisplayMode Full } - private partial class DateLabel : DrawableDate - { - public DateLabel(DateTimeOffset date) - : base(date) - { - Font = OsuFont.Style.Caption1.With(weight: FontWeight.SemiBold); - } - - protected override LocalisableString Format() => Date.ToShortRelativeTime(TimeSpan.FromSeconds(30)); - } - private partial class ScoreComponentLabel : Container { private readonly LocalisableString name; @@ -707,42 +556,5 @@ private void load(OsuColour colours, OverlayColourProvider colourProvider) }; } } - - private partial class RankLabel : Container, IHasTooltip - { - private readonly bool darkText; - private readonly OsuSpriteText text; - - public RankLabel(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; } - } - - public enum HighlightType - { - Own, - Friend, - } } } diff --git a/osu.Game/Screens/Select/BeatmapLeaderboardWedge.cs b/osu.Game/Screens/Select/BeatmapLeaderboardWedge.cs index 4373b7b0736c..cc1bc772668b 100644 --- a/osu.Game/Screens/Select/BeatmapLeaderboardWedge.cs +++ b/osu.Game/Screens/Select/BeatmapLeaderboardWedge.cs @@ -298,12 +298,12 @@ protected void SetScores(IEnumerable scores, ScoreInfo? userScore = n LoadComponentsAsync(scores.Select((s, i) => { - BeatmapLeaderboardScore.HighlightType? highlightType = null; + LeaderboardRankDisplay.HighlightType? highlightType = null; if (s.OnlineID == userScore?.OnlineID) - highlightType = BeatmapLeaderboardScore.HighlightType.Own; + highlightType = LeaderboardRankDisplay.HighlightType.Own; else if (api.LocalUserState.Friends.Any(r => r.TargetID == s.UserID) && Scope.Value != BeatmapLeaderboardScope.Friend) - highlightType = BeatmapLeaderboardScore.HighlightType.Friend; + highlightType = LeaderboardRankDisplay.HighlightType.Friend; return new BeatmapLeaderboardScore(s) { @@ -366,7 +366,7 @@ protected void SetScores(IEnumerable scores, ScoreInfo? userScore = n personalBestDisplay.FadeIn(600, Easing.OutQuint); personalBestScoreContainer.Child = new BeatmapLeaderboardScore(userScore) { - Highlight = BeatmapLeaderboardScore.HighlightType.Own, + Highlight = LeaderboardRankDisplay.HighlightType.Own, Rank = userScore.Position, SelectedMods = { BindTarget = mods }, Action = () => onLeaderboardScoreClicked(userScore),