1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-11 10:57:20 +08:00

Merge pull request #31623 from Layendan/room-context-menu

Add view in browser context menu functionality to multiplayer/playlist rooms
This commit is contained in:
Dean Herbert 2025-01-24 20:31:49 +09:00 committed by GitHub
commit a94681158d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 48 additions and 13 deletions

View File

@ -12,15 +12,19 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.Chat;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
@ -31,11 +35,17 @@ using Container = osu.Framework.Graphics.Containers.Container;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public abstract partial class DrawableRoom : CompositeDrawable
public abstract partial class DrawableRoom : CompositeDrawable, IHasContextMenu
{
protected const float CORNER_RADIUS = 10;
private const float height = 100;
[Resolved]
private IAPIProvider api { get; set; } = null!;
[Resolved]
private OsuGame? game { get; set; }
public readonly Room Room;
protected readonly Bindable<PlaylistItem?> SelectedItem = new Bindable<PlaylistItem?>();
@ -330,6 +340,26 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
}
}
public virtual MenuItem[] ContextMenuItems
{
get
{
var items = new List<MenuItem>();
if (Room.RoomID.HasValue)
{
items.AddRange([
new OsuMenuItem("View in browser", MenuItemType.Standard, () => game?.OpenUrlExternally(formatRoomUrl(Room.RoomID.Value))),
new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyUrlToClipboard(formatRoomUrl(Room.RoomID.Value)))
]);
}
return items.ToArray();
string formatRoomUrl(long id) => $@"{api.WebsiteRootUrl}/multiplayer/rooms/{id}";
}
}
protected virtual UpdateableBeatmapBackgroundSprite CreateBackground() => new UpdateableBeatmapBackgroundSprite();
protected virtual IEnumerable<Drawable> CreateBottomDetails()

View File

@ -39,7 +39,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
/// <summary>
/// A <see cref="DrawableRoom"/> with lounge-specific interactions such as selection and hover sounds.
/// </summary>
public partial class DrawableLoungeRoom : DrawableRoom, IFilterable, IHasContextMenu, IHasPopover, IKeyBindingHandler<GlobalAction>
public partial class DrawableLoungeRoom : DrawableRoom, IFilterable, IHasPopover, IKeyBindingHandler<GlobalAction>
{
private const float transition_duration = 60;
private const float selection_border_width = 4;
@ -155,17 +155,16 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
public Popover GetPopover() => new PasswordEntryPopover(Room);
public MenuItem[] ContextMenuItems
public override MenuItem[] ContextMenuItems
{
get
{
var items = new List<MenuItem>
{
new OsuMenuItem("Create copy", MenuItemType.Standard, () =>
{
lounge?.OpenCopy(Room);
})
};
var items = new List<MenuItem>();
items.AddRange(base.ContextMenuItems);
items.Add(new OsuMenuItemSpacer());
items.Add(new OsuMenuItem("Create copy", MenuItemType.Standard, () => lounge?.OpenCopy(Room)));
if (Room.Type == MatchType.Playlists && Room.Host?.Id == api.LocalUser.Value.Id && Room.StartDate?.AddMinutes(5) >= DateTimeOffset.Now && !Room.HasEnded)
{

View File

@ -18,6 +18,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Screens;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Cursor;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
@ -156,10 +157,15 @@ namespace osu.Game.Screens.OnlinePlay.Match
{
new Drawable[]
{
new DrawableMatchRoom(Room, allowEdit)
new OsuContextMenuContainer
{
OnEdit = () => settingsOverlay.Show(),
SelectedItem = SelectedItem
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = new DrawableMatchRoom(Room, allowEdit)
{
OnEdit = () => settingsOverlay.Show(),
SelectedItem = SelectedItem
}
}
},
null,