2020-02-14 14:01:45 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-11-15 23:09:49 +08:00
|
|
|
using System.Collections.Generic;
|
2020-02-17 14:06:14 +08:00
|
|
|
using System.Collections.Specialized;
|
2021-11-15 23:09:49 +08:00
|
|
|
using System.Linq;
|
2020-02-14 14:01:45 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Containers;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-02-14 14:01:45 +08:00
|
|
|
using osuTK;
|
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
public class DrawableRoomPlaylist : OsuRearrangeableListContainer<PlaylistItem>
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
|
|
|
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
|
|
|
|
|
|
|
private readonly bool allowEdit;
|
|
|
|
private readonly bool allowSelection;
|
|
|
|
|
2021-11-15 23:09:38 +08:00
|
|
|
public DrawableRoomPlaylist(bool allowEdit, bool allowSelection, bool reverse = false)
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
|
|
|
this.allowEdit = allowEdit;
|
|
|
|
this.allowSelection = allowSelection;
|
2021-11-15 23:09:38 +08:00
|
|
|
|
|
|
|
((ReversibleFillFlowContainer)ListContainer).Reverse = reverse;
|
2020-02-14 14:01:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-02-14 15:55:05 +08:00
|
|
|
// Scheduled since items are removed and re-added upon rearrangement
|
2020-02-17 14:06:14 +08:00
|
|
|
Items.CollectionChanged += (_, args) => Schedule(() =>
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
2020-02-17 14:06:14 +08:00
|
|
|
switch (args.Action)
|
|
|
|
{
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
2021-11-15 23:09:49 +08:00
|
|
|
if (allowSelection && args.OldItems.Contains(SelectedItem))
|
2020-02-17 14:06:14 +08:00
|
|
|
SelectedItem.Value = null;
|
|
|
|
break;
|
|
|
|
}
|
2020-02-14 15:48:23 +08:00
|
|
|
});
|
2020-02-14 14:01:45 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:36:47 +08:00
|
|
|
protected override ScrollContainer<Drawable> CreateScrollContainer() => base.CreateScrollContainer().With(d =>
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
d.ScrollbarVisible = false;
|
|
|
|
});
|
2020-02-14 14:01:45 +08:00
|
|
|
|
2021-11-15 23:09:38 +08:00
|
|
|
protected override FillFlowContainer<RearrangeableListItem<PlaylistItem>> CreateListFillFlowContainer() => new ReversibleFillFlowContainer
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
|
|
|
Spacing = new Vector2(0, 2)
|
|
|
|
};
|
|
|
|
|
2020-02-14 14:36:47 +08:00
|
|
|
protected override OsuRearrangeableListItem<PlaylistItem> CreateOsuDrawable(PlaylistItem item) => new DrawableRoomPlaylistItem(item, allowEdit, allowSelection)
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
2020-02-14 15:55:05 +08:00
|
|
|
SelectedItem = { BindTarget = SelectedItem },
|
2020-02-14 14:01:45 +08:00
|
|
|
RequestDeletion = requestDeletion
|
|
|
|
};
|
|
|
|
|
|
|
|
private void requestDeletion(PlaylistItem item)
|
|
|
|
{
|
2021-11-15 23:09:49 +08:00
|
|
|
if (allowSelection && SelectedItem.Value == item)
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
|
|
|
if (Items.Count == 1)
|
|
|
|
SelectedItem.Value = null;
|
|
|
|
else
|
|
|
|
SelectedItem.Value = Items.GetNext(item) ?? Items[^2];
|
|
|
|
}
|
|
|
|
|
|
|
|
Items.Remove(item);
|
|
|
|
}
|
2021-11-15 23:09:38 +08:00
|
|
|
|
|
|
|
private class ReversibleFillFlowContainer : FillFlowContainer<RearrangeableListItem<PlaylistItem>>
|
|
|
|
{
|
|
|
|
private bool reverse;
|
|
|
|
|
|
|
|
public bool Reverse
|
|
|
|
{
|
|
|
|
get => reverse;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
reverse = value;
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override IEnumerable<Drawable> FlowingChildren => Reverse ? base.FlowingChildren.OrderBy(d => -GetLayoutPosition(d)) : base.FlowingChildren;
|
|
|
|
}
|
2020-02-14 14:01:45 +08:00
|
|
|
}
|
|
|
|
}
|