From ad077042ba61a9e4fa297e0c9f5e971f3047008c Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Sun, 15 Dec 2019 02:18:12 -0800 Subject: [PATCH 01/27] Created ContextMenu for scores by adding OsuContextMenuContainer as a child of LeaderboardScore and a Drawable that extended the IHasContextMenu interface to the MenuContainer. Tried to the LeaderboardScore extend IHASContextMenu itself, but it is not working yet. --- .../Online/Leaderboards/LeaderboardScore.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index 6ac5219282..c4bc306f05 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -11,10 +11,13 @@ using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Game.Graphics; +using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets.UI; using osu.Game.Scoring; using osu.Game.Users.Drawables; @@ -227,9 +230,28 @@ namespace osu.Game.Online.Leaderboards }, }; + Add( + new OsuContextMenuContainer + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] { + new ContextMenuArea{ + RelativeSizeAxes = Axes.Both + } + } + } + ); + innerAvatar.OnLoadComplete += d => d.FadeInFromZero(200); } + private class ContextMenuArea : Drawable, IHasContextMenu + { + public MenuItem[] ContextMenuItems => new MenuItem[] + { + new OsuMenuItem("Delete", MenuItemType.Destructive), + }; + } public override void Show() { foreach (var d in new[] { avatar, nameLabel, scoreLabel, scoreRank, flagBadgeContainer, modsContainer }.Concat(statisticsLabels)) From bef9637fdf8806f302185fbbc3545c7b85cf0936 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Mon, 16 Dec 2019 19:25:28 -0800 Subject: [PATCH 02/27] Implemented delete local score individually. Currently does not refresh the score screen after the delete is compelete. --- osu.Game/Online/Leaderboards/Leaderboard.cs | 9 +++-- .../Online/Leaderboards/LeaderboardScore.cs | 34 +++++++------------ .../Select/BeatmapClearScoresDialog.cs | 26 ++++++++++++++ .../Select/Leaderboards/BeatmapLeaderboard.cs | 12 ++++--- 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/osu.Game/Online/Leaderboards/Leaderboard.cs b/osu.Game/Online/Leaderboards/Leaderboard.cs index 94c50185da..0e2864e88c 100644 --- a/osu.Game/Online/Leaderboards/Leaderboard.cs +++ b/osu.Game/Online/Leaderboards/Leaderboard.cs @@ -12,6 +12,7 @@ using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Threading; using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Cursor; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osuTK; @@ -180,10 +181,14 @@ namespace osu.Game.Online.Leaderboards { new Drawable[] { - scrollContainer = new OsuScrollContainer + new OsuContextMenuContainer { RelativeSizeAxes = Axes.Both, - ScrollbarVisible = false, + Child = scrollContainer = new OsuScrollContainer + { + RelativeSizeAxes = Axes.Both, + ScrollbarVisible = false, + } } }, new Drawable[] diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index c4bc306f05..3e5096b051 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -14,11 +14,12 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Game.Graphics; -using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays; using osu.Game.Rulesets.UI; +using osu.Game.Screens.Select; using osu.Game.Scoring; using osu.Game.Users.Drawables; using osuTK; @@ -28,7 +29,7 @@ using osu.Game.Online.API; namespace osu.Game.Online.Leaderboards { - public class LeaderboardScore : OsuClickableContainer + public class LeaderboardScore : OsuClickableContainer, IHasContextMenu { public const float HEIGHT = 60; @@ -53,6 +54,8 @@ namespace osu.Game.Online.Leaderboards private FillFlowContainer modsContainer; private List statisticsLabels; + + private DialogOverlay dialogOverlay; public LeaderboardScore(ScoreInfo score, int rank, bool allowHighlight = true) { @@ -65,9 +68,10 @@ namespace osu.Game.Online.Leaderboards } [BackgroundDependencyLoader] - private void load(IAPIProvider api, OsuColour colour) + private void load(IAPIProvider api, OsuColour colour, DialogOverlay overlay) { var user = score.User; + dialogOverlay = overlay; statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList(); @@ -230,28 +234,9 @@ namespace osu.Game.Online.Leaderboards }, }; - Add( - new OsuContextMenuContainer - { - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] { - new ContextMenuArea{ - RelativeSizeAxes = Axes.Both - } - } - } - ); - innerAvatar.OnLoadComplete += d => d.FadeInFromZero(200); } - private class ContextMenuArea : Drawable, IHasContextMenu - { - public MenuItem[] ContextMenuItems => new MenuItem[] - { - new OsuMenuItem("Delete", MenuItemType.Destructive), - }; - } public override void Show() { foreach (var d in new[] { avatar, nameLabel, scoreLabel, scoreRank, flagBadgeContainer, modsContainer }.Concat(statisticsLabels)) @@ -381,5 +366,10 @@ namespace osu.Game.Online.Leaderboards Value = value; } } + + public MenuItem[] ContextMenuItems => new MenuItem[] + { + new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new BeatmapClearScoresDialog(this.score, null))) + }; } } diff --git a/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs b/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs index c9b6ca7bb3..b4889bfffc 100644 --- a/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs +++ b/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs @@ -39,6 +39,32 @@ namespace osu.Game.Screens.Select }; } + public BeatmapClearScoresDialog(ScoreInfo score, Action onCompletion) + { + string accuracy = string.Format(score?.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score?.Accuracy); + + BodyText = $@"{score?.Beatmap?.Metadata?.Artist} - {score?.Beatmap?.Metadata?.Title} {Environment.NewLine} {score?.User} - Rank: {score?.Rank} - Max Combo: {score?.MaxCombo} - {accuracy} - {score?.Date.Date.ToShortDateString()}"; + + Icon = FontAwesome.Solid.Eraser; + HeaderText = @"Clearing this local score. Are you sure?"; + Buttons = new PopupDialogButton[] + { + new PopupDialogOkButton + { + Text = @"Yes. Please.", + Action = () => + { + Task.Run(() => scoreManager.Delete(score)) + .ContinueWith(_ => onCompletion); + } + }, + new PopupDialogCancelButton + { + Text = @"No, I'm still attached.", + }, + }; + } + [BackgroundDependencyLoader] private void load(ScoreManager scoreManager) { diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index 1b45a9d270..d609ee3bdc 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -182,9 +182,13 @@ namespace osu.Game.Screens.Select.Leaderboards return req; } - protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) => new LeaderboardScore(model, index, IsOnlineScope) - { - Action = () => ScoreSelected?.Invoke(model) - }; + protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index){ + model.Beatmap = beatmap; + + return new LeaderboardScore(model, index, IsOnlineScope) + { + Action = () => ScoreSelected?.Invoke(model) + }; + } } } From 8aeef3f59a59747e42bc898cb155048204143ff0 Mon Sep 17 00:00:00 2001 From: wltu Date: Tue, 17 Dec 2019 12:56:30 -0800 Subject: [PATCH 03/27] Added refresh scoreboard upon deleting local score and formatted the code --- .../Online/Leaderboards/LeaderboardScore.cs | 17 +++++++++++++---- .../Screens/Select/BeatmapClearScoresDialog.cs | 6 +----- .../Select/Leaderboards/BeatmapLeaderboard.cs | 10 +++++++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index 3e5096b051..ccac748535 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -1,6 +1,7 @@ // 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 System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; @@ -54,9 +55,11 @@ namespace osu.Game.Online.Leaderboards private FillFlowContainer modsContainer; private List statisticsLabels; - + private DialogOverlay dialogOverlay; + public Action RefreshAction { get; set; } + public LeaderboardScore(ScoreInfo score, int rank, bool allowHighlight = true) { this.score = score; @@ -367,9 +370,15 @@ namespace osu.Game.Online.Leaderboards } } - public MenuItem[] ContextMenuItems => new MenuItem[] + public MenuItem[] ContextMenuItems { - new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new BeatmapClearScoresDialog(this.score, null))) - }; + get + { + return (this.allowHighlight) ? null : new MenuItem[] + { + new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new BeatmapClearScoresDialog(this.score, () => Schedule(this.RefreshAction)))) + }; + } + } } } diff --git a/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs b/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs index b4889bfffc..2c5427993b 100644 --- a/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs +++ b/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs @@ -52,11 +52,7 @@ namespace osu.Game.Screens.Select new PopupDialogOkButton { Text = @"Yes. Please.", - Action = () => - { - Task.Run(() => scoreManager.Delete(score)) - .ContinueWith(_ => onCompletion); - } + Action = (() => scoreManager.Delete(score)) + onCompletion }, new PopupDialogCancelButton { diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index d609ee3bdc..ee360d1e57 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -15,6 +15,8 @@ using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Scoring; +using osu.Framework.Graphics.UserInterface; + namespace osu.Game.Screens.Select.Leaderboards { public class BeatmapLeaderboard : Leaderboard @@ -182,12 +184,14 @@ namespace osu.Game.Screens.Select.Leaderboards return req; } - protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index){ + protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) + { model.Beatmap = beatmap; - + return new LeaderboardScore(model, index, IsOnlineScope) { - Action = () => ScoreSelected?.Invoke(model) + Action = () => ScoreSelected?.Invoke(model), + RefreshAction = () => this.RefreshScores() }; } } From 4646524bf9ff4a3f3923f3a77af9a9fb5f0b08d6 Mon Sep 17 00:00:00 2001 From: wltu Date: Tue, 17 Dec 2019 13:18:20 -0800 Subject: [PATCH 04/27] Remove unnecessary library --- osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index ee360d1e57..8747bc2d28 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -15,8 +15,6 @@ using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Scoring; -using osu.Framework.Graphics.UserInterface; - namespace osu.Game.Screens.Select.Leaderboards { public class BeatmapLeaderboard : Leaderboard From 531ac16743edde6d824ae149cd46e26247e12b34 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Wed, 18 Dec 2019 19:22:42 -0800 Subject: [PATCH 05/27] Update Scoreboard Refresh Method for deleting individual scores --- .../Online/Leaderboards/LeaderboardScore.cs | 11 +++- .../Select/BeatmapClearScoresDialog.cs | 22 ------- .../Select/Leaderboards/BeatmapLeaderboard.cs | 25 +++++++- .../Screens/Select/LocalScoreDeleteDialog.cs | 59 +++++++++++++++++++ 4 files changed, 90 insertions(+), 27 deletions(-) create mode 100644 osu.Game/Screens/Select/LocalScoreDeleteDialog.cs diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index ccac748535..2578b6bbea 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -58,8 +58,6 @@ namespace osu.Game.Online.Leaderboards private DialogOverlay dialogOverlay; - public Action RefreshAction { get; set; } - public LeaderboardScore(ScoreInfo score, int rank, bool allowHighlight = true) { this.score = score; @@ -370,13 +368,20 @@ namespace osu.Game.Online.Leaderboards } } + private void deleteLocalScore(ScoreInfo score) + { + if (score == null || score.ID <= 0) return; + + dialogOverlay?.Push(new LocalScoreDeleteDialog(score)); + } + public MenuItem[] ContextMenuItems { get { return (this.allowHighlight) ? null : new MenuItem[] { - new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new BeatmapClearScoresDialog(this.score, () => Schedule(this.RefreshAction)))) + new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteLocalScore(this.score)) }; } } diff --git a/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs b/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs index 2c5427993b..c9b6ca7bb3 100644 --- a/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs +++ b/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs @@ -39,28 +39,6 @@ namespace osu.Game.Screens.Select }; } - public BeatmapClearScoresDialog(ScoreInfo score, Action onCompletion) - { - string accuracy = string.Format(score?.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score?.Accuracy); - - BodyText = $@"{score?.Beatmap?.Metadata?.Artist} - {score?.Beatmap?.Metadata?.Title} {Environment.NewLine} {score?.User} - Rank: {score?.Rank} - Max Combo: {score?.MaxCombo} - {accuracy} - {score?.Date.Date.ToShortDateString()}"; - - Icon = FontAwesome.Solid.Eraser; - HeaderText = @"Clearing this local score. Are you sure?"; - Buttons = new PopupDialogButton[] - { - new PopupDialogOkButton - { - Text = @"Yes. Please.", - Action = (() => scoreManager.Delete(score)) + onCompletion - }, - new PopupDialogCancelButton - { - Text = @"No, I'm still attached.", - }, - }; - } - [BackgroundDependencyLoader] private void load(ScoreManager scoreManager) { diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index 8747bc2d28..751ea7fffd 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -19,8 +19,10 @@ namespace osu.Game.Screens.Select.Leaderboards { public class BeatmapLeaderboard : Leaderboard { + public Action ScoreSelected; + [Resolved] private RulesetStore rulesets { get; set; } @@ -103,6 +105,8 @@ namespace osu.Game.Screens.Select.Leaderboards { ScoreSelected = s => ScoreSelected?.Invoke(s) }); + + scoreManager.ItemRemoved += deleteLocalScore; } protected override void Reset() @@ -111,6 +115,16 @@ namespace osu.Game.Screens.Select.Leaderboards TopScore = null; } + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + if (scoreManager != null) + { + scoreManager.ItemRemoved -= deleteLocalScore; + } + } + protected override bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local; protected override APIRequest FetchScores(Action> scoresCallback) @@ -188,9 +202,16 @@ namespace osu.Game.Screens.Select.Leaderboards return new LeaderboardScore(model, index, IsOnlineScope) { - Action = () => ScoreSelected?.Invoke(model), - RefreshAction = () => this.RefreshScores() + Action = () => ScoreSelected?.Invoke(model) }; } + + private void deleteLocalScore(ScoreInfo score) + { + if (score == null) + return; + + Schedule(() => this.RefreshScores()); + } } } diff --git a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs new file mode 100644 index 0000000000..fb0954bdf2 --- /dev/null +++ b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs @@ -0,0 +1,59 @@ +// 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.Game.Overlays.Dialog; +using osu.Game.Scoring; +using System; +using System.Threading.Tasks; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Logging; + +namespace osu.Game.Screens.Select +{ + public class LocalScoreDeleteDialog : PopupDialog + { + private ScoreManager scoreManager; + + public LocalScoreDeleteDialog (ScoreInfo score) + { + try{ + string accuracy = string.Format(score?.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score?.Accuracy); + + BodyText = $@"{score} {Environment.NewLine} Rank: {score.Rank} - Max Combo: {score.MaxCombo} - {accuracy}"; + Icon = FontAwesome.Solid.Eraser; + HeaderText = @"Clearing this local score. Are you sure?"; + Buttons = new PopupDialogButton[] + { + new PopupDialogOkButton + { + Text = @"Yes. Please.", + Action = () => scoreManager.Delete(score) + }, + new PopupDialogCancelButton + { + Text = @"No, I'm still attached.", + }, + }; + } catch (Exception e){ + Logger.Error(e, "ScoreInfo cannot be null!"); + + HeaderText = $@"ScoreInfo cannot be null!"; + Icon = FontAwesome.Solid.Ambulance; + Buttons = new PopupDialogButton[] + { + new PopupDialogCancelButton + { + Text = @"OK, thanks.", + }, + }; + } + } + + [BackgroundDependencyLoader] + private void load(ScoreManager scoreManager) + { + this.scoreManager = scoreManager; + } + } +} From b67f9860588d1369333d43409ede90b36354ebcb Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Wed, 18 Dec 2019 19:26:35 -0800 Subject: [PATCH 06/27] Fix CodeFactor issues --- .../Screens/Select/Leaderboards/BeatmapLeaderboard.cs | 2 -- osu.Game/Screens/Select/LocalScoreDeleteDialog.cs | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index 751ea7fffd..df29666a8a 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -19,10 +19,8 @@ namespace osu.Game.Screens.Select.Leaderboards { public class BeatmapLeaderboard : Leaderboard { - public Action ScoreSelected; - [Resolved] private RulesetStore rulesets { get; set; } diff --git a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs index fb0954bdf2..9aa2e5c6e6 100644 --- a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs +++ b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs @@ -15,9 +15,10 @@ namespace osu.Game.Screens.Select { private ScoreManager scoreManager; - public LocalScoreDeleteDialog (ScoreInfo score) + public LocalScoreDeleteDialog(ScoreInfo score) { - try{ + try + { string accuracy = string.Format(score?.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score?.Accuracy); BodyText = $@"{score} {Environment.NewLine} Rank: {score.Rank} - Max Combo: {score.MaxCombo} - {accuracy}"; @@ -35,7 +36,9 @@ namespace osu.Game.Screens.Select Text = @"No, I'm still attached.", }, }; - } catch (Exception e){ + } + catch (Exception e) + { Logger.Error(e, "ScoreInfo cannot be null!"); HeaderText = $@"ScoreInfo cannot be null!"; From 27163a51338a37cb2eee249d7102aca7d5c49547 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Wed, 18 Dec 2019 21:04:10 -0800 Subject: [PATCH 07/27] Removed unnecessary code for deleting individual local score. --- .../Online/Leaderboards/LeaderboardScore.cs | 7 +-- .../Select/Leaderboards/BeatmapLeaderboard.cs | 5 +- .../Screens/Select/LocalScoreDeleteDialog.cs | 49 +++++++------------ 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index 2578b6bbea..54eebd69c1 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -1,7 +1,6 @@ // 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 System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; @@ -370,8 +369,6 @@ namespace osu.Game.Online.Leaderboards private void deleteLocalScore(ScoreInfo score) { - if (score == null || score.ID <= 0) return; - dialogOverlay?.Push(new LocalScoreDeleteDialog(score)); } @@ -379,9 +376,9 @@ namespace osu.Game.Online.Leaderboards { get { - return (this.allowHighlight) ? null : new MenuItem[] + return (allowHighlight) ? null : new MenuItem[] { - new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteLocalScore(this.score)) + new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteLocalScore(score)), }; } } diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index df29666a8a..8442e91712 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -206,10 +206,7 @@ namespace osu.Game.Screens.Select.Leaderboards private void deleteLocalScore(ScoreInfo score) { - if (score == null) - return; - - Schedule(() => this.RefreshScores()); + Schedule(RefreshScores); } } } diff --git a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs index 9aa2e5c6e6..635906c08a 100644 --- a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs +++ b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs @@ -5,7 +5,7 @@ using osu.Framework.Allocation; using osu.Game.Overlays.Dialog; using osu.Game.Scoring; using System; -using System.Threading.Tasks; +using System.Diagnostics; using osu.Framework.Graphics.Sprites; using osu.Framework.Logging; @@ -17,40 +17,25 @@ namespace osu.Game.Screens.Select public LocalScoreDeleteDialog(ScoreInfo score) { - try - { - string accuracy = string.Format(score?.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score?.Accuracy); + Debug.Assert(score != null); - BodyText = $@"{score} {Environment.NewLine} Rank: {score.Rank} - Max Combo: {score.MaxCombo} - {accuracy}"; - Icon = FontAwesome.Solid.Eraser; - HeaderText = @"Clearing this local score. Are you sure?"; - Buttons = new PopupDialogButton[] - { - new PopupDialogOkButton - { - Text = @"Yes. Please.", - Action = () => scoreManager.Delete(score) - }, - new PopupDialogCancelButton - { - Text = @"No, I'm still attached.", - }, - }; - } - catch (Exception e) - { - Logger.Error(e, "ScoreInfo cannot be null!"); + string accuracy = string.Format(score.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score.Accuracy); - HeaderText = $@"ScoreInfo cannot be null!"; - Icon = FontAwesome.Solid.Ambulance; - Buttons = new PopupDialogButton[] + BodyText = $@"{score} {Environment.NewLine} Rank: {score.Rank} - Max Combo: {score.MaxCombo} - {accuracy}"; + Icon = FontAwesome.Solid.Eraser; + HeaderText = @"Deleting this local score. Are you sure?"; + Buttons = new PopupDialogButton[] + { + new PopupDialogOkButton { - new PopupDialogCancelButton - { - Text = @"OK, thanks.", - }, - }; - } + Text = @"Yes. Please.", + Action = () => scoreManager.Delete(score) + }, + new PopupDialogCancelButton + { + Text = @"No, I'm still attached.", + }, + }; } [BackgroundDependencyLoader] From ed07b779b167284f7b51d2031fb67f20bca97eb5 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Wed, 18 Dec 2019 21:54:02 -0800 Subject: [PATCH 08/27] Update to use score.ID identify local scores --- osu.Game/Online/Leaderboards/LeaderboardScore.cs | 9 +++------ osu.Game/Screens/Select/LocalScoreDeleteDialog.cs | 1 - 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index 54eebd69c1..d2d82d849d 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -374,13 +374,10 @@ namespace osu.Game.Online.Leaderboards public MenuItem[] ContextMenuItems { - get + get => (score.ID == 0) ? null : new MenuItem[] { - return (allowHighlight) ? null : new MenuItem[] - { - new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteLocalScore(score)), - }; - } + new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteLocalScore(score)), + }; } } } diff --git a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs index 635906c08a..d5f2195c42 100644 --- a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs +++ b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs @@ -7,7 +7,6 @@ using osu.Game.Scoring; using System; using System.Diagnostics; using osu.Framework.Graphics.Sprites; -using osu.Framework.Logging; namespace osu.Game.Screens.Select { From 643911ada972f93bcb17d34514b17878dc758a40 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Wed, 18 Dec 2019 22:41:07 -0800 Subject: [PATCH 09/27] Fix code format for CI --- osu.Game/Online/Leaderboards/LeaderboardScore.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index d2d82d849d..c6a3368a91 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -372,12 +372,18 @@ namespace osu.Game.Online.Leaderboards dialogOverlay?.Push(new LocalScoreDeleteDialog(score)); } + public MenuItem[] ContextMenuItems { - get => (score.ID == 0) ? null : new MenuItem[] + get { - new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteLocalScore(score)), - }; + List items = new List(); + + if (score.ID != 0) + items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteLocalScore(score))); + + return items.ToArray(); + } } } } From d4d4ddc624c194751e9adbcd319cf42e170798d1 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Wed, 18 Dec 2019 22:42:26 -0800 Subject: [PATCH 10/27] Remove new line for CodeFactor --- osu.Game/Online/Leaderboards/LeaderboardScore.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index c6a3368a91..c0d366f642 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -372,7 +372,6 @@ namespace osu.Game.Online.Leaderboards dialogOverlay?.Push(new LocalScoreDeleteDialog(score)); } - public MenuItem[] ContextMenuItems { get From 8ab26e8889ee5ca41d129e0aa9e0ba2db7c2fb8a Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Thu, 19 Dec 2019 21:29:54 -0800 Subject: [PATCH 11/27] Update Tests with dependencies on LeaderboardScore. Added its dependency on DialogOverlay for the tests. Added test for deleting individual local score --- .../SongSelect/TestSceneBeatmapLeaderboard.cs | 21 +- .../TestSceneUserTopScoreContainer.cs | 22 +- .../TestSceneDeleteLocalScore.cs | 230 ++++++++++++++++++ .../Online/Leaderboards/LeaderboardScore.cs | 2 +- 4 files changed, 270 insertions(+), 5 deletions(-) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs index 57e297bcd5..551fffde54 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs @@ -3,10 +3,12 @@ using System; using System.Collections.Generic; +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Leaderboards; +using osu.Game.Overlays; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Scoring; using osu.Game.Screens.Select.Leaderboards; @@ -28,15 +30,22 @@ namespace osu.Game.Tests.Visual.SongSelect private readonly FailableLeaderboard leaderboard; + private DialogOverlay dialogOverlay; + public TestSceneBeatmapLeaderboard() { - Add(leaderboard = new FailableLeaderboard + Add(dialogOverlay = new DialogOverlay() + { + Depth = -1 + }); + + leaderboard = new FailableLeaderboard { Origin = Anchor.Centre, Anchor = Anchor.Centre, Size = new Vector2(550f, 450f), Scope = BeatmapLeaderboardScope.Global, - }); + }; AddStep(@"New Scores", newScores); AddStep(@"Show personal best", showPersonalBest); @@ -281,5 +290,13 @@ namespace osu.Game.Tests.Visual.SongSelect PlaceholderState = state; } } + + [BackgroundDependencyLoader] + private void load() + { + Dependencies.Cache(dialogOverlay); + + Add(leaderboard); + } } } diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs index e34e1844ce..0545f13d44 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs @@ -1,11 +1,13 @@ // 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.Shapes; using osuTK.Graphics; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Overlays; using osu.Game.Scoring; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Screens.Select.Leaderboards; @@ -15,11 +17,19 @@ namespace osu.Game.Tests.Visual.SongSelect { public class TestSceneUserTopScoreContainer : OsuTestScene { + private DialogOverlay dialogOverlay; + private Container container; + public TestSceneUserTopScoreContainer() { UserTopScoreContainer topScoreContainer; - Add(new Container + Add(dialogOverlay = new DialogOverlay() + { + Depth = -1 + }); + + container = new Container { Origin = Anchor.BottomCentre, Anchor = Anchor.Centre, @@ -38,7 +48,7 @@ namespace osu.Game.Tests.Visual.SongSelect Anchor = Anchor.BottomCentre, } } - }); + }; var scores = new[] { @@ -114,5 +124,13 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep(@"Add score(rank 22333)", () => topScoreContainer.Score.Value = scores[2]); AddStep(@"Add null score", () => topScoreContainer.Score.Value = null); } + + [BackgroundDependencyLoader] + private void load() + { + Dependencies.Cache(dialogOverlay); + + Add(container); + } } } diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs new file mode 100644 index 0000000000..5a75cb3e08 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -0,0 +1,230 @@ +// 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 System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using osu.Framework.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Graphics.Sprites; +using osu.Game.Beatmaps; +using osu.Game.Graphics.UserInterface; +using osu.Game.Online.API; +using osu.Game.Online.Leaderboards; +using osu.Game.Overlays; +using osu.Game.Overlays.Dialog; +using osu.Game.Scoring; +using osu.Game.Screens.Select.Leaderboards; +using osu.Game.Users; +using osuTK; +using osuTK.Input; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneDeleteLocalScore : ManualInputManagerTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(Placeholder), + typeof(MessagePlaceholder), + typeof(RetrievalFailurePlaceholder), + typeof(UserTopScoreContainer), + typeof(Leaderboard), + typeof(LeaderboardScore), + + }; + + private readonly FailableLeaderboard leaderboard; + + private DialogOverlay dialogOverlay; + + public TestSceneDeleteLocalScore() + { + Add(dialogOverlay = new DialogOverlay() + { + Depth = -1 + }); + + leaderboard = new FailableLeaderboard(dialogOverlay) + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Size = new Vector2(550f, 450f), + Scope = BeatmapLeaderboardScope.Local, + Beatmap = new BeatmapInfo + { + ID = 1, + Metadata = new BeatmapMetadata + { + ID = 1, + Title = "TestSong", + Artist = "TestArtist", + Author = new User + { + Username = "TestAuthor" + }, + }, + Version = "Insane" + }, + }; + + AddStep("Insert Locacl Scores", null); + + TestConfirmDeleteLocalScore(); + TestCancelDeleteLocalScore(); + } + + private void TestConfirmDeleteLocalScore() + { + AddStep("Move to leaderboard", () => InputManager.MoveMouseTo(leaderboard)); + AddStep("Show ContextMenu", () => InputManager.Click(MouseButton.Right)); + AddUntilStep("Wait for ContextMenu", () => typeof(OsuContextMenu) == InputManager.FocusedDrawable.GetType() && InputManager.FocusedDrawable.IsLoaded); + AddStep("Move to Delete Context Menu", () => InputManager.MoveMouseTo(InputManager.FocusedDrawable)); + AddStep("Show Delete Score Dialog", () => InputManager.Click(MouseButton.Left)); + AddUntilStep("Wait for DialogOverlay", () => dialogOverlay.CurrentDialog.IsLoaded); + AddStep("Move to confirm button", () => InputManager.MoveMouseTo(((TestLocalScoreDeleteDialog)dialogOverlay.CurrentDialog).confirmButton)); + AddStep("Confirm Action", () => InputManager.Click(MouseButton.Left)); + AddAssert("Check Score Count", () => leaderboard.ScoreCount() == 49); + } + + private void TestCancelDeleteLocalScore() + { + AddStep("Move to leaderboard", () => InputManager.MoveMouseTo(leaderboard)); + AddStep("Show ContextMenu", () => InputManager.Click(MouseButton.Right)); + AddUntilStep("Wait for ContextMenu", () => typeof(OsuContextMenu) == InputManager.FocusedDrawable.GetType() && InputManager.FocusedDrawable.IsLoaded); + AddStep("Move to Delete Context Menu", () => InputManager.MoveMouseTo(InputManager.FocusedDrawable)); + AddStep("Show Delete Score Dialog", () => InputManager.Click(MouseButton.Left)); + AddUntilStep("Wait for DialogOverlay", () => dialogOverlay.CurrentDialog.IsLoaded); + AddStep("Move to cancel button", () => InputManager.MoveMouseTo(((TestLocalScoreDeleteDialog)dialogOverlay.CurrentDialog).cancelButton)); + AddStep("Cancel Action", () => InputManager.Click(MouseButton.Left)); + AddAssert("Check Score Count", () => leaderboard.ScoreCount() == 49); + } + + [BackgroundDependencyLoader] + private void load() + { + Dependencies.Cache(dialogOverlay); + Add(leaderboard); + } + + private class FailableLeaderboard : BeatmapLeaderboard + { + private DialogOverlay dialogOverlay; + + private List scoreList; + + private Random rnd; + + private bool initialLoad; + + public void DeleteScore(ScoreInfo score) + { + scoreList.Remove(score); + RefreshScores(); + } + + public int ScoreCount() + { + return scoreList.Count; + } + + public FailableLeaderboard(DialogOverlay dialogOverlay) + : base() + { + this.dialogOverlay = dialogOverlay; + initialLoad = true; + } + + public void SetRetrievalState(PlaceholderState state) + { + PlaceholderState = state; + } + + protected override APIRequest FetchScores(Action> scoresCallback) + { + if (initialLoad) + { + rnd = new Random(); + + scoreList = Enumerable.Range(1, 50).Select(createScore).ToList(); + Scores = scoreList.OrderByDescending(s => s.TotalScore).ToArray(); + + initialLoad = false; + } + else + { + Scores = scoreList.OrderByDescending(s => s.TotalScore).ToArray(); + } + + return null; + } + + private ScoreInfo createScore(int id) => new ScoreInfo + { + ID = id, + Accuracy = rnd.NextDouble(), + PP = rnd.Next(1, 1000000), + TotalScore = rnd.Next(1, 1000000), + MaxCombo = rnd.Next(1, 1000), + Rank = ScoreRank.XH, + User = new User { Username = "TestUser" }, + }; + + protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) + { + model.Beatmap = Beatmap; + return new TestLeaderboardScore(model, index, dialogOverlay, this, IsOnlineScope); + } + } + + private class TestLeaderboardScore : LeaderboardScore + { + private DialogOverlay dialogOverlay; + + private FailableLeaderboard leaderboard; + + public TestLeaderboardScore(ScoreInfo score, int rank, DialogOverlay dialogOverlay, FailableLeaderboard leaderboard, bool allowHighlight = true) + : base(score, rank, allowHighlight) + { + this.dialogOverlay = dialogOverlay; + this.leaderboard = leaderboard; + } + + protected override void deleteLocalScore(ScoreInfo score) + { + dialogOverlay?.Push(new TestLocalScoreDeleteDialog(score, leaderboard)); + } + } + + private class TestLocalScoreDeleteDialog : PopupDialog + { + public PopupDialogOkButton confirmButton; + + public PopupDialogCancelButton cancelButton; + + public TestLocalScoreDeleteDialog(ScoreInfo score, FailableLeaderboard leaderboard) + { + Debug.Assert(score != null); + + string accuracy = string.Format(score.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score.Accuracy); + + BodyText = $@"{score} {Environment.NewLine} Rank: {score.Rank} - Max Combo: {score.MaxCombo} - {accuracy}"; + Icon = FontAwesome.Solid.Eraser; + HeaderText = @"Deleting this local score. Are you sure?"; + Buttons = new PopupDialogButton[] + { + confirmButton = new PopupDialogOkButton + { + Text = @"Yes. Please.", + Action = () => leaderboard.DeleteScore(score) + }, + cancelButton = new PopupDialogCancelButton + { + Text = @"No, I'm still attached.", + }, + }; + } + } + } +} diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index c0d366f642..b706adb8ff 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -367,7 +367,7 @@ namespace osu.Game.Online.Leaderboards } } - private void deleteLocalScore(ScoreInfo score) + protected virtual void deleteLocalScore(ScoreInfo score) { dialogOverlay?.Push(new LocalScoreDeleteDialog(score)); } From e42894cfcf86f6a5a78036b5833f819eed7d7238 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Thu, 19 Dec 2019 21:32:54 -0800 Subject: [PATCH 12/27] Fixed error for CodeFactor --- osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index 5a75cb3e08..fbfe3b835e 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -32,7 +32,6 @@ namespace osu.Game.Tests.Visual.UserInterface typeof(UserTopScoreContainer), typeof(Leaderboard), typeof(LeaderboardScore), - }; private readonly FailableLeaderboard leaderboard; From 6abbd33b512b34cca22eec8b64629b02aa4fbd93 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Thu, 19 Dec 2019 21:57:14 -0800 Subject: [PATCH 13/27] Fixed CI issues --- .../SongSelect/TestSceneBeatmapLeaderboard.cs | 4 +-- .../TestSceneUserTopScoreContainer.cs | 6 ++--- .../TestSceneDeleteLocalScore.cs | 25 +++++++++---------- .../Online/Leaderboards/LeaderboardScore.cs | 4 +-- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs index 551fffde54..386fadc0d3 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs @@ -30,11 +30,11 @@ namespace osu.Game.Tests.Visual.SongSelect private readonly FailableLeaderboard leaderboard; - private DialogOverlay dialogOverlay; + private readonly DialogOverlay dialogOverlay; public TestSceneBeatmapLeaderboard() { - Add(dialogOverlay = new DialogOverlay() + Add(dialogOverlay = new DialogOverlay { Depth = -1 }); diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs index 0545f13d44..c69626321d 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs @@ -17,14 +17,14 @@ namespace osu.Game.Tests.Visual.SongSelect { public class TestSceneUserTopScoreContainer : OsuTestScene { - private DialogOverlay dialogOverlay; - private Container container; + private readonly DialogOverlay dialogOverlay; + private readonly Container container; public TestSceneUserTopScoreContainer() { UserTopScoreContainer topScoreContainer; - Add(dialogOverlay = new DialogOverlay() + Add(dialogOverlay = new DialogOverlay { Depth = -1 }); diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index fbfe3b835e..e804891444 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -36,11 +36,11 @@ namespace osu.Game.Tests.Visual.UserInterface private readonly FailableLeaderboard leaderboard; - private DialogOverlay dialogOverlay; + private readonly DialogOverlay dialogOverlay; public TestSceneDeleteLocalScore() { - Add(dialogOverlay = new DialogOverlay() + Add(dialogOverlay = new DialogOverlay { Depth = -1 }); @@ -70,11 +70,11 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("Insert Locacl Scores", null); - TestConfirmDeleteLocalScore(); - TestCancelDeleteLocalScore(); + testConfirmDeleteLocalScore(); + testCancelDeleteLocalScore(); } - private void TestConfirmDeleteLocalScore() + private void testConfirmDeleteLocalScore() { AddStep("Move to leaderboard", () => InputManager.MoveMouseTo(leaderboard)); AddStep("Show ContextMenu", () => InputManager.Click(MouseButton.Right)); @@ -87,7 +87,7 @@ namespace osu.Game.Tests.Visual.UserInterface AddAssert("Check Score Count", () => leaderboard.ScoreCount() == 49); } - private void TestCancelDeleteLocalScore() + private void testCancelDeleteLocalScore() { AddStep("Move to leaderboard", () => InputManager.MoveMouseTo(leaderboard)); AddStep("Show ContextMenu", () => InputManager.Click(MouseButton.Right)); @@ -109,7 +109,7 @@ namespace osu.Game.Tests.Visual.UserInterface private class FailableLeaderboard : BeatmapLeaderboard { - private DialogOverlay dialogOverlay; + private readonly DialogOverlay dialogOverlay; private List scoreList; @@ -129,7 +129,6 @@ namespace osu.Game.Tests.Visual.UserInterface } public FailableLeaderboard(DialogOverlay dialogOverlay) - : base() { this.dialogOverlay = dialogOverlay; initialLoad = true; @@ -179,9 +178,9 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestLeaderboardScore : LeaderboardScore { - private DialogOverlay dialogOverlay; + private readonly DialogOverlay dialogOverlay; - private FailableLeaderboard leaderboard; + private readonly FailableLeaderboard leaderboard; public TestLeaderboardScore(ScoreInfo score, int rank, DialogOverlay dialogOverlay, FailableLeaderboard leaderboard, bool allowHighlight = true) : base(score, rank, allowHighlight) @@ -190,7 +189,7 @@ namespace osu.Game.Tests.Visual.UserInterface this.leaderboard = leaderboard; } - protected override void deleteLocalScore(ScoreInfo score) + protected override void DeleteLocalScore(ScoreInfo score) { dialogOverlay?.Push(new TestLocalScoreDeleteDialog(score, leaderboard)); } @@ -198,9 +197,9 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestLocalScoreDeleteDialog : PopupDialog { - public PopupDialogOkButton confirmButton; + public readonly PopupDialogOkButton confirmButton; - public PopupDialogCancelButton cancelButton; + public readonly PopupDialogCancelButton cancelButton; public TestLocalScoreDeleteDialog(ScoreInfo score, FailableLeaderboard leaderboard) { diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index b706adb8ff..b49a8bf483 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -367,7 +367,7 @@ namespace osu.Game.Online.Leaderboards } } - protected virtual void deleteLocalScore(ScoreInfo score) + protected virtual void DeleteLocalScore(ScoreInfo score) { dialogOverlay?.Push(new LocalScoreDeleteDialog(score)); } @@ -379,7 +379,7 @@ namespace osu.Game.Online.Leaderboards List items = new List(); if (score.ID != 0) - items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteLocalScore(score))); + items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => DeleteLocalScore(score))); return items.ToArray(); } From 6672cf60590f101acb7d7c7871597d2a9b039df4 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Thu, 19 Dec 2019 22:22:46 -0800 Subject: [PATCH 14/27] Update variable name --- .../Visual/UserInterface/TestSceneDeleteLocalScore.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index e804891444..635ad904e3 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -82,7 +82,7 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("Move to Delete Context Menu", () => InputManager.MoveMouseTo(InputManager.FocusedDrawable)); AddStep("Show Delete Score Dialog", () => InputManager.Click(MouseButton.Left)); AddUntilStep("Wait for DialogOverlay", () => dialogOverlay.CurrentDialog.IsLoaded); - AddStep("Move to confirm button", () => InputManager.MoveMouseTo(((TestLocalScoreDeleteDialog)dialogOverlay.CurrentDialog).confirmButton)); + AddStep("Move to confirm button", () => InputManager.MoveMouseTo(((TestLocalScoreDeleteDialog)dialogOverlay.CurrentDialog).ConfirmButton)); AddStep("Confirm Action", () => InputManager.Click(MouseButton.Left)); AddAssert("Check Score Count", () => leaderboard.ScoreCount() == 49); } @@ -95,7 +95,7 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("Move to Delete Context Menu", () => InputManager.MoveMouseTo(InputManager.FocusedDrawable)); AddStep("Show Delete Score Dialog", () => InputManager.Click(MouseButton.Left)); AddUntilStep("Wait for DialogOverlay", () => dialogOverlay.CurrentDialog.IsLoaded); - AddStep("Move to cancel button", () => InputManager.MoveMouseTo(((TestLocalScoreDeleteDialog)dialogOverlay.CurrentDialog).cancelButton)); + AddStep("Move to cancel button", () => InputManager.MoveMouseTo(((TestLocalScoreDeleteDialog)dialogOverlay.CurrentDialog).CancelButton)); AddStep("Cancel Action", () => InputManager.Click(MouseButton.Left)); AddAssert("Check Score Count", () => leaderboard.ScoreCount() == 49); } @@ -197,9 +197,9 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestLocalScoreDeleteDialog : PopupDialog { - public readonly PopupDialogOkButton confirmButton; + public readonly PopupDialogOkButton ConfirmButton; - public readonly PopupDialogCancelButton cancelButton; + public readonly PopupDialogCancelButton CancelButton; public TestLocalScoreDeleteDialog(ScoreInfo score, FailableLeaderboard leaderboard) { From afc11aa547b8401cf0b22f5478e186cabdc61762 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Thu, 19 Dec 2019 22:37:09 -0800 Subject: [PATCH 15/27] Fixed issues caused by renaming variables --- .../Visual/UserInterface/TestSceneDeleteLocalScore.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index 635ad904e3..da91051175 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -212,12 +212,12 @@ namespace osu.Game.Tests.Visual.UserInterface HeaderText = @"Deleting this local score. Are you sure?"; Buttons = new PopupDialogButton[] { - confirmButton = new PopupDialogOkButton + ConfirmButton = new PopupDialogOkButton { Text = @"Yes. Please.", Action = () => leaderboard.DeleteScore(score) }, - cancelButton = new PopupDialogCancelButton + CancelButton = new PopupDialogCancelButton { Text = @"No, I'm still attached.", }, From ba2cff60ca15827c16836ff9f222452e15a01499 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Fri, 20 Dec 2019 02:13:49 -0800 Subject: [PATCH 16/27] Removed Automation Testing steps for delete local scores. Only manual testing now. --- .../TestSceneDeleteLocalScore.cs | 60 +++++-------------- 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index da91051175..0441d8659e 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -9,7 +9,6 @@ using osu.Framework.Graphics; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; using osu.Game.Beatmaps; -using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.Leaderboards; using osu.Game.Overlays; @@ -18,7 +17,6 @@ using osu.Game.Scoring; using osu.Game.Screens.Select.Leaderboards; using osu.Game.Users; using osuTK; -using osuTK.Input; namespace osu.Game.Tests.Visual.UserInterface { @@ -45,7 +43,7 @@ namespace osu.Game.Tests.Visual.UserInterface Depth = -1 }); - leaderboard = new FailableLeaderboard(dialogOverlay) + leaderboard = new FailableLeaderboard { Origin = Anchor.Centre, Anchor = Anchor.Centre, @@ -68,36 +66,13 @@ namespace osu.Game.Tests.Visual.UserInterface }, }; - AddStep("Insert Locacl Scores", null); - - testConfirmDeleteLocalScore(); - testCancelDeleteLocalScore(); + AddStep("Insert Local Scores", () => reset()); } - private void testConfirmDeleteLocalScore() + private void reset() { - AddStep("Move to leaderboard", () => InputManager.MoveMouseTo(leaderboard)); - AddStep("Show ContextMenu", () => InputManager.Click(MouseButton.Right)); - AddUntilStep("Wait for ContextMenu", () => typeof(OsuContextMenu) == InputManager.FocusedDrawable.GetType() && InputManager.FocusedDrawable.IsLoaded); - AddStep("Move to Delete Context Menu", () => InputManager.MoveMouseTo(InputManager.FocusedDrawable)); - AddStep("Show Delete Score Dialog", () => InputManager.Click(MouseButton.Left)); - AddUntilStep("Wait for DialogOverlay", () => dialogOverlay.CurrentDialog.IsLoaded); - AddStep("Move to confirm button", () => InputManager.MoveMouseTo(((TestLocalScoreDeleteDialog)dialogOverlay.CurrentDialog).ConfirmButton)); - AddStep("Confirm Action", () => InputManager.Click(MouseButton.Left)); - AddAssert("Check Score Count", () => leaderboard.ScoreCount() == 49); - } - - private void testCancelDeleteLocalScore() - { - AddStep("Move to leaderboard", () => InputManager.MoveMouseTo(leaderboard)); - AddStep("Show ContextMenu", () => InputManager.Click(MouseButton.Right)); - AddUntilStep("Wait for ContextMenu", () => typeof(OsuContextMenu) == InputManager.FocusedDrawable.GetType() && InputManager.FocusedDrawable.IsLoaded); - AddStep("Move to Delete Context Menu", () => InputManager.MoveMouseTo(InputManager.FocusedDrawable)); - AddStep("Show Delete Score Dialog", () => InputManager.Click(MouseButton.Left)); - AddUntilStep("Wait for DialogOverlay", () => dialogOverlay.CurrentDialog.IsLoaded); - AddStep("Move to cancel button", () => InputManager.MoveMouseTo(((TestLocalScoreDeleteDialog)dialogOverlay.CurrentDialog).CancelButton)); - AddStep("Cancel Action", () => InputManager.Click(MouseButton.Left)); - AddAssert("Check Score Count", () => leaderboard.ScoreCount() == 49); + leaderboard.initialLoad = true; + leaderboard.RefreshScores(); } [BackgroundDependencyLoader] @@ -109,13 +84,11 @@ namespace osu.Game.Tests.Visual.UserInterface private class FailableLeaderboard : BeatmapLeaderboard { - private readonly DialogOverlay dialogOverlay; - private List scoreList; private Random rnd; - private bool initialLoad; + public bool initialLoad; public void DeleteScore(ScoreInfo score) { @@ -123,14 +96,8 @@ namespace osu.Game.Tests.Visual.UserInterface RefreshScores(); } - public int ScoreCount() + public FailableLeaderboard() { - return scoreList.Count; - } - - public FailableLeaderboard(DialogOverlay dialogOverlay) - { - this.dialogOverlay = dialogOverlay; initialLoad = true; } @@ -172,20 +139,19 @@ namespace osu.Game.Tests.Visual.UserInterface protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) { model.Beatmap = Beatmap; - return new TestLeaderboardScore(model, index, dialogOverlay, this, IsOnlineScope); + return new TestLeaderboardScore(model, index, this, IsOnlineScope); } } private class TestLeaderboardScore : LeaderboardScore { - private readonly DialogOverlay dialogOverlay; + private DialogOverlay dialogOverlay; private readonly FailableLeaderboard leaderboard; - public TestLeaderboardScore(ScoreInfo score, int rank, DialogOverlay dialogOverlay, FailableLeaderboard leaderboard, bool allowHighlight = true) + public TestLeaderboardScore(ScoreInfo score, int rank, FailableLeaderboard leaderboard, bool allowHighlight = true) : base(score, rank, allowHighlight) { - this.dialogOverlay = dialogOverlay; this.leaderboard = leaderboard; } @@ -193,6 +159,12 @@ namespace osu.Game.Tests.Visual.UserInterface { dialogOverlay?.Push(new TestLocalScoreDeleteDialog(score, leaderboard)); } + + [BackgroundDependencyLoader] + private void load(DialogOverlay dialogOverlay) + { + this.dialogOverlay = dialogOverlay; + } } private class TestLocalScoreDeleteDialog : PopupDialog From a55e5c5c437da004583e22e4297632f5e29d376e Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Fri, 20 Dec 2019 11:16:54 -0800 Subject: [PATCH 17/27] Removed unnecessary code --- .../TestSceneDeleteLocalScore.cs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index 0441d8659e..6ca75ea9cb 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -66,12 +66,12 @@ namespace osu.Game.Tests.Visual.UserInterface }, }; - AddStep("Insert Local Scores", () => reset()); + AddStep("Insert Local Scores", reset); } private void reset() { - leaderboard.initialLoad = true; + leaderboard.InitialLoad = true; leaderboard.RefreshScores(); } @@ -88,7 +88,7 @@ namespace osu.Game.Tests.Visual.UserInterface private Random rnd; - public bool initialLoad; + public bool InitialLoad; public void DeleteScore(ScoreInfo score) { @@ -98,7 +98,7 @@ namespace osu.Game.Tests.Visual.UserInterface public FailableLeaderboard() { - initialLoad = true; + InitialLoad = true; } public void SetRetrievalState(PlaceholderState state) @@ -108,14 +108,14 @@ namespace osu.Game.Tests.Visual.UserInterface protected override APIRequest FetchScores(Action> scoresCallback) { - if (initialLoad) + if (InitialLoad) { rnd = new Random(); scoreList = Enumerable.Range(1, 50).Select(createScore).ToList(); Scores = scoreList.OrderByDescending(s => s.TotalScore).ToArray(); - initialLoad = false; + InitialLoad = false; } else { @@ -169,10 +169,6 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestLocalScoreDeleteDialog : PopupDialog { - public readonly PopupDialogOkButton ConfirmButton; - - public readonly PopupDialogCancelButton CancelButton; - public TestLocalScoreDeleteDialog(ScoreInfo score, FailableLeaderboard leaderboard) { Debug.Assert(score != null); @@ -184,12 +180,12 @@ namespace osu.Game.Tests.Visual.UserInterface HeaderText = @"Deleting this local score. Are you sure?"; Buttons = new PopupDialogButton[] { - ConfirmButton = new PopupDialogOkButton + new PopupDialogOkButton { Text = @"Yes. Please.", Action = () => leaderboard.DeleteScore(score) }, - CancelButton = new PopupDialogCancelButton + new PopupDialogCancelButton { Text = @"No, I'm still attached.", }, From 8353c893c07200bc6a97f00b3153e17c446b0b0b Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Fri, 20 Dec 2019 12:00:10 -0800 Subject: [PATCH 18/27] Update BodyText of LocalScoreDeleteDialog --- .../Visual/UserInterface/TestSceneDeleteLocalScore.cs | 2 +- osu.Game/Screens/Select/LocalScoreDeleteDialog.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index 6ca75ea9cb..2369b22ec2 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -175,7 +175,7 @@ namespace osu.Game.Tests.Visual.UserInterface string accuracy = string.Format(score.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score.Accuracy); - BodyText = $@"{score} {Environment.NewLine} Rank: {score.Rank} - Max Combo: {score.MaxCombo} - {accuracy}"; + BodyText = $@"{score.User}'s {accuracy} {score.Rank} Rank on {score.Beatmap}"; Icon = FontAwesome.Solid.Eraser; HeaderText = @"Deleting this local score. Are you sure?"; Buttons = new PopupDialogButton[] diff --git a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs index d5f2195c42..3f52b54e64 100644 --- a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs +++ b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs @@ -20,7 +20,7 @@ namespace osu.Game.Screens.Select string accuracy = string.Format(score.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score.Accuracy); - BodyText = $@"{score} {Environment.NewLine} Rank: {score.Rank} - Max Combo: {score.MaxCombo} - {accuracy}"; + BodyText = $@"{score.User}'s {accuracy} {score.Rank} Rank on {score.Beatmap}"; Icon = FontAwesome.Solid.Eraser; HeaderText = @"Deleting this local score. Are you sure?"; Buttons = new PopupDialogButton[] From 8e60ae70393e891776cee0f2431eb927b8eef007 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Fri, 20 Dec 2019 15:45:20 -0800 Subject: [PATCH 19/27] Removed directive is not required --- osu.Game/Screens/Select/LocalScoreDeleteDialog.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs index 3f52b54e64..514c5adf95 100644 --- a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs +++ b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs @@ -4,7 +4,6 @@ using osu.Framework.Allocation; using osu.Game.Overlays.Dialog; using osu.Game.Scoring; -using System; using System.Diagnostics; using osu.Framework.Graphics.Sprites; From e23c71be803ddc3f30d1070d3c1fe2bdd04ee6c9 Mon Sep 17 00:00:00 2001 From: Willy Tu Date: Fri, 3 Jan 2020 11:34:26 -0800 Subject: [PATCH 20/27] Update Resolved and Cached attribute issues --- .../SongSelect/TestSceneBeatmapLeaderboard.cs | 13 +++--------- .../TestSceneUserTopScoreContainer.cs | 14 +++---------- .../TestSceneDeleteLocalScore.cs | 21 +++++-------------- .../Online/Leaderboards/LeaderboardScore.cs | 6 +++--- .../Select/BeatmapClearScoresDialog.cs | 9 ++------ .../Screens/Select/LocalScoreDeleteDialog.cs | 9 ++------ 6 files changed, 18 insertions(+), 54 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs index 386fadc0d3..6ae0a80123 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapLeaderboard.cs @@ -30,6 +30,7 @@ namespace osu.Game.Tests.Visual.SongSelect private readonly FailableLeaderboard leaderboard; + [Cached] private readonly DialogOverlay dialogOverlay; public TestSceneBeatmapLeaderboard() @@ -39,13 +40,13 @@ namespace osu.Game.Tests.Visual.SongSelect Depth = -1 }); - leaderboard = new FailableLeaderboard + Add(leaderboard = new FailableLeaderboard { Origin = Anchor.Centre, Anchor = Anchor.Centre, Size = new Vector2(550f, 450f), Scope = BeatmapLeaderboardScope.Global, - }; + }); AddStep(@"New Scores", newScores); AddStep(@"Show personal best", showPersonalBest); @@ -290,13 +291,5 @@ namespace osu.Game.Tests.Visual.SongSelect PlaceholderState = state; } } - - [BackgroundDependencyLoader] - private void load() - { - Dependencies.Cache(dialogOverlay); - - Add(leaderboard); - } } } diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs index c69626321d..0598324110 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneUserTopScoreContainer.cs @@ -17,8 +17,8 @@ namespace osu.Game.Tests.Visual.SongSelect { public class TestSceneUserTopScoreContainer : OsuTestScene { + [Cached] private readonly DialogOverlay dialogOverlay; - private readonly Container container; public TestSceneUserTopScoreContainer() { @@ -29,7 +29,7 @@ namespace osu.Game.Tests.Visual.SongSelect Depth = -1 }); - container = new Container + Add(new Container { Origin = Anchor.BottomCentre, Anchor = Anchor.Centre, @@ -48,7 +48,7 @@ namespace osu.Game.Tests.Visual.SongSelect Anchor = Anchor.BottomCentre, } } - }; + }); var scores = new[] { @@ -124,13 +124,5 @@ namespace osu.Game.Tests.Visual.SongSelect AddStep(@"Add score(rank 22333)", () => topScoreContainer.Score.Value = scores[2]); AddStep(@"Add null score", () => topScoreContainer.Score.Value = null); } - - [BackgroundDependencyLoader] - private void load() - { - Dependencies.Cache(dialogOverlay); - - Add(container); - } } } diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index 2369b22ec2..de10eaccca 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -34,6 +34,7 @@ namespace osu.Game.Tests.Visual.UserInterface private readonly FailableLeaderboard leaderboard; + [Cached] private readonly DialogOverlay dialogOverlay; public TestSceneDeleteLocalScore() @@ -43,7 +44,7 @@ namespace osu.Game.Tests.Visual.UserInterface Depth = -1 }); - leaderboard = new FailableLeaderboard + Add(leaderboard = new FailableLeaderboard { Origin = Anchor.Centre, Anchor = Anchor.Centre, @@ -64,7 +65,7 @@ namespace osu.Game.Tests.Visual.UserInterface }, Version = "Insane" }, - }; + }); AddStep("Insert Local Scores", reset); } @@ -75,13 +76,6 @@ namespace osu.Game.Tests.Visual.UserInterface leaderboard.RefreshScores(); } - [BackgroundDependencyLoader] - private void load() - { - Dependencies.Cache(dialogOverlay); - Add(leaderboard); - } - private class FailableLeaderboard : BeatmapLeaderboard { private List scoreList; @@ -145,7 +139,8 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestLeaderboardScore : LeaderboardScore { - private DialogOverlay dialogOverlay; + [Resolved] + private DialogOverlay dialogOverlay { get; set; } private readonly FailableLeaderboard leaderboard; @@ -159,12 +154,6 @@ namespace osu.Game.Tests.Visual.UserInterface { dialogOverlay?.Push(new TestLocalScoreDeleteDialog(score, leaderboard)); } - - [BackgroundDependencyLoader] - private void load(DialogOverlay dialogOverlay) - { - this.dialogOverlay = dialogOverlay; - } } private class TestLocalScoreDeleteDialog : PopupDialog diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index b49a8bf483..7e24dc990b 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -55,7 +55,8 @@ namespace osu.Game.Online.Leaderboards private List statisticsLabels; - private DialogOverlay dialogOverlay; + [Resolved] + private DialogOverlay dialogOverlay { get; set; } public LeaderboardScore(ScoreInfo score, int rank, bool allowHighlight = true) { @@ -68,10 +69,9 @@ namespace osu.Game.Online.Leaderboards } [BackgroundDependencyLoader] - private void load(IAPIProvider api, OsuColour colour, DialogOverlay overlay) + private void load(IAPIProvider api, OsuColour colour) { var user = score.User; - dialogOverlay = overlay; statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList(); diff --git a/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs b/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs index c9b6ca7bb3..b32416b361 100644 --- a/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs +++ b/osu.Game/Screens/Select/BeatmapClearScoresDialog.cs @@ -14,7 +14,8 @@ namespace osu.Game.Screens.Select { public class BeatmapClearScoresDialog : PopupDialog { - private ScoreManager scoreManager; + [Resolved] + private ScoreManager scoreManager { get; set; } public BeatmapClearScoresDialog(BeatmapInfo beatmap, Action onCompletion) { @@ -38,11 +39,5 @@ namespace osu.Game.Screens.Select }, }; } - - [BackgroundDependencyLoader] - private void load(ScoreManager scoreManager) - { - this.scoreManager = scoreManager; - } } } diff --git a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs index 514c5adf95..c1d680fd45 100644 --- a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs +++ b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs @@ -11,7 +11,8 @@ namespace osu.Game.Screens.Select { public class LocalScoreDeleteDialog : PopupDialog { - private ScoreManager scoreManager; + [Resolved] + private ScoreManager scoreManager { get; set; } public LocalScoreDeleteDialog(ScoreInfo score) { @@ -35,11 +36,5 @@ namespace osu.Game.Screens.Select }, }; } - - [BackgroundDependencyLoader] - private void load(ScoreManager scoreManager) - { - this.scoreManager = scoreManager; - } } } From ee15967c4a7faeae023fc2a0fe553f2bc64e641f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 6 Jan 2020 17:15:59 +0900 Subject: [PATCH 21/27] Rewrite test scene to be automated --- .../TestSceneDeleteLocalScore.cs | 255 +++++++++--------- 1 file changed, 120 insertions(+), 135 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index de10eaccca..e896b0fab6 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -3,20 +3,26 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; +using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Allocation; -using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Cursor; +using osu.Framework.MathUtils; +using osu.Framework.Platform; +using osu.Framework.Testing; using osu.Game.Beatmaps; -using osu.Game.Online.API; +using osu.Game.Graphics.Cursor; +using osu.Game.Graphics.UserInterface; using osu.Game.Online.Leaderboards; using osu.Game.Overlays; -using osu.Game.Overlays.Dialog; +using osu.Game.Rulesets; using osu.Game.Scoring; using osu.Game.Screens.Select.Leaderboards; +using osu.Game.Tests.Resources; using osu.Game.Users; using osuTK; +using osuTK.Input; namespace osu.Game.Tests.Visual.UserInterface { @@ -32,154 +38,133 @@ namespace osu.Game.Tests.Visual.UserInterface typeof(LeaderboardScore), }; - private readonly FailableLeaderboard leaderboard; + private readonly ContextMenuContainer contextMenuContainer; + private readonly BeatmapLeaderboard leaderboard; + + private RulesetStore rulesetStore; + private BeatmapManager beatmapManager; + private ScoreManager scoreManager; + + private readonly List scores = new List(); + private BeatmapInfo beatmap; [Cached] private readonly DialogOverlay dialogOverlay; public TestSceneDeleteLocalScore() { - Add(dialogOverlay = new DialogOverlay + Children = new Drawable[] { - Depth = -1 - }); - - Add(leaderboard = new FailableLeaderboard - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Size = new Vector2(550f, 450f), - Scope = BeatmapLeaderboardScope.Local, - Beatmap = new BeatmapInfo + contextMenuContainer = new OsuContextMenuContainer { - ID = 1, - Metadata = new BeatmapMetadata + RelativeSizeAxes = Axes.Both, + Child = leaderboard = new BeatmapLeaderboard { - ID = 1, - Title = "TestSong", - Artist = "TestArtist", - Author = new User + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Size = new Vector2(550f, 450f), + Scope = BeatmapLeaderboardScope.Local, + Beatmap = new BeatmapInfo { - Username = "TestAuthor" + ID = 1, + Metadata = new BeatmapMetadata + { + ID = 1, + Title = "TestSong", + Artist = "TestArtist", + Author = new User + { + Username = "TestAuthor" + }, + }, + Version = "Insane" }, - }, - Version = "Insane" + } }, + dialogOverlay = new DialogOverlay() + }; + } + + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); + + dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory)); + dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, Audio, dependencies.Get(), Beatmap.Default)); + dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, null, ContextFactory)); + + beatmap = beatmapManager.Import(TestResources.GetTestBeatmapForImport()).Result.Beatmaps[0]; + + for (int i = 0; i < 50; i++) + { + var score = new ScoreInfo + { + OnlineScoreID = i, + Beatmap = beatmap, + BeatmapInfoID = beatmap.ID, + Accuracy = RNG.NextDouble(), + TotalScore = RNG.Next(1, 1000000), + MaxCombo = RNG.Next(1, 1000), + Rank = ScoreRank.XH, + User = new User { Username = "TestUser" }, + }; + + scores.Add(scoreManager.Import(score).Result); + } + + scores.Sort(Comparer.Create((s1, s2) => s2.TotalScore.CompareTo(s1.TotalScore))); + + return dependencies; + } + + [SetUp] + public void Setup() => Schedule(() => + { + // Due to soft deletions, we can re-use deleted scores between test runs + scoreManager.Undelete(scoreManager.QueryScores(s => s.DeletePending).ToList()); + + leaderboard.Beatmap = beatmap; + leaderboard.RefreshScores(); + }); + + [Test] + public void TestDeleteViaRightClick() + { + // Ensure the leaderboard items have finished showing up + AddStep("finish transforms", () => leaderboard.FinishTransforms(true)); + + AddStep("open menu for top score", () => + { + InputManager.MoveMouseTo(leaderboard.ChildrenOfType().First()); + InputManager.Click(MouseButton.Right); }); - AddStep("Insert Local Scores", reset); + // Ensure the context menu has finished showing + AddStep("finish transforms", () => contextMenuContainer.FinishTransforms(true)); + + AddStep("click delete option", () => + { + InputManager.MoveMouseTo(contextMenuContainer.ChildrenOfType().First(i => i.Item.Text.Value.ToLowerInvariant() == "delete")); + InputManager.Click(MouseButton.Left); + }); + + // Ensure the dialog has finished showing + AddStep("finish transforms", () => dialogOverlay.FinishTransforms(true)); + + AddStep("click delete button", () => + { + InputManager.MoveMouseTo(dialogOverlay.ChildrenOfType().First()); + InputManager.Click(MouseButton.Left); + }); + + AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != scores[0].OnlineScoreID)); } - private void reset() + [Test] + public void TestDeleteViaDatabase() { - leaderboard.InitialLoad = true; - leaderboard.RefreshScores(); - } - - private class FailableLeaderboard : BeatmapLeaderboard - { - private List scoreList; - - private Random rnd; - - public bool InitialLoad; - - public void DeleteScore(ScoreInfo score) - { - scoreList.Remove(score); - RefreshScores(); - } - - public FailableLeaderboard() - { - InitialLoad = true; - } - - public void SetRetrievalState(PlaceholderState state) - { - PlaceholderState = state; - } - - protected override APIRequest FetchScores(Action> scoresCallback) - { - if (InitialLoad) - { - rnd = new Random(); - - scoreList = Enumerable.Range(1, 50).Select(createScore).ToList(); - Scores = scoreList.OrderByDescending(s => s.TotalScore).ToArray(); - - InitialLoad = false; - } - else - { - Scores = scoreList.OrderByDescending(s => s.TotalScore).ToArray(); - } - - return null; - } - - private ScoreInfo createScore(int id) => new ScoreInfo - { - ID = id, - Accuracy = rnd.NextDouble(), - PP = rnd.Next(1, 1000000), - TotalScore = rnd.Next(1, 1000000), - MaxCombo = rnd.Next(1, 1000), - Rank = ScoreRank.XH, - User = new User { Username = "TestUser" }, - }; - - protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) - { - model.Beatmap = Beatmap; - return new TestLeaderboardScore(model, index, this, IsOnlineScope); - } - } - - private class TestLeaderboardScore : LeaderboardScore - { - [Resolved] - private DialogOverlay dialogOverlay { get; set; } - - private readonly FailableLeaderboard leaderboard; - - public TestLeaderboardScore(ScoreInfo score, int rank, FailableLeaderboard leaderboard, bool allowHighlight = true) - : base(score, rank, allowHighlight) - { - this.leaderboard = leaderboard; - } - - protected override void DeleteLocalScore(ScoreInfo score) - { - dialogOverlay?.Push(new TestLocalScoreDeleteDialog(score, leaderboard)); - } - } - - private class TestLocalScoreDeleteDialog : PopupDialog - { - public TestLocalScoreDeleteDialog(ScoreInfo score, FailableLeaderboard leaderboard) - { - Debug.Assert(score != null); - - string accuracy = string.Format(score.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score.Accuracy); - - BodyText = $@"{score.User}'s {accuracy} {score.Rank} Rank on {score.Beatmap}"; - Icon = FontAwesome.Solid.Eraser; - HeaderText = @"Deleting this local score. Are you sure?"; - Buttons = new PopupDialogButton[] - { - new PopupDialogOkButton - { - Text = @"Yes. Please.", - Action = () => leaderboard.DeleteScore(score) - }, - new PopupDialogCancelButton - { - Text = @"No, I'm still attached.", - }, - }; - } + AddStep("delete top score", () => scoreManager.Delete(scores[0])); + AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineScoreID != scores[0].OnlineScoreID)); } } } From 4a7f5f98dff7ac42191e664fd98e8f9f67467a6a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 6 Jan 2020 17:20:09 +0900 Subject: [PATCH 22/27] Cleanup methods/events --- .../Online/Leaderboards/LeaderboardScore.cs | 7 +------ .../Select/Leaderboards/BeatmapLeaderboard.cs | 19 +++++++------------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index 7e24dc990b..9c7324d913 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -367,11 +367,6 @@ namespace osu.Game.Online.Leaderboards } } - protected virtual void DeleteLocalScore(ScoreInfo score) - { - dialogOverlay?.Push(new LocalScoreDeleteDialog(score)); - } - public MenuItem[] ContextMenuItems { get @@ -379,7 +374,7 @@ namespace osu.Game.Online.Leaderboards List items = new List(); if (score.ID != 0) - items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => DeleteLocalScore(score))); + items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new LocalScoreDeleteDialog(score)))); return items.ToArray(); } diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index 8442e91712..9cf328e900 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -104,7 +104,7 @@ namespace osu.Game.Screens.Select.Leaderboards ScoreSelected = s => ScoreSelected?.Invoke(s) }); - scoreManager.ItemRemoved += deleteLocalScore; + scoreManager.ItemRemoved += onScoreRemoved; } protected override void Reset() @@ -113,15 +113,7 @@ namespace osu.Game.Screens.Select.Leaderboards TopScore = null; } - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - - if (scoreManager != null) - { - scoreManager.ItemRemoved -= deleteLocalScore; - } - } + private void onScoreRemoved(ScoreInfo score) => Schedule(RefreshScores); protected override bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local; @@ -204,9 +196,12 @@ namespace osu.Game.Screens.Select.Leaderboards }; } - private void deleteLocalScore(ScoreInfo score) + protected override void Dispose(bool isDisposing) { - Schedule(RefreshScores); + base.Dispose(isDisposing); + + if (scoreManager != null) + scoreManager.ItemRemoved -= onScoreRemoved; } } } From 61c269b17b78e5e1b08c58b22a096e9043b4f1d8 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 6 Jan 2020 17:32:24 +0900 Subject: [PATCH 23/27] Leaderboard should not change the model --- .../Select/Leaderboards/BeatmapLeaderboard.cs | 11 +++-------- .../Screens/Select/LocalScoreDeleteDialog.cs | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index 9cf328e900..e36493c82f 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -186,15 +186,10 @@ namespace osu.Game.Screens.Select.Leaderboards return req; } - protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) + protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) => new LeaderboardScore(model, index, IsOnlineScope) { - model.Beatmap = beatmap; - - return new LeaderboardScore(model, index, IsOnlineScope) - { - Action = () => ScoreSelected?.Invoke(model) - }; - } + Action = () => ScoreSelected?.Invoke(model) + }; protected override void Dispose(bool isDisposing) { diff --git a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs index c1d680fd45..d607706fc3 100644 --- a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs +++ b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs @@ -6,21 +6,35 @@ using osu.Game.Overlays.Dialog; using osu.Game.Scoring; using System.Diagnostics; using osu.Framework.Graphics.Sprites; +using osu.Game.Beatmaps; namespace osu.Game.Screens.Select { public class LocalScoreDeleteDialog : PopupDialog { + private readonly ScoreInfo score; + [Resolved] private ScoreManager scoreManager { get; set; } + [Resolved] + private BeatmapManager beatmapManager { get; set; } + public LocalScoreDeleteDialog(ScoreInfo score) { + this.score = score; Debug.Assert(score != null); + } + + [BackgroundDependencyLoader] + private void load() + { + BeatmapInfo beatmap = beatmapManager.QueryBeatmap(b => b.ID == score.BeatmapInfoID); + Debug.Assert(beatmap != null); string accuracy = string.Format(score.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score.Accuracy); - BodyText = $@"{score.User}'s {accuracy} {score.Rank} Rank on {score.Beatmap}"; + BodyText = $@"{score.User}'s {accuracy} {score.Rank} Rank on {beatmap}"; Icon = FontAwesome.Solid.Eraser; HeaderText = @"Deleting this local score. Are you sure?"; Buttons = new PopupDialogButton[] @@ -28,7 +42,7 @@ namespace osu.Game.Screens.Select new PopupDialogOkButton { Text = @"Yes. Please.", - Action = () => scoreManager.Delete(score) + Action = () => scoreManager?.Delete(score) }, new PopupDialogCancelButton { From 28510674acee6420d4eb28add332b4981939c41f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 6 Jan 2020 17:46:38 +0900 Subject: [PATCH 24/27] Shorten body text --- osu.Game/Screens/Select/LocalScoreDeleteDialog.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs index d607706fc3..97df40fa6d 100644 --- a/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs +++ b/osu.Game/Screens/Select/LocalScoreDeleteDialog.cs @@ -32,21 +32,21 @@ namespace osu.Game.Screens.Select BeatmapInfo beatmap = beatmapManager.QueryBeatmap(b => b.ID == score.BeatmapInfoID); Debug.Assert(beatmap != null); - string accuracy = string.Format(score.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score.Accuracy); + string accuracy = string.Format(score.Accuracy == 1 ? "{0:P0}" : "{0:P2}", score.Accuracy); + BodyText = $"{score.User} ({accuracy}, {score.Rank})"; - BodyText = $@"{score.User}'s {accuracy} {score.Rank} Rank on {beatmap}"; - Icon = FontAwesome.Solid.Eraser; - HeaderText = @"Deleting this local score. Are you sure?"; + Icon = FontAwesome.Regular.TrashAlt; + HeaderText = "Confirm deletion of local score"; Buttons = new PopupDialogButton[] { new PopupDialogOkButton { - Text = @"Yes. Please.", + Text = "Yes. Please.", Action = () => scoreManager?.Delete(score) }, new PopupDialogCancelButton { - Text = @"No, I'm still attached.", + Text = "No, I'm still attached.", }, }; } From 4a68c791375248441fcb307a0a903aa502c23c2e Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 7 Jan 2020 13:06:30 +0900 Subject: [PATCH 25/27] Make tests safer against async loads / transforms --- .../UserInterface/TestSceneDeleteLocalScore.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index e896b0fab6..289c01fbf3 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -123,16 +123,26 @@ namespace osu.Game.Tests.Visual.UserInterface // Due to soft deletions, we can re-use deleted scores between test runs scoreManager.Undelete(scoreManager.QueryScores(s => s.DeletePending).ToList()); + leaderboard.Scores = null; + leaderboard.FinishTransforms(true); // After setting scores, we may be waiting for transforms to expire drawables + leaderboard.Beatmap = beatmap; - leaderboard.RefreshScores(); + leaderboard.RefreshScores(); // Required in the case that the beatmap hasn't changed }); + [SetUpSteps] + public void SetupSteps() + { + // Ensure the leaderboard has finished async-loading drawables + AddUntilStep("wait for drawables", () => leaderboard.ChildrenOfType().Any()); + + // Ensure the leaderboard items have finished showing up + AddStep("finish transforms", () => leaderboard.FinishTransforms(true)); + } + [Test] public void TestDeleteViaRightClick() { - // Ensure the leaderboard items have finished showing up - AddStep("finish transforms", () => leaderboard.FinishTransforms(true)); - AddStep("open menu for top score", () => { InputManager.MoveMouseTo(leaderboard.ChildrenOfType().First()); From 26c80e35fbdeb7af8ecdb144628b863e3b1d25ee Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 9 Jan 2020 17:17:08 +0800 Subject: [PATCH 26/27] Fix missing namespace --- osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index 289c01fbf3..d2ac1bf079 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -15,6 +15,7 @@ using osu.Game.Beatmaps; using osu.Game.Graphics.Cursor; using osu.Game.Graphics.UserInterface; using osu.Game.Online.Leaderboards; +using osu.Game.Online.Placeholders; using osu.Game.Overlays; using osu.Game.Rulesets; using osu.Game.Scoring; From 14829837c467c07c2eae8445e9e1c7dfce262006 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 10 Jan 2020 01:38:03 +0800 Subject: [PATCH 27/27] Update namespace specifications --- .../Visual/UserInterface/TestSceneDeleteLocalScore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs index d2ac1bf079..1e5e26e4c5 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneDeleteLocalScore.cs @@ -8,9 +8,9 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Allocation; using osu.Framework.Graphics.Cursor; -using osu.Framework.MathUtils; using osu.Framework.Platform; using osu.Framework.Testing; +using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Graphics.Cursor; using osu.Game.Graphics.UserInterface;