mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
show selected mod and use ILocalisedBindableString in np
This commit is contained in:
parent
85ce1bcea9
commit
a2ea7a3f58
@ -11,6 +11,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
@ -77,6 +78,16 @@ namespace osu.Game.Tests.Visual.Online
|
||||
AddAssert("Check link not present", () => !postTarget.LastMessage.Contains("https://"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestModPresence()
|
||||
{
|
||||
AddStep("Add Hidden mod", () => SelectedMods.Value = new[] { Ruleset.Value.CreateInstance().CreateMod<ModHidden>() });
|
||||
|
||||
AddStep("Run command", () => Add(new NowPlayingCommand()));
|
||||
|
||||
AddAssert("Check mod is present", () => postTarget.LastMessage.Contains("+Hidden"));
|
||||
}
|
||||
|
||||
public class PostTarget : Component, IChannelPostTarget
|
||||
{
|
||||
public void PostMessage(string text, bool isAction = false, Channel target = null)
|
||||
|
@ -1,13 +1,15 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.Chat
|
||||
@ -15,21 +17,27 @@ namespace osu.Game.Online.Chat
|
||||
public class NowPlayingCommand : Component
|
||||
{
|
||||
[Resolved]
|
||||
private IChannelPostTarget channelManager { get; set; }
|
||||
private IChannelPostTarget channelManager { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private Bindable<WorkingBeatmap> currentBeatmap { get; set; }
|
||||
private Bindable<WorkingBeatmap> currentBeatmap { get; set; } = null!;
|
||||
|
||||
private readonly Channel target;
|
||||
[Resolved]
|
||||
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private LocalisationManager localisation { get; set; } = null!;
|
||||
|
||||
private readonly Channel? target;
|
||||
|
||||
/// <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)
|
||||
public NowPlayingCommand(Channel? target = null)
|
||||
{
|
||||
this.target = target;
|
||||
}
|
||||
@ -59,9 +67,31 @@ namespace osu.Game.Online.Chat
|
||||
break;
|
||||
}
|
||||
|
||||
string beatmapString = beatmapInfo.OnlineID > 0 ? $"[{api.WebsiteRootUrl}/b/{beatmapInfo.OnlineID} {beatmapInfo}]" : beatmapInfo.ToString();
|
||||
string beatmapString()
|
||||
{
|
||||
string beatmapInfoString = localisation.GetLocalisedBindableString(beatmapInfo.GetDisplayTitleRomanisable()).Value;
|
||||
|
||||
channelManager.PostMessage($"is {verb} {beatmapString}", true, target);
|
||||
return beatmapInfo.OnlineID > 0 ? $"[{api.WebsiteRootUrl}/b/{beatmapInfo.OnlineID} {beatmapInfoString}]" : beatmapInfoString;
|
||||
}
|
||||
|
||||
string modString()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
channelManager.PostMessage($"is {verb} {beatmapString()} {modString()}", true, target);
|
||||
Expire();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user