// 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.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Rooms; using osu.Game.Screens.OnlinePlay.Match; namespace osu.Game.Screens.OnlinePlay { /// /// A that exposes bindables for properties. /// public class OnlinePlayComposite : CompositeDrawable { [Resolved(typeof(Room))] protected Bindable RoomID { get; private set; } [Resolved(typeof(Room), nameof(Room.Name))] protected Bindable RoomName { get; private set; } [Resolved(typeof(Room))] protected Bindable Host { get; private set; } [Resolved(typeof(Room))] protected Bindable Status { get; private set; } [Resolved(typeof(Room))] protected Bindable Type { get; private set; } [Resolved(typeof(Room))] protected BindableList Playlist { get; private set; } [Resolved(typeof(Room))] protected Bindable Category { get; private set; } [Resolved(typeof(Room))] protected BindableList RecentParticipants { get; private set; } [Resolved(typeof(Room))] protected Bindable ParticipantCount { get; private set; } [Resolved(typeof(Room))] protected Bindable MaxParticipants { get; private set; } [Resolved(typeof(Room))] protected Bindable MaxAttempts { get; private set; } [Resolved(typeof(Room))] public Bindable UserScore { get; private set; } [Resolved(typeof(Room))] protected Bindable EndDate { get; private set; } [Resolved(typeof(Room))] protected Bindable Availability { get; private set; } [Resolved(typeof(Room), nameof(Room.Password))] public Bindable Password { get; private set; } [Resolved(typeof(Room))] protected Bindable Duration { get; private set; } [Resolved(CanBeNull = true)] private IBindable subScreenSelectedItem { get; set; } /// /// The currently selected item in the , or the last item from /// if this is not within a . /// protected readonly Bindable SelectedItem = new Bindable(); protected override void LoadComplete() { base.LoadComplete(); subScreenSelectedItem?.BindValueChanged(_ => UpdateSelectedItem()); Playlist.BindCollectionChanged((_, __) => UpdateSelectedItem(), true); } protected virtual void UpdateSelectedItem() => SelectedItem.Value = RoomID.Value == null || subScreenSelectedItem == null ? Playlist.LastOrDefault() : subScreenSelectedItem.Value; } }