mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 08:22:56 +08:00
Allow rearranging playlist tracks
This commit is contained in:
parent
5f746c1c6a
commit
5c3b7ac12c
@ -8,6 +8,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
@ -28,6 +29,7 @@ namespace osu.Game.Overlays.Music
|
||||
private IEnumerable<SpriteText> titleSprites;
|
||||
private UnicodeBindableString titleBind;
|
||||
private UnicodeBindableString artistBind;
|
||||
private FillFlowContainer<PlaylistItem> Playlist;
|
||||
|
||||
public readonly BeatmapSetInfo BeatmapSetInfo;
|
||||
|
||||
@ -48,8 +50,9 @@ namespace osu.Game.Overlays.Music
|
||||
}
|
||||
}
|
||||
|
||||
public PlaylistItem(BeatmapSetInfo setInfo)
|
||||
public PlaylistItem(FillFlowContainer<PlaylistItem> playlist, BeatmapSetInfo setInfo)
|
||||
{
|
||||
Playlist = playlist;
|
||||
BeatmapSetInfo = setInfo;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
@ -132,6 +135,44 @@ namespace osu.Game.Overlays.Music
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnDragStart(InputState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Maybe render some ghost text
|
||||
protected override bool OnDrag(InputState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private int clamp(int value, int min, int max)
|
||||
{
|
||||
return (value <= min) ? min : (value >= max) ? max : value;
|
||||
}
|
||||
|
||||
protected override bool OnDragEnd(InputState state)
|
||||
{
|
||||
int src = (int) Depth;
|
||||
int dst = clamp((int) ((state.Mouse.Position.Y - Parent.DrawPosition.Y) / Height), 0, Playlist.Count - 1);
|
||||
|
||||
if (src == dst)
|
||||
return true;
|
||||
|
||||
if (src < dst)
|
||||
{
|
||||
for (int i = src + 1; i <= dst; i++)
|
||||
Playlist.ChangeChildDepth(Playlist[i], i - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = dst; i < src; i++)
|
||||
Playlist.ChangeChildDepth(Playlist[i], i + 1);
|
||||
}
|
||||
Playlist.ChangeChildDepth(this, dst);
|
||||
return true;
|
||||
}
|
||||
|
||||
public string[] FilterTerms { get; private set; }
|
||||
|
||||
private bool matching = true;
|
||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Overlays.Music
|
||||
{
|
||||
set
|
||||
{
|
||||
items.Children = value.Select(item => new PlaylistItem(item) { OnSelect = itemSelected }).ToList();
|
||||
items.Children = value.Select((item, index) => new PlaylistItem(items, item) { OnSelect = itemSelected, Depth = index }).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ namespace osu.Game.Overlays.Music
|
||||
|
||||
public void AddBeatmapSet(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
items.Add(new PlaylistItem(beatmapSet) { OnSelect = itemSelected });
|
||||
items.Add(new PlaylistItem(items, beatmapSet) { OnSelect = itemSelected, Depth = items.Count });
|
||||
}
|
||||
|
||||
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet)
|
||||
@ -96,6 +96,9 @@ namespace osu.Game.Overlays.Music
|
||||
}
|
||||
}
|
||||
|
||||
// Compare with reversed ChildID and Depth
|
||||
protected override int Compare(Drawable x, Drawable y) => base.Compare(y, x);
|
||||
|
||||
public IEnumerable<IFilterable> FilterableChildren => Children;
|
||||
|
||||
public ItemSearchContainer()
|
||||
|
Loading…
Reference in New Issue
Block a user