1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +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");
/// <summary>
/// "Invite player"
/// "Invite to room"
/// </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}";
}

View File

@ -13,6 +13,7 @@ using osu.Game.Overlays;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Screens;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
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.Localisation;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens;
using osu.Game.Screens.Play;
namespace osu.Game.Users
{
@ -60,6 +63,9 @@ namespace osu.Game.Users
[Resolved]
protected OverlayColourProvider? ColourProvider { get; private set; }
[Resolved]
private IPerformFromScreenRunner? performer { get; set; }
[Resolved]
protected OsuColour Colours { get; private set; } = null!;
@ -113,23 +119,26 @@ namespace osu.Game.Users
new OsuMenuItem(ContextMenuStrings.ViewProfile, MenuItemType.Highlighted, ViewProfile)
};
if (!User.Equals(api.LocalUser.Value))
{
items.Add(new OsuMenuItem(UsersStrings.CardSendMessage, MenuItemType.Standard, () =>
{
channelManager?.OpenPrivateChannel(User);
chatOverlay?.Show();
}));
}
if (User.Equals(api.LocalUser.Value))
return items.ToArray();
if (
// 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(UsersStrings.CardSendMessage, MenuItemType.Standard, () =>
{
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();