1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Add the ability to spectate a user by right clicking their user panel

This commit is contained in:
Dean Herbert 2023-12-28 17:35:10 +09:00
parent 3a3b4d445c
commit 2ec9343868
No known key found for this signature in database
2 changed files with 31 additions and 17 deletions

View File

@ -20,9 +20,14 @@ namespace osu.Game.Localisation
public static LocalisableString ViewBeatmap => new TranslatableString(getKey(@"view_beatmap"), @"View beatmap"); public static LocalisableString ViewBeatmap => new TranslatableString(getKey(@"view_beatmap"), @"View beatmap");
/// <summary> /// <summary>
/// "Invite player" /// "Invite to room"
/// </summary> /// </summary>
public static LocalisableString InvitePlayer => new TranslatableString(getKey(@"invite_player"), @"Invite player"); public static LocalisableString InvitePlayer => new TranslatableString(getKey(@"invite_player"), @"Invite to room");
/// <summary>
/// "Spectate"
/// </summary>
public static LocalisableString SpectatePlayer => new TranslatableString(getKey(@"spectate_player"), @"Spectate");
private static string getKey(string key) => $@"{prefix}:{key}"; private static string getKey(string key) => $@"{prefix}:{key}";
} }

View File

@ -13,6 +13,7 @@ using osu.Game.Overlays;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Screens;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
@ -20,6 +21,8 @@ using osu.Game.Online.Chat;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Screens;
using osu.Game.Screens.Play;
namespace osu.Game.Users namespace osu.Game.Users
{ {
@ -60,6 +63,9 @@ namespace osu.Game.Users
[Resolved] [Resolved]
protected OverlayColourProvider? ColourProvider { get; private set; } protected OverlayColourProvider? ColourProvider { get; private set; }
[Resolved]
private IPerformFromScreenRunner? performer { get; set; }
[Resolved] [Resolved]
protected OsuColour Colours { get; private set; } = null!; protected OsuColour Colours { get; private set; } = null!;
@ -113,23 +119,26 @@ namespace osu.Game.Users
new OsuMenuItem(ContextMenuStrings.ViewProfile, MenuItemType.Highlighted, ViewProfile) new OsuMenuItem(ContextMenuStrings.ViewProfile, MenuItemType.Highlighted, ViewProfile)
}; };
if (!User.Equals(api.LocalUser.Value)) if (User.Equals(api.LocalUser.Value))
{ return items.ToArray();
items.Add(new OsuMenuItem(UsersStrings.CardSendMessage, MenuItemType.Standard, () =>
{
channelManager?.OpenPrivateChannel(User);
chatOverlay?.Show();
}));
}
if ( items.Add(new OsuMenuItem(UsersStrings.CardSendMessage, MenuItemType.Standard, () =>
// TODO: uncomment this once lazer / osu-web is updating online states
// User.IsOnline &&
multiplayerClient?.Room != null &&
multiplayerClient.Room.Users.All(u => u.UserID != User.Id)
)
{ {
items.Add(new OsuMenuItem(ContextMenuStrings.InvitePlayer, MenuItemType.Standard, () => multiplayerClient.InvitePlayer(User.Id))); channelManager?.OpenPrivateChannel(User);
chatOverlay?.Show();
}));
if (User.IsOnline)
{
items.Add(new OsuMenuItem(ContextMenuStrings.SpectatePlayer, MenuItemType.Standard, () =>
{
performer?.PerformFromScreen(s => s.Push(new SoloSpectatorScreen(User)));
}));
if (multiplayerClient?.Room?.Users.All(u => u.UserID != User.Id) == true)
{
items.Add(new OsuMenuItem(ContextMenuStrings.InvitePlayer, MenuItemType.Standard, () => multiplayerClient.InvitePlayer(User.Id)));
}
} }
return items.ToArray(); return items.ToArray();