1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 22:27:25 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylist.cs

79 lines
2.8 KiB
C#
Raw Normal View History

// 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.
using System.Collections.Specialized;
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;
using osuTK;
namespace osu.Game.Screens.OnlinePlay
{
public class DrawableRoomPlaylist : OsuRearrangeableListContainer<PlaylistItem>
{
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
private readonly bool allowEdit;
private readonly bool allowSelection;
2021-11-26 16:40:45 +08:00
private readonly bool showItemOwner;
2021-12-01 19:24:14 +08:00
public DrawableRoomPlaylist(bool allowEdit, bool allowSelection, bool showItemOwner = false)
{
this.allowEdit = allowEdit;
this.allowSelection = allowSelection;
2021-11-26 16:40:45 +08:00
this.showItemOwner = showItemOwner;
2021-11-15 23:09:38 +08:00
((ReversibleFillFlowContainer)ListContainer).Reverse = reverse;
}
protected override void LoadComplete()
{
base.LoadComplete();
2020-02-14 15:55:05 +08:00
// Scheduled since items are removed and re-added upon rearrangement
Items.CollectionChanged += (_, args) => Schedule(() =>
{
switch (args.Action)
{
case NotifyCollectionChangedAction.Remove:
if (allowSelection && args.OldItems.Contains(SelectedItem))
SelectedItem.Value = null;
break;
}
});
}
protected override ScrollContainer<Drawable> CreateScrollContainer() => base.CreateScrollContainer().With(d =>
{
d.ScrollbarVisible = false;
});
protected override FillFlowContainer<RearrangeableListItem<PlaylistItem>> CreateListFillFlowContainer() => new FillFlowContainer<RearrangeableListItem<PlaylistItem>>
{
Spacing = new Vector2(0, 2)
};
2021-11-26 16:40:45 +08:00
protected override OsuRearrangeableListItem<PlaylistItem> CreateOsuDrawable(PlaylistItem item) => new DrawableRoomPlaylistItem(item, allowEdit, allowSelection, showItemOwner)
{
2020-02-14 15:55:05 +08:00
SelectedItem = { BindTarget = SelectedItem },
RequestDeletion = requestDeletion
};
private void requestDeletion(PlaylistItem item)
{
if (allowSelection && SelectedItem.Value == item)
{
if (Items.Count == 1)
SelectedItem.Value = null;
else
SelectedItem.Value = Items.GetNext(item) ?? Items[^2];
}
Items.Remove(item);
}
}
}