1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 14:13:01 +08:00

Add beatmap deletion support.

Note that this is a very naive approach and will result in file access exceptions. This will be fixed in a further commit.
This commit is contained in:
Dean Herbert 2017-02-24 14:37:54 +09:00
parent 3a89348413
commit 6c3bda18b6
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
4 changed files with 61 additions and 7 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -22,6 +23,7 @@ namespace osu.Game.Database
private SQLiteConnection connection { get; set; }
private Storage storage;
public event Action<BeatmapSetInfo> BeatmapSetAdded;
public event Action<BeatmapSetInfo> BeatmapSetRemoved;
private BeatmapImporter ipc;
@ -157,6 +159,13 @@ namespace osu.Game.Database
connection.Commit();
}
public void Delete(BeatmapSetInfo beatmapSet)
{
storage.Delete(beatmapSet.Path);
connection.Delete(beatmapSet);
BeatmapSetRemoved?.Invoke(beatmapSet);
}
public ArchiveReader GetReader(BeatmapSetInfo beatmapSet)
{
if (string.IsNullOrEmpty(beatmapSet.Path))

View File

@ -254,14 +254,16 @@ namespace osu.Game.Overlays
{
progress.IsEnabled = (beatmapSource.Value != null);
if (beatmapSource.Value == current) return;
bool audioEquals = current?.BeatmapInfo.AudioEquals(beatmapSource.Value.BeatmapInfo) ?? false;
bool audioEquals = current?.BeatmapInfo?.AudioEquals(beatmapSource?.Value?.BeatmapInfo) ?? false;
current = beatmapSource.Value;
updateDisplay(current, audioEquals ? TransformDirection.None : TransformDirection.Next);
appendToHistory(current.BeatmapInfo);
appendToHistory(current?.BeatmapInfo);
}
private void appendToHistory(BeatmapInfo beatmap)
{
if (beatmap == null) return;
if (playHistoryIndex >= 0)
{
if (beatmap.AudioEquals(playHistory[playHistoryIndex]))

View File

@ -15,6 +15,7 @@ using osu.Framework.Timing;
using osu.Framework.Input;
using OpenTK.Input;
using System.Collections;
using System.Diagnostics;
using osu.Framework.MathUtils;
namespace osu.Game.Screens.Select
@ -95,6 +96,15 @@ namespace osu.Game.Screens.Select
computeYPositions();
}
public void RemoveGroup(BeatmapGroup group)
{
groups.Remove(group);
scrollableContent.Remove(group.Header);
scrollableContent.Remove(group.BeatmapPanels);
computeYPositions();
}
private void movePanel(Panel panel, bool advance, bool animated, ref float currentY)
{
yPositions.Add(currentY);
@ -276,6 +286,12 @@ namespace osu.Game.Screens.Select
if (direction == 0)
return base.OnKeyDown(state, args);
SelectNext(direction, skipDifficulties);
return true;
}
public void SelectNext(int direction = 1, bool skipDifficulties = true)
{
if (!skipDifficulties)
{
int i = SelectedGroup.BeatmapPanels.IndexOf(SelectedPanel) + direction;
@ -284,7 +300,7 @@ namespace osu.Game.Screens.Select
{
//changing difficulty panel, not set.
SelectGroup(SelectedGroup, SelectedGroup.BeatmapPanels[i]);
return true;
return;
}
}
@ -297,11 +313,9 @@ namespace osu.Game.Screens.Select
if (groups[index].State != BeatmapGroupState.Hidden)
{
SelectBeatmap(groups[index].BeatmapPanels.First().Beatmap);
return true;
return;
}
} while (index != startIndex);
return true;
}
public void SelectRandom()

View File

@ -139,6 +139,7 @@ namespace osu.Game.Screens.Select
database = beatmaps;
database.BeatmapSetAdded += onDatabaseOnBeatmapSetAdded;
database.BeatmapSetRemoved += onDatabaseOnBeatmapSetRemoved;
trackManager = audio.Track;
@ -189,6 +190,11 @@ namespace osu.Game.Screens.Select
Schedule(() => addBeatmapSet(s, Game, true));
}
private void onDatabaseOnBeatmapSetRemoved(BeatmapSetInfo s)
{
Schedule(() => removeBeatmapSet(s));
}
protected override void OnEntering(Screen last)
{
base.OnEntering(last);
@ -247,6 +253,7 @@ namespace osu.Game.Screens.Select
playMode.ValueChanged -= playMode_ValueChanged;
database.BeatmapSetAdded -= onDatabaseOnBeatmapSetAdded;
database.BeatmapSetRemoved -= onDatabaseOnBeatmapSetRemoved;
initialAddSetsTask.Cancel();
}
@ -278,7 +285,7 @@ namespace osu.Game.Screens.Select
//todo: change background in selectionChanged instead; support per-difficulty backgrounds.
changeBackground(beatmap);
carousel.SelectBeatmap(beatmap.BeatmapInfo);
carousel.SelectBeatmap(beatmap?.BeatmapInfo);
}
/// <summary>
@ -353,6 +360,21 @@ namespace osu.Game.Screens.Select
}));
}
private void removeBeatmapSet(BeatmapSetInfo beatmapSet)
{
var group = beatmapGroups.Find(b => b.BeatmapSet.ID == beatmapSet.ID);
if (group == null) return;
if (carousel.SelectedGroup == group)
carousel.SelectNext();
beatmapGroups.Remove(group);
carousel.RemoveGroup(group);
if (beatmapGroups.Count == 0)
Beatmap = null;
}
private void addBeatmapSets(Framework.Game game, CancellationToken token)
{
foreach (var beatmapSet in database.Query<BeatmapSetInfo>())
@ -369,6 +391,13 @@ namespace osu.Game.Screens.Select
case Key.Enter:
footer.StartButton.TriggerClick();
return true;
case Key.Delete:
if (Beatmap != null)
{
Beatmap.Dispose();
database.Delete(Beatmap.BeatmapSetInfo);
}
return true;
}
return base.OnKeyDown(state, args);