1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +08:00

Cleanup draggedItem usages and make them more safe

This commit is contained in:
smoogipoo 2019-09-19 13:53:52 +09:00
parent 0644443979
commit 4b97327b37

View File

@ -87,25 +87,24 @@ namespace osu.Game.Overlays.Music
beatmapBacking.ValueChanged += _ => updateSelectedSet();
}
private void addBeatmapSet(BeatmapSetInfo obj) => Schedule(() =>
{
if (obj == draggedItem?.BeatmapSetInfo)
{
draggedItem = null;
return;
}
items.Insert(items.Count - 1, new PlaylistItem(obj) { OnSelect = set => Selected?.Invoke(set) });
});
private void removeBeatmapSet(BeatmapSetInfo obj) => Schedule(() =>
private void addBeatmapSet(BeatmapSetInfo obj)
{
if (obj == draggedItem?.BeatmapSetInfo) return;
var itemToRemove = items.FirstOrDefault(i => i.BeatmapSetInfo.ID == obj.ID);
if (itemToRemove != null)
items.Remove(itemToRemove);
});
Schedule(() => items.Insert(items.Count - 1, new PlaylistItem(obj) { OnSelect = set => Selected?.Invoke(set) }));
}
private void removeBeatmapSet(BeatmapSetInfo obj)
{
if (obj == draggedItem?.BeatmapSetInfo) return;
Schedule(() =>
{
var itemToRemove = items.FirstOrDefault(i => i.BeatmapSetInfo.ID == obj.ID);
if (itemToRemove != null)
items.Remove(itemToRemove);
});
}
private void updateSelectedSet()
{
@ -146,19 +145,16 @@ namespace osu.Game.Overlays.Music
{
nativeDragPosition = e.ScreenSpaceMousePosition;
if (draggedItem != null)
{
if (dragDestination != null)
{
// draggedItem is nulled when the BindableList's add event is received so we can quietly ignore the callbacks.
musicController.ChangeBeatmapSetPosition(draggedItem.BeatmapSetInfo, dragDestination.Value);
dragDestination = null;
}
if (draggedItem == null)
return base.OnDragEnd(e);
return true;
}
if (dragDestination != null)
musicController.ChangeBeatmapSetPosition(draggedItem.BeatmapSetInfo, dragDestination.Value);
return base.OnDragEnd(e);
draggedItem = null;
dragDestination = null;
return true;
}
protected override void Update()