mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 14:52:55 +08:00
Merge pull request #23890 from cdwcgt/tournament-chatcolor
Tint username of team members in tournament chat according to the team colour
This commit is contained in:
commit
318260bbfd
@ -38,10 +38,17 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
private void clear() => AddStep("clear messages", textContainer.Clear);
|
private void clear() => AddStep("clear messages", textContainer.Clear);
|
||||||
|
|
||||||
private void addMessageWithChecks(string text, bool isAction = false, bool isImportant = false, string username = null)
|
private void addMessageWithChecks(string text, bool isAction = false, bool isImportant = false, string username = null, Colour4? color = null)
|
||||||
{
|
{
|
||||||
int index = textContainer.Count + 1;
|
int index = textContainer.Count + 1;
|
||||||
var newLine = new ChatLine(new DummyMessage(text, isAction, isImportant, index, username));
|
|
||||||
|
var newLine = color != null
|
||||||
|
? new ChatLine(new DummyMessage(text, isAction, isImportant, index, username))
|
||||||
|
{
|
||||||
|
UsernameColour = color.Value
|
||||||
|
}
|
||||||
|
: new ChatLine(new DummyMessage(text, isAction, isImportant, index, username));
|
||||||
|
|
||||||
textContainer.Add(newLine);
|
textContainer.Add(newLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +58,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
addMessageWithChecks($"Wide {a} character username.", username: new string('w', a));
|
addMessageWithChecks($"Wide {a} character username.", username: new string('w', a));
|
||||||
addMessageWithChecks("Short name with spaces.", username: "sho rt name");
|
addMessageWithChecks("Short name with spaces.", username: "sho rt name");
|
||||||
addMessageWithChecks("Long name with spaces.", username: "long name with s p a c e s");
|
addMessageWithChecks("Long name with spaces.", username: "long name with s p a c e s");
|
||||||
|
addMessageWithChecks("message with custom color", username: "I have custom color", color: Colour4.Green);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DummyMessage : Message
|
private class DummyMessage : Message
|
||||||
|
@ -3,11 +3,15 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Online.Chat;
|
using osu.Game.Online.Chat;
|
||||||
|
using osu.Game.Overlays.Chat;
|
||||||
using osu.Game.Tests.Visual;
|
using osu.Game.Tests.Visual;
|
||||||
using osu.Game.Tournament.Components;
|
using osu.Game.Tournament.Components;
|
||||||
using osu.Game.Tournament.IPC;
|
using osu.Game.Tournament.IPC;
|
||||||
@ -39,6 +43,12 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
OnlineID = 4,
|
OnlineID = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private readonly TournamentUser blueUserWithCustomColour = new TournamentUser
|
||||||
|
{
|
||||||
|
Username = "nekodex",
|
||||||
|
OnlineID = 5,
|
||||||
|
};
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private LadderInfo ladderInfo = new LadderInfo();
|
private LadderInfo ladderInfo = new LadderInfo();
|
||||||
|
|
||||||
@ -63,7 +73,7 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
},
|
},
|
||||||
Team2 =
|
Team2 =
|
||||||
{
|
{
|
||||||
Value = new TournamentTeam { Players = new BindableList<TournamentUser> { blueUser } }
|
Value = new TournamentTeam { Players = new BindableList<TournamentUser> { blueUser, blueUserWithCustomColour } }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -86,6 +96,9 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
Content = "I am team red."
|
Content = "I am team red."
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
AddUntilStep("message from team red is red color", () =>
|
||||||
|
this.ChildrenOfType<DrawableChatUsername>().Last().AccentColour, () => Is.EqualTo(TournamentGame.COLOUR_RED));
|
||||||
|
|
||||||
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
||||||
{
|
{
|
||||||
Sender = redUser.ToAPIUser(),
|
Sender = redUser.ToAPIUser(),
|
||||||
@ -98,6 +111,24 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
|
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
AddUntilStep("message from team blue is blue color", () =>
|
||||||
|
this.ChildrenOfType<DrawableChatUsername>().Last().AccentColour, () => Is.EqualTo(TournamentGame.COLOUR_BLUE));
|
||||||
|
|
||||||
|
var userWithCustomColour = blueUserWithCustomColour.ToAPIUser();
|
||||||
|
userWithCustomColour.Colour = "#e45678";
|
||||||
|
|
||||||
|
AddStep("message from team blue with custom colour", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
||||||
|
{
|
||||||
|
Sender = userWithCustomColour,
|
||||||
|
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
|
||||||
|
}));
|
||||||
|
|
||||||
|
AddUntilStep("message from team blue is blue color", () =>
|
||||||
|
this.ChildrenOfType<DrawableChatUsername>().Last().AccentColour, () => Is.EqualTo(TournamentGame.COLOUR_BLUE));
|
||||||
|
|
||||||
|
AddUntilStep("message from user with custom colour is inverted", () =>
|
||||||
|
this.ChildrenOfType<DrawableChatUsername>().Last().Inverted, () => Is.EqualTo(true));
|
||||||
|
|
||||||
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(nextMessageId())
|
||||||
{
|
{
|
||||||
Sender = admin,
|
Sender = admin,
|
||||||
|
@ -21,6 +21,9 @@ namespace osu.Game.Tournament.Components
|
|||||||
|
|
||||||
private ChannelManager manager;
|
private ChannelManager manager;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private LadderInfo ladderInfo { get; set; }
|
||||||
|
|
||||||
public TournamentMatchChatDisplay()
|
public TournamentMatchChatDisplay()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
@ -71,7 +74,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
|
|
||||||
public void Contract() => this.FadeOut(200);
|
public void Contract() => this.FadeOut(200);
|
||||||
|
|
||||||
protected override ChatLine CreateMessage(Message message) => new MatchMessage(message);
|
protected override ChatLine CreateMessage(Message message) => new MatchMessage(message, ladderInfo);
|
||||||
|
|
||||||
protected override StandAloneDrawableChannel CreateDrawableChannel(Channel channel) => new MatchChannel(channel);
|
protected override StandAloneDrawableChannel CreateDrawableChannel(Channel channel) => new MatchChannel(channel);
|
||||||
|
|
||||||
@ -86,19 +89,13 @@ namespace osu.Game.Tournament.Components
|
|||||||
|
|
||||||
protected partial class MatchMessage : StandAloneMessage
|
protected partial class MatchMessage : StandAloneMessage
|
||||||
{
|
{
|
||||||
public MatchMessage(Message message)
|
public MatchMessage(Message message, LadderInfo info)
|
||||||
: base(message)
|
: base(message)
|
||||||
{
|
{
|
||||||
}
|
if (info.CurrentMatch.Value.Team1.Value.Players.Any(u => u.OnlineID == Message.Sender.OnlineID))
|
||||||
|
UsernameColour = TournamentGame.COLOUR_RED;
|
||||||
private void load(LadderInfo info)
|
else if (info.CurrentMatch.Value.Team2.Value.Players.Any(u => u.OnlineID == Message.Sender.OnlineID))
|
||||||
{
|
UsernameColour = TournamentGame.COLOUR_BLUE;
|
||||||
// if (info.CurrentMatch.Value.Team1.Value.Players.Any(u => u.Id == Message.Sender.Id))
|
|
||||||
// SenderText.Colour = TournamentGame.COLOUR_RED;
|
|
||||||
// else if (info.CurrentMatch.Value.Team2.Value.Players.Any(u => u.Id == Message.Sender.Id))
|
|
||||||
// SenderText.Colour = TournamentGame.COLOUR_BLUE;
|
|
||||||
// else if (Message.Sender.Colour != null)
|
|
||||||
// SenderText.Colour = ColourBox.Colour = Color4Extensions.FromHex(Message.Sender.Colour);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,10 @@ using osu.Game.Configuration;
|
|||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Online.Chat;
|
using osu.Game.Online.Chat;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
using Message = osu.Game.Online.Chat.Message;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Chat
|
namespace osu.Game.Overlays.Chat
|
||||||
{
|
{
|
||||||
@ -66,12 +69,31 @@ namespace osu.Game.Overlays.Chat
|
|||||||
|
|
||||||
private Container? highlight;
|
private Container? highlight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The colour used to paint the author's username.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The colour can be set explicitly by consumers via the property initialiser.
|
||||||
|
/// If unspecified, the colour is by default initialised to:
|
||||||
|
/// <list type="bullet">
|
||||||
|
/// <item><see cref="APIUser.Colour">message.Sender.Colour</see>, if non-empty,</item>
|
||||||
|
/// <item>a random colour from <see cref="default_username_colours"/> if the above is empty.</item>
|
||||||
|
/// </list>
|
||||||
|
/// </remarks>
|
||||||
|
public Color4 UsernameColour { get; init; }
|
||||||
|
|
||||||
public ChatLine(Message message)
|
public ChatLine(Message message)
|
||||||
{
|
{
|
||||||
Message = message;
|
Message = message;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
|
// initialise using sane defaults.
|
||||||
|
// consumers can use the initialiser of `UsernameColour` to override this if they wish to.
|
||||||
|
UsernameColour = !string.IsNullOrEmpty(message.Sender.Colour)
|
||||||
|
? Color4Extensions.FromHex(message.Sender.Colour)
|
||||||
|
: default_username_colours[message.SenderId % default_username_colours.Length];
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -111,6 +133,8 @@ namespace osu.Game.Overlays.Chat
|
|||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Margin = new MarginPadding { Horizontal = Spacing },
|
Margin = new MarginPadding { Horizontal = Spacing },
|
||||||
|
AccentColour = UsernameColour,
|
||||||
|
Inverted = !string.IsNullOrEmpty(message.Sender.Colour),
|
||||||
},
|
},
|
||||||
drawableContentFlow = new LinkFlowContainer(styleMessageContent)
|
drawableContentFlow = new LinkFlowContainer(styleMessageContent)
|
||||||
{
|
{
|
||||||
@ -195,5 +219,44 @@ namespace osu.Game.Overlays.Chat
|
|||||||
{
|
{
|
||||||
drawableTimestamp.Text = message.Timestamp.LocalDateTime.ToLocalisableString(prefer24HourTime.Value ? @"HH:mm:ss" : @"hh:mm:ss tt");
|
drawableTimestamp.Text = message.Timestamp.LocalDateTime.ToLocalisableString(prefer24HourTime.Value ? @"HH:mm:ss" : @"hh:mm:ss tt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly Color4[] default_username_colours =
|
||||||
|
{
|
||||||
|
Color4Extensions.FromHex("588c7e"),
|
||||||
|
Color4Extensions.FromHex("b2a367"),
|
||||||
|
Color4Extensions.FromHex("c98f65"),
|
||||||
|
Color4Extensions.FromHex("bc5151"),
|
||||||
|
Color4Extensions.FromHex("5c8bd6"),
|
||||||
|
Color4Extensions.FromHex("7f6ab7"),
|
||||||
|
Color4Extensions.FromHex("a368ad"),
|
||||||
|
Color4Extensions.FromHex("aa6880"),
|
||||||
|
|
||||||
|
Color4Extensions.FromHex("6fad9b"),
|
||||||
|
Color4Extensions.FromHex("f2e394"),
|
||||||
|
Color4Extensions.FromHex("f2ae72"),
|
||||||
|
Color4Extensions.FromHex("f98f8a"),
|
||||||
|
Color4Extensions.FromHex("7daef4"),
|
||||||
|
Color4Extensions.FromHex("a691f2"),
|
||||||
|
Color4Extensions.FromHex("c894d3"),
|
||||||
|
Color4Extensions.FromHex("d895b0"),
|
||||||
|
|
||||||
|
Color4Extensions.FromHex("53c4a1"),
|
||||||
|
Color4Extensions.FromHex("eace5c"),
|
||||||
|
Color4Extensions.FromHex("ea8c47"),
|
||||||
|
Color4Extensions.FromHex("fc4f4f"),
|
||||||
|
Color4Extensions.FromHex("3d94ea"),
|
||||||
|
Color4Extensions.FromHex("7760ea"),
|
||||||
|
Color4Extensions.FromHex("af52c6"),
|
||||||
|
Color4Extensions.FromHex("e25696"),
|
||||||
|
|
||||||
|
Color4Extensions.FromHex("677c66"),
|
||||||
|
Color4Extensions.FromHex("9b8732"),
|
||||||
|
Color4Extensions.FromHex("8c5129"),
|
||||||
|
Color4Extensions.FromHex("8c3030"),
|
||||||
|
Color4Extensions.FromHex("1f5d91"),
|
||||||
|
Color4Extensions.FromHex("4335a5"),
|
||||||
|
Color4Extensions.FromHex("812a96"),
|
||||||
|
Color4Extensions.FromHex("992861"),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,16 @@ namespace osu.Game.Overlays.Chat
|
|||||||
{
|
{
|
||||||
public Action? ReportRequested;
|
public Action? ReportRequested;
|
||||||
|
|
||||||
public Color4 AccentColour { get; }
|
/// <summary>
|
||||||
|
/// The primary colour to use for the username.
|
||||||
|
/// </summary>
|
||||||
|
public Color4 AccentColour { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If set to <see langword="false"/>, the username will be drawn as plain text in <see cref="AccentColour"/>.
|
||||||
|
/// If set to <see langword="true"/>, the username will be drawn as black text inside a rounded rectangle in <see cref="AccentColour"/>.
|
||||||
|
/// </summary>
|
||||||
|
public bool Inverted { get; init; }
|
||||||
|
|
||||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
|
||||||
colouredDrawable.ReceivePositionalInputAt(screenSpacePos);
|
colouredDrawable.ReceivePositionalInputAt(screenSpacePos);
|
||||||
@ -75,7 +84,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
private readonly APIUser user;
|
private readonly APIUser user;
|
||||||
private readonly OsuSpriteText drawableText;
|
private readonly OsuSpriteText drawableText;
|
||||||
|
|
||||||
private readonly Drawable colouredDrawable;
|
private Drawable colouredDrawable = null!;
|
||||||
|
|
||||||
public DrawableChatUsername(APIUser user)
|
public DrawableChatUsername(APIUser user)
|
||||||
{
|
{
|
||||||
@ -89,17 +98,17 @@ namespace osu.Game.Overlays.Chat
|
|||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(user.Colour))
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
if (!Inverted)
|
||||||
{
|
{
|
||||||
AccentColour = default_colours[user.Id % default_colours.Length];
|
|
||||||
|
|
||||||
Add(colouredDrawable = drawableText);
|
Add(colouredDrawable = drawableText);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AccentColour = Color4Extensions.FromHex(user.Colour);
|
|
||||||
|
|
||||||
Add(new Container
|
Add(new Container
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
@ -141,7 +150,6 @@ namespace osu.Game.Overlays.Chat
|
|||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
drawableText.Colour = colours.ChatBlue;
|
drawableText.Colour = colours.ChatBlue;
|
||||||
colouredDrawable.Colour = AccentColour;
|
colouredDrawable.Colour = AccentColour;
|
||||||
}
|
}
|
||||||
@ -200,44 +208,5 @@ namespace osu.Game.Overlays.Chat
|
|||||||
|
|
||||||
colouredDrawable.FadeColour(AccentColour, 800, Easing.OutQuint);
|
colouredDrawable.FadeColour(AccentColour, 800, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Color4[] default_colours =
|
|
||||||
{
|
|
||||||
Color4Extensions.FromHex("588c7e"),
|
|
||||||
Color4Extensions.FromHex("b2a367"),
|
|
||||||
Color4Extensions.FromHex("c98f65"),
|
|
||||||
Color4Extensions.FromHex("bc5151"),
|
|
||||||
Color4Extensions.FromHex("5c8bd6"),
|
|
||||||
Color4Extensions.FromHex("7f6ab7"),
|
|
||||||
Color4Extensions.FromHex("a368ad"),
|
|
||||||
Color4Extensions.FromHex("aa6880"),
|
|
||||||
|
|
||||||
Color4Extensions.FromHex("6fad9b"),
|
|
||||||
Color4Extensions.FromHex("f2e394"),
|
|
||||||
Color4Extensions.FromHex("f2ae72"),
|
|
||||||
Color4Extensions.FromHex("f98f8a"),
|
|
||||||
Color4Extensions.FromHex("7daef4"),
|
|
||||||
Color4Extensions.FromHex("a691f2"),
|
|
||||||
Color4Extensions.FromHex("c894d3"),
|
|
||||||
Color4Extensions.FromHex("d895b0"),
|
|
||||||
|
|
||||||
Color4Extensions.FromHex("53c4a1"),
|
|
||||||
Color4Extensions.FromHex("eace5c"),
|
|
||||||
Color4Extensions.FromHex("ea8c47"),
|
|
||||||
Color4Extensions.FromHex("fc4f4f"),
|
|
||||||
Color4Extensions.FromHex("3d94ea"),
|
|
||||||
Color4Extensions.FromHex("7760ea"),
|
|
||||||
Color4Extensions.FromHex("af52c6"),
|
|
||||||
Color4Extensions.FromHex("e25696"),
|
|
||||||
|
|
||||||
Color4Extensions.FromHex("677c66"),
|
|
||||||
Color4Extensions.FromHex("9b8732"),
|
|
||||||
Color4Extensions.FromHex("8c5129"),
|
|
||||||
Color4Extensions.FromHex("8c3030"),
|
|
||||||
Color4Extensions.FromHex("1f5d91"),
|
|
||||||
Color4Extensions.FromHex("4335a5"),
|
|
||||||
Color4Extensions.FromHex("812a96"),
|
|
||||||
Color4Extensions.FromHex("992861"),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user