mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 18:42:56 +08:00
Localise OrderChanged handling and fix callbacks
The dragged item's position now only updates after the drag finishes. Local handling changes were required to ignore the bindable remove/add events that are fired as a result.
This commit is contained in:
parent
7e791f7cd7
commit
91bdece9af
@ -19,7 +19,6 @@ namespace osu.Game.Overlays.Music
|
|||||||
public class PlaylistList : CompositeDrawable
|
public class PlaylistList : CompositeDrawable
|
||||||
{
|
{
|
||||||
public Action<BeatmapSetInfo> Selected;
|
public Action<BeatmapSetInfo> Selected;
|
||||||
public Action<BeatmapSetInfo, int> OrderChanged;
|
|
||||||
|
|
||||||
private readonly ItemsScrollContainer items;
|
private readonly ItemsScrollContainer items;
|
||||||
|
|
||||||
@ -29,7 +28,6 @@ namespace osu.Game.Overlays.Music
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Selected = set => Selected?.Invoke(set),
|
Selected = set => Selected?.Invoke(set),
|
||||||
OrderChanged = (s, i) => OrderChanged?.Invoke(s, i)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,16 +43,17 @@ namespace osu.Game.Overlays.Music
|
|||||||
|
|
||||||
private class ItemsScrollContainer : OsuScrollContainer
|
private class ItemsScrollContainer : OsuScrollContainer
|
||||||
{
|
{
|
||||||
private BindableList<BeatmapSetInfo> beatmaps;
|
private IBindableList<BeatmapSetInfo> beatmaps;
|
||||||
|
|
||||||
public Action<BeatmapSetInfo> Selected;
|
public Action<BeatmapSetInfo> Selected;
|
||||||
public Action<BeatmapSetInfo, int> OrderChanged;
|
|
||||||
|
|
||||||
private readonly SearchContainer search;
|
private readonly SearchContainer search;
|
||||||
private readonly FillFlowContainer<PlaylistItem> items;
|
private readonly FillFlowContainer<PlaylistItem> items;
|
||||||
|
|
||||||
private readonly IBindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>();
|
private readonly IBindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>();
|
||||||
|
|
||||||
|
private MusicController musicController;
|
||||||
|
|
||||||
public ItemsScrollContainer()
|
public ItemsScrollContainer()
|
||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -78,6 +77,8 @@ namespace osu.Game.Overlays.Music
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(MusicController musicController, IBindable<WorkingBeatmap> beatmap)
|
private void load(MusicController musicController, IBindable<WorkingBeatmap> beatmap)
|
||||||
{
|
{
|
||||||
|
this.musicController = musicController;
|
||||||
|
|
||||||
beatmaps = musicController.BeatmapSets.GetBoundCopy();
|
beatmaps = musicController.BeatmapSets.GetBoundCopy();
|
||||||
|
|
||||||
beatmaps.ItemsAdded += i => i.ForEach(addBeatmapSet);
|
beatmaps.ItemsAdded += i => i.ForEach(addBeatmapSet);
|
||||||
@ -88,10 +89,21 @@ namespace osu.Game.Overlays.Music
|
|||||||
beatmapBacking.ValueChanged += _ => updateSelectedSet();
|
beatmapBacking.ValueChanged += _ => updateSelectedSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBeatmapSet(BeatmapSetInfo obj) => Schedule(() => { items.Insert(items.Count - 1, new PlaylistItem(obj) { OnSelect = set => Selected?.Invoke(set) }); });
|
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 removeBeatmapSet(BeatmapSetInfo obj) => Schedule(() =>
|
||||||
{
|
{
|
||||||
|
if (obj == draggedItem?.BeatmapSetInfo) return;
|
||||||
|
|
||||||
var itemToRemove = items.FirstOrDefault(i => i.BeatmapSetInfo.ID == obj.ID);
|
var itemToRemove = items.FirstOrDefault(i => i.BeatmapSetInfo.ID == obj.ID);
|
||||||
if (itemToRemove != null)
|
if (itemToRemove != null)
|
||||||
items.Remove(itemToRemove);
|
items.Remove(itemToRemove);
|
||||||
@ -114,6 +126,8 @@ namespace osu.Game.Overlays.Music
|
|||||||
private Vector2 nativeDragPosition;
|
private Vector2 nativeDragPosition;
|
||||||
private PlaylistItem draggedItem;
|
private PlaylistItem draggedItem;
|
||||||
|
|
||||||
|
private int? dragDestination;
|
||||||
|
|
||||||
protected override bool OnDragStart(DragStartEvent e)
|
protected override bool OnDragStart(DragStartEvent e)
|
||||||
{
|
{
|
||||||
nativeDragPosition = e.ScreenSpaceMousePosition;
|
nativeDragPosition = e.ScreenSpaceMousePosition;
|
||||||
@ -133,10 +147,20 @@ namespace osu.Game.Overlays.Music
|
|||||||
protected override bool OnDragEnd(DragEndEvent e)
|
protected override bool OnDragEnd(DragEndEvent e)
|
||||||
{
|
{
|
||||||
nativeDragPosition = e.ScreenSpaceMousePosition;
|
nativeDragPosition = e.ScreenSpaceMousePosition;
|
||||||
var handled = draggedItem != null || base.OnDragEnd(e);
|
|
||||||
draggedItem = null;
|
|
||||||
|
|
||||||
return handled;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.OnDragEnd(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
@ -212,7 +236,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
}
|
}
|
||||||
|
|
||||||
items.SetLayoutPosition(draggedItem, dstIndex);
|
items.SetLayoutPosition(draggedItem, dstIndex);
|
||||||
OrderChanged?.Invoke(draggedItem.BeatmapSetInfo, dstIndex);
|
dragDestination = dstIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ItemSearchContainer : FillFlowContainer<PlaylistItem>, IHasFilterableChildren
|
private class ItemSearchContainer : FillFlowContainer<PlaylistItem>, IHasFilterableChildren
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -22,12 +21,6 @@ namespace osu.Game.Overlays.Music
|
|||||||
private const float transition_duration = 600;
|
private const float transition_duration = 600;
|
||||||
private const float playlist_height = 510;
|
private const float playlist_height = 510;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked when the order of an item in the list has changed.
|
|
||||||
/// The second parameter indicates the new index of the item.
|
|
||||||
/// </summary>
|
|
||||||
public Action<BeatmapSetInfo, int> OrderChanged;
|
|
||||||
|
|
||||||
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
||||||
private BeatmapManager beatmaps;
|
private BeatmapManager beatmaps;
|
||||||
|
|
||||||
@ -65,7 +58,6 @@ namespace osu.Game.Overlays.Music
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Padding = new MarginPadding { Top = 95, Bottom = 10, Right = 10 },
|
Padding = new MarginPadding { Top = 95, Bottom = 10, Right = 10 },
|
||||||
Selected = itemSelected,
|
Selected = itemSelected,
|
||||||
OrderChanged = (s, i) => OrderChanged?.Invoke(s, i)
|
|
||||||
},
|
},
|
||||||
filter = new FilterControl
|
filter = new FilterControl
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,6 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Y = player_height + 10,
|
Y = player_height + 10,
|
||||||
OrderChanged = musicController.ChangeBeatmapSetPosition
|
|
||||||
},
|
},
|
||||||
playerContainer = new Container
|
playerContainer = new Container
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user