-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Extract common components from BeatmapLeaderboardScore
#37079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LiquidPL
wants to merge
5
commits into
ppy:master
Choose a base branch
from
LiquidPL:leaderboard-common-component
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1046d2b
Extract rank component from `BeatmapLeaderboardScore`
LiquidPL 24b499d
Remove `RankLabel` class
LiquidPL c86b359
Pass duration in method
LiquidPL 567002a
Minor field renames
LiquidPL 8fb6b63
Extract common components from `BeatmapLeaderboardScore`
LiquidPL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
osu.Game/Online/Leaderboards/LeaderboardCommonDisplay.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| // 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 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)); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno about naming here.
How about
LeaderboardScoreUserInfo?All these components may work better as partial classes inside
LeaderboardScoregiven how they are all just pieces of that component (i think?)See something like
BeatmapTitleWedgeand adjacent files as an example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it look awkward if I then reuse them on a potential
PlaylistsLeaderboardScoreand it'll have a bunch of references toBeatmapLeaderboardScore.<something>? I don't think it's that big of a deal but it would be at least a little eyebrow raising.But then on the other hand I am already pulling in constants from it in some places so I guess it's fine?