mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Adds hard-delete for a beatmap diff
This commit is contained in:
parent
3febd6d644
commit
dd315ff97b
@ -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>
|
||||
/// Delete videos from a list of beatmaps.
|
||||
/// This will post notifications tracking progress.
|
||||
|
@ -851,7 +851,16 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
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()
|
||||
@ -859,8 +868,19 @@ namespace osu.Game.Screens.Edit
|
||||
var current = playableBeatmap.BeatmapInfo;
|
||||
if (current is null) return;
|
||||
|
||||
beatmapManager.Hide(current);
|
||||
this.Exit();
|
||||
beatmapManager.DeleteLocal(current);
|
||||
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()
|
||||
|
@ -9,7 +9,7 @@ namespace osu.Game.Screens.Edit
|
||||
{
|
||||
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?";
|
||||
|
||||
@ -17,9 +17,14 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
Buttons = new PopupDialogButton[]
|
||||
{
|
||||
new PopupDialogOkButton
|
||||
{
|
||||
Text = @"Hide this difficulty instead (recommended)",
|
||||
Action = hide
|
||||
},
|
||||
new PopupDialogDangerousButton
|
||||
{
|
||||
Text = @"Yes, delete this difficulty!",
|
||||
Text = @"Yes, DELETE this difficulty!",
|
||||
Action = delete
|
||||
},
|
||||
new PopupDialogCancelButton
|
||||
|
Loading…
Reference in New Issue
Block a user