Adds hard-delete for a beatmap diff

This commit is contained in:
Micahel Kelly 2022-07-27 21:21:16 +10:00
parent 3febd6d644
commit dd315ff97b
3 changed files with 55 additions and 5 deletions

View File

@ -358,6 +358,31 @@ namespace osu.Game.Beatmaps
}); });
} }
/// <summary>
/// Hard-Delete a beatmap difficulty locally.
/// </summary>
/// <remarks><see cref="Hide"/> is generally preferred as it keeps the local beatmap set in sync with the server.</remarks>
/// <param name="beatmapInfo">The beatmap difficulty to hide.</param>
public void DeleteLocal(BeatmapInfo beatmapInfo)
{
Realm.Run(r =>
{
using (var transaction = r.BeginWrite())
{
if (!beatmapInfo.IsManaged)
beatmapInfo = r.Find<BeatmapInfo>(beatmapInfo.ID);
var setInfo = beatmapInfo.BeatmapSet!;
DeleteFile(setInfo, beatmapInfo.File!);
setInfo.Beatmaps.Remove(beatmapInfo);
var liveSetInfo = r.Find<BeatmapSetInfo>(setInfo.ID);
setInfo.CopyChangesToRealm(liveSetInfo);
transaction.Commit();
}
});
}
/// <summary> /// <summary>
/// Delete videos from a list of beatmaps. /// Delete videos from a list of beatmaps.
/// This will post notifications tracking progress. /// This will post notifications tracking progress.

View File

@ -851,7 +851,16 @@ namespace osu.Game.Screens.Edit
private void deleteDifficulty() private void deleteDifficulty()
{ {
dialogOverlay?.Push(new PromptForDifficultyDeleteDialog(confirmDifficultyDelete, () => { })); dialogOverlay?.Push(new PromptForDifficultyDeleteDialog(confirmDifficultyHide, confirmDifficultyDelete, () => { }));
}
private void confirmDifficultyHide()
{
var current = playableBeatmap.BeatmapInfo;
if (current is null) return;
beatmapManager.Hide(current);
switchBeatmapOrExit(current.BeatmapSet);
} }
private void confirmDifficultyDelete() private void confirmDifficultyDelete()
@ -859,8 +868,19 @@ namespace osu.Game.Screens.Edit
var current = playableBeatmap.BeatmapInfo; var current = playableBeatmap.BeatmapInfo;
if (current is null) return; if (current is null) return;
beatmapManager.Hide(current); beatmapManager.DeleteLocal(current);
this.Exit(); switchBeatmapOrExit(current.BeatmapSet);
}
private void switchBeatmapOrExit([CanBeNull] BeatmapSetInfo setInfo)
{
if (setInfo is null || setInfo.Beatmaps.Count() <= 1)
this.Exit();
var nextBeatmap = setInfo!.Beatmaps.First();
// Force a refresh of the beatmap (and beatmap set) so the `Change difficulty` list is also updated.
Beatmap.Value = beatmapManager.GetWorkingBeatmap(nextBeatmap, true);
SwitchToDifficulty(Beatmap.Value.BeatmapInfo);
} }
private void updateLastSavedHash() private void updateLastSavedHash()

View File

@ -9,7 +9,7 @@ namespace osu.Game.Screens.Edit
{ {
public class PromptForDifficultyDeleteDialog : PopupDialog public class PromptForDifficultyDeleteDialog : PopupDialog
{ {
public PromptForDifficultyDeleteDialog(Action delete, Action cancel) public PromptForDifficultyDeleteDialog(Action hide, Action delete, Action cancel)
{ {
HeaderText = "Are you sure you want to delete this difficulty?"; HeaderText = "Are you sure you want to delete this difficulty?";
@ -17,9 +17,14 @@ namespace osu.Game.Screens.Edit
Buttons = new PopupDialogButton[] Buttons = new PopupDialogButton[]
{ {
new PopupDialogOkButton
{
Text = @"Hide this difficulty instead (recommended)",
Action = hide
},
new PopupDialogDangerousButton new PopupDialogDangerousButton
{ {
Text = @"Yes, delete this difficulty!", Text = @"Yes, DELETE this difficulty!",
Action = delete Action = delete
}, },
new PopupDialogCancelButton new PopupDialogCancelButton