1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

Merge pull request #22529 from ItsShamed/dsc/presence

Add support for `Watching` and `Spectating` activities in `ReplayPlayer` and `SoloSpectatingPlayer`
This commit is contained in:
Dean Herbert 2023-02-11 17:29:47 +09:00 committed by GitHub
commit 0c5dae5f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 14 deletions

View File

@ -98,7 +98,7 @@ namespace osu.Desktop
if (status.Value is UserStatusOnline && activity.Value != null) if (status.Value is UserStatusOnline && activity.Value != null)
{ {
presence.State = truncate(activity.Value.Status); presence.State = truncate(activity.Value.GetStatus(privacyMode.Value == DiscordRichPresenceMode.Limited));
presence.Details = truncate(getDetails(activity.Value)); presence.Details = truncate(getDetails(activity.Value));
if (getBeatmap(activity.Value) is IBeatmapInfo beatmap && beatmap.OnlineID > 0) if (getBeatmap(activity.Value) is IBeatmapInfo beatmap && beatmap.OnlineID > 0)
@ -186,6 +186,9 @@ namespace osu.Desktop
case UserActivity.Editing edit: case UserActivity.Editing edit:
return edit.BeatmapInfo.ToString() ?? string.Empty; return edit.BeatmapInfo.ToString() ?? string.Empty;
case UserActivity.Watching watching:
return watching.BeatmapInfo.ToString();
case UserActivity.InLobby lobby: case UserActivity.InLobby lobby:
return privacyMode.Value == DiscordRichPresenceMode.Limited ? string.Empty : lobby.Room.Name.Value; return privacyMode.Value == DiscordRichPresenceMode.Limited ? string.Empty : lobby.Room.Name.Value;
} }

View File

@ -11,6 +11,8 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Tests.Beatmaps;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
@ -107,7 +109,8 @@ namespace osu.Game.Tests.Visual.Online
AddStep("set online status", () => status.Value = new UserStatusOnline()); AddStep("set online status", () => status.Value = new UserStatusOnline());
AddStep("idle", () => activity.Value = null); AddStep("idle", () => activity.Value = null);
AddStep("spectating", () => activity.Value = new UserActivity.Spectating()); AddStep("watching", () => activity.Value = new UserActivity.Watching(createScore(@"nats")));
AddStep("spectating", () => activity.Value = new UserActivity.Spectating(createScore(@"mrekk")));
AddStep("solo (osu!)", () => activity.Value = soloGameStatusForRuleset(0)); AddStep("solo (osu!)", () => activity.Value = soloGameStatusForRuleset(0));
AddStep("solo (osu!taiko)", () => activity.Value = soloGameStatusForRuleset(1)); AddStep("solo (osu!taiko)", () => activity.Value = soloGameStatusForRuleset(1));
AddStep("solo (osu!catch)", () => activity.Value = soloGameStatusForRuleset(2)); AddStep("solo (osu!catch)", () => activity.Value = soloGameStatusForRuleset(2));
@ -132,6 +135,14 @@ namespace osu.Game.Tests.Visual.Online
private UserActivity soloGameStatusForRuleset(int rulesetId) => new UserActivity.InSoloGame(null, rulesetStore.GetRuleset(rulesetId)); private UserActivity soloGameStatusForRuleset(int rulesetId) => new UserActivity.InSoloGame(null, rulesetStore.GetRuleset(rulesetId));
private ScoreInfo createScore(string name) => new ScoreInfo(new TestBeatmap(Ruleset.Value).BeatmapInfo)
{
User = new APIUser
{
Username = name,
}
};
private partial class TestUserListPanel : UserListPanel private partial class TestUserListPanel : UserListPanel
{ {
public TestUserListPanel(APIUser user) public TestUserListPanel(APIUser user)

View File

@ -15,6 +15,7 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
using osu.Game.Users;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
@ -24,6 +25,8 @@ namespace osu.Game.Screens.Play
private readonly bool replayIsFailedScore; private readonly bool replayIsFailedScore;
protected override UserActivity InitialActivity => new UserActivity.Watching(Score.ScoreInfo);
// Disallow replays from failing. (see https://github.com/ppy/osu/issues/6108) // Disallow replays from failing. (see https://github.com/ppy/osu/issues/6108)
protected override bool CheckModsAllowFailure() protected override bool CheckModsAllowFailure()
{ {

View File

@ -7,6 +7,7 @@ using osu.Framework.Allocation;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Users;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
@ -14,6 +15,8 @@ namespace osu.Game.Screens.Play
{ {
private readonly Score score; private readonly Score score;
protected override UserActivity InitialActivity => new UserActivity.Spectating(Score.ScoreInfo);
public SoloSpectatorPlayer(Score score, PlayerConfiguration configuration = null) public SoloSpectatorPlayer(Score score, PlayerConfiguration configuration = null)
: base(score, configuration) : base(score, configuration)
{ {

View File

@ -106,7 +106,7 @@ namespace osu.Game.Users
// Set status message based on activity (if we have one) and status is not offline // Set status message based on activity (if we have one) and status is not offline
if (activity != null && !(status is UserStatusOffline)) if (activity != null && !(status is UserStatusOffline))
{ {
statusMessage.Text = activity.Status; statusMessage.Text = activity.GetStatus();
statusIcon.FadeColour(activity.GetAppropriateColour(Colours), 500, Easing.OutQuint); statusIcon.FadeColour(activity.GetAppropriateColour(Colours), 500, Easing.OutQuint);
return; return;
} }

View File

@ -7,24 +7,26 @@ using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Scoring;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Users namespace osu.Game.Users
{ {
public abstract class UserActivity public abstract class UserActivity
{ {
public abstract string Status { get; } public abstract string GetStatus(bool hideIdentifiableInformation = false);
public virtual Color4 GetAppropriateColour(OsuColour colours) => colours.GreenDarker; public virtual Color4 GetAppropriateColour(OsuColour colours) => colours.GreenDarker;
public class Modding : UserActivity public class Modding : UserActivity
{ {
public override string Status => "Modding a map"; public override string GetStatus(bool hideIdentifiableInformation = false) => "Modding a map";
public override Color4 GetAppropriateColour(OsuColour colours) => colours.PurpleDark; public override Color4 GetAppropriateColour(OsuColour colours) => colours.PurpleDark;
} }
public class ChoosingBeatmap : UserActivity public class ChoosingBeatmap : UserActivity
{ {
public override string Status => "Choosing a beatmap"; public override string GetStatus(bool hideIdentifiableInformation = false) => "Choosing a beatmap";
} }
public abstract class InGame : UserActivity public abstract class InGame : UserActivity
@ -39,7 +41,7 @@ namespace osu.Game.Users
Ruleset = ruleset; Ruleset = ruleset;
} }
public override string Status => Ruleset.CreateInstance().PlayingVerb; public override string GetStatus(bool hideIdentifiableInformation = false) => Ruleset.CreateInstance().PlayingVerb;
} }
public class InMultiplayerGame : InGame public class InMultiplayerGame : InGame
@ -49,7 +51,7 @@ namespace osu.Game.Users
{ {
} }
public override string Status => $@"{base.Status} with others"; public override string GetStatus(bool hideIdentifiableInformation = false) => $@"{base.GetStatus(hideIdentifiableInformation)} with others";
} }
public class SpectatingMultiplayerGame : InGame public class SpectatingMultiplayerGame : InGame
@ -59,7 +61,7 @@ namespace osu.Game.Users
{ {
} }
public override string Status => $"Watching others {base.Status.ToLowerInvariant()}"; public override string GetStatus(bool hideIdentifiableInformation = false) => $"Watching others {base.GetStatus(hideIdentifiableInformation).ToLowerInvariant()}";
} }
public class InPlaylistGame : InGame public class InPlaylistGame : InGame
@ -87,22 +89,43 @@ namespace osu.Game.Users
BeatmapInfo = info; BeatmapInfo = info;
} }
public override string Status => @"Editing a beatmap"; public override string GetStatus(bool hideIdentifiableInformation = false) => @"Editing a beatmap";
} }
public class Spectating : UserActivity public class Watching : UserActivity
{ {
public override string Status => @"Spectating a game"; private readonly ScoreInfo score;
protected string Username => score.User.Username;
public BeatmapInfo BeatmapInfo => score.BeatmapInfo;
public Watching(ScoreInfo score)
{
this.score = score;
}
public override string GetStatus(bool hideIdentifiableInformation = false) => hideIdentifiableInformation ? @"Watching a replay" : $@"Watching {Username}'s replay";
}
public class Spectating : Watching
{
public override string GetStatus(bool hideIdentifiableInformation = false) => hideIdentifiableInformation ? @"Spectating a user" : $@"Spectating {Username}";
public Spectating(ScoreInfo score)
: base(score)
{
}
} }
public class SearchingForLobby : UserActivity public class SearchingForLobby : UserActivity
{ {
public override string Status => @"Looking for a lobby"; public override string GetStatus(bool hideIdentifiableInformation = false) => @"Looking for a lobby";
} }
public class InLobby : UserActivity public class InLobby : UserActivity
{ {
public override string Status => @"In a lobby"; public override string GetStatus(bool hideIdentifiableInformation = false) => @"In a lobby";
public readonly Room Room; public readonly Room Room;