mirror of
https://github.com/ppy/osu.git
synced 2025-03-18 03:27:20 +08:00
Cache LoungeSubScreen, separate method, rename option
This commit is contained in:
parent
3a97ee4712
commit
9e4b9188e1
@ -104,47 +104,55 @@ namespace osu.Game.Online.Multiplayer
|
||||
public readonly Bindable<int> Position = new Bindable<int>(-1);
|
||||
|
||||
/// <summary>
|
||||
/// Copies the properties from another <see cref="Room"/> to this room.
|
||||
/// Create a copy of this room, without information specific to it, such as Room ID or host
|
||||
/// </summary>
|
||||
/// <param name="other">The room to copy</param>
|
||||
/// <param name="duplicate">Whether the copy should exclude information unique to a specific room (i.e. when duplicating a room)</param>
|
||||
public void CopyFrom(Room other, bool duplicate = false)
|
||||
public Room CreateCopy()
|
||||
{
|
||||
if (!duplicate)
|
||||
Room newRoom = new Room
|
||||
{
|
||||
RoomID.Value = other.RoomID.Value;
|
||||
Name = { Value = Name.Value },
|
||||
Availability = { Value = Availability.Value },
|
||||
Type = { Value = Type.Value },
|
||||
MaxParticipants = { Value = MaxParticipants.Value }
|
||||
};
|
||||
|
||||
if (other.Host.Value != null && Host.Value?.Id != other.Host.Value.Id)
|
||||
Host.Value = other.Host.Value;
|
||||
newRoom.Playlist.AddRange(Playlist);
|
||||
|
||||
ChannelId.Value = other.ChannelId.Value;
|
||||
Status.Value = other.Status.Value;
|
||||
ParticipantCount.Value = other.ParticipantCount.Value;
|
||||
EndDate.Value = other.EndDate.Value;
|
||||
|
||||
if (DateTimeOffset.Now >= EndDate.Value)
|
||||
Status.Value = new RoomStatusEnded();
|
||||
|
||||
if (!RecentParticipants.SequenceEqual(other.RecentParticipants))
|
||||
{
|
||||
RecentParticipants.Clear();
|
||||
RecentParticipants.AddRange(other.RecentParticipants);
|
||||
}
|
||||
|
||||
Position.Value = other.Position.Value;
|
||||
}
|
||||
return newRoom;
|
||||
}
|
||||
|
||||
public void CopyFrom(Room other)
|
||||
{
|
||||
RoomID.Value = other.RoomID.Value;
|
||||
Name.Value = other.Name.Value;
|
||||
|
||||
if (other.Host.Value != null && Host.Value?.Id != other.Host.Value.Id)
|
||||
Host.Value = other.Host.Value;
|
||||
|
||||
ChannelId.Value = other.ChannelId.Value;
|
||||
Status.Value = other.Status.Value;
|
||||
Availability.Value = other.Availability.Value;
|
||||
Type.Value = other.Type.Value;
|
||||
MaxParticipants.Value = other.MaxParticipants.Value;
|
||||
ParticipantCount.Value = other.ParticipantCount.Value;
|
||||
EndDate.Value = other.EndDate.Value;
|
||||
|
||||
if (DateTimeOffset.Now >= EndDate.Value)
|
||||
Status.Value = new RoomStatusEnded();
|
||||
|
||||
if (!Playlist.SequenceEqual(other.Playlist))
|
||||
{
|
||||
Playlist.Clear();
|
||||
Playlist.AddRange(other.Playlist);
|
||||
}
|
||||
|
||||
if (!RecentParticipants.SequenceEqual(other.RecentParticipants))
|
||||
{
|
||||
RecentParticipants.Clear();
|
||||
RecentParticipants.AddRange(other.RecentParticipants);
|
||||
}
|
||||
|
||||
Position.Value = other.Position.Value;
|
||||
}
|
||||
|
||||
public bool ShouldSerializeRoomID() => false;
|
||||
|
@ -38,7 +38,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
|
||||
public event Action<SelectionState> StateChanged;
|
||||
|
||||
public Action<Room> DuplicateRoom;
|
||||
public Action DuplicateRoom;
|
||||
|
||||
private readonly Box selectionBox;
|
||||
private CachedModelDependencyContainer<Room> dependencies;
|
||||
@ -239,7 +239,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
|
||||
public MenuItem[] ContextMenuItems => new MenuItem[]
|
||||
{
|
||||
new OsuMenuItem("Duplicate", MenuItemType.Standard, () => DuplicateRoom?.Invoke(Room))
|
||||
new OsuMenuItem("Create copy", MenuItemType.Standard, DuplicateRoom)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
[Resolved]
|
||||
private IRoomManager roomManager { get; set; }
|
||||
|
||||
public Action<Room> DuplicateRoom;
|
||||
[Resolved]
|
||||
private LoungeSubScreen loungeSubScreen { get; set; }
|
||||
|
||||
public RoomsContainer()
|
||||
{
|
||||
@ -96,7 +97,13 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
{
|
||||
roomFlow.Add(new DrawableRoom(room)
|
||||
{
|
||||
DuplicateRoom = DuplicateRoom,
|
||||
DuplicateRoom = () =>
|
||||
{
|
||||
Room newRoom = room.CreateCopy();
|
||||
newRoom.Name.Value = $"Copy of {room.Name.Value}";
|
||||
|
||||
loungeSubScreen.Open(newRoom);
|
||||
},
|
||||
Action = () =>
|
||||
{
|
||||
if (room == selectedRoom.Value)
|
||||
|
@ -18,6 +18,7 @@ using osu.Game.Screens.Multi.Match;
|
||||
|
||||
namespace osu.Game.Screens.Multi.Lounge
|
||||
{
|
||||
[Cached]
|
||||
public class LoungeSubScreen : MultiplayerSubScreen
|
||||
{
|
||||
public override string Title => "Lounge";
|
||||
@ -62,18 +63,7 @@ namespace osu.Game.Screens.Multi.Lounge
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
ScrollbarOverlapsContent = false,
|
||||
Padding = new MarginPadding(10),
|
||||
Child = roomsContainer = new RoomsContainer
|
||||
{
|
||||
JoinRequested = joinRequested,
|
||||
DuplicateRoom = room =>
|
||||
{
|
||||
Room newRoom = new Room();
|
||||
newRoom.CopyFrom(room, true);
|
||||
newRoom.Name.Value = $"Copy of {room.Name.Value}";
|
||||
|
||||
Open(newRoom);
|
||||
}
|
||||
}
|
||||
Child = roomsContainer = new RoomsContainer { JoinRequested = joinRequested }
|
||||
},
|
||||
loadingLayer = new LoadingLayer(roomsContainer),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user