// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Configuration; using osu.Game.Beatmaps; using osu.Game.Online.Multiplayer; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Users; namespace osu.Game.Screens.Multi { /// /// Helper class which binds to values from a . /// public class RoomBindings { public RoomBindings() { Playlist.ItemsAdded += _ => updatePlaylist(); Playlist.ItemsRemoved += _ => updatePlaylist(); } private Room room; /// /// The to bind to. /// public Room Room { get => room; set { if (room == value) return; if (room != null) { Name.UnbindFrom(room.Name); Host.UnbindFrom(room.Host); Status.UnbindFrom(room.Status); Type.UnbindFrom(room.Type); Playlist.UnbindFrom(room.Playlist); Participants.UnbindFrom(room.Participants); ParticipantCount.UnbindFrom(room.ParticipantCount); MaxParticipants.UnbindFrom(room.MaxParticipants); EndDate.UnbindFrom(room.EndDate); Availability.UnbindFrom(room.Availability); Duration.UnbindFrom(room.Duration); } room = value; if (room != null) { Name.BindTo(room.Name); Host.BindTo(room.Host); Status.BindTo(room.Status); Type.BindTo(room.Type); Playlist.BindTo(room.Playlist); Participants.BindTo(room.Participants); ParticipantCount.BindTo(room.ParticipantCount); MaxParticipants.BindTo(room.MaxParticipants); EndDate.BindTo(room.EndDate); Availability.BindTo(room.Availability); Duration.BindTo(room.Duration); } } } private void updatePlaylist() { // Todo: We only ever have one playlist item for now. In the future, this will be user-settable var playlistItem = Playlist.FirstOrDefault(); currentBeatmap.Value = playlistItem?.Beatmap; currentMods.Value = playlistItem?.RequiredMods ?? Enumerable.Empty(); currentRuleset.Value = playlistItem?.Ruleset; } public readonly Bindable Name = new Bindable(); public readonly Bindable Host = new Bindable(); public readonly Bindable Status = new Bindable(); public readonly Bindable Type = new Bindable(); public readonly BindableCollection Playlist = new BindableCollection(); public readonly Bindable> Participants = new Bindable>(); public readonly Bindable ParticipantCount = new Bindable(); public readonly Bindable MaxParticipants = new Bindable(); public readonly Bindable EndDate = new Bindable(); public readonly Bindable Availability = new Bindable(); public readonly Bindable Duration = new Bindable(); private readonly Bindable currentBeatmap = new Bindable(); public IBindable CurrentBeatmap => currentBeatmap; private readonly Bindable> currentMods = new Bindable>(); public IBindable> CurrentMods => currentMods; private readonly Bindable currentRuleset = new Bindable(); public IBindable CurrentRuleset => currentRuleset; } }