diff --git a/osu.Game/Online/Leaderboards/Leaderboard.cs b/osu.Game/Online/Leaderboards/Leaderboard.cs index 83cc289bc1..d9d78245bb 100644 --- a/osu.Game/Online/Leaderboards/Leaderboard.cs +++ b/osu.Game/Online/Leaderboards/Leaderboard.cs @@ -18,14 +18,14 @@ using osuTK.Graphics; namespace osu.Game.Online.Leaderboards { - public abstract class Leaderboard : Container + public abstract class Leaderboard : Container { private const double fade_duration = 300; private readonly ScrollContainer scrollContainer; private readonly Container placeholderContainer; - private FillFlowContainer> scrollFlow; + private FillFlowContainer scrollFlow; private readonly LoadingAnimation loading; @@ -33,9 +33,9 @@ namespace osu.Game.Online.Leaderboards private bool scoresLoadedOnce; - private IEnumerable scores; + private IEnumerable scores; - public IEnumerable Scores + public IEnumerable Scores { get { return scores; } set @@ -55,13 +55,13 @@ namespace osu.Game.Online.Leaderboards // ensure placeholder is hidden when displaying scores PlaceholderState = PlaceholderState.Successful; - var flow = scrollFlow = new FillFlowContainer> + var flow = scrollFlow = new FillFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Spacing = new Vector2(0f, 5f), Padding = new MarginPadding { Top = 10, Bottom = 5 }, - ChildrenEnumerable = scores.Select((s, index) => CreateScoreVisualiser(s, index + 1)) + ChildrenEnumerable = scores.Select((s, index) => CreateDrawableScore(s, index + 1)) }; // schedule because we may not be loaded yet (LoadComponentAsync complains). @@ -240,7 +240,7 @@ namespace osu.Game.Online.Leaderboards }); } - protected abstract APIRequest FetchScores(Action> scoresCallback); + protected abstract APIRequest FetchScores(Action> scoresCallback); private Placeholder currentPlaceholder; @@ -295,6 +295,6 @@ namespace osu.Game.Online.Leaderboards } } - protected abstract LeaderboardScore CreateScoreVisualiser(TScoreModel model, int index); + protected abstract LeaderboardScore CreateDrawableScore(ScoreInfo model, int index); } } diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index 63352754a8..8269e02847 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -13,7 +13,6 @@ using osu.Framework.Input.Events; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; -using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; using osu.Game.Scoring; using osu.Game.Users; @@ -22,15 +21,12 @@ using osuTK.Graphics; namespace osu.Game.Online.Leaderboards { - public static class LeaderboardScore - { - public const float HEIGHT = 60; - } - - public abstract class LeaderboardScore : OsuClickableContainer + public class LeaderboardScore : OsuClickableContainer { public readonly int RankPosition; + public const float HEIGHT = 60; + private const float corner_radius = 5; private const float edge_margin = 5; private const float background_alpha = 0.25f; @@ -38,7 +34,7 @@ namespace osu.Game.Online.Leaderboards protected Container RankContainer { get; private set; } - private readonly TScoreModel score; + private readonly ScoreInfo score; private Box background; private Container content; @@ -51,21 +47,27 @@ namespace osu.Game.Online.Leaderboards private List statisticsLabels; - protected LeaderboardScore(TScoreModel score, int rank) + public LeaderboardScore(ScoreInfo score, int rank) { this.score = score; RankPosition = rank; RelativeSizeAxes = Axes.X; - Height = LeaderboardScore.HEIGHT; + Height = HEIGHT; } + protected virtual IEnumerable GetStatistics(ScoreInfo model) => new[] + { + new LeaderboardScoreStatistic(FontAwesome.fa_link, "Max Combo", model.MaxCombo.ToString()), + new LeaderboardScoreStatistic(FontAwesome.fa_crosshairs, "Accuracy", string.Format(model.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", model.Accuracy)) + }; + [BackgroundDependencyLoader] private void load() { - var user = GetUser(score); + var user = score.User; - statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s.icon, s.value, s.name)).ToList(); + statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList(); Children = new Drawable[] { @@ -129,13 +131,13 @@ namespace osu.Game.Online.Leaderboards }) { RelativeSizeAxes = Axes.None, - Size = new Vector2(LeaderboardScore.HEIGHT - edge_margin * 2, LeaderboardScore.HEIGHT - edge_margin * 2), + Size = new Vector2(HEIGHT - edge_margin * 2, HEIGHT - edge_margin * 2), }, new Container { RelativeSizeAxes = Axes.Y, AutoSizeAxes = Axes.X, - Position = new Vector2(LeaderboardScore.HEIGHT - edge_margin, 0f), + Position = new Vector2(HEIGHT - edge_margin, 0f), Children = new Drawable[] { nameLabel = new OsuSpriteText @@ -191,13 +193,13 @@ namespace osu.Game.Online.Leaderboards Spacing = new Vector2(5f, 0f), Children = new Drawable[] { - scoreLabel = new GlowingSpriteText(GetTotalScore(score).ToString(@"N0"), @"Venera", 23, Color4.White, OsuColour.FromHex(@"83ccfa")), + scoreLabel = new GlowingSpriteText(score.TotalScore.ToString(@"N0"), @"Venera", 23, Color4.White, OsuColour.FromHex(@"83ccfa")), RankContainer = new Container { Size = new Vector2(40f, 20f), Children = new[] { - scoreRank = new DrawableRank(GetRank(score)) + scoreRank = new DrawableRank(score.Rank) { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -213,7 +215,7 @@ namespace osu.Game.Online.Leaderboards Origin = Anchor.BottomRight, AutoSizeAxes = Axes.Both, Direction = FillDirection.Horizontal, - ChildrenEnumerable = GetMods(score).Select(mod => new ModIcon(mod) { Scale = new Vector2(0.375f) }) + ChildrenEnumerable = score.Mods.Select(mod => new ModIcon(mod) { Scale = new Vector2(0.375f) }) }, }, }, @@ -271,16 +273,6 @@ namespace osu.Game.Online.Leaderboards base.OnHoverLost(e); } - protected abstract User GetUser(TScoreModel model); - - protected abstract IEnumerable GetMods(TScoreModel model); - - protected abstract IEnumerable<(FontAwesome icon, string value, string name)> GetStatistics(TScoreModel model); - - protected abstract int GetTotalScore(TScoreModel model); - - protected abstract ScoreRank GetRank(TScoreModel model); - private class GlowingSpriteText : Container { public GlowingSpriteText(string text, string font, int textSize, Color4 textColour, Color4 glowColour) @@ -339,9 +331,9 @@ namespace osu.Game.Online.Leaderboards public string TooltipText => name; - public ScoreComponentLabel(FontAwesome icon, string value, string name) + public ScoreComponentLabel(LeaderboardScoreStatistic statistic) { - this.name = name; + name = statistic.Name; AutoSizeAxes = Axes.Both; Child = content = new FillFlowContainer @@ -373,11 +365,11 @@ namespace osu.Game.Online.Leaderboards Origin = Anchor.Centre, Size = new Vector2(icon_size - 6), Colour = OsuColour.FromHex(@"a4edff"), - Icon = icon, + Icon = statistic.Icon, }, }, }, - new GlowingSpriteText(value, @"Exo2.0-Bold", 17, Color4.White, OsuColour.FromHex(@"83ccfa")) + new GlowingSpriteText(statistic.Value, @"Exo2.0-Bold", 17, Color4.White, OsuColour.FromHex(@"83ccfa")) { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, @@ -386,5 +378,19 @@ namespace osu.Game.Online.Leaderboards }; } } + + public class LeaderboardScoreStatistic + { + public FontAwesome Icon; + public string Value; + public string Name; + + public LeaderboardScoreStatistic(FontAwesome icon, string name, string value) + { + Icon = icon; + Name = name; + Value = value; + } + } } } diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index b0cfad314c..9f8726c86a 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -79,7 +79,7 @@ namespace osu.Game.Screens.Select.Leaderboards return req; } - protected override LeaderboardScore CreateScoreVisualiser(ScoreInfo model, int index) => new BeatmapLeaderboardScore(model, index) + protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) => new LeaderboardScore(model, index) { Action = () => ScoreSelected?.Invoke(model) }; diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboardScore.cs deleted file mode 100644 index 098fff4052..0000000000 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboardScore.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System.Collections.Generic; -using osu.Game.Graphics; -using osu.Game.Online.Leaderboards; -using osu.Game.Rulesets.Mods; -using osu.Game.Scoring; -using osu.Game.Users; - -namespace osu.Game.Screens.Select.Leaderboards -{ - public class BeatmapLeaderboardScore : LeaderboardScore - { - public BeatmapLeaderboardScore(ScoreInfo score, int rank) - : base(score, rank) - { - } - - protected override User GetUser(ScoreInfo model) => model.User; - - protected override IEnumerable GetMods(ScoreInfo model) => model.Mods; - - protected override IEnumerable<(FontAwesome icon, string value, string name)> GetStatistics(ScoreInfo model) => new[] - { - (FontAwesome.fa_link, model.MaxCombo.ToString(), "Max Combo"), - (FontAwesome.fa_crosshairs, string.Format(model.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", model.Accuracy), "Accuracy") - }; - - protected override int GetTotalScore(ScoreInfo model) => model.TotalScore; - - protected override ScoreRank GetRank(ScoreInfo model) => model.Rank; - } -}