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

feat: add name and rulset verb display support

This commit is contained in:
tsrk 2023-02-06 12:44:00 +00:00
parent b3f38b0f4c
commit bc89f8dc5b
No known key found for this signature in database
GPG Key ID: EBD46BB3049B56D6
5 changed files with 45 additions and 6 deletions

View File

@ -98,7 +98,7 @@ namespace osu.Desktop
if (status.Value is UserStatusOnline && activity.Value != null)
{
presence.State = truncate(activity.Value.Status);
presence.State = truncate(privacyMode.Value == DiscordRichPresenceMode.Limited ? activity.Value.LimitedStatus : activity.Value.Status);
presence.Details = truncate(getDetails(activity.Value));
if (getBeatmap(activity.Value) is IBeatmapInfo beatmap && beatmap.OnlineID > 0)
@ -186,6 +186,9 @@ namespace osu.Desktop
case UserActivity.Editing edit:
return edit.BeatmapInfo.ToString() ?? string.Empty;
case UserActivity.Watching watching:
return watching.BeatmapInfo.ToString();
case UserActivity.InLobby lobby:
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.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Tests.Beatmaps;
using osu.Game.Users;
using osuTK;
@ -107,8 +109,8 @@ namespace osu.Game.Tests.Visual.Online
AddStep("set online status", () => status.Value = new UserStatusOnline());
AddStep("idle", () => activity.Value = null);
AddStep("watching", () => activity.Value = new UserActivity.Watching());
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!taiko)", () => activity.Value = soloGameStatusForRuleset(1));
AddStep("solo (osu!catch)", () => activity.Value = soloGameStatusForRuleset(2));
@ -133,6 +135,14 @@ namespace osu.Game.Tests.Visual.Online
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
{
public TestUserListPanel(APIUser user)

View File

@ -25,7 +25,7 @@ namespace osu.Game.Screens.Play
private readonly bool replayIsFailedScore;
protected override UserActivity InitialActivity => new UserActivity.Watching();
protected override UserActivity InitialActivity => new UserActivity.Watching(Score.ScoreInfo);
// Disallow replays from failing. (see https://github.com/ppy/osu/issues/6108)
protected override bool CheckModsAllowFailure()

View File

@ -15,7 +15,7 @@ namespace osu.Game.Screens.Play
{
private readonly Score score;
protected override UserActivity InitialActivity => new UserActivity.Spectating();
protected override UserActivity InitialActivity => new UserActivity.Spectating(Score.ScoreInfo);
public SoloSpectatorPlayer(Score score, PlayerConfiguration configuration = null)
: base(score, configuration)

View File

@ -4,9 +4,11 @@
#nullable disable
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osuTK.Graphics;
namespace osu.Game.Users
@ -14,6 +16,12 @@ namespace osu.Game.Users
public abstract class UserActivity
{
public abstract string Status { get; }
/// <summary>
/// This property is used when the <see cref="DiscordRichPresenceMode"/> is <see cref="DiscordRichPresenceMode.Limited"/>
/// </summary>
public virtual string LimitedStatus => Status;
public virtual Color4 GetAppropriateColour(OsuColour colours) => colours.GreenDarker;
public class Modding : UserActivity
@ -92,14 +100,32 @@ namespace osu.Game.Users
public class Watching : UserActivity
{
private readonly ScoreInfo score;
private string username => score.User.Username;
private string playingVerb => score.BeatmapInfo.Ruleset.CreateInstance().PlayingVerb;
public BeatmapInfo BeatmapInfo => score.BeatmapInfo;
public Watching(ScoreInfo score)
{
this.score = score;
}
protected virtual string Verb => @"Watching";
public override string Status => @$"{Verb} a game";
public override string Status => @$"{Verb} {username} {playingVerb.ToLowerInvariant()}";
public override string LimitedStatus => $@"{Verb} a game";
}
public class Spectating : Watching
{
protected override string Verb => @"Spectating";
public Spectating(ScoreInfo score)
: base(score)
{
}
}
public class SearchingForLobby : UserActivity