From d9537017c8e353c76fbf072eb81c6fe97de993f6 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 5 Feb 2019 15:56:18 +0900 Subject: [PATCH] Use CMC in the Multiplayer screen --- osu.Game/Online/Multiplayer/Room.cs | 2 +- osu.Game/Screens/Multi/Multiplayer.cs | 9 +++++++++ osu.Game/Screens/Multi/RoomManager.cs | 12 ++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/Multiplayer/Room.cs b/osu.Game/Online/Multiplayer/Room.cs index c20780aecc..46c22ef0cd 100644 --- a/osu.Game/Online/Multiplayer/Room.cs +++ b/osu.Game/Online/Multiplayer/Room.cs @@ -83,7 +83,7 @@ namespace osu.Game.Online.Multiplayer /// The position of this in the list. This is not read from or written to the API. /// [JsonIgnore] - public int Position = -1; + public Bindable Position { get; private set; } = new Bindable(-1); public void CopyFrom(Room other) { diff --git a/osu.Game/Screens/Multi/Multiplayer.cs b/osu.Game/Screens/Multi/Multiplayer.cs index be9650019d..f0297cdfa9 100644 --- a/osu.Game/Screens/Multi/Multiplayer.cs +++ b/osu.Game/Screens/Multi/Multiplayer.cs @@ -149,6 +149,15 @@ namespace osu.Game.Screens.Multi isIdle.BindTo(idleTracker.IsIdle); } + private CachedModelDependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + dependencies = new CachedModelDependencyContainer(base.CreateChildDependencies(parent)); + dependencies.Model.BindTo(roomManager.CurrentRoom); + return dependencies; + } + protected override void LoadComplete() { base.LoadComplete(); diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index 1457261770..d9ddd6f867 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -23,7 +23,7 @@ namespace osu.Game.Screens.Multi private readonly BindableList rooms = new BindableList(); public IBindableList Rooms => rooms; - private Room currentRoom; + public readonly Bindable CurrentRoom = new Bindable(); [Resolved] private APIAccess api { get; set; } @@ -77,7 +77,7 @@ namespace osu.Game.Screens.Multi currentJoinRoomRequest = new JoinRoomRequest(room, api.LocalUser.Value); currentJoinRoomRequest.Success += () => { - currentRoom = room; + CurrentRoom.Value = room; onSuccess?.Invoke(room); }; @@ -92,11 +92,11 @@ namespace osu.Game.Screens.Multi public void PartRoom() { - if (currentRoom == null) + if (CurrentRoom.Value == null) return; - api.Queue(new PartRoomRequest(currentRoom, api.LocalUser.Value)); - currentRoom = null; + api.Queue(new PartRoomRequest(CurrentRoom.Value, api.LocalUser.Value)); + CurrentRoom.Value = null; } public void UpdateRooms(List newRooms) @@ -111,7 +111,7 @@ namespace osu.Game.Screens.Multi for (int i = 0; i < newRooms.Count; i++) { var r = newRooms[i]; - r.Position = i; + r.Position.Value = i; update(r, r); addRoom(r);