mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 00:02:56 +08:00
Merge pull request #17187 from smoogipoo/fix-playlist-copy
Fix unable to copy playlist rooms without first opening
This commit is contained in:
commit
df500dec04
@ -10,12 +10,11 @@ using osu.Game.IO.Serialization.Converters;
|
|||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.Rooms.RoomStatuses;
|
using osu.Game.Online.Rooms.RoomStatuses;
|
||||||
using osu.Game.Utils;
|
|
||||||
|
|
||||||
namespace osu.Game.Online.Rooms
|
namespace osu.Game.Online.Rooms
|
||||||
{
|
{
|
||||||
[JsonObject(MemberSerialization.OptIn)]
|
[JsonObject(MemberSerialization.OptIn)]
|
||||||
public class Room : IDeepCloneable<Room>
|
public class Room
|
||||||
{
|
{
|
||||||
[Cached]
|
[Cached]
|
||||||
[JsonProperty("id")]
|
[JsonProperty("id")]
|
||||||
@ -153,22 +152,6 @@ namespace osu.Game.Online.Rooms
|
|||||||
Password.BindValueChanged(p => HasPassword.Value = !string.IsNullOrEmpty(p.NewValue));
|
Password.BindValueChanged(p => HasPassword.Value = !string.IsNullOrEmpty(p.NewValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
|
||||||
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)
|
public void CopyFrom(Room other)
|
||||||
{
|
{
|
||||||
RoomID.Value = other.RoomID.Value;
|
RoomID.Value = other.RoomID.Value;
|
||||||
|
@ -128,7 +128,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
{
|
{
|
||||||
new OsuMenuItem("Create copy", MenuItemType.Standard, () =>
|
new OsuMenuItem("Create copy", MenuItemType.Standard, () =>
|
||||||
{
|
{
|
||||||
lounge?.Open(Room.DeepClone());
|
lounge?.OpenCopy(Room);
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ using osu.Framework.Threading;
|
|||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Input;
|
using osu.Game.Input;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
@ -63,6 +64,9 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<RulesetInfo> ruleset { get; set; }
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
[CanBeNull]
|
[CanBeNull]
|
||||||
private IDisposable joiningRoomOperation { get; set; }
|
private IDisposable joiningRoomOperation { get; set; }
|
||||||
|
|
||||||
@ -310,6 +314,42 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Copies a room and opens it as a fresh (not-yet-created) one.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="room">The room to copy.</param>
|
||||||
|
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 += exception =>
|
||||||
|
{
|
||||||
|
Logger.Error(exception, "Couldn't create a copy of this room.");
|
||||||
|
joiningRoomOperation?.Dispose();
|
||||||
|
joiningRoomOperation = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
api.Queue(req);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Push a room as a new subscreen.
|
/// Push a room as a new subscreen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user