diff --git a/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs b/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs index 19e999547b..a2a9f9a01b 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs @@ -31,8 +31,10 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; + CornerRadius = 3; Masking = true; + Children = new Drawable[] { background = new Box diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs index d69bc39bc6..4723fcaf2b 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs @@ -5,47 +5,50 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Online.API.Requests.Responses; using System.Collections.Generic; +using System.Linq; namespace osu.Game.Overlays.BeatmapSet.Scores { - public class ScoreTable : FillFlowContainer + public class ScoreTable : CompositeDrawable { - private IEnumerable scores; + private readonly FillFlowContainer scoresFlow; + + public ScoreTable() + { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + + InternalChild = scoresFlow = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical + }; + } public IEnumerable Scores { set { - scores = value; + scoresFlow.Clear(); + + if (value == null || !value.Any()) + return; int maxModsAmount = 0; - foreach (var s in scores) + foreach (var s in value) { var scoreModsAmount = s.Mods.Length; if (scoreModsAmount > maxModsAmount) maxModsAmount = scoreModsAmount; } - Add(new ScoreTextLine(maxModsAmount)); + scoresFlow.Add(new ScoreTextLine(maxModsAmount)); int index = 0; - foreach (var s in scores) - Add(new DrawableScore(index++, s, maxModsAmount)); + foreach (var s in value) + scoresFlow.Add(new DrawableScore(index++, s, maxModsAmount)); } - get => scores; - } - - public ScoreTable() - { - RelativeSizeAxes = Axes.X; - AutoSizeAxes = Axes.Y; - Direction = FillDirection.Vertical; - } - - public void ClearScores() - { - scores = null; - Clear(); } } } diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index d99f391d21..6c90e192ac 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -17,7 +17,7 @@ using System.Linq; namespace osu.Game.Overlays.BeatmapSet.Scores { - public class ScoresContainer : Container + public class ScoresContainer : CompositeDrawable { private const int spacing = 15; private const int fade_duration = 200; @@ -28,77 +28,15 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly DrawableTopScore topScore; private readonly LoadingAnimation loadingAnimation; - private bool loading - { - set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); - } - - private IEnumerable scores; - private BeatmapInfo beatmap; - - public IEnumerable Scores - { - get => scores; - set - { - getScoresRequest?.Cancel(); - scores = value; - - updateDisplay(); - } - } - - private GetScoresRequest getScoresRequest; - private APIAccess api; - - public BeatmapInfo Beatmap - { - get => beatmap; - set - { - beatmap = value; - - Scores = null; - - if (beatmap?.OnlineBeatmapID.HasValue != true) - return; - - loading = true; - - getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset); - getScoresRequest.Success += r => Schedule(() => Scores = r.Scores); - api.Queue(getScoresRequest); - } - } - - private void updateDisplay() - { - scoreTable.ClearScores(); - - loading = false; - - var scoreCount = scores?.Count() ?? 0; - - if (scoreCount == 0) - { - topScore.Hide(); - return; - } - - topScore.Score = scores.FirstOrDefault(); - topScore.Show(); - - if (scoreCount < 2) - return; - - scoreTable.Scores = scores; - } + [Resolved] + private APIAccess api { get; set; } public ScoresContainer() { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - Children = new Drawable[] + + InternalChildren = new Drawable[] { background = new Box { @@ -135,12 +73,76 @@ namespace osu.Game.Overlays.BeatmapSet.Scores [BackgroundDependencyLoader] private void load(APIAccess api, OsuColour colours) { - this.api = api; - background.Colour = colours.Gray2; updateDisplay(); } + private bool loading + { + set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); + } + + private GetScoresRequest getScoresRequest; + + private IEnumerable scores; + + public IEnumerable Scores + { + get => scores; + set + { + getScoresRequest?.Cancel(); + scores = value; + + updateDisplay(); + } + } + + private BeatmapInfo beatmap; + + public BeatmapInfo Beatmap + { + get => beatmap; + set + { + beatmap = value; + + Scores = null; + + if (beatmap?.OnlineBeatmapID.HasValue != true) + return; + + loading = true; + + getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset); + getScoresRequest.Success += r => Schedule(() => Scores = r.Scores); + api.Queue(getScoresRequest); + } + } + + private void updateDisplay() + { + scoreTable.Scores = Enumerable.Empty(); + + loading = false; + + var scoreCount = scores?.Count() ?? 0; + + if (scoreCount == 0) + { + topScore.Hide(); + return; + } + + topScore.Score = scores.FirstOrDefault(); + topScore.Show(); + + if (scoreCount < 2) + return; + + scoreTable.Scores = scores; + } + protected override void Dispose(bool isDisposing) { getScoresRequest?.Cancel();