mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 00:42:55 +08:00
Context menu for duplicating multi rooms
This commit is contained in:
parent
d8ffc00f75
commit
3a97ee4712
@ -103,31 +103,28 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public readonly Bindable<int> Position = new Bindable<int>(-1);
|
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)
|
||||||
|
{
|
||||||
|
if (!duplicate)
|
||||||
{
|
{
|
||||||
RoomID.Value = other.RoomID.Value;
|
RoomID.Value = other.RoomID.Value;
|
||||||
Name.Value = other.Name.Value;
|
|
||||||
|
|
||||||
if (other.Host.Value != null && Host.Value?.Id != other.Host.Value.Id)
|
if (other.Host.Value != null && Host.Value?.Id != other.Host.Value.Id)
|
||||||
Host.Value = other.Host.Value;
|
Host.Value = other.Host.Value;
|
||||||
|
|
||||||
ChannelId.Value = other.ChannelId.Value;
|
ChannelId.Value = other.ChannelId.Value;
|
||||||
Status.Value = other.Status.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;
|
ParticipantCount.Value = other.ParticipantCount.Value;
|
||||||
EndDate.Value = other.EndDate.Value;
|
EndDate.Value = other.EndDate.Value;
|
||||||
|
|
||||||
if (DateTimeOffset.Now >= EndDate.Value)
|
if (DateTimeOffset.Now >= EndDate.Value)
|
||||||
Status.Value = new RoomStatusEnded();
|
Status.Value = new RoomStatusEnded();
|
||||||
|
|
||||||
if (!Playlist.SequenceEqual(other.Playlist))
|
|
||||||
{
|
|
||||||
Playlist.Clear();
|
|
||||||
Playlist.AddRange(other.Playlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!RecentParticipants.SequenceEqual(other.RecentParticipants))
|
if (!RecentParticipants.SequenceEqual(other.RecentParticipants))
|
||||||
{
|
{
|
||||||
RecentParticipants.Clear();
|
RecentParticipants.Clear();
|
||||||
@ -137,6 +134,19 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
Position.Value = other.Position.Value;
|
Position.Value = other.Position.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Name.Value = other.Name.Value;
|
||||||
|
|
||||||
|
Availability.Value = other.Availability.Value;
|
||||||
|
Type.Value = other.Type.Value;
|
||||||
|
MaxParticipants.Value = other.MaxParticipants.Value;
|
||||||
|
|
||||||
|
if (!Playlist.SequenceEqual(other.Playlist))
|
||||||
|
{
|
||||||
|
Playlist.Clear();
|
||||||
|
Playlist.AddRange(other.Playlist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool ShouldSerializeRoomID() => false;
|
public bool ShouldSerializeRoomID() => false;
|
||||||
public bool ShouldSerializeHost() => false;
|
public bool ShouldSerializeHost() => false;
|
||||||
public bool ShouldSerializeEndDate() => false;
|
public bool ShouldSerializeEndDate() => false;
|
||||||
|
@ -21,10 +21,12 @@ using osu.Game.Online.Multiplayer;
|
|||||||
using osu.Game.Screens.Multi.Components;
|
using osu.Game.Screens.Multi.Components;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Lounge.Components
|
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;
|
public const float SELECTION_BORDER_WIDTH = 4;
|
||||||
private const float corner_radius = 5;
|
private const float corner_radius = 5;
|
||||||
@ -36,6 +38,8 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
|
|
||||||
public event Action<SelectionState> StateChanged;
|
public event Action<SelectionState> StateChanged;
|
||||||
|
|
||||||
|
public Action<Room> DuplicateRoom;
|
||||||
|
|
||||||
private readonly Box selectionBox;
|
private readonly Box selectionBox;
|
||||||
private CachedModelDependencyContainer<Room> dependencies;
|
private CachedModelDependencyContainer<Room> dependencies;
|
||||||
|
|
||||||
@ -232,5 +236,10 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
Current = name;
|
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.Input.Bindings;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using osu.Game.Graphics.Cursor;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Lounge.Components
|
namespace osu.Game.Screens.Multi.Lounge.Components
|
||||||
{
|
{
|
||||||
@ -37,17 +38,24 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private IRoomManager roomManager { get; set; }
|
private IRoomManager roomManager { get; set; }
|
||||||
|
|
||||||
|
public Action<Room> DuplicateRoom;
|
||||||
|
|
||||||
public RoomsContainer()
|
public RoomsContainer()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
InternalChild = roomFlow = new FillFlowContainer<DrawableRoom>
|
InternalChild = new OsuContextMenuContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Child = roomFlow = new FillFlowContainer<DrawableRoom>
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
Spacing = new Vector2(2),
|
Spacing = new Vector2(2),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +96,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
|||||||
{
|
{
|
||||||
roomFlow.Add(new DrawableRoom(room)
|
roomFlow.Add(new DrawableRoom(room)
|
||||||
{
|
{
|
||||||
|
DuplicateRoom = DuplicateRoom,
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
if (room == selectedRoom.Value)
|
if (room == selectedRoom.Value)
|
||||||
|
@ -62,7 +62,18 @@ namespace osu.Game.Screens.Multi.Lounge
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
ScrollbarOverlapsContent = false,
|
ScrollbarOverlapsContent = false,
|
||||||
Padding = new MarginPadding(10),
|
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),
|
loadingLayer = new LoadingLayer(roomsContainer),
|
||||||
}
|
}
|
||||||
@ -126,7 +137,7 @@ namespace osu.Game.Screens.Multi.Lounge
|
|||||||
if (selectedRoom.Value?.RoomID.Value == null)
|
if (selectedRoom.Value?.RoomID.Value == null)
|
||||||
selectedRoom.Value = new Room();
|
selectedRoom.Value = new Room();
|
||||||
|
|
||||||
music.EnsurePlayingSomething();
|
music?.EnsurePlayingSomething();
|
||||||
|
|
||||||
onReturning();
|
onReturning();
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace osu.Game.Screens.Multi
|
|||||||
[Cached]
|
[Cached]
|
||||||
private readonly Bindable<FilterCriteria> currentFilter = new Bindable<FilterCriteria>(new FilterCriteria());
|
private readonly Bindable<FilterCriteria> currentFilter = new Bindable<FilterCriteria>(new FilterCriteria());
|
||||||
|
|
||||||
[Resolved]
|
[Resolved(CanBeNull = true)]
|
||||||
private MusicController music { get; set; }
|
private MusicController music { get; set; }
|
||||||
|
|
||||||
[Cached(Type = typeof(IRoomManager))]
|
[Cached(Type = typeof(IRoomManager))]
|
||||||
@ -350,7 +350,7 @@ namespace osu.Game.Screens.Multi
|
|||||||
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
|
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
|
||||||
track.Looping = true;
|
track.Looping = true;
|
||||||
|
|
||||||
music.EnsurePlayingSomething();
|
music?.EnsurePlayingSomething();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user