2020-04-19 14:12:36 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Chat
|
|
|
|
{
|
|
|
|
public class NowPlayingCommand : Component
|
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private IChannelPostTarget channelManager { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Bindable<WorkingBeatmap> currentBeatmap { get; set; }
|
|
|
|
|
2021-06-29 14:58:07 +08:00
|
|
|
private readonly Channel target;
|
|
|
|
|
2021-06-29 15:30:40 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="NowPlayingCommand"/> to post the currently-playing beatmap to a parenting <see cref="IChannelPostTarget"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="target">The target channel to post to. If <c>null</c>, the currently-selected channel will be posted to.</param>
|
|
|
|
public NowPlayingCommand(Channel target = null)
|
2021-06-29 14:58:07 +08:00
|
|
|
{
|
|
|
|
this.target = target;
|
|
|
|
}
|
|
|
|
|
2020-04-19 14:12:36 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
string verb;
|
2021-10-02 23:55:29 +08:00
|
|
|
BeatmapInfo beatmapInfo;
|
2020-04-19 14:12:36 +08:00
|
|
|
|
|
|
|
switch (api.Activity.Value)
|
|
|
|
{
|
2021-08-16 06:32:33 +08:00
|
|
|
case UserActivity.InGame game:
|
2020-04-19 14:12:36 +08:00
|
|
|
verb = "playing";
|
2021-10-02 23:55:29 +08:00
|
|
|
beatmapInfo = game.BeatmapInfo;
|
2020-04-19 14:12:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UserActivity.Editing edit:
|
|
|
|
verb = "editing";
|
2021-10-02 23:55:29 +08:00
|
|
|
beatmapInfo = edit.BeatmapInfo;
|
2020-04-19 14:12:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
verb = "listening to";
|
2021-10-02 23:55:29 +08:00
|
|
|
beatmapInfo = currentBeatmap.Value.BeatmapInfo;
|
2020-04-19 14:12:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-02 23:55:29 +08:00
|
|
|
var beatmapString = beatmapInfo.OnlineBeatmapID.HasValue ? $"[{api.WebsiteRootUrl}/b/{beatmapInfo.OnlineBeatmapID} {beatmapInfo}]" : beatmapInfo.ToString();
|
2020-04-19 14:12:36 +08:00
|
|
|
|
2021-06-29 14:58:07 +08:00
|
|
|
channelManager.PostMessage($"is {verb} {beatmapString}", true, target);
|
2020-04-19 14:12:36 +08:00
|
|
|
Expire();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|