mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 17:13:06 +08:00
Context menu for duplicating multi rooms
This commit is contained in:
parent
d8ffc00f75
commit
3a97ee4712
@ -103,38 +103,48 @@ namespace osu.Game.Online.Multiplayer
|
||||
[JsonIgnore]
|
||||
public readonly Bindable<int> Position = new Bindable<int>(-1);
|
||||
|
||||
public void CopyFrom(Room other)
|
||||
/// <summary>
|
||||
/// Copies the properties from another <see cref="Room"/> to this room.
|
||||
/// </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)
|
||||
{
|
||||
RoomID.Value = other.RoomID.Value;
|
||||
if (!duplicate)
|
||||
{
|
||||
RoomID.Value = other.RoomID.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;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -21,10 +21,12 @@ using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Screens.Multi.Components;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
{
|
||||
public class DrawableRoom : OsuClickableContainer, IStateful<SelectionState>, IFilterable
|
||||
public class DrawableRoom : OsuClickableContainer, IStateful<SelectionState>, IFilterable, IHasContextMenu
|
||||
{
|
||||
public const float SELECTION_BORDER_WIDTH = 4;
|
||||
private const float corner_radius = 5;
|
||||
@ -36,6 +38,8 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
|
||||
public event Action<SelectionState> StateChanged;
|
||||
|
||||
public Action<Room> DuplicateRoom;
|
||||
|
||||
private readonly Box selectionBox;
|
||||
private CachedModelDependencyContainer<Room> dependencies;
|
||||
|
||||
@ -232,5 +236,10 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
Current = name;
|
||||
}
|
||||
}
|
||||
|
||||
public MenuItem[] ContextMenuItems => new MenuItem[]
|
||||
{
|
||||
new OsuMenuItem("Duplicate", MenuItemType.Standard, () => DuplicateRoom?.Invoke(Room))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osuTK;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
|
||||
namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
{
|
||||
@ -37,17 +38,24 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
[Resolved]
|
||||
private IRoomManager roomManager { get; set; }
|
||||
|
||||
public Action<Room> DuplicateRoom;
|
||||
|
||||
public RoomsContainer()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
InternalChild = roomFlow = new FillFlowContainer<DrawableRoom>
|
||||
InternalChild = new OsuContextMenuContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(2),
|
||||
Child = roomFlow = new FillFlowContainer<DrawableRoom>
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(2),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -88,6 +96,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
{
|
||||
roomFlow.Add(new DrawableRoom(room)
|
||||
{
|
||||
DuplicateRoom = DuplicateRoom,
|
||||
Action = () =>
|
||||
{
|
||||
if (room == selectedRoom.Value)
|
||||
|
@ -62,7 +62,18 @@ namespace osu.Game.Screens.Multi.Lounge
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
ScrollbarOverlapsContent = false,
|
||||
Padding = new MarginPadding(10),
|
||||
Child = roomsContainer = new RoomsContainer { JoinRequested = joinRequested }
|
||||
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);
|
||||
}
|
||||
}
|
||||
},
|
||||
loadingLayer = new LoadingLayer(roomsContainer),
|
||||
}
|
||||
@ -126,7 +137,7 @@ namespace osu.Game.Screens.Multi.Lounge
|
||||
if (selectedRoom.Value?.RoomID.Value == null)
|
||||
selectedRoom.Value = new Room();
|
||||
|
||||
music.EnsurePlayingSomething();
|
||||
music?.EnsurePlayingSomething();
|
||||
|
||||
onReturning();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace osu.Game.Screens.Multi
|
||||
[Cached]
|
||||
private readonly Bindable<FilterCriteria> currentFilter = new Bindable<FilterCriteria>(new FilterCriteria());
|
||||
|
||||
[Resolved]
|
||||
[Resolved(CanBeNull = true)]
|
||||
private MusicController music { get; set; }
|
||||
|
||||
[Cached(Type = typeof(IRoomManager))]
|
||||
@ -350,7 +350,7 @@ namespace osu.Game.Screens.Multi
|
||||
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
|
||||
track.Looping = true;
|
||||
|
||||
music.EnsurePlayingSomething();
|
||||
music?.EnsurePlayingSomething();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user