mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
allow custom username color for chatLine
user's color (e.g. green for NAT) will be ignore
This commit is contained in:
parent
226bb4f387
commit
430938fbb2
@ -38,10 +38,13 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
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;
|
||||
var newLine = new ChatLine(new DummyMessage(text, isAction, isImportant, index, username));
|
||||
var newLine = new ChatLine(new DummyMessage(text, isAction, isImportant, index, username))
|
||||
{
|
||||
UsernameColour = color
|
||||
};
|
||||
textContainer.Add(newLine);
|
||||
}
|
||||
|
||||
@ -51,6 +54,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
addMessageWithChecks($"Wide {a} character username.", username: new string('w', a));
|
||||
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("message with custom color", username: "I have custom color", color: Colour4.Green);
|
||||
}
|
||||
|
||||
private class DummyMessage : Message
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
@ -18,6 +19,7 @@ using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Chat;
|
||||
|
||||
namespace osu.Game.Overlays.Chat
|
||||
@ -66,6 +68,24 @@ namespace osu.Game.Overlays.Chat
|
||||
|
||||
private Container? highlight;
|
||||
|
||||
private Colour4? usernameColour;
|
||||
|
||||
/// <summary>
|
||||
/// if set, it will override <see cref="APIUser.Colour"/> or <see cref="DrawableChatUsername.default_colours"/>.
|
||||
/// Must be set when constructor, otherwise throw <see cref="InvalidOperationException"/>.
|
||||
/// </summary>
|
||||
public Colour4? UsernameColour
|
||||
{
|
||||
get => usernameColour;
|
||||
set
|
||||
{
|
||||
if (drawableUsername != null)
|
||||
throw new InvalidOperationException("Can't change Username color after DrawableChatUsername created");
|
||||
|
||||
usernameColour = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ChatLine(Message message)
|
||||
{
|
||||
Message = message;
|
||||
@ -103,7 +123,7 @@ namespace osu.Game.Overlays.Chat
|
||||
Font = OsuFont.GetFont(size: FontSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true),
|
||||
AlwaysPresent = true,
|
||||
},
|
||||
drawableUsername = new DrawableChatUsername(message.Sender)
|
||||
drawableUsername = new DrawableChatUsername(message.Sender, usernameColour)
|
||||
{
|
||||
Width = UsernameWidth,
|
||||
FontSize = FontSize,
|
||||
|
@ -77,7 +77,7 @@ namespace osu.Game.Overlays.Chat
|
||||
|
||||
private readonly Drawable colouredDrawable;
|
||||
|
||||
public DrawableChatUsername(APIUser user)
|
||||
public DrawableChatUsername(APIUser user, Color4? customColor = null)
|
||||
{
|
||||
this.user = user;
|
||||
|
||||
@ -92,6 +92,14 @@ namespace osu.Game.Overlays.Chat
|
||||
Origin = Anchor.TopRight,
|
||||
};
|
||||
|
||||
if (customColor != null)
|
||||
{
|
||||
AccentColour = customColor.Value;
|
||||
|
||||
Add(colouredDrawable = drawableText);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(user.Colour))
|
||||
{
|
||||
AccentColour = default_colours[user.Id % default_colours.Length];
|
||||
|
Loading…
Reference in New Issue
Block a user