From 680a3e2aa4ad88e875b3843d290aceaa0c44bbec Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 13 Dec 2018 18:38:03 +0900 Subject: [PATCH] Update with proper playlist usage --- .../UpdateableBeatmapBackgroundSprite.cs | 2 +- osu.Game/Online/Multiplayer/Room.cs | 12 ----- .../Multi/Lounge/Components/DrawableRoom.cs | 32 ++++++++---- .../Multi/Lounge/Components/RoomInspector.cs | 23 +++++--- .../Screens/Multi/Match/Components/Header.cs | 2 +- .../Match/Components/RoomSettingsOverlay.cs | 7 ++- osu.Game/Screens/Multi/Match/MatchScreen.cs | 52 +++++++++++++++---- osu.Game/Screens/Multi/RoomManager.cs | 3 -- 8 files changed, 87 insertions(+), 46 deletions(-) diff --git a/osu.Game/Beatmaps/Drawables/UpdateableBeatmapBackgroundSprite.cs b/osu.Game/Beatmaps/Drawables/UpdateableBeatmapBackgroundSprite.cs index 0a9726b121..15b89d27bd 100644 --- a/osu.Game/Beatmaps/Drawables/UpdateableBeatmapBackgroundSprite.cs +++ b/osu.Game/Beatmaps/Drawables/UpdateableBeatmapBackgroundSprite.cs @@ -11,7 +11,7 @@ namespace osu.Game.Beatmaps.Drawables { public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable { - public readonly IBindable Beatmap = new Bindable(); + public readonly Bindable Beatmap = new Bindable(); [Resolved] private BeatmapManager beatmaps { get; set; } diff --git a/osu.Game/Online/Multiplayer/Room.cs b/osu.Game/Online/Multiplayer/Room.cs index e2322db397..5e9fc4f008 100644 --- a/osu.Game/Online/Multiplayer/Room.cs +++ b/osu.Game/Online/Multiplayer/Room.cs @@ -18,9 +18,6 @@ namespace osu.Game.Online.Multiplayer [JsonProperty("id")] public Bindable RoomID { get; } = new Bindable(); - [JsonIgnore] - public readonly Bindable Beatmap = new Bindable(); - [JsonProperty("name")] public readonly Bindable Name = new Bindable("My awesome room!"); @@ -52,15 +49,6 @@ namespace osu.Game.Online.Multiplayer public Bindable MaxParticipants = new Bindable(); public Bindable> Participants = new Bindable>(Enumerable.Empty()); - public Room() - { - Beatmap.BindValueChanged(b => - { - Playlist.Clear(); - Playlist.Add(new PlaylistItem { Beatmap = b }); - }); - } - public void CopyFrom(Room other) { RoomID.Value = other.RoomID; diff --git a/osu.Game/Screens/Multi/Lounge/Components/DrawableRoom.cs b/osu.Game/Screens/Multi/Lounge/Components/DrawableRoom.cs index 647913308d..c425f8ef0a 100644 --- a/osu.Game/Screens/Multi/Lounge/Components/DrawableRoom.cs +++ b/osu.Game/Screens/Multi/Lounge/Components/DrawableRoom.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Configuration; @@ -39,14 +40,18 @@ namespace osu.Game.Screens.Multi.Lounge.Components private readonly Box selectionBox; private readonly Bindable nameBind = new Bindable(); - private readonly Bindable beatmapBind = new Bindable(); private readonly Bindable hostBind = new Bindable(); private readonly Bindable statusBind = new Bindable(); private readonly Bindable typeBind = new Bindable(); private readonly Bindable> participantsBind = new Bindable>(); + private readonly IBindableCollection playlistBind = new BindableCollection(); private readonly Bindable beatmap = new Bindable(); + private UpdateableBeatmapBackgroundSprite background; + private BeatmapTitle beatmapTitle; + private ModeTypeInfo modeTypeInfo; + [Resolved] private BeatmapManager beatmaps { get; set; } @@ -104,11 +109,9 @@ namespace osu.Game.Screens.Multi.Lounge.Components private void load(OsuColour colours) { Box sideStrip; - UpdateableBeatmapBackgroundSprite background; OsuSpriteText status; ParticipantInfo participantInfo; - BeatmapTitle beatmapTitle; - ModeTypeInfo modeTypeInfo; + OsuSpriteText name; Children = new Drawable[] @@ -213,24 +216,24 @@ namespace osu.Game.Screens.Multi.Lounge.Components d.FadeColour(s.GetAppropriateColour(colours), transition_duration); }; - beatmapBind.BindValueChanged(b => beatmap.Value = beatmaps.GetWorkingBeatmap(b)); nameBind.BindValueChanged(n => name.Text = n); nameBind.BindTo(Room.Name); hostBind.BindTo(Room.Host); statusBind.BindTo(Room.Status); typeBind.BindTo(Room.Type); - beatmapBind.BindTo(Room.Beatmap); + playlistBind.BindTo(Room.Playlist); participantsBind.BindTo(Room.Participants); - background.Beatmap.BindTo(beatmapBind); - modeTypeInfo.Beatmap.BindTo(beatmapBind); modeTypeInfo.Type.BindTo(typeBind); participantInfo.Host.BindTo(hostBind); participantInfo.Participants.BindTo(participantsBind); - beatmapTitle.Beatmap.BindTo(beatmapBind); + playlistBind.ItemsAdded += _ => updatePlaylist(); + playlistBind.ItemsRemoved += _ => updatePlaylist(); + + updatePlaylist(); } protected override void LoadComplete() @@ -238,5 +241,16 @@ namespace osu.Game.Screens.Multi.Lounge.Components base.LoadComplete(); this.FadeInFromZero(transition_duration); } + + private void updatePlaylist() + { + // For now, only the first playlist item is supported + var item = playlistBind.First(); + + beatmap.Value = beatmaps.GetWorkingBeatmap(item.Beatmap); + background.Beatmap.Value = item.Beatmap; + modeTypeInfo.Beatmap.Value = item.Beatmap; + beatmapTitle.Beatmap.Value = item.Beatmap; + } } } diff --git a/osu.Game/Screens/Multi/Lounge/Components/RoomInspector.cs b/osu.Game/Screens/Multi/Lounge/Components/RoomInspector.cs index 5b796b5a3d..1a2ff4c3d8 100644 --- a/osu.Game/Screens/Multi/Lounge/Components/RoomInspector.cs +++ b/osu.Game/Screens/Multi/Lounge/Components/RoomInspector.cs @@ -32,12 +32,12 @@ namespace osu.Game.Screens.Multi.Lounge.Components private readonly MarginPadding contentPadding = new MarginPadding { Horizontal = 20, Vertical = 10 }; private readonly Bindable nameBind = new Bindable(); - private readonly Bindable beatmapBind = new Bindable(); private readonly Bindable hostBind = new Bindable(); private readonly Bindable statusBind = new Bindable(); private readonly Bindable typeBind = new Bindable(); private readonly Bindable maxParticipantsBind = new Bindable(); private readonly Bindable> participantsBind = new Bindable>(); + private readonly IBindableCollection playlistBind = new BindableCollection(); private readonly Bindable beatmap = new Bindable(); @@ -174,14 +174,14 @@ namespace osu.Game.Screens.Multi.Lounge.Components }, }; + playlistBind.ItemsAdded += _ => updatePlaylist(); + playlistBind.ItemsRemoved += _ => updatePlaylist(); + statusBind.BindValueChanged(displayStatus); - beatmapBind.BindValueChanged(b => beatmap.Value = beatmaps.GetWorkingBeatmap(b)); participantsBind.BindValueChanged(p => participantsFlow.ChildrenEnumerable = p.Select(u => new UserTile(u))); nameBind.BindValueChanged(n => name.Text = n); - background.Beatmap.BindTo(beatmapBind); - participantInfo.Host.BindTo(hostBind); participantInfo.Participants.BindTo(participantsBind); @@ -189,7 +189,6 @@ namespace osu.Game.Screens.Multi.Lounge.Components participantCount.MaxParticipants.BindTo(maxParticipantsBind); beatmapTypeInfo.Type.BindTo(typeBind); - beatmapTypeInfo.Beatmap.BindTo(beatmapBind); Room.BindValueChanged(updateRoom, true); } @@ -204,7 +203,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components hostBind.UnbindFrom(lastRoom.Host); statusBind.UnbindFrom(lastRoom.Status); typeBind.UnbindFrom(lastRoom.Type); - beatmapBind.UnbindFrom(lastRoom.Beatmap); + playlistBind.UnbindFrom(lastRoom.Playlist); maxParticipantsBind.UnbindFrom(lastRoom.MaxParticipants); participantsBind.UnbindFrom(lastRoom.Participants); } @@ -215,7 +214,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components hostBind.BindTo(newRoom.Host); statusBind.BindTo(newRoom.Status); typeBind.BindTo(newRoom.Type); - beatmapBind.BindTo(newRoom.Beatmap); + playlistBind.BindTo(newRoom.Playlist); maxParticipantsBind.BindTo(newRoom.MaxParticipants); participantsBind.BindTo(newRoom.Participants); @@ -239,6 +238,16 @@ namespace osu.Game.Screens.Multi.Lounge.Components lastRoom = newRoom; } + private void updatePlaylist() + { + // For now, only the first playlist item is supported + var item = playlistBind.First(); + + beatmap.Value = beatmaps.GetWorkingBeatmap(item.Beatmap); + background.Beatmap.Value = item.Beatmap; + beatmapTypeInfo.Beatmap.Value = item.Beatmap; + } + protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); diff --git a/osu.Game/Screens/Multi/Match/Components/Header.cs b/osu.Game/Screens/Multi/Match/Components/Header.cs index 005378756e..4e3349056c 100644 --- a/osu.Game/Screens/Multi/Match/Components/Header.cs +++ b/osu.Game/Screens/Multi/Match/Components/Header.cs @@ -23,7 +23,7 @@ namespace osu.Game.Screens.Multi.Match.Components { public const float HEIGHT = 200; - public readonly IBindable Beatmap = new Bindable(); + public readonly Bindable Beatmap = new Bindable(); private readonly Box tabStrip; diff --git a/osu.Game/Screens/Multi/Match/Components/RoomSettingsOverlay.cs b/osu.Game/Screens/Multi/Match/Components/RoomSettingsOverlay.cs index e4eb2046b2..d6098674c1 100644 --- a/osu.Game/Screens/Multi/Match/Components/RoomSettingsOverlay.cs +++ b/osu.Game/Screens/Multi/Match/Components/RoomSettingsOverlay.cs @@ -6,7 +6,6 @@ using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; @@ -23,10 +22,10 @@ namespace osu.Game.Screens.Multi.Match.Components private const float field_padding = 45; private readonly Bindable nameBind = new Bindable(); - private readonly Bindable beatmapBind = new Bindable(); private readonly Bindable availabilityBind = new Bindable(); private readonly Bindable typeBind = new Bindable(); private readonly Bindable maxParticipantsBind = new Bindable(); + private readonly IBindableCollection playlistBind = new BindableCollection(); private readonly Container content; @@ -160,7 +159,7 @@ namespace osu.Game.Screens.Multi.Match.Components typeLabel.Colour = colours.Yellow; nameBind.BindTo(room.Name); - beatmapBind.BindTo(room.Beatmap); + playlistBind.BindTo(room.Playlist); availabilityBind.BindTo(room.Availability); typeBind.BindTo(room.Type); maxParticipantsBind.BindTo(room.MaxParticipants); @@ -179,7 +178,7 @@ namespace osu.Game.Screens.Multi.Match.Components ApplyButton.Enabled.Value = hasValidSettings; } - private bool hasValidSettings => NameField.Text.Length > 0 && beatmapBind.Value != null; + private bool hasValidSettings => NameField.Text.Length > 0 && playlistBind.Count > 0; protected override void PopIn() { diff --git a/osu.Game/Screens/Multi/Match/MatchScreen.cs b/osu.Game/Screens/Multi/Match/MatchScreen.cs index a2a7c4e70d..b4ff73bbe4 100644 --- a/osu.Game/Screens/Multi/Match/MatchScreen.cs +++ b/osu.Game/Screens/Multi/Match/MatchScreen.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; @@ -20,12 +21,12 @@ namespace osu.Game.Screens.Multi.Match private readonly Participants participants; private readonly Bindable nameBind = new Bindable(); - private readonly Bindable beatmapBind = new Bindable(); private readonly Bindable statusBind = new Bindable(); private readonly Bindable availabilityBind = new Bindable(); private readonly Bindable typeBind = new Bindable(); private readonly Bindable maxParticipantsBind = new Bindable(); private readonly Bindable> participantsBind = new Bindable>(); + private readonly BindableCollection playlistBind = new BindableCollection(); protected override Drawable TransitionContent => participants; @@ -33,6 +34,9 @@ namespace osu.Game.Screens.Multi.Match public override string ShortTitle => "room"; + private readonly Components.Header header; + private readonly Info info; + [Cached] private readonly Room room; @@ -47,16 +51,13 @@ namespace osu.Game.Screens.Multi.Match this.room = room; nameBind.BindTo(room.Name); - beatmapBind.BindTo(room.Beatmap); statusBind.BindTo(room.Status); availabilityBind.BindTo(room.Availability); typeBind.BindTo(room.Type); participantsBind.BindTo(room.Participants); maxParticipantsBind.BindTo(room.MaxParticipants); - Components.Header header; RoomSettingsOverlay settings; - Info info; Children = new Drawable[] { @@ -86,7 +87,6 @@ namespace osu.Game.Screens.Multi.Match }; header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect()); - header.Beatmap.BindTo(beatmapBind); header.Tabs.Current.ValueChanged += t => { @@ -96,7 +96,6 @@ namespace osu.Game.Screens.Multi.Match settings.Hide(); }; - info.Beatmap.BindTo(beatmapBind); info.Name.BindTo(nameBind); info.Status.BindTo(statusBind); info.Availability.BindTo(availabilityBind); @@ -104,14 +103,49 @@ namespace osu.Game.Screens.Multi.Match participants.Users.BindTo(participantsBind); participants.MaxParticipants.BindTo(maxParticipantsBind); + + playlistBind.ItemsAdded += _ => updatePlaylist(); + playlistBind.ItemsRemoved += _ => updatePlaylist(); } [BackgroundDependencyLoader] private void load() { - beatmapBind.BindTo(room.Beatmap); - beatmapBind.BindValueChanged(b => Beatmap.Value = beatmapManager.GetWorkingBeatmap(room.Beatmap.Value), true); - Beatmap.BindValueChanged(b => beatmapBind.Value = b.BeatmapInfo); + Beatmap.BindValueChanged(b => + { + playlistBind.Clear(); + + var newItem = new PlaylistItem + { + Beatmap = b.BeatmapInfo, + Ruleset = Ruleset.Value + }; + + newItem.RequiredMods.Clear(); + newItem.RequiredMods.AddRange(b.Mods.Value); + + playlistBind.Add(newItem); + }); + + playlistBind.BindTo(room.Playlist); + } + + private void updatePlaylist() + { + if (playlistBind.Count == 0) + return; + + // For now, only the first playlist item is supported + var item = playlistBind.First(); + + header.Beatmap.Value = item.Beatmap; + info.Beatmap.Value = item.Beatmap; + + if (Beatmap.Value?.BeatmapInfo != item.Beatmap) + { + Beatmap.Value = beatmapManager.GetWorkingBeatmap(item.Beatmap); + Beatmap.Value.Mods.Value = item.RequiredMods.ToArray(); + } } } } diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index d6c5a12d33..fead90f9a2 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -69,9 +69,6 @@ namespace osu.Game.Screens.Multi pi.SetRulesets(rulesets); } - // Temporarily - r.Beatmap.Value = r.Playlist.FirstOrDefault()?.Beatmap; - var existing = rooms.FirstOrDefault(e => e.RoomID.Value == r.RoomID.Value); if (existing == null) rooms.Add(r);