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