Add option for character name colors in chat & move coloration to clientside (#24625)
* Adds option to disable character names in chat/speechbubbles * Moved the coloring of names to clientside * Move string functions to SharedChatSystem to avoid duplicate code in SpeechBubble.cs * Changed to be put under Accessibility section * Cache CVar
This commit is contained in:
@@ -13,7 +13,6 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Decals;
|
||||
using Content.Shared.Ghost;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.IdentityManagement;
|
||||
@@ -27,7 +26,6 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects.Components.Localization;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -70,10 +68,6 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
private bool _critLoocEnabled;
|
||||
private readonly bool _adminLoocEnabled = true;
|
||||
|
||||
[ValidatePrototypeId<ColorPalettePrototype>]
|
||||
private const string ChatNamePalette = "ChatNames";
|
||||
private string[] _chatNameColors = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -83,13 +77,6 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
_configurationManager.OnValueChanged(CCVars.CritLoocEnabled, OnCritLoocEnabledChanged, true);
|
||||
|
||||
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnGameChange);
|
||||
|
||||
var nameColors = _prototypeManager.Index<ColorPalettePrototype>(ChatNamePalette).Colors.Values.ToArray();
|
||||
_chatNameColors = new string[nameColors.Length];
|
||||
for (var i = 0; i < nameColors.Length; i++)
|
||||
{
|
||||
_chatNameColors[i] = nameColors[i].ToHex();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
@@ -424,13 +411,8 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
|
||||
name = FormattedMessage.EscapeText(name);
|
||||
|
||||
// color the name unless it's something like "the old man"
|
||||
string coloredName = name;
|
||||
if (!TryComp<GrammarComponent>(source, out var grammar) || grammar.ProperNoun == true)
|
||||
coloredName = $"[color={GetNameColor(name)}]{name}[/color]";
|
||||
|
||||
var wrappedMessage = Loc.GetString(speech.Bold ? "chat-manager-entity-say-bold-wrap-message" : "chat-manager-entity-say-wrap-message",
|
||||
("entityName", coloredName),
|
||||
("entityName", name),
|
||||
("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))),
|
||||
("fontType", speech.FontId),
|
||||
("fontSize", speech.FontSize),
|
||||
@@ -499,10 +481,6 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
}
|
||||
name = FormattedMessage.EscapeText(name);
|
||||
|
||||
// color the name unless it's something like "the old man"
|
||||
if (!TryComp<GrammarComponent>(source, out var grammar) || grammar.ProperNoun == true)
|
||||
name = $"[color={GetNameColor(name)}]{name}[/color]";
|
||||
|
||||
var wrappedMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
|
||||
("entityName", name), ("message", FormattedMessage.EscapeText(message)));
|
||||
|
||||
@@ -643,17 +621,6 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
|
||||
#region Utility
|
||||
|
||||
/// <summary>
|
||||
/// Returns the chat name color for a mob
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the mob</param>
|
||||
/// <returns>Hex value of the color</returns>
|
||||
public string GetNameColor(string name)
|
||||
{
|
||||
var colorIdx = Math.Abs(name.GetHashCode() % _chatNameColors.Length);
|
||||
return _chatNameColors[colorIdx];
|
||||
}
|
||||
|
||||
private enum MessageRangeCheckResult
|
||||
{
|
||||
Disallowed,
|
||||
|
||||
Reference in New Issue
Block a user