mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09: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:
@ -2,6 +2,7 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -22,6 +23,7 @@ namespace osu.Game.Database
|
|||||||
private SQLiteConnection connection { get; set; }
|
private SQLiteConnection connection { get; set; }
|
||||||
private Storage storage;
|
private Storage storage;
|
||||||
public event Action<BeatmapSetInfo> BeatmapSetAdded;
|
public event Action<BeatmapSetInfo> BeatmapSetAdded;
|
||||||
|
public event Action<BeatmapSetInfo> BeatmapSetRemoved;
|
||||||
|
|
||||||
private BeatmapImporter ipc;
|
private BeatmapImporter ipc;
|
||||||
|
|
||||||
@ -157,6 +159,13 @@ namespace osu.Game.Database
|
|||||||
connection.Commit();
|
connection.Commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Delete(BeatmapSetInfo beatmapSet)
|
||||||
|
{
|
||||||
|
storage.Delete(beatmapSet.Path);
|
||||||
|
connection.Delete(beatmapSet);
|
||||||
|
BeatmapSetRemoved?.Invoke(beatmapSet);
|
||||||
|
}
|
||||||
|
|
||||||
public ArchiveReader GetReader(BeatmapSetInfo beatmapSet)
|
public ArchiveReader GetReader(BeatmapSetInfo beatmapSet)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(beatmapSet.Path))
|
if (string.IsNullOrEmpty(beatmapSet.Path))
|
||||||
|
@ -254,14 +254,16 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
progress.IsEnabled = (beatmapSource.Value != null);
|
progress.IsEnabled = (beatmapSource.Value != null);
|
||||||
if (beatmapSource.Value == current) return;
|
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;
|
current = beatmapSource.Value;
|
||||||
updateDisplay(current, audioEquals ? TransformDirection.None : TransformDirection.Next);
|
updateDisplay(current, audioEquals ? TransformDirection.None : TransformDirection.Next);
|
||||||
appendToHistory(current.BeatmapInfo);
|
appendToHistory(current?.BeatmapInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendToHistory(BeatmapInfo beatmap)
|
private void appendToHistory(BeatmapInfo beatmap)
|
||||||
{
|
{
|
||||||
|
if (beatmap == null) return;
|
||||||
|
|
||||||
if (playHistoryIndex >= 0)
|
if (playHistoryIndex >= 0)
|
||||||
{
|
{
|
||||||
if (beatmap.AudioEquals(playHistory[playHistoryIndex]))
|
if (beatmap.AudioEquals(playHistory[playHistoryIndex]))
|
||||||
|
@ -15,6 +15,7 @@ using osu.Framework.Timing;
|
|||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Diagnostics;
|
||||||
using osu.Framework.MathUtils;
|
using osu.Framework.MathUtils;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select
|
namespace osu.Game.Screens.Select
|
||||||
@ -95,6 +96,15 @@ namespace osu.Game.Screens.Select
|
|||||||
computeYPositions();
|
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)
|
private void movePanel(Panel panel, bool advance, bool animated, ref float currentY)
|
||||||
{
|
{
|
||||||
yPositions.Add(currentY);
|
yPositions.Add(currentY);
|
||||||
@ -276,6 +286,12 @@ namespace osu.Game.Screens.Select
|
|||||||
if (direction == 0)
|
if (direction == 0)
|
||||||
return base.OnKeyDown(state, args);
|
return base.OnKeyDown(state, args);
|
||||||
|
|
||||||
|
SelectNext(direction, skipDifficulties);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SelectNext(int direction = 1, bool skipDifficulties = true)
|
||||||
|
{
|
||||||
if (!skipDifficulties)
|
if (!skipDifficulties)
|
||||||
{
|
{
|
||||||
int i = SelectedGroup.BeatmapPanels.IndexOf(SelectedPanel) + direction;
|
int i = SelectedGroup.BeatmapPanels.IndexOf(SelectedPanel) + direction;
|
||||||
@ -284,7 +300,7 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
//changing difficulty panel, not set.
|
//changing difficulty panel, not set.
|
||||||
SelectGroup(SelectedGroup, SelectedGroup.BeatmapPanels[i]);
|
SelectGroup(SelectedGroup, SelectedGroup.BeatmapPanels[i]);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,11 +313,9 @@ namespace osu.Game.Screens.Select
|
|||||||
if (groups[index].State != BeatmapGroupState.Hidden)
|
if (groups[index].State != BeatmapGroupState.Hidden)
|
||||||
{
|
{
|
||||||
SelectBeatmap(groups[index].BeatmapPanels.First().Beatmap);
|
SelectBeatmap(groups[index].BeatmapPanels.First().Beatmap);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
} while (index != startIndex);
|
} while (index != startIndex);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectRandom()
|
public void SelectRandom()
|
||||||
|
@ -139,6 +139,7 @@ namespace osu.Game.Screens.Select
|
|||||||
database = beatmaps;
|
database = beatmaps;
|
||||||
|
|
||||||
database.BeatmapSetAdded += onDatabaseOnBeatmapSetAdded;
|
database.BeatmapSetAdded += onDatabaseOnBeatmapSetAdded;
|
||||||
|
database.BeatmapSetRemoved += onDatabaseOnBeatmapSetRemoved;
|
||||||
|
|
||||||
trackManager = audio.Track;
|
trackManager = audio.Track;
|
||||||
|
|
||||||
@ -189,6 +190,11 @@ namespace osu.Game.Screens.Select
|
|||||||
Schedule(() => addBeatmapSet(s, Game, true));
|
Schedule(() => addBeatmapSet(s, Game, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onDatabaseOnBeatmapSetRemoved(BeatmapSetInfo s)
|
||||||
|
{
|
||||||
|
Schedule(() => removeBeatmapSet(s));
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnEntering(Screen last)
|
protected override void OnEntering(Screen last)
|
||||||
{
|
{
|
||||||
base.OnEntering(last);
|
base.OnEntering(last);
|
||||||
@ -247,6 +253,7 @@ namespace osu.Game.Screens.Select
|
|||||||
playMode.ValueChanged -= playMode_ValueChanged;
|
playMode.ValueChanged -= playMode_ValueChanged;
|
||||||
|
|
||||||
database.BeatmapSetAdded -= onDatabaseOnBeatmapSetAdded;
|
database.BeatmapSetAdded -= onDatabaseOnBeatmapSetAdded;
|
||||||
|
database.BeatmapSetRemoved -= onDatabaseOnBeatmapSetRemoved;
|
||||||
|
|
||||||
initialAddSetsTask.Cancel();
|
initialAddSetsTask.Cancel();
|
||||||
}
|
}
|
||||||
@ -278,7 +285,7 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
//todo: change background in selectionChanged instead; support per-difficulty backgrounds.
|
//todo: change background in selectionChanged instead; support per-difficulty backgrounds.
|
||||||
changeBackground(beatmap);
|
changeBackground(beatmap);
|
||||||
carousel.SelectBeatmap(beatmap.BeatmapInfo);
|
carousel.SelectBeatmap(beatmap?.BeatmapInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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)
|
private void addBeatmapSets(Framework.Game game, CancellationToken token)
|
||||||
{
|
{
|
||||||
foreach (var beatmapSet in database.Query<BeatmapSetInfo>())
|
foreach (var beatmapSet in database.Query<BeatmapSetInfo>())
|
||||||
@ -369,6 +391,13 @@ namespace osu.Game.Screens.Select
|
|||||||
case Key.Enter:
|
case Key.Enter:
|
||||||
footer.StartButton.TriggerClick();
|
footer.StartButton.TriggerClick();
|
||||||
return true;
|
return true;
|
||||||
|
case Key.Delete:
|
||||||
|
if (Beatmap != null)
|
||||||
|
{
|
||||||
|
Beatmap.Dispose();
|
||||||
|
database.Delete(Beatmap.BeatmapSetInfo);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnKeyDown(state, args);
|
return base.OnKeyDown(state, args);
|
||||||
|
Reference in New Issue
Block a user