Update with proper playlist usage

This commit is contained in:
smoogipoo
2018-12-13 18:38:03 +09:00
parent 264bd0e2aa
commit 680a3e2aa4
8 changed files with 87 additions and 46 deletions

View File

@ -11,7 +11,7 @@ namespace osu.Game.Beatmaps.Drawables
{ {
public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<BeatmapInfo> public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<BeatmapInfo>
{ {
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>(); public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
[Resolved] [Resolved]
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }

View File

@ -18,9 +18,6 @@ namespace osu.Game.Online.Multiplayer
[JsonProperty("id")] [JsonProperty("id")]
public Bindable<int?> RoomID { get; } = new Bindable<int?>(); public Bindable<int?> RoomID { get; } = new Bindable<int?>();
[JsonIgnore]
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
[JsonProperty("name")] [JsonProperty("name")]
public readonly Bindable<string> Name = new Bindable<string>("My awesome room!"); public readonly Bindable<string> Name = new Bindable<string>("My awesome room!");
@ -52,15 +49,6 @@ namespace osu.Game.Online.Multiplayer
public Bindable<int?> MaxParticipants = new Bindable<int?>(); public Bindable<int?> MaxParticipants = new Bindable<int?>();
public Bindable<IEnumerable<User>> Participants = new Bindable<IEnumerable<User>>(Enumerable.Empty<User>()); public Bindable<IEnumerable<User>> Participants = new Bindable<IEnumerable<User>>(Enumerable.Empty<User>());
public Room()
{
Beatmap.BindValueChanged(b =>
{
Playlist.Clear();
Playlist.Add(new PlaylistItem { Beatmap = b });
});
}
public void CopyFrom(Room other) public void CopyFrom(Room other)
{ {
RoomID.Value = other.RoomID; RoomID.Value = other.RoomID;

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Framework; using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
@ -39,14 +40,18 @@ namespace osu.Game.Screens.Multi.Lounge.Components
private readonly Box selectionBox; private readonly Box selectionBox;
private readonly Bindable<string> nameBind = new Bindable<string>(); private readonly Bindable<string> nameBind = new Bindable<string>();
private readonly Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
private readonly Bindable<User> hostBind = new Bindable<User>(); private readonly Bindable<User> hostBind = new Bindable<User>();
private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>(); private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
private readonly Bindable<GameType> typeBind = new Bindable<GameType>(); private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>(); private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>();
private readonly IBindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>(); private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
private UpdateableBeatmapBackgroundSprite background;
private BeatmapTitle beatmapTitle;
private ModeTypeInfo modeTypeInfo;
[Resolved] [Resolved]
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }
@ -104,11 +109,9 @@ namespace osu.Game.Screens.Multi.Lounge.Components
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
Box sideStrip; Box sideStrip;
UpdateableBeatmapBackgroundSprite background;
OsuSpriteText status; OsuSpriteText status;
ParticipantInfo participantInfo; ParticipantInfo participantInfo;
BeatmapTitle beatmapTitle;
ModeTypeInfo modeTypeInfo;
OsuSpriteText name; OsuSpriteText name;
Children = new Drawable[] Children = new Drawable[]
@ -213,24 +216,24 @@ namespace osu.Game.Screens.Multi.Lounge.Components
d.FadeColour(s.GetAppropriateColour(colours), transition_duration); d.FadeColour(s.GetAppropriateColour(colours), transition_duration);
}; };
beatmapBind.BindValueChanged(b => beatmap.Value = beatmaps.GetWorkingBeatmap(b));
nameBind.BindValueChanged(n => name.Text = n); nameBind.BindValueChanged(n => name.Text = n);
nameBind.BindTo(Room.Name); nameBind.BindTo(Room.Name);
hostBind.BindTo(Room.Host); hostBind.BindTo(Room.Host);
statusBind.BindTo(Room.Status); statusBind.BindTo(Room.Status);
typeBind.BindTo(Room.Type); typeBind.BindTo(Room.Type);
beatmapBind.BindTo(Room.Beatmap); playlistBind.BindTo(Room.Playlist);
participantsBind.BindTo(Room.Participants); participantsBind.BindTo(Room.Participants);
background.Beatmap.BindTo(beatmapBind);
modeTypeInfo.Beatmap.BindTo(beatmapBind);
modeTypeInfo.Type.BindTo(typeBind); modeTypeInfo.Type.BindTo(typeBind);
participantInfo.Host.BindTo(hostBind); participantInfo.Host.BindTo(hostBind);
participantInfo.Participants.BindTo(participantsBind); participantInfo.Participants.BindTo(participantsBind);
beatmapTitle.Beatmap.BindTo(beatmapBind); playlistBind.ItemsAdded += _ => updatePlaylist();
playlistBind.ItemsRemoved += _ => updatePlaylist();
updatePlaylist();
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -238,5 +241,16 @@ namespace osu.Game.Screens.Multi.Lounge.Components
base.LoadComplete(); base.LoadComplete();
this.FadeInFromZero(transition_duration); 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;
}
} }
} }

View File

@ -32,12 +32,12 @@ namespace osu.Game.Screens.Multi.Lounge.Components
private readonly MarginPadding contentPadding = new MarginPadding { Horizontal = 20, Vertical = 10 }; private readonly MarginPadding contentPadding = new MarginPadding { Horizontal = 20, Vertical = 10 };
private readonly Bindable<string> nameBind = new Bindable<string>(); private readonly Bindable<string> nameBind = new Bindable<string>();
private readonly Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
private readonly Bindable<User> hostBind = new Bindable<User>(); private readonly Bindable<User> hostBind = new Bindable<User>();
private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>(); private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
private readonly Bindable<GameType> typeBind = new Bindable<GameType>(); private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>(); private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>(); private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>();
private readonly IBindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>(); private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
@ -174,14 +174,14 @@ namespace osu.Game.Screens.Multi.Lounge.Components
}, },
}; };
playlistBind.ItemsAdded += _ => updatePlaylist();
playlistBind.ItemsRemoved += _ => updatePlaylist();
statusBind.BindValueChanged(displayStatus); statusBind.BindValueChanged(displayStatus);
beatmapBind.BindValueChanged(b => beatmap.Value = beatmaps.GetWorkingBeatmap(b));
participantsBind.BindValueChanged(p => participantsFlow.ChildrenEnumerable = p.Select(u => new UserTile(u))); participantsBind.BindValueChanged(p => participantsFlow.ChildrenEnumerable = p.Select(u => new UserTile(u)));
nameBind.BindValueChanged(n => name.Text = n); nameBind.BindValueChanged(n => name.Text = n);
background.Beatmap.BindTo(beatmapBind);
participantInfo.Host.BindTo(hostBind); participantInfo.Host.BindTo(hostBind);
participantInfo.Participants.BindTo(participantsBind); participantInfo.Participants.BindTo(participantsBind);
@ -189,7 +189,6 @@ namespace osu.Game.Screens.Multi.Lounge.Components
participantCount.MaxParticipants.BindTo(maxParticipantsBind); participantCount.MaxParticipants.BindTo(maxParticipantsBind);
beatmapTypeInfo.Type.BindTo(typeBind); beatmapTypeInfo.Type.BindTo(typeBind);
beatmapTypeInfo.Beatmap.BindTo(beatmapBind);
Room.BindValueChanged(updateRoom, true); Room.BindValueChanged(updateRoom, true);
} }
@ -204,7 +203,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
hostBind.UnbindFrom(lastRoom.Host); hostBind.UnbindFrom(lastRoom.Host);
statusBind.UnbindFrom(lastRoom.Status); statusBind.UnbindFrom(lastRoom.Status);
typeBind.UnbindFrom(lastRoom.Type); typeBind.UnbindFrom(lastRoom.Type);
beatmapBind.UnbindFrom(lastRoom.Beatmap); playlistBind.UnbindFrom(lastRoom.Playlist);
maxParticipantsBind.UnbindFrom(lastRoom.MaxParticipants); maxParticipantsBind.UnbindFrom(lastRoom.MaxParticipants);
participantsBind.UnbindFrom(lastRoom.Participants); participantsBind.UnbindFrom(lastRoom.Participants);
} }
@ -215,7 +214,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
hostBind.BindTo(newRoom.Host); hostBind.BindTo(newRoom.Host);
statusBind.BindTo(newRoom.Status); statusBind.BindTo(newRoom.Status);
typeBind.BindTo(newRoom.Type); typeBind.BindTo(newRoom.Type);
beatmapBind.BindTo(newRoom.Beatmap); playlistBind.BindTo(newRoom.Playlist);
maxParticipantsBind.BindTo(newRoom.MaxParticipants); maxParticipantsBind.BindTo(newRoom.MaxParticipants);
participantsBind.BindTo(newRoom.Participants); participantsBind.BindTo(newRoom.Participants);
@ -239,6 +238,16 @@ namespace osu.Game.Screens.Multi.Lounge.Components
lastRoom = newRoom; 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() protected override void UpdateAfterChildren()
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();

View File

@ -23,7 +23,7 @@ namespace osu.Game.Screens.Multi.Match.Components
{ {
public const float HEIGHT = 200; public const float HEIGHT = 200;
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>(); public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
private readonly Box tabStrip; private readonly Box tabStrip;

View File

@ -6,7 +6,6 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -23,10 +22,10 @@ namespace osu.Game.Screens.Multi.Match.Components
private const float field_padding = 45; private const float field_padding = 45;
private readonly Bindable<string> nameBind = new Bindable<string>(); private readonly Bindable<string> nameBind = new Bindable<string>();
private readonly Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
private readonly Bindable<RoomAvailability> availabilityBind = new Bindable<RoomAvailability>(); private readonly Bindable<RoomAvailability> availabilityBind = new Bindable<RoomAvailability>();
private readonly Bindable<GameType> typeBind = new Bindable<GameType>(); private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>(); private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
private readonly IBindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
private readonly Container content; private readonly Container content;
@ -160,7 +159,7 @@ namespace osu.Game.Screens.Multi.Match.Components
typeLabel.Colour = colours.Yellow; typeLabel.Colour = colours.Yellow;
nameBind.BindTo(room.Name); nameBind.BindTo(room.Name);
beatmapBind.BindTo(room.Beatmap); playlistBind.BindTo(room.Playlist);
availabilityBind.BindTo(room.Availability); availabilityBind.BindTo(room.Availability);
typeBind.BindTo(room.Type); typeBind.BindTo(room.Type);
maxParticipantsBind.BindTo(room.MaxParticipants); maxParticipantsBind.BindTo(room.MaxParticipants);
@ -179,7 +178,7 @@ namespace osu.Game.Screens.Multi.Match.Components
ApplyButton.Enabled.Value = hasValidSettings; 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() protected override void PopIn()
{ {

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -20,12 +21,12 @@ namespace osu.Game.Screens.Multi.Match
private readonly Participants participants; private readonly Participants participants;
private readonly Bindable<string> nameBind = new Bindable<string>(); private readonly Bindable<string> nameBind = new Bindable<string>();
private readonly Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>(); private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
private readonly Bindable<RoomAvailability> availabilityBind = new Bindable<RoomAvailability>(); private readonly Bindable<RoomAvailability> availabilityBind = new Bindable<RoomAvailability>();
private readonly Bindable<GameType> typeBind = new Bindable<GameType>(); private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>(); private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>(); private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>();
private readonly BindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
protected override Drawable TransitionContent => participants; protected override Drawable TransitionContent => participants;
@ -33,6 +34,9 @@ namespace osu.Game.Screens.Multi.Match
public override string ShortTitle => "room"; public override string ShortTitle => "room";
private readonly Components.Header header;
private readonly Info info;
[Cached] [Cached]
private readonly Room room; private readonly Room room;
@ -47,16 +51,13 @@ namespace osu.Game.Screens.Multi.Match
this.room = room; this.room = room;
nameBind.BindTo(room.Name); nameBind.BindTo(room.Name);
beatmapBind.BindTo(room.Beatmap);
statusBind.BindTo(room.Status); statusBind.BindTo(room.Status);
availabilityBind.BindTo(room.Availability); availabilityBind.BindTo(room.Availability);
typeBind.BindTo(room.Type); typeBind.BindTo(room.Type);
participantsBind.BindTo(room.Participants); participantsBind.BindTo(room.Participants);
maxParticipantsBind.BindTo(room.MaxParticipants); maxParticipantsBind.BindTo(room.MaxParticipants);
Components.Header header;
RoomSettingsOverlay settings; RoomSettingsOverlay settings;
Info info;
Children = new Drawable[] Children = new Drawable[]
{ {
@ -86,7 +87,6 @@ namespace osu.Game.Screens.Multi.Match
}; };
header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect()); header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect());
header.Beatmap.BindTo(beatmapBind);
header.Tabs.Current.ValueChanged += t => header.Tabs.Current.ValueChanged += t =>
{ {
@ -96,7 +96,6 @@ namespace osu.Game.Screens.Multi.Match
settings.Hide(); settings.Hide();
}; };
info.Beatmap.BindTo(beatmapBind);
info.Name.BindTo(nameBind); info.Name.BindTo(nameBind);
info.Status.BindTo(statusBind); info.Status.BindTo(statusBind);
info.Availability.BindTo(availabilityBind); info.Availability.BindTo(availabilityBind);
@ -104,14 +103,49 @@ namespace osu.Game.Screens.Multi.Match
participants.Users.BindTo(participantsBind); participants.Users.BindTo(participantsBind);
participants.MaxParticipants.BindTo(maxParticipantsBind); participants.MaxParticipants.BindTo(maxParticipantsBind);
playlistBind.ItemsAdded += _ => updatePlaylist();
playlistBind.ItemsRemoved += _ => updatePlaylist();
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
beatmapBind.BindTo(room.Beatmap); Beatmap.BindValueChanged(b =>
beatmapBind.BindValueChanged(b => Beatmap.Value = beatmapManager.GetWorkingBeatmap(room.Beatmap.Value), true); {
Beatmap.BindValueChanged(b => beatmapBind.Value = b.BeatmapInfo); 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();
}
} }
} }
} }

View File

@ -69,9 +69,6 @@ namespace osu.Game.Screens.Multi
pi.SetRulesets(rulesets); pi.SetRulesets(rulesets);
} }
// Temporarily
r.Beatmap.Value = r.Playlist.FirstOrDefault()?.Beatmap;
var existing = rooms.FirstOrDefault(e => e.RoomID.Value == r.RoomID.Value); var existing = rooms.FirstOrDefault(e => e.RoomID.Value == r.RoomID.Value);
if (existing == null) if (existing == null)
rooms.Add(r); rooms.Add(r);