diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/BeatmapSelectionControl.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/BeatmapSelectionControl.cs
index 3af0d5b715..ebe63e26d6 100644
--- a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/BeatmapSelectionControl.cs
+++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/BeatmapSelectionControl.cs
@@ -11,7 +11,7 @@ using osu.Game.Screens.OnlinePlay.Match.Components;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
{
- public class BeatmapSelectionControl : OnlinePlayComposite
+ public class BeatmapSelectionControl : RoomSubScreenComposite
{
[Resolved]
private MultiplayerMatchSubScreen matchSubScreen { get; set; }
diff --git a/osu.Game/Screens/OnlinePlay/OnlinePlayComposite.cs b/osu.Game/Screens/OnlinePlay/OnlinePlayComposite.cs
index f203ef927c..eb0b23f13f 100644
--- a/osu.Game/Screens/OnlinePlay/OnlinePlayComposite.cs
+++ b/osu.Game/Screens/OnlinePlay/OnlinePlayComposite.cs
@@ -2,9 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
-using System.Collections.Specialized;
using System.Linq;
-using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
@@ -14,6 +12,9 @@ using osu.Game.Users;
namespace osu.Game.Screens.OnlinePlay
{
+ ///
+ /// A that exposes bindables for properties.
+ ///
public class OnlinePlayComposite : CompositeDrawable
{
[Resolved(typeof(Room))]
@@ -62,41 +63,18 @@ namespace osu.Game.Screens.OnlinePlay
/// The currently selected item in the , or the first item from
/// if this is not within a .
///
- protected IBindable SelectedItem => selectedItem;
-
- private readonly Bindable selectedItem = new Bindable();
-
- [CanBeNull]
- [Resolved(CanBeNull = true)]
- private IBindable subScreenSelectedItem { get; set; }
+ protected readonly Bindable SelectedItem = new Bindable();
protected override void LoadComplete()
{
base.LoadComplete();
- if (subScreenSelectedItem != null)
- subScreenSelectedItem.BindValueChanged(onSelectedItemChanged, true);
- else
- Playlist.BindCollectionChanged(onPlaylistChanged, true);
+ Playlist.BindCollectionChanged((_, __) => UpdateSelectedItem(), true);
}
- ///
- /// Invoked when the selected item from within a changes.
- /// Does not occur when this is outside a .
- ///
- private void onSelectedItemChanged(ValueChangedEvent item)
+ protected virtual void UpdateSelectedItem()
{
- // If the room hasn't been created yet, fall-back to the first item from the playlist.
- selectedItem.Value = RoomID.Value == null ? Playlist.FirstOrDefault() : item.NewValue;
- }
-
- ///
- /// Invoked when the playlist changes.
- /// Does not occur when this is inside a .
- ///
- private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- selectedItem.Value = Playlist.FirstOrDefault();
+ SelectedItem.Value = Playlist.FirstOrDefault();
}
}
}
diff --git a/osu.Game/Screens/OnlinePlay/RoomSubScreenComposite.cs b/osu.Game/Screens/OnlinePlay/RoomSubScreenComposite.cs
new file mode 100644
index 0000000000..4cfd881aa3
--- /dev/null
+++ b/osu.Game/Screens/OnlinePlay/RoomSubScreenComposite.cs
@@ -0,0 +1,38 @@
+// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence.
+// See the LICENCE file in the repository root for full licence text.
+
+using osu.Framework.Allocation;
+using osu.Framework.Bindables;
+using osu.Game.Online.Rooms;
+using osu.Game.Screens.OnlinePlay.Match;
+
+namespace osu.Game.Screens.OnlinePlay
+{
+ ///
+ /// An with additional logic tracking the currently-selected inside a .
+ ///
+ public class RoomSubScreenComposite : OnlinePlayComposite
+ {
+ [Resolved]
+ private IBindable subScreenSelectedItem { get; set; }
+
+ protected override void LoadComplete()
+ {
+ base.LoadComplete();
+
+ subScreenSelectedItem.BindValueChanged(_ => UpdateSelectedItem(), true);
+ }
+
+ protected override void UpdateSelectedItem()
+ {
+ if (RoomID.Value == null)
+ {
+ // If the room hasn't been created yet, fall-back to the base logic.
+ base.UpdateSelectedItem();
+ return;
+ }
+
+ SelectedItem.Value = subScreenSelectedItem.Value;
+ }
+ }
+}