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; + } + } +}