From ab462a232f50977dd22a485e2a6296bcd022d320 Mon Sep 17 00:00:00 2001 From: Matthias Coenraerds Date: Fri, 4 Jan 2019 20:13:32 +0100 Subject: [PATCH] Implement clear scores on beatmap --- osu.Game/Scoring/ScoreManager.cs | 4 +- osu.Game/Screens/Select/ClearScoreDialog.cs | 46 +++++++++++++++++++ .../Select/Leaderboards/BeatmapLeaderboard.cs | 2 +- osu.Game/Screens/Select/SongSelect.cs | 23 +++++++--- 4 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 osu.Game/Screens/Select/ClearScoreDialog.cs diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 663f441f2f..fc50178ba8 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -55,9 +55,7 @@ protected override ScoreInfo CreateModel(ArchiveReader archive) public Score GetScore(ScoreInfo score) => new LegacyDatabasedScore(score, rulesets, beatmaps, Files.Store); - public List GetAllUsableScores() => ModelStore.ConsumableItems.Where(s => !s.DeletePending).ToList(); - - public IEnumerable QueryScores(Expression> query) => ModelStore.ConsumableItems.AsNoTracking().Where(query); + public IEnumerable GetAllUsableScores() => ModelStore.ConsumableItems.Where(s => !s.DeletePending); public ScoreInfo Query(Expression> query) => ModelStore.ConsumableItems.AsNoTracking().FirstOrDefault(query); } diff --git a/osu.Game/Screens/Select/ClearScoreDialog.cs b/osu.Game/Screens/Select/ClearScoreDialog.cs new file mode 100644 index 0000000000..38577902e9 --- /dev/null +++ b/osu.Game/Screens/Select/ClearScoreDialog.cs @@ -0,0 +1,46 @@ +using osu.Framework.Allocation; +using osu.Game.Beatmaps; +using osu.Game.Graphics; +using osu.Game.Overlays.Dialog; +using osu.Game.Scoring; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace osu.Game.Screens.Select +{ + public class ClearScoresDialog : PopupDialog + { + private ScoreManager manager; + + [BackgroundDependencyLoader] + private void load(ScoreManager beatmapManager) + { + manager = beatmapManager; + } + + public ClearScoresDialog(BeatmapSetInfo beatmap, IEnumerable scores, Action refresh) + { + BodyText = $@"{beatmap.Metadata?.Artist} - {beatmap.Metadata?.Title}"; + + Icon = FontAwesome.fa_eraser; + HeaderText = $@"Clearing {scores.Count()} local score(s). Are you sure?"; + Buttons = new PopupDialogButton[] + { + new PopupDialogOkButton + { + Text = @"Yes. Please.", + Action = () => + { + manager.Delete(scores.ToList()); + refresh(); + } + }, + new PopupDialogCancelButton + { + Text = @"No, I'm still attached.", + }, + }; + } + } +} diff --git a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs index 9f8726c86a..8d91be9ca1 100644 --- a/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs @@ -55,7 +55,7 @@ protected override APIRequest FetchScores(Action> scoresC { if (Scope == BeatmapLeaderboardScope.Local) { - Scores = scoreManager.QueryScores(s => s.Beatmap.ID == Beatmap.ID).ToArray(); + Scores = scoreManager.GetAllUsableScores().Where(s => s.Beatmap.ID == Beatmap.ID).ToArray(); PlaceholderState = Scores.Any() ? PlaceholderState.Successful : PlaceholderState.NoScores; return null; } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index f65cc0e49d..e70ff42418 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -1,11 +1,6 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using System.Collections.Generic; -using System.Linq; -using osuTK; -using osuTK.Input; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; @@ -13,8 +8,8 @@ using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Logging; using osu.Framework.Input.Events; +using osu.Framework.Logging; using osu.Framework.Screens; using osu.Framework.Threading; using osu.Game.Beatmaps; @@ -31,6 +26,11 @@ using osu.Game.Screens.Play; using osu.Game.Screens.Select.Options; using osu.Game.Skinning; +using osuTK; +using osuTK.Input; +using System; +using System.Collections.Generic; +using System.Linq; namespace osu.Game.Screens.Select { @@ -227,7 +227,7 @@ private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dia BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.fa_trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo), Key.Number4, float.MaxValue); BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.fa_times_circle_o, colours.Purple, null, Key.Number1); - BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.fa_eraser, colours.Purple, null, Key.Number2); + BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.fa_eraser, colours.Purple, () => clearScores(Beatmap.Value.BeatmapSetInfo), Key.Number2); } if (this.beatmaps == null) @@ -625,6 +625,15 @@ private void delete(BeatmapSetInfo beatmap) dialogOverlay?.Push(new BeatmapDeleteDialog(beatmap)); } + private void clearScores(BeatmapSetInfo beatmap) + { + if (beatmap == null || beatmap.ID <= 0) return; + + if (BeatmapDetails.Leaderboard.Scores == null || !BeatmapDetails.Leaderboard.Scores.Any()) return; + + dialogOverlay?.Push(new ClearScoresDialog(beatmap, BeatmapDetails.Leaderboard.Scores, () => BeatmapDetails.Leaderboard.RefreshScores())); + } + public override bool OnPressed(GlobalAction action) { if (!IsCurrentScreen) return false;