From a0efd50f629476bda2f1bfa86e7d801cd2662a48 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 8 Jul 2019 11:25:25 +0300 Subject: [PATCH 01/18] Extend APILegacyScores request --- osu.Game/Online/API/Requests/GetScoresRequest.cs | 8 ++++++++ .../Online/API/Requests/Responses/APILegacyScores.cs | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index 6b0e680eb5..50844fa256 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -42,6 +42,14 @@ namespace osu.Game.Online.API.Requests score.Beatmap = beatmap; score.Ruleset = ruleset; } + + var userScore = r.UserScore; + + if (userScore != null) + { + userScore.Score.Beatmap = beatmap; + userScore.Score.Ruleset = ruleset; + } } protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores{createQueryParameters()}"; diff --git a/osu.Game/Online/API/Requests/Responses/APILegacyScores.cs b/osu.Game/Online/API/Requests/Responses/APILegacyScores.cs index c629caaa6f..318fcb00de 100644 --- a/osu.Game/Online/API/Requests/Responses/APILegacyScores.cs +++ b/osu.Game/Online/API/Requests/Responses/APILegacyScores.cs @@ -10,5 +10,17 @@ namespace osu.Game.Online.API.Requests.Responses { [JsonProperty(@"scores")] public List Scores; + + [JsonProperty(@"userScore")] + public APILegacyUserTopScoreInfo UserScore; + } + + public class APILegacyUserTopScoreInfo + { + [JsonProperty(@"position")] + public int Position; + + [JsonProperty(@"score")] + public APILegacyScoreInfo Score; } } From 67a6abb96c7e08c0afa5e4f5eb49c0e6bbeb369c Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 8 Jul 2019 11:49:33 +0300 Subject: [PATCH 02/18] Add user top score on selected beatmap --- .../BeatmapSet/Scores/DrawableTopScore.cs | 22 +++------- .../BeatmapSet/Scores/ScoresContainer.cs | 41 +++++++++++++++---- .../BeatmapSet/Scores/TopScoreUserSection.cs | 4 +- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs index 8e806c6747..bdae730f7e 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs @@ -23,10 +23,8 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private Color4 backgroundHoveredColour; private readonly Box background; - private readonly TopScoreUserSection userSection; - private readonly TopScoreStatisticsSection statisticsSection; - public DrawableTopScore() + public DrawableTopScore(ScoreInfo score, int position = 1) { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -61,16 +59,18 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { new Drawable[] { - userSection = new TopScoreUserSection + new TopScoreUserSection(position) { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, + Score = score, }, null, - statisticsSection = new TopScoreStatisticsSection + new TopScoreStatisticsSection { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, + Score = score, } }, }, @@ -91,18 +91,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores background.Colour = backgroundIdleColour; } - /// - /// Sets the score to be displayed. - /// - public ScoreInfo Score - { - set - { - userSection.Score = value; - statisticsSection.Score = value; - } - } - protected override bool OnHover(HoverEvent e) { background.FadeColour(backgroundHoveredColour, fade_duration, Easing.OutQuint); diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index 3e6c938802..30685fb826 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -14,6 +14,7 @@ using osuTK; using System.Collections.Generic; using System.Linq; using osu.Game.Scoring; +using osu.Game.Online.API.Requests.Responses; namespace osu.Game.Overlays.BeatmapSet.Scores { @@ -25,7 +26,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly Box background; private readonly ScoreTable scoreTable; - private readonly DrawableTopScore topScore; + private readonly FillFlowContainer topScoresContainer; private readonly LoadingAnimation loadingAnimation; [Resolved] @@ -54,7 +55,13 @@ namespace osu.Game.Overlays.BeatmapSet.Scores Margin = new MarginPadding { Vertical = spacing }, Children = new Drawable[] { - topScore = new DrawableTopScore(), + topScoresContainer = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), + }, scoreTable = new ScoreTable { Anchor = Anchor.TopCentre, @@ -97,6 +104,20 @@ namespace osu.Game.Overlays.BeatmapSet.Scores } } + private APILegacyUserTopScoreInfo userScore; + + public APILegacyUserTopScoreInfo UserScore + { + get => userScore; + set + { + getScoresRequest?.Cancel(); + userScore = value; + + updateDisplay(); + } + } + private BeatmapInfo beatmap; public BeatmapInfo Beatmap @@ -114,7 +135,12 @@ namespace osu.Game.Overlays.BeatmapSet.Scores loading = true; getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset); - getScoresRequest.Success += r => Schedule(() => Scores = r.Scores); + getScoresRequest.Success += r => Schedule(() => + { + scores = r.Scores; + userScore = r.UserScore; + updateDisplay(); + }); api.Queue(getScoresRequest); } } @@ -122,17 +148,18 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private void updateDisplay() { loading = false; + topScoresContainer.Clear(); scoreTable.Scores = scores?.Count > 1 ? scores : new List(); scoreTable.FadeTo(scores?.Count > 1 ? 1 : 0); if (scores?.Any() == true) { - topScore.Score = scores.FirstOrDefault(); - topScore.Show(); + topScoresContainer.Add(new DrawableTopScore(scores.FirstOrDefault())); + + if (userScore != null && userScore.Position != 1) + topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position)); } - else - topScore.Hide(); } protected override void Dispose(bool isDisposing) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs index 1d9c4e7fc8..1314573cb4 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs @@ -28,7 +28,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly SpriteText date; private readonly UpdateableFlag flag; - public TopScoreUserSection() + public TopScoreUserSection(int position) { AutoSizeAxes = Axes.Both; @@ -43,7 +43,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Text = "#1", + Text = position.ToString(), Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true) }, rank = new UpdateableRank(ScoreRank.D) From 59cfd39670c62df39ba8ce95f71e23c86395e7f1 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 8 Jul 2019 12:02:10 +0300 Subject: [PATCH 03/18] Add testcase --- .../Visual/Online/TestSceneScoresContainer.cs | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index 06414af865..e4e6acec06 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -10,6 +10,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.MathUtils; using osu.Game.Graphics; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays.BeatmapSet.Scores; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Mods; @@ -165,6 +166,29 @@ namespace osu.Game.Tests.Visual.Online }, }; + var myBestScore = new APILegacyUserTopScoreInfo + { + Score = new APILegacyScoreInfo + { + User = new User + { + Id = 7151382, + Username = @"Mayuri Hana", + Country = new Country + { + FullName = @"Thailand", + FlagName = @"TH", + }, + }, + Rank = ScoreRank.D, + PP = 160, + MaxCombo = 1234, + TotalScore = 123456, + Accuracy = 0.6543, + }, + Position = 1337, + }; + foreach (var s in scores) { s.Statistics.Add(HitResult.Great, RNG.Next(2000)); @@ -173,9 +197,18 @@ namespace osu.Game.Tests.Visual.Online s.Statistics.Add(HitResult.Miss, RNG.Next(2000)); } - AddStep("Load all scores", () => scoresContainer.Scores = scores); - AddStep("Load null scores", () => scoresContainer.Scores = null); + AddStep("Load all scores", () => + { + scoresContainer.Scores = scores; + scoresContainer.UserScore = myBestScore; + }); + AddStep("Load null scores", () => + { + scoresContainer.Scores = null; + scoresContainer.UserScore = null; + }); AddStep("Load only one score", () => scoresContainer.Scores = new[] { scores.First() }); + AddStep("Add my best score", () => scoresContainer.UserScore = myBestScore); } [BackgroundDependencyLoader] From 1e5639acee4858571dfe4c832354a04fef38432d Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 8 Jul 2019 12:10:08 +0300 Subject: [PATCH 04/18] Add forgotten symbol --- osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs index 1314573cb4..385d8ff38c 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs @@ -43,7 +43,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Text = position.ToString(), + Text = $"#{position.ToString()}", Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true) }, rank = new UpdateableRank(ScoreRank.D) From 5d81445454bd03c1018bce7c660e65fc931af915 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 9 Jul 2019 08:05:34 +0300 Subject: [PATCH 05/18] Move api request outside the scores container --- .../Visual/Online/TestSceneScoresContainer.cs | 243 ++++++++++-------- .../BeatmapSet/Scores/ScoresContainer.cs | 82 ++---- osu.Game/Overlays/BeatmapSetOverlay.cs | 30 ++- 3 files changed, 184 insertions(+), 171 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index e4e6acec06..730bf0d4e2 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -50,120 +50,123 @@ namespace osu.Game.Tests.Visual.Online } }; - var scores = new List + var allScores = new APILegacyScores { - new ScoreInfo + Scores = new List { - User = new User + new APILegacyScoreInfo { - Id = 6602580, - Username = @"waaiiru", - Country = new Country + User = new User { - FullName = @"Spain", - FlagName = @"ES", + Id = 6602580, + Username = @"waaiiru", + Country = new Country + { + FullName = @"Spain", + FlagName = @"ES", + }, }, - }, - Mods = new Mod[] - { - new OsuModDoubleTime(), - new OsuModHidden(), - new OsuModFlashlight(), - new OsuModHardRock(), - }, - Rank = ScoreRank.XH, - PP = 200, - MaxCombo = 1234, - TotalScore = 1234567890, - Accuracy = 1, - }, - new ScoreInfo - { - User = new User - { - Id = 4608074, - Username = @"Skycries", - Country = new Country + Mods = new Mod[] { - FullName = @"Brazil", - FlagName = @"BR", + new OsuModDoubleTime(), + new OsuModHidden(), + new OsuModFlashlight(), + new OsuModHardRock(), }, + Rank = ScoreRank.XH, + PP = 200, + MaxCombo = 1234, + TotalScore = 1234567890, + Accuracy = 1, }, - Mods = new Mod[] + new APILegacyScoreInfo { - new OsuModDoubleTime(), - new OsuModHidden(), - new OsuModFlashlight(), - }, - Rank = ScoreRank.S, - PP = 190, - MaxCombo = 1234, - TotalScore = 1234789, - Accuracy = 0.9997, - }, - new ScoreInfo - { - User = new User - { - Id = 1014222, - Username = @"eLy", - Country = new Country + User = new User { - FullName = @"Japan", - FlagName = @"JP", + Id = 4608074, + Username = @"Skycries", + Country = new Country + { + FullName = @"Brazil", + FlagName = @"BR", + }, }, - }, - Mods = new Mod[] - { - new OsuModDoubleTime(), - new OsuModHidden(), - }, - Rank = ScoreRank.B, - PP = 180, - MaxCombo = 1234, - TotalScore = 12345678, - Accuracy = 0.9854, - }, - new ScoreInfo - { - User = new User - { - Id = 1541390, - Username = @"Toukai", - Country = new Country + Mods = new Mod[] { - FullName = @"Canada", - FlagName = @"CA", + new OsuModDoubleTime(), + new OsuModHidden(), + new OsuModFlashlight(), }, + Rank = ScoreRank.S, + PP = 190, + MaxCombo = 1234, + TotalScore = 1234789, + Accuracy = 0.9997, }, - Mods = new Mod[] + new APILegacyScoreInfo { - new OsuModDoubleTime(), - }, - Rank = ScoreRank.C, - PP = 170, - MaxCombo = 1234, - TotalScore = 1234567, - Accuracy = 0.8765, - }, - new ScoreInfo - { - User = new User - { - Id = 7151382, - Username = @"Mayuri Hana", - Country = new Country + User = new User { - FullName = @"Thailand", - FlagName = @"TH", + Id = 1014222, + Username = @"eLy", + Country = new Country + { + FullName = @"Japan", + FlagName = @"JP", + }, }, + Mods = new Mod[] + { + new OsuModDoubleTime(), + new OsuModHidden(), + }, + Rank = ScoreRank.B, + PP = 180, + MaxCombo = 1234, + TotalScore = 12345678, + Accuracy = 0.9854, }, - Rank = ScoreRank.D, - PP = 160, - MaxCombo = 1234, - TotalScore = 123456, - Accuracy = 0.6543, - }, + new APILegacyScoreInfo + { + User = new User + { + Id = 1541390, + Username = @"Toukai", + Country = new Country + { + FullName = @"Canada", + FlagName = @"CA", + }, + }, + Mods = new Mod[] + { + new OsuModDoubleTime(), + }, + Rank = ScoreRank.C, + PP = 170, + MaxCombo = 1234, + TotalScore = 1234567, + Accuracy = 0.8765, + }, + new APILegacyScoreInfo + { + User = new User + { + Id = 7151382, + Username = @"Mayuri Hana", + Country = new Country + { + FullName = @"Thailand", + FlagName = @"TH", + }, + }, + Rank = ScoreRank.D, + PP = 160, + MaxCombo = 1234, + TotalScore = 123456, + Accuracy = 0.6543, + }, + } }; var myBestScore = new APILegacyUserTopScoreInfo @@ -189,7 +192,39 @@ namespace osu.Game.Tests.Visual.Online Position = 1337, }; - foreach (var s in scores) + var oneScore = new APILegacyScores + { + Scores = new List + { + new APILegacyScoreInfo + { + User = new User + { + Id = 6602580, + Username = @"waaiiru", + Country = new Country + { + FullName = @"Spain", + FlagName = @"ES", + }, + }, + Mods = new Mod[] + { + new OsuModDoubleTime(), + new OsuModHidden(), + new OsuModFlashlight(), + new OsuModHardRock(), + }, + Rank = ScoreRank.XH, + PP = 200, + MaxCombo = 1234, + TotalScore = 1234567890, + Accuracy = 1, + } + } + }; + + foreach (var s in allScores.Scores) { s.Statistics.Add(HitResult.Great, RNG.Next(2000)); s.Statistics.Add(HitResult.Good, RNG.Next(2000)); @@ -199,16 +234,16 @@ namespace osu.Game.Tests.Visual.Online AddStep("Load all scores", () => { - scoresContainer.Scores = scores; - scoresContainer.UserScore = myBestScore; + allScores.UserScore = null; + scoresContainer.Scores = allScores; }); - AddStep("Load null scores", () => + AddStep("Load null scores", () => scoresContainer.Scores = null); + AddStep("Load only one score", () => scoresContainer.Scores = oneScore); + AddStep("Load scores with my best", () => { - scoresContainer.Scores = null; - scoresContainer.UserScore = null; + allScores.UserScore = myBestScore; + scoresContainer.Scores = allScores; }); - AddStep("Load only one score", () => scoresContainer.Scores = new[] { scores.First() }); - AddStep("Add my best score", () => scoresContainer.UserScore = myBestScore); } [BackgroundDependencyLoader] diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index 30685fb826..7e0f3d0b1c 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -5,15 +5,11 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; -using osu.Game.Online.API; -using osu.Game.Online.API.Requests; using osuTK; using System.Collections.Generic; using System.Linq; -using osu.Game.Scoring; using osu.Game.Online.API.Requests.Responses; namespace osu.Game.Overlays.BeatmapSet.Scores @@ -29,9 +25,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly FillFlowContainer topScoresContainer; private readonly LoadingAnimation loadingAnimation; - [Resolved] - private IAPIProvider api { get; set; } - public ScoresContainer() { RelativeSizeAxes = Axes.X; @@ -72,7 +65,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores loadingAnimation = new LoadingAnimation { Alpha = 0, - Margin = new MarginPadding(20) + Margin = new MarginPadding(20), }, }; } @@ -84,87 +77,46 @@ namespace osu.Game.Overlays.BeatmapSet.Scores updateDisplay(); } - private bool loading + public bool Loading { - set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); + set + { + loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); + + if (value) + Scores = null; + } } - private GetScoresRequest getScoresRequest; - private IReadOnlyList scores; + private APILegacyScores scores; - public IReadOnlyList Scores + public APILegacyScores Scores { get => scores; set { - getScoresRequest?.Cancel(); scores = value; updateDisplay(); } } - private APILegacyUserTopScoreInfo userScore; - - public APILegacyUserTopScoreInfo UserScore - { - get => userScore; - set - { - getScoresRequest?.Cancel(); - userScore = 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; - userScore = r.UserScore; - updateDisplay(); - }); - api.Queue(getScoresRequest); - } - } - private void updateDisplay() { - loading = false; topScoresContainer.Clear(); - scoreTable.Scores = scores?.Count > 1 ? scores : new List(); - scoreTable.FadeTo(scores?.Count > 1 ? 1 : 0); + scoreTable.Scores = scores?.Scores.Count > 1 ? scores.Scores : new List(); + scoreTable.FadeTo(scores?.Scores.Count > 1 ? 1 : 0); - if (scores?.Any() == true) + if (scores?.Scores.Any() == true) { - topScoresContainer.Add(new DrawableTopScore(scores.FirstOrDefault())); + topScoresContainer.Add(new DrawableTopScore(scores.Scores.FirstOrDefault())); + + var userScore = scores.UserScore; if (userScore != null && userScore.Position != 1) topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position)); } } - - protected override void Dispose(bool isDisposing) - { - getScoresRequest?.Cancel(); - } } } diff --git a/osu.Game/Overlays/BeatmapSetOverlay.cs b/osu.Game/Overlays/BeatmapSetOverlay.cs index 19f6a3f692..df132f9d47 100644 --- a/osu.Game/Overlays/BeatmapSetOverlay.cs +++ b/osu.Game/Overlays/BeatmapSetOverlay.cs @@ -11,6 +11,7 @@ using osu.Framework.Input.Events; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Containers; +using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Overlays.BeatmapSet; using osu.Game.Overlays.BeatmapSet.Scores; @@ -30,9 +31,14 @@ namespace osu.Game.Overlays protected readonly Header Header; private RulesetStore rulesets; + private ScoresContainer scores; + private GetScoresRequest getScoresRequest; private readonly Bindable beatmapSet = new Bindable(); + [Resolved] + private IAPIProvider api { get; set; } + // receive input outside our bounds so we can trigger a close event on ourselves. public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true; @@ -40,7 +46,6 @@ namespace osu.Game.Overlays { OsuScrollContainer scroll; Info info; - ScoresContainer scores; Children = new Drawable[] { @@ -74,12 +79,33 @@ namespace osu.Game.Overlays Header.Picker.Beatmap.ValueChanged += b => { info.Beatmap = b.NewValue; - scores.Beatmap = b.NewValue; + getScores(b.NewValue); scroll.ScrollToStart(); }; } + private void getScores(BeatmapInfo b) + { + getScoresRequest?.Cancel(); + + if (b?.OnlineBeatmapID.HasValue != true) + { + scores.Scores = null; + return; + } + + scores.Loading = true; + + getScoresRequest = new GetScoresRequest(b, b.Ruleset); + getScoresRequest.Success += r => Schedule(() => + { + scores.Scores = r; + scores.Loading = false; + }); + api.Queue(getScoresRequest); + } + [BackgroundDependencyLoader] private void load(RulesetStore rulesets) { From 8d46d4a28e6fc0a6ba3c72df86faac97c4439dfd Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 9 Jul 2019 08:09:31 +0300 Subject: [PATCH 06/18] Fix grade layout --- .../BeatmapSet/Scores/TopScoreUserSection.cs | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs index 385d8ff38c..056fe71a39 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs @@ -39,19 +39,30 @@ namespace osu.Game.Overlays.BeatmapSet.Scores Spacing = new Vector2(10, 0), Children = new Drawable[] { - rankText = new OsuSpriteText + new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Text = $"#{position.ToString()}", - Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true) - }, - rank = new UpdateableRank(ScoreRank.D) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(40), - FillMode = FillMode.Fit, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 3), + Children = new Drawable[] + { + rankText = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = $"#{position.ToString()}", + Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true) + }, + rank = new UpdateableRank(ScoreRank.D) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(40), + FillMode = FillMode.Fit, + }, + } }, avatar = new UpdateableAvatar(hideImmediately: true) { From eb4ef8f6ac8a2c32cb53f4f1cc006e687e7252dc Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 9 Jul 2019 08:25:10 +0300 Subject: [PATCH 07/18] CI fixes --- osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs | 1 - osu.Game/Overlays/BeatmapSetOverlay.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index 730bf0d4e2..827a300a5e 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Game/Overlays/BeatmapSetOverlay.cs b/osu.Game/Overlays/BeatmapSetOverlay.cs index df132f9d47..44475dc53c 100644 --- a/osu.Game/Overlays/BeatmapSetOverlay.cs +++ b/osu.Game/Overlays/BeatmapSetOverlay.cs @@ -31,7 +31,7 @@ namespace osu.Game.Overlays protected readonly Header Header; private RulesetStore rulesets; - private ScoresContainer scores; + private readonly ScoresContainer scores; private GetScoresRequest getScoresRequest; private readonly Bindable beatmapSet = new Bindable(); From 8d6af1625abda2a84879c508419e116c57448e75 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 9 Jul 2019 11:40:51 +0300 Subject: [PATCH 08/18] Visibility improvements --- .../Visual/Online/TestSceneScoresContainer.cs | 1 + .../BeatmapSet/Scores/ScoresContainer.cs | 142 ++++++++++++++---- osu.Game/Overlays/BeatmapSetOverlay.cs | 6 +- 3 files changed, 118 insertions(+), 31 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index 827a300a5e..c414b6b940 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -243,6 +243,7 @@ namespace osu.Game.Tests.Visual.Online allScores.UserScore = myBestScore; scoresContainer.Scores = allScores; }); + AddStep("Trigger loading", () => scoresContainer.Loading = !scoresContainer.Loading); } [BackgroundDependencyLoader] diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index 7e0f3d0b1c..eacbe6200a 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -17,13 +17,14 @@ namespace osu.Game.Overlays.BeatmapSet.Scores public class ScoresContainer : CompositeDrawable { private const int spacing = 15; - private const int fade_duration = 200; + private const int padding = 20; private readonly Box background; private readonly ScoreTable scoreTable; private readonly FillFlowContainer topScoresContainer; - private readonly LoadingAnimation loadingAnimation; + private readonly ContentContainer resizableContainer; + private readonly LoadingContainer loadingContainer; public ScoresContainer() { @@ -38,53 +39,85 @@ namespace osu.Game.Overlays.BeatmapSet.Scores }, new FillFlowContainer { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Width = 0.95f, Direction = FillDirection.Vertical, - Spacing = new Vector2(0, spacing), - Margin = new MarginPadding { Vertical = spacing }, + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, Children = new Drawable[] { - topScoresContainer = new FillFlowContainer + loadingContainer = new LoadingContainer { RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 5), + Masking = true, }, - scoreTable = new ScoreTable + resizableContainer = new ContentContainer { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - } + RelativeSizeAxes = Axes.X, + Masking = true, + Children = new Drawable[] + { + new FillFlowContainer + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Width = 0.95f, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, spacing), + Padding = new MarginPadding { Vertical = padding }, + Children = new Drawable[] + { + topScoresContainer = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), + }, + scoreTable = new ScoreTable + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + } + } + }, + } + }, } - }, - loadingAnimation = new LoadingAnimation - { - Alpha = 0, - Margin = new MarginPadding(20), - }, + } }; + + Loading = true; } [BackgroundDependencyLoader] private void load(OsuColour colours) { background.Colour = colours.Gray2; - updateDisplay(); } + private bool loading; + public bool Loading { + get => loading; set { - loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); + if (loading == value) + return; + + loading = value; if (value) - Scores = null; + { + loadingContainer.Show(); + resizableContainer.Hide(); + } + else + { + loadingContainer.Hide(); + resizableContainer.Show(); + } } } @@ -117,6 +150,63 @@ namespace osu.Game.Overlays.BeatmapSet.Scores if (userScore != null && userScore.Position != 1) topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position)); } + + Loading = false; + } + + private class ContentContainer : VisibilityContainer + { + private const int duration = 300; + + private float maxHeight; + + protected override void PopIn() => this.ResizeHeightTo(maxHeight, duration, Easing.OutQuint); + + protected override void PopOut() => this.ResizeHeightTo(0, duration, Easing.OutQuint); + + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + if (State.Value == Visibility.Hidden) + return; + + float height = 0; + + foreach (var c in Children) + { + height += c.Height; + } + + maxHeight = height; + + this.ResizeHeightTo(maxHeight, duration, Easing.OutQuint); + } + } + + private class LoadingContainer : VisibilityContainer + { + private const int duration = 300; + private const int height = 50; + + private readonly LoadingAnimation loadingAnimation; + + public LoadingContainer() + { + Child = loadingAnimation = new LoadingAnimation(); + } + + protected override void PopIn() + { + this.ResizeHeightTo(height, duration, Easing.OutQuint); + loadingAnimation.Show(); + } + + protected override void PopOut() + { + this.ResizeHeightTo(0, duration, Easing.OutQuint); + loadingAnimation.Hide(); + } } } } diff --git a/osu.Game/Overlays/BeatmapSetOverlay.cs b/osu.Game/Overlays/BeatmapSetOverlay.cs index 44475dc53c..1c408ead54 100644 --- a/osu.Game/Overlays/BeatmapSetOverlay.cs +++ b/osu.Game/Overlays/BeatmapSetOverlay.cs @@ -98,11 +98,7 @@ namespace osu.Game.Overlays scores.Loading = true; getScoresRequest = new GetScoresRequest(b, b.Ruleset); - getScoresRequest.Success += r => Schedule(() => - { - scores.Scores = r; - scores.Loading = false; - }); + getScoresRequest.Success += r => Schedule(() => scores.Scores = r); api.Queue(getScoresRequest); } From e8b9b1b0bfe52812948b27b6fbaf834699f27ef3 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 9 Jul 2019 12:16:58 +0300 Subject: [PATCH 09/18] visibility logic adjustments --- .../Visual/Online/TestSceneScoresContainer.cs | 15 ++--- .../BeatmapSet/Scores/ScoresContainer.cs | 67 ++++++++----------- 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index c414b6b940..10207ea192 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -3,12 +3,10 @@ using System; using System.Collections.Generic; -using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.MathUtils; -using osu.Game.Graphics; using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays.BeatmapSet.Scores; using osu.Game.Rulesets.Mods; @@ -16,6 +14,7 @@ using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; using osu.Game.Users; +using osuTK.Graphics; namespace osu.Game.Tests.Visual.Online { @@ -44,7 +43,11 @@ namespace osu.Game.Tests.Visual.Online Width = 0.8f, Children = new Drawable[] { - background = new Box { RelativeSizeAxes = Axes.Both }, + background = new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + }, scoresContainer = new ScoresContainer(), } }; @@ -245,11 +248,5 @@ namespace osu.Game.Tests.Visual.Online }); AddStep("Trigger loading", () => scoresContainer.Loading = !scoresContainer.Loading); } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - background.Colour = colours.Gray2; - } } } diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index eacbe6200a..63e18f3da7 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -23,7 +23,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly ScoreTable scoreTable; private readonly FillFlowContainer topScoresContainer; - private readonly ContentContainer resizableContainer; + private readonly ContentContainer contentContainer; private readonly LoadingContainer loadingContainer; public ScoresContainer() @@ -49,36 +49,33 @@ namespace osu.Game.Overlays.BeatmapSet.Scores RelativeSizeAxes = Axes.X, Masking = true, }, - resizableContainer = new ContentContainer + contentContainer = new ContentContainer { RelativeSizeAxes = Axes.X, Masking = true, - Children = new Drawable[] + Child = new FillFlowContainer { - new FillFlowContainer + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Width = 0.95f, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, spacing), + Padding = new MarginPadding { Vertical = padding }, + Children = new Drawable[] { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Width = 0.95f, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, spacing), - Padding = new MarginPadding { Vertical = padding }, - Children = new Drawable[] + topScoresContainer = new FillFlowContainer { - topScoresContainer = new FillFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 5), - }, - scoreTable = new ScoreTable - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - } + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), + }, + scoreTable = new ScoreTable + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, } }, } @@ -103,20 +100,21 @@ namespace osu.Game.Overlays.BeatmapSet.Scores get => loading; set { - if (loading == value) - return; - loading = value; if (value) { loadingContainer.Show(); - resizableContainer.Hide(); + contentContainer.Hide(); } else { loadingContainer.Hide(); - resizableContainer.Show(); + + if (scores == null || scores?.Scores.Count < 1) + contentContainer.Hide(); + else + contentContainer.Show(); } } } @@ -171,14 +169,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores if (State.Value == Visibility.Hidden) return; - float height = 0; - - foreach (var c in Children) - { - height += c.Height; - } - - maxHeight = height; + maxHeight = Child.DrawHeight; this.ResizeHeightTo(maxHeight, duration, Easing.OutQuint); } From 276873ff8ada90e18a9fde2b8f6e2641828c2e17 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 9 Jul 2019 12:28:59 +0300 Subject: [PATCH 10/18] remove unused field --- osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index 10207ea192..4ce689ce6b 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -29,8 +29,6 @@ namespace osu.Game.Tests.Visual.Online typeof(ScoreTableRowBackground), }; - private readonly Box background; - public TestSceneScoresContainer() { ScoresContainer scoresContainer; @@ -43,7 +41,7 @@ namespace osu.Game.Tests.Visual.Online Width = 0.8f, Children = new Drawable[] { - background = new Box + new Box { RelativeSizeAxes = Axes.Both, Colour = Color4.Black, From 9907a58ec4aaf3427769b2044248d060f3a0563b Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 9 Jul 2019 17:38:17 +0300 Subject: [PATCH 11/18] Revert animations and apply suggested changes --- .../Visual/Online/TestSceneScoresContainer.cs | 1 - .../BeatmapSet/Scores/DrawableTopScore.cs | 3 +- .../BeatmapSet/Scores/ScoresContainer.cs | 137 ++++-------------- .../BeatmapSet/Scores/TopScoreUserSection.cs | 9 +- osu.Game/Overlays/BeatmapSetOverlay.cs | 14 +- 5 files changed, 45 insertions(+), 119 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index 4ce689ce6b..824280fe68 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -244,7 +244,6 @@ namespace osu.Game.Tests.Visual.Online allScores.UserScore = myBestScore; scoresContainer.Scores = allScores; }); - AddStep("Trigger loading", () => scoresContainer.Loading = !scoresContainer.Loading); } } } diff --git a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs index bdae730f7e..d263483046 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs @@ -59,11 +59,12 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { new Drawable[] { - new TopScoreUserSection(position) + new TopScoreUserSection { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Score = score, + ScorePosition = position, }, null, new TopScoreStatisticsSection diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index 63e18f3da7..94bcfdee4f 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -17,20 +17,17 @@ namespace osu.Game.Overlays.BeatmapSet.Scores public class ScoresContainer : CompositeDrawable { private const int spacing = 15; - private const int padding = 20; + private const int fade_duration = 200; private readonly Box background; private readonly ScoreTable scoreTable; - private readonly FillFlowContainer topScoresContainer; - private readonly ContentContainer contentContainer; - private readonly LoadingContainer loadingContainer; + private readonly LoadingAnimation loadingAnimation; public ScoresContainer() { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - InternalChildren = new Drawable[] { background = new Box @@ -39,83 +36,53 @@ namespace osu.Game.Overlays.BeatmapSet.Scores }, new FillFlowContainer { - Direction = FillDirection.Vertical, - AutoSizeAxes = Axes.Y, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Width = 0.95f, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, spacing), + Margin = new MarginPadding { Vertical = spacing }, Children = new Drawable[] { - loadingContainer = new LoadingContainer + topScoresContainer = new FillFlowContainer { RelativeSizeAxes = Axes.X, - Masking = true, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), }, - contentContainer = new ContentContainer + scoreTable = new ScoreTable { - RelativeSizeAxes = Axes.X, - Masking = true, - Child = new FillFlowContainer - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Width = 0.95f, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, spacing), - Padding = new MarginPadding { Vertical = padding }, - Children = new Drawable[] - { - topScoresContainer = new FillFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 5), - }, - scoreTable = new ScoreTable - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - } - }, - } - }, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + } } - } + }, + loadingAnimation = new LoadingAnimation + { + Alpha = 0, + Margin = new MarginPadding(20), + }, }; - - Loading = true; } [BackgroundDependencyLoader] private void load(OsuColour colours) { background.Colour = colours.Gray2; + updateDisplay(); } - private bool loading; - public bool Loading { - get => loading; set { - loading = value; + loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); if (value) - { - loadingContainer.Show(); - contentContainer.Hide(); - } - else - { - loadingContainer.Hide(); - - if (scores == null || scores?.Scores.Count < 1) - contentContainer.Hide(); - else - contentContainer.Show(); - } + Scores = null; } } @@ -139,7 +106,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores scoreTable.Scores = scores?.Scores.Count > 1 ? scores.Scores : new List(); scoreTable.FadeTo(scores?.Scores.Count > 1 ? 1 : 0); - if (scores?.Scores.Any() == true) + if (scores?.Scores.Any() ?? false) { topScoresContainer.Add(new DrawableTopScore(scores.Scores.FirstOrDefault())); @@ -148,56 +115,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores if (userScore != null && userScore.Position != 1) topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position)); } - - Loading = false; - } - - private class ContentContainer : VisibilityContainer - { - private const int duration = 300; - - private float maxHeight; - - protected override void PopIn() => this.ResizeHeightTo(maxHeight, duration, Easing.OutQuint); - - protected override void PopOut() => this.ResizeHeightTo(0, duration, Easing.OutQuint); - - protected override void UpdateAfterChildren() - { - base.UpdateAfterChildren(); - - if (State.Value == Visibility.Hidden) - return; - - maxHeight = Child.DrawHeight; - - this.ResizeHeightTo(maxHeight, duration, Easing.OutQuint); - } - } - - private class LoadingContainer : VisibilityContainer - { - private const int duration = 300; - private const int height = 50; - - private readonly LoadingAnimation loadingAnimation; - - public LoadingContainer() - { - Child = loadingAnimation = new LoadingAnimation(); - } - - protected override void PopIn() - { - this.ResizeHeightTo(height, duration, Easing.OutQuint); - loadingAnimation.Show(); - } - - protected override void PopOut() - { - this.ResizeHeightTo(0, duration, Easing.OutQuint); - loadingAnimation.Hide(); - } } } } diff --git a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs index 056fe71a39..36e60b3fd9 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs @@ -28,7 +28,12 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly SpriteText date; private readonly UpdateableFlag flag; - public TopScoreUserSection(int position) + public int ScorePosition + { + set => rankText.Text = $"#{value}"; + } + + public TopScoreUserSection() { AutoSizeAxes = Axes.Both; @@ -52,7 +57,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Text = $"#{position.ToString()}", + Text = $"#1", Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true) }, rank = new UpdateableRank(ScoreRank.D) diff --git a/osu.Game/Overlays/BeatmapSetOverlay.cs b/osu.Game/Overlays/BeatmapSetOverlay.cs index 1c408ead54..abd86df920 100644 --- a/osu.Game/Overlays/BeatmapSetOverlay.cs +++ b/osu.Game/Overlays/BeatmapSetOverlay.cs @@ -17,17 +17,14 @@ using osu.Game.Overlays.BeatmapSet; using osu.Game.Overlays.BeatmapSet.Scores; using osu.Game.Rulesets; using osuTK; - namespace osu.Game.Overlays { public class BeatmapSetOverlay : FullscreenOverlay { private const int fade_duration = 300; - public const float X_PADDING = 40; public const float TOP_PADDING = 25; public const float RIGHT_WIDTH = 275; - protected readonly Header Header; private RulesetStore rulesets; @@ -46,7 +43,6 @@ namespace osu.Game.Overlays { OsuScrollContainer scroll; Info info; - Children = new Drawable[] { new Box @@ -98,7 +94,11 @@ namespace osu.Game.Overlays scores.Loading = true; getScoresRequest = new GetScoresRequest(b, b.Ruleset); - getScoresRequest.Success += r => Schedule(() => scores.Scores = r); + getScoresRequest.Success += r => Schedule(() => + { + scores.Scores = r; + scores.Loading = false; + }); api.Queue(getScoresRequest); } @@ -123,6 +123,7 @@ namespace osu.Game.Overlays public void FetchAndShowBeatmap(int beatmapId) { beatmapSet.Value = null; + var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId); req.Success += res => { @@ -130,15 +131,18 @@ namespace osu.Game.Overlays Header.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId); }; API.Queue(req); + Show(); } public void FetchAndShowBeatmapSet(int beatmapSetId) { beatmapSet.Value = null; + var req = new GetBeatmapSetRequest(beatmapSetId); req.Success += res => beatmapSet.Value = res.ToBeatmapSet(rulesets); API.Queue(req); + Show(); } From a0389c338ba2d89e6c07579b397e101d6c4e1c1d Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 9 Jul 2019 17:56:08 +0300 Subject: [PATCH 12/18] CI fixes --- osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs | 1 - osu.Game/Overlays/BeatmapSetOverlay.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs index 36e60b3fd9..6d43ec6177 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs @@ -57,7 +57,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Text = $"#1", Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true) }, rank = new UpdateableRank(ScoreRank.D) diff --git a/osu.Game/Overlays/BeatmapSetOverlay.cs b/osu.Game/Overlays/BeatmapSetOverlay.cs index abd86df920..3a17b6eec1 100644 --- a/osu.Game/Overlays/BeatmapSetOverlay.cs +++ b/osu.Game/Overlays/BeatmapSetOverlay.cs @@ -17,11 +17,11 @@ using osu.Game.Overlays.BeatmapSet; using osu.Game.Overlays.BeatmapSet.Scores; using osu.Game.Rulesets; using osuTK; + namespace osu.Game.Overlays { public class BeatmapSetOverlay : FullscreenOverlay { - private const int fade_duration = 300; public const float X_PADDING = 40; public const float TOP_PADDING = 25; public const float RIGHT_WIDTH = 275; From f21e700b7af378f7196732cf1a725137433de8fc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 00:42:14 +0900 Subject: [PATCH 13/18] Code style cleanup --- osu.Game/Overlays/BeatmapSetOverlay.cs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSetOverlay.cs b/osu.Game/Overlays/BeatmapSetOverlay.cs index 3a17b6eec1..154e6f20f6 100644 --- a/osu.Game/Overlays/BeatmapSetOverlay.cs +++ b/osu.Game/Overlays/BeatmapSetOverlay.cs @@ -28,7 +28,9 @@ namespace osu.Game.Overlays protected readonly Header Header; private RulesetStore rulesets; - private readonly ScoresContainer scores; + + private readonly ScoresContainer scoreContainer; + private GetScoresRequest getScoresRequest; private readonly Bindable beatmapSet = new Bindable(); @@ -63,7 +65,7 @@ namespace osu.Game.Overlays { Header = new Header(), info = new Info(), - scores = new ScoresContainer(), + scoreContainer = new ScoresContainer(), }, }, }, @@ -81,23 +83,24 @@ namespace osu.Game.Overlays }; } - private void getScores(BeatmapInfo b) + private void getScores(BeatmapInfo beatmap) { getScoresRequest?.Cancel(); + getScoresRequest = null; - if (b?.OnlineBeatmapID.HasValue != true) + if (beatmap?.OnlineBeatmapID.HasValue != true) { - scores.Scores = null; + scoreContainer.Scores = null; return; } - scores.Loading = true; + scoreContainer.Loading = true; - getScoresRequest = new GetScoresRequest(b, b.Ruleset); - getScoresRequest.Success += r => Schedule(() => + getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset); + getScoresRequest.Success += scores => Schedule(() => { - scores.Scores = r; - scores.Loading = false; + scoreContainer.Scores = scores; + scoreContainer.Loading = false; }); api.Queue(getScoresRequest); } From 953d32366c8f067fe11f41825d64268e18889ed4 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 10 Jul 2019 19:40:29 +0300 Subject: [PATCH 14/18] Move request inside the ScoresContainer again --- .../Visual/Online/TestSceneScoresContainer.cs | 12 +++- .../BeatmapSet/Scores/ScoresContainer.cs | 64 ++++++++++++++++--- osu.Game/Overlays/BeatmapSetOverlay.cs | 34 +--------- 3 files changed, 68 insertions(+), 42 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs index 824280fe68..b26de1984a 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs @@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.Online public TestSceneScoresContainer() { - ScoresContainer scoresContainer; + TestScoresContainer scoresContainer; Child = new Container { @@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.Online RelativeSizeAxes = Axes.Both, Colour = Color4.Black, }, - scoresContainer = new ScoresContainer(), + scoresContainer = new TestScoresContainer(), } }; @@ -245,5 +245,13 @@ namespace osu.Game.Tests.Visual.Online scoresContainer.Scores = allScores; }); } + + private class TestScoresContainer : ScoresContainer + { + public new APILegacyScores Scores + { + set => base.Scores = value; + } + } } } diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index 94bcfdee4f..bcb9383d0b 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -11,6 +11,9 @@ using osuTK; using System.Collections.Generic; using System.Linq; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Beatmaps; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; namespace osu.Game.Overlays.BeatmapSet.Scores { @@ -24,6 +27,40 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly FillFlowContainer topScoresContainer; private readonly LoadingAnimation loadingAnimation; + [Resolved] + private IAPIProvider api { get; set; } + + private GetScoresRequest getScoresRequest; + + private APILegacyScores scores; + + protected APILegacyScores Scores + { + get => scores; + set + { + scores = value; + + updateDisplay(); + } + } + + private BeatmapInfo beatmap; + + public BeatmapInfo Beatmap + { + get => beatmap; + set + { + if (beatmap == value) + return; + + beatmap = value; + + getScores(beatmap); + } + } + public ScoresContainer() { RelativeSizeAxes = Axes.X; @@ -75,7 +112,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores updateDisplay(); } - public bool Loading + private bool loading { set { @@ -86,17 +123,26 @@ namespace osu.Game.Overlays.BeatmapSet.Scores } } - private APILegacyScores scores; - - public APILegacyScores Scores + private void getScores(BeatmapInfo beatmap) { - get => scores; - set - { - scores = value; + getScoresRequest?.Cancel(); + getScoresRequest = null; - updateDisplay(); + if (beatmap?.OnlineBeatmapID.HasValue != true) + { + Scores = null; + return; } + + loading = true; + + getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset); + getScoresRequest.Success += scores => Schedule(() => + { + Scores = scores; + loading = false; + }); + api.Queue(getScoresRequest); } private void updateDisplay() diff --git a/osu.Game/Overlays/BeatmapSetOverlay.cs b/osu.Game/Overlays/BeatmapSetOverlay.cs index 154e6f20f6..c20e6368d8 100644 --- a/osu.Game/Overlays/BeatmapSetOverlay.cs +++ b/osu.Game/Overlays/BeatmapSetOverlay.cs @@ -11,7 +11,6 @@ using osu.Framework.Input.Events; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Containers; -using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Overlays.BeatmapSet; using osu.Game.Overlays.BeatmapSet.Scores; @@ -29,15 +28,8 @@ namespace osu.Game.Overlays private RulesetStore rulesets; - private readonly ScoresContainer scoreContainer; - - private GetScoresRequest getScoresRequest; - private readonly Bindable beatmapSet = new Bindable(); - [Resolved] - private IAPIProvider api { get; set; } - // receive input outside our bounds so we can trigger a close event on ourselves. public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true; @@ -45,6 +37,8 @@ namespace osu.Game.Overlays { OsuScrollContainer scroll; Info info; + ScoresContainer scoreContainer; + Children = new Drawable[] { new Box @@ -77,34 +71,12 @@ namespace osu.Game.Overlays Header.Picker.Beatmap.ValueChanged += b => { info.Beatmap = b.NewValue; - getScores(b.NewValue); + scoreContainer.Beatmap = b.NewValue; scroll.ScrollToStart(); }; } - private void getScores(BeatmapInfo beatmap) - { - getScoresRequest?.Cancel(); - getScoresRequest = null; - - if (beatmap?.OnlineBeatmapID.HasValue != true) - { - scoreContainer.Scores = null; - return; - } - - scoreContainer.Loading = true; - - getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset); - getScoresRequest.Success += scores => Schedule(() => - { - scoreContainer.Scores = scores; - scoreContainer.Loading = false; - }); - api.Queue(getScoresRequest); - } - [BackgroundDependencyLoader] private void load(RulesetStore rulesets) { From a49bde7ed3369a734f27957b3a08e4456cbc8f90 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 10:38:32 +0900 Subject: [PATCH 15/18] Move protected below public --- .../BeatmapSet/Scores/ScoresContainer.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index bcb9383d0b..dfe6c45750 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -32,19 +32,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private GetScoresRequest getScoresRequest; - private APILegacyScores scores; - - protected APILegacyScores Scores - { - get => scores; - set - { - scores = value; - - updateDisplay(); - } - } - private BeatmapInfo beatmap; public BeatmapInfo Beatmap @@ -61,6 +48,19 @@ namespace osu.Game.Overlays.BeatmapSet.Scores } } + private APILegacyScores scores; + + protected APILegacyScores Scores + { + get => scores; + set + { + scores = value; + + updateDisplay(); + } + } + public ScoresContainer() { RelativeSizeAxes = Axes.X; From cc9ee472d6090584587c56098c92bee6f5e34d30 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 11:07:30 +0900 Subject: [PATCH 16/18] Move score nulling out of loading property --- .../Overlays/BeatmapSet/Scores/ScoresContainer.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index dfe6c45750..5f200d7343 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -114,13 +114,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private bool loading { - set - { - loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); - - if (value) - Scores = null; - } + set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); } private void getScores(BeatmapInfo beatmap) @@ -128,11 +122,10 @@ namespace osu.Game.Overlays.BeatmapSet.Scores getScoresRequest?.Cancel(); getScoresRequest = null; + Scores = null; + if (beatmap?.OnlineBeatmapID.HasValue != true) - { - Scores = null; return; - } loading = true; From 8f9b8ed5a19d121977a08c16b308dc734ef2d3a8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 11:17:33 +0900 Subject: [PATCH 17/18] Simplify information propagation logic --- .../Overlays/BeatmapSet/Scores/ScoreTable.cs | 2 +- .../BeatmapSet/Scores/ScoresContainer.cs | 60 +++++++++---------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs index 15816be327..347522fb48 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs @@ -59,7 +59,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores Content = null; backgroundFlow.Clear(); - if (value == null || !value.Any()) + if (value?.Any() != true) return; for (int i = 0; i < value.Count; i++) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index 5f200d7343..22d7ea9c97 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; using osuTK; -using System.Collections.Generic; using System.Linq; using osu.Game.Online.API.Requests.Responses; using osu.Game.Beatmaps; @@ -48,16 +47,34 @@ namespace osu.Game.Overlays.BeatmapSet.Scores } } - private APILegacyScores scores; - protected APILegacyScores Scores { - get => scores; set { - scores = value; + Schedule(() => + { + loading = false; - updateDisplay(); + topScoresContainer.Clear(); + + if (value?.Scores.Any() != true) + { + scoreTable.Scores = null; + scoreTable.Hide(); + return; + } + + scoreTable.Scores = value.Scores; + scoreTable.Show(); + + var topScore = value.Scores.First(); + var userScore = value.UserScore; + + topScoresContainer.Add(new DrawableTopScore(topScore)); + + if (userScore != null && userScore.Score.OnlineScoreID != topScore.OnlineScoreID) + topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position)); + }); } } @@ -109,7 +126,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private void load(OsuColour colours) { background.Colour = colours.Gray2; - updateDisplay(); } private bool loading @@ -125,35 +141,15 @@ namespace osu.Game.Overlays.BeatmapSet.Scores Scores = null; if (beatmap?.OnlineBeatmapID.HasValue != true) + { + loading = false; return; - - loading = true; + } getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset); - getScoresRequest.Success += scores => Schedule(() => - { - Scores = scores; - loading = false; - }); + getScoresRequest.Success += scores => Scores = scores; api.Queue(getScoresRequest); - } - - private void updateDisplay() - { - topScoresContainer.Clear(); - - scoreTable.Scores = scores?.Scores.Count > 1 ? scores.Scores : new List(); - scoreTable.FadeTo(scores?.Scores.Count > 1 ? 1 : 0); - - if (scores?.Scores.Any() ?? false) - { - topScoresContainer.Add(new DrawableTopScore(scores.Scores.FirstOrDefault())); - - var userScore = scores.UserScore; - - if (userScore != null && userScore.Position != 1) - topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position)); - } + loading = true; } } } From 85f2212ebcb8d3612e41304f49d4caf0289374ec Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 11:32:42 +0900 Subject: [PATCH 18/18] Reduce spacing and font for rank position --- .../BeatmapSet/Scores/TopScoreUserSection.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs index 6d43ec6177..a15d3c5fd1 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs @@ -28,11 +28,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly SpriteText date; private readonly UpdateableFlag flag; - public int ScorePosition - { - set => rankText.Text = $"#{value}"; - } - public TopScoreUserSection() { AutoSizeAxes = Axes.Both; @@ -50,14 +45,13 @@ namespace osu.Game.Overlays.BeatmapSet.Scores Origin = Anchor.Centre, AutoSizeAxes = Axes.Both, Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 3), Children = new Drawable[] { rankText = new OsuSpriteText { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true) + Font = OsuFont.GetFont(size: 24, weight: FontWeight.Bold, italics: true) }, rank = new UpdateableRank(ScoreRank.D) { @@ -124,6 +118,11 @@ namespace osu.Game.Overlays.BeatmapSet.Scores rankText.Colour = colours.Yellow; } + public int ScorePosition + { + set => rankText.Text = $"#{value}"; + } + /// /// Sets the score to be displayed. ///