From be51ee4ed5b266da78be77df3c44e19d1f3d3122 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 5 Feb 2019 16:14:37 +0900 Subject: [PATCH] Implement MultiplayerComposite, replaces RoomBindings --- .../Screens/Multi/MultiplayerComposite.cs | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 osu.Game/Screens/Multi/MultiplayerComposite.cs diff --git a/osu.Game/Screens/Multi/MultiplayerComposite.cs b/osu.Game/Screens/Multi/MultiplayerComposite.cs new file mode 100644 index 0000000000..f09750b112 --- /dev/null +++ b/osu.Game/Screens/Multi/MultiplayerComposite.cs @@ -0,0 +1,89 @@ +// 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.Collections.Generic; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics.Containers; +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 +{ + public class MultiplayerComposite : CompositeDrawable + { + [Resolved] + public Room Room { get; private set; } + + [Resolved(typeof(Room))] + public Bindable RoomID { get; private set; } + + [Resolved(typeof(Room))] + public Bindable Name { get; private set; } + + [Resolved(typeof(Room))] + public Bindable Host { get; private set; } + + [Resolved(typeof(Room))] + public Bindable Status { get; private set; } + + [Resolved(typeof(Room))] + public Bindable Type { get; private set; } + + [Resolved(typeof(Room))] + public BindableList Playlist { get; private set; } + + [Resolved(typeof(Room))] + public Bindable> Participants { get; private set; } + + [Resolved(typeof(Room))] + public Bindable ParticipantCount { get; private set; } + + [Resolved(typeof(Room))] + public Bindable MaxParticipants { get; private set; } + + [Resolved(typeof(Room))] + public Bindable EndDate { get; private set; } + + [Resolved(typeof(Room))] + public Bindable Availability { get; private set; } + + [Resolved(typeof(Room))] + public Bindable Duration { get; private set; } + + 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; + + protected override void LoadComplete() + { + base.LoadComplete(); + + Playlist.ItemsAdded += _ => updatePlaylist(); + Playlist.ItemsRemoved += _ => updatePlaylist(); + + updatePlaylist(); + } + + 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; + } + } +}