// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Containers; using osu.Game.Online.Rooms; using osuTK; namespace osu.Game.Screens.OnlinePlay { /// /// A list scrollable list which displays the s in a . /// public class DrawableRoomPlaylist : OsuRearrangeableListContainer { /// /// The currently-selected item, used to show a border around items. /// May be updated by playlist items if is true. /// public readonly Bindable SelectedItem = new Bindable(); /// /// Invoked when an item is requested to be deleted. /// public Action DeletionRequested; /// /// Invoked when an item requests its results to be shown. /// public Action ShowResultsRequested; private bool allowReordering; /// /// Whether to allow reordering items in the playlist. /// public bool AllowReordering { get => allowReordering; set { allowReordering = value; foreach (var item in ListContainer.OfType()) item.AllowReordering = value; } } private bool allowDeletion; /// /// Whether to allow deleting items from the playlist. /// If true, requests to delete items may be satisfied via . /// public bool AllowDeletion { get => allowDeletion; set { allowDeletion = value; foreach (var item in ListContainer.OfType()) item.AllowDeletion = value; } } private bool allowSelection; /// /// Whether to allow selecting items from the playlist. /// If true, clicking on items in the playlist will change the value of . /// public bool AllowSelection { get => allowSelection; set { allowSelection = value; foreach (var item in ListContainer.OfType()) item.AllowSelection = value; } } private bool allowShowingResults; /// /// Whether to allow items to request their results to be shown. /// If true, requests to show the results may be satisfied via . /// public bool AllowShowingResults { get => allowShowingResults; set { allowShowingResults = value; foreach (var item in ListContainer.OfType()) item.AllowShowingResults = value; } } private bool showItemOwners; /// /// Whether to show the avatar of users which own each playlist item. /// public bool ShowItemOwners { get => showItemOwners; set { showItemOwners = value; foreach (var item in ListContainer.OfType()) item.ShowItemOwner = value; } } protected override ScrollContainer CreateScrollContainer() => base.CreateScrollContainer().With(d => { d.ScrollbarVisible = false; }); protected override FillFlowContainer> CreateListFillFlowContainer() => new FillFlowContainer> { Spacing = new Vector2(0, 2) }; protected override OsuRearrangeableListItem CreateOsuDrawable(PlaylistItem item) => new DrawableRoomPlaylistItem(item) { SelectedItem = { BindTarget = SelectedItem }, RequestDeletion = i => DeletionRequested?.Invoke(i), AllowReordering = AllowReordering, AllowDeletion = AllowDeletion, AllowSelection = AllowSelection, AllowShowingResults = AllowShowingResults, ShowItemOwner = ShowItemOwners, ShowResultsRequested = i => ShowResultsRequested?.Invoke(i) }; } }