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.
|
|
|
|
|
2022-09-08 02:20:48 +08:00
|
|
|
using System.Collections.Generic;
|
2022-11-27 08:42:55 +08:00
|
|
|
using System.Linq;
|
2022-09-08 02:20:48 +08:00
|
|
|
using System.Text;
|
2020-04-19 14:12:36 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Online.API;
|
2022-11-30 13:47:16 +08:00
|
|
|
using osu.Game.Rulesets;
|
2022-09-08 02:20:48 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-04-19 14:12:36 +08:00
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Chat
|
|
|
|
{
|
|
|
|
public partial class NowPlayingCommand : Component
|
|
|
|
{
|
|
|
|
[Resolved]
|
2022-09-08 02:20:48 +08:00
|
|
|
private IChannelPostTarget channelManager { get; set; } = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2020-04-19 14:12:36 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2022-09-08 02:20:48 +08:00
|
|
|
private Bindable<WorkingBeatmap> currentBeatmap { get; set; } = null!;
|
2020-04-19 14:12:36 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2022-09-08 02:20:48 +08:00
|
|
|
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
2020-04-19 14:12:36 +08:00
|
|
|
|
2022-11-30 13:47:16 +08:00
|
|
|
[Resolved]
|
|
|
|
private IBindable<RulesetInfo> currentRuleset { get; set; } = null!;
|
|
|
|
|
2022-09-08 02:20:48 +08:00
|
|
|
private readonly Channel? target;
|
2021-06-29 14:58:07 +08:00
|
|
|
|
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>
|
2022-11-30 13:30:20 +08:00
|
|
|
public NowPlayingCommand(Channel target)
|
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;
|
2023-12-07 01:16:45 +08:00
|
|
|
|
|
|
|
int beatmapOnlineID;
|
|
|
|
string beatmapDisplayTitle;
|
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";
|
2023-12-07 01:16:45 +08:00
|
|
|
beatmapOnlineID = game.BeatmapID;
|
|
|
|
beatmapDisplayTitle = game.BeatmapDisplayTitle;
|
2020-04-19 14:12:36 +08:00
|
|
|
break;
|
|
|
|
|
2023-02-13 04:32:17 +08:00
|
|
|
case UserActivity.EditingBeatmap edit:
|
2020-04-19 14:12:36 +08:00
|
|
|
verb = "editing";
|
2023-12-07 01:16:45 +08:00
|
|
|
beatmapOnlineID = edit.BeatmapID;
|
|
|
|
beatmapDisplayTitle = edit.BeatmapDisplayTitle;
|
2020-04-19 14:12:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
verb = "listening to";
|
2023-12-07 01:16:45 +08:00
|
|
|
beatmapOnlineID = currentBeatmap.Value.BeatmapInfo.OnlineID;
|
|
|
|
beatmapDisplayTitle = currentBeatmap.Value.BeatmapInfo.GetDisplayTitle();
|
2020-04-19 14:12:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-30 13:43:21 +08:00
|
|
|
string[] pieces =
|
|
|
|
{
|
|
|
|
"is",
|
|
|
|
verb,
|
|
|
|
getBeatmapPart(),
|
2022-11-30 13:47:16 +08:00
|
|
|
getRulesetPart(),
|
2022-11-30 13:43:21 +08:00
|
|
|
getModPart(),
|
|
|
|
};
|
|
|
|
|
|
|
|
channelManager.PostMessage(string.Join(' ', pieces.Where(p => !string.IsNullOrEmpty(p))), true, target);
|
2022-11-30 13:31:54 +08:00
|
|
|
Expire();
|
|
|
|
|
2022-11-27 08:41:08 +08:00
|
|
|
string getBeatmapPart()
|
2022-09-08 02:20:48 +08:00
|
|
|
{
|
2023-12-07 01:16:45 +08:00
|
|
|
return beatmapOnlineID > 0 ? $"[{api.WebsiteRootUrl}/b/{beatmapOnlineID} {beatmapDisplayTitle}]" : beatmapDisplayTitle;
|
2022-09-08 02:20:48 +08:00
|
|
|
}
|
|
|
|
|
2022-11-30 13:47:16 +08:00
|
|
|
string getRulesetPart()
|
|
|
|
{
|
|
|
|
if (api.Activity.Value is not UserActivity.InGame) return string.Empty;
|
|
|
|
|
|
|
|
return $"<{currentRuleset.Value.Name}>";
|
|
|
|
}
|
|
|
|
|
2022-11-27 08:41:08 +08:00
|
|
|
string getModPart()
|
2022-09-08 02:20:48 +08:00
|
|
|
{
|
2022-11-27 08:42:55 +08:00
|
|
|
if (api.Activity.Value is not UserActivity.InGame) return string.Empty;
|
2022-11-27 08:41:41 +08:00
|
|
|
|
2022-09-08 02:20:48 +08:00
|
|
|
if (selectedMods.Value.Count == 0)
|
|
|
|
{
|
|
|
|
return string.Empty;
|
|
|
|
}
|
|
|
|
|
2022-11-30 13:31:54 +08:00
|
|
|
StringBuilder modsString = new StringBuilder();
|
2022-09-08 02:20:48 +08:00
|
|
|
|
2022-11-27 08:42:55 +08:00
|
|
|
foreach (var mod in selectedMods.Value.Where(mod => mod.Type == ModType.DifficultyIncrease))
|
2022-09-08 02:20:48 +08:00
|
|
|
{
|
2022-11-30 13:31:54 +08:00
|
|
|
modsString.Append($"+{mod.Acronym} ");
|
2022-11-27 08:42:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var mod in selectedMods.Value.Where(mod => mod.Type != ModType.DifficultyIncrease))
|
|
|
|
{
|
2022-11-30 13:31:54 +08:00
|
|
|
modsString.Append($"-{mod.Acronym} ");
|
2022-09-08 02:20:48 +08:00
|
|
|
}
|
|
|
|
|
2022-11-30 13:31:54 +08:00
|
|
|
return modsString.ToString().Trim();
|
2022-09-08 02:20:48 +08:00
|
|
|
}
|
2020-04-19 14:12:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|