2020-04-19 06:12:36 +00: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.
|
|
|
|
|
2022-09-07 18:20:48 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
2020-04-19 06:12:36 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2022-09-07 18:20:48 +00:00
|
|
|
using osu.Framework.Localisation;
|
2020-04-19 06:12:36 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Online.API;
|
2022-09-07 18:20:48 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-04-19 06:12:36 +00:00
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Chat
|
|
|
|
{
|
|
|
|
public class NowPlayingCommand : Component
|
|
|
|
{
|
|
|
|
[Resolved]
|
2022-09-07 18:20:48 +00:00
|
|
|
private IChannelPostTarget channelManager { get; set; } = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2020-04-19 06:12:36 +00:00
|
|
|
|
|
|
|
[Resolved]
|
2022-09-07 18:20:48 +00:00
|
|
|
private Bindable<WorkingBeatmap> currentBeatmap { get; set; } = null!;
|
2020-04-19 06:12:36 +00:00
|
|
|
|
|
|
|
[Resolved]
|
2022-09-07 18:20:48 +00:00
|
|
|
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
2020-04-19 06:12:36 +00:00
|
|
|
|
2022-09-07 18:20:48 +00:00
|
|
|
[Resolved]
|
|
|
|
private LocalisationManager localisation { get; set; } = null!;
|
|
|
|
|
|
|
|
private readonly Channel? target;
|
2021-06-29 06:58:07 +00:00
|
|
|
|
2021-06-29 07:30:40 +00: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>
|
2022-09-07 18:20:48 +00:00
|
|
|
public NowPlayingCommand(Channel? target = null)
|
2021-06-29 06:58:07 +00:00
|
|
|
{
|
|
|
|
this.target = target;
|
|
|
|
}
|
|
|
|
|
2020-04-19 06:12:36 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
string verb;
|
2021-11-15 09:46:11 +00:00
|
|
|
IBeatmapInfo beatmapInfo;
|
2020-04-19 06:12:36 +00:00
|
|
|
|
|
|
|
switch (api.Activity.Value)
|
|
|
|
{
|
2021-08-15 22:32:33 +00:00
|
|
|
case UserActivity.InGame game:
|
2020-04-19 06:12:36 +00:00
|
|
|
verb = "playing";
|
2021-10-02 15:55:29 +00:00
|
|
|
beatmapInfo = game.BeatmapInfo;
|
2020-04-19 06:12:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UserActivity.Editing edit:
|
|
|
|
verb = "editing";
|
2021-10-02 15:55:29 +00:00
|
|
|
beatmapInfo = edit.BeatmapInfo;
|
2020-04-19 06:12:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
verb = "listening to";
|
2021-10-02 15:55:29 +00:00
|
|
|
beatmapInfo = currentBeatmap.Value.BeatmapInfo;
|
2020-04-19 06:12:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-27 00:41:08 +00:00
|
|
|
string getBeatmapPart()
|
2022-09-07 18:20:48 +00:00
|
|
|
{
|
|
|
|
string beatmapInfoString = localisation.GetLocalisedBindableString(beatmapInfo.GetDisplayTitleRomanisable()).Value;
|
|
|
|
|
|
|
|
return beatmapInfo.OnlineID > 0 ? $"[{api.WebsiteRootUrl}/b/{beatmapInfo.OnlineID} {beatmapInfoString}]" : beatmapInfoString;
|
|
|
|
}
|
|
|
|
|
2022-11-27 00:41:08 +00:00
|
|
|
string getModPart()
|
2022-09-07 18:20:48 +00:00
|
|
|
{
|
2022-11-27 00:41:41 +00:00
|
|
|
if (api.Activity.Value is UserActivity.InGame) return string.Empty;
|
|
|
|
|
2022-09-07 18:20:48 +00:00
|
|
|
if (selectedMods.Value.Count == 0)
|
|
|
|
{
|
|
|
|
return string.Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder modS = new StringBuilder();
|
|
|
|
|
|
|
|
foreach (var mod in selectedMods.Value)
|
|
|
|
{
|
|
|
|
modS.Append($"+{mod.Name} ");
|
|
|
|
}
|
|
|
|
|
|
|
|
return modS.ToString();
|
|
|
|
}
|
2020-04-19 06:12:36 +00:00
|
|
|
|
2022-11-27 00:41:08 +00:00
|
|
|
channelManager.PostMessage($"is {verb} {getBeatmapPart()} {getModPart()}", true, target);
|
2020-04-19 06:12:36 +00:00
|
|
|
Expire();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|