diff --git a/osu.Game/Online/Rooms/Room.cs b/osu.Game/Online/Rooms/Room.cs index a33150fe08..543b176b51 100644 --- a/osu.Game/Online/Rooms/Room.cs +++ b/osu.Game/Online/Rooms/Room.cs @@ -10,12 +10,11 @@ using osu.Game.IO.Serialization.Converters; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Multiplayer; using osu.Game.Online.Rooms.RoomStatuses; -using osu.Game.Utils; namespace osu.Game.Online.Rooms { [JsonObject(MemberSerialization.OptIn)] - public class Room : IDeepCloneable + public class Room { [Cached] [JsonProperty("id")] @@ -153,22 +152,6 @@ namespace osu.Game.Online.Rooms Password.BindValueChanged(p => HasPassword.Value = !string.IsNullOrEmpty(p.NewValue)); } - /// - /// Create a copy of this room without online information. - /// Should be used to create a local copy of a room for submitting in the future. - /// - public Room DeepClone() - { - var copy = new Room(); - - copy.CopyFrom(this); - - // ID must be unset as we use this as a marker for whether this is a client-side (not-yet-created) room or not. - copy.RoomID.Value = null; - - return copy; - } - public void CopyFrom(Room other) { RoomID.Value = other.RoomID.Value; diff --git a/osu.Game/Screens/OnlinePlay/Lounge/DrawableLoungeRoom.cs b/osu.Game/Screens/OnlinePlay/Lounge/DrawableLoungeRoom.cs index 27743e709f..7baa346c6f 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/DrawableLoungeRoom.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/DrawableLoungeRoom.cs @@ -128,7 +128,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge { new OsuMenuItem("Create copy", MenuItemType.Standard, () => { - lounge?.Open(Room.DeepClone()); + lounge?.OpenCopy(Room); }) }; diff --git a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs index cd1c8a0a64..08b4ae9db2 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs @@ -20,6 +20,7 @@ using osu.Framework.Threading; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Input; +using osu.Game.Online.API; using osu.Game.Online.Rooms; using osu.Game.Overlays; using osu.Game.Rulesets; @@ -63,6 +64,9 @@ namespace osu.Game.Screens.OnlinePlay.Lounge [Resolved] private IBindable ruleset { get; set; } + [Resolved] + private IAPIProvider api { get; set; } + [CanBeNull] private IDisposable joiningRoomOperation { get; set; } @@ -310,6 +314,41 @@ namespace osu.Game.Screens.OnlinePlay.Lounge }); }); + /// + /// Copies a room and opens it as a fresh (not-yet-created) one. + /// + /// The room to copy. + public void OpenCopy(Room room) + { + Debug.Assert(room.RoomID.Value != null); + + if (joiningRoomOperation != null) + return; + + joiningRoomOperation = ongoingOperationTracker?.BeginOperation(); + + var req = new GetRoomRequest(room.RoomID.Value.Value); + + req.Success += r => + { + // ID must be unset as we use this as a marker for whether this is a client-side (not-yet-created) room or not. + r.RoomID.Value = null; + + Open(r); + + joiningRoomOperation?.Dispose(); + joiningRoomOperation = null; + }; + + req.Failure += _ => + { + joiningRoomOperation?.Dispose(); + joiningRoomOperation = null; + }; + + api.Queue(req); + } + /// /// Push a room as a new subscreen. ///