Ports colored chat names (#24478)
* Ports colored chat names * Update name color on every message --------- Co-authored-by: ike709 <ike709@github.com>
This commit is contained in:
@@ -13,7 +13,9 @@ using Content.Shared.ActionBlocker;
|
|||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.Chat;
|
using Content.Shared.Chat;
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
|
using Content.Shared.Decals;
|
||||||
using Content.Shared.Ghost;
|
using Content.Shared.Ghost;
|
||||||
|
using Content.Shared.Humanoid;
|
||||||
using Content.Shared.IdentityManagement;
|
using Content.Shared.IdentityManagement;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Mobs.Systems;
|
using Content.Shared.Mobs.Systems;
|
||||||
@@ -25,6 +27,7 @@ using Robust.Shared.Audio;
|
|||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
using Robust.Shared.Configuration;
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
|
using Robust.Shared.GameObjects.Components.Localization;
|
||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
@@ -67,6 +70,10 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
private bool _critLoocEnabled;
|
private bool _critLoocEnabled;
|
||||||
private readonly bool _adminLoocEnabled = true;
|
private readonly bool _adminLoocEnabled = true;
|
||||||
|
|
||||||
|
[ValidatePrototypeId<ColorPalettePrototype>]
|
||||||
|
private const string _chatNamePalette = "Material";
|
||||||
|
private string[] _chatNameColors = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -76,6 +83,13 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
_configurationManager.OnValueChanged(CCVars.CritLoocEnabled, OnCritLoocEnabledChanged, true);
|
_configurationManager.OnValueChanged(CCVars.CritLoocEnabled, OnCritLoocEnabledChanged, true);
|
||||||
|
|
||||||
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnGameChange);
|
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()
|
public override void Shutdown()
|
||||||
@@ -409,6 +423,11 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
name = FormattedMessage.EscapeText(name);
|
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(speech.Bold ? "chat-manager-entity-say-bold-wrap-message" : "chat-manager-entity-say-wrap-message",
|
var wrappedMessage = Loc.GetString(speech.Bold ? "chat-manager-entity-say-bold-wrap-message" : "chat-manager-entity-say-wrap-message",
|
||||||
("entityName", name),
|
("entityName", name),
|
||||||
("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))),
|
("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))),
|
||||||
@@ -479,6 +498,10 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
}
|
}
|
||||||
name = FormattedMessage.EscapeText(name);
|
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",
|
var wrappedMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
|
||||||
("entityName", name), ("message", FormattedMessage.EscapeText(message)));
|
("entityName", name), ("message", FormattedMessage.EscapeText(message)));
|
||||||
|
|
||||||
@@ -619,6 +642,17 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
|
|
||||||
#region Utility
|
#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
|
private enum MessageRangeCheckResult
|
||||||
{
|
{
|
||||||
Disallowed,
|
Disallowed,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Shared.Decals;
|
||||||
using Content.Shared.Humanoid.Markings;
|
using Content.Shared.Humanoid.Markings;
|
||||||
using Content.Shared.Humanoid.Prototypes;
|
using Content.Shared.Humanoid.Prototypes;
|
||||||
using Content.Shared.Preferences;
|
using Content.Shared.Preferences;
|
||||||
|
|||||||
35
Resources/Prototypes/Palettes/text.yml
Normal file
35
Resources/Prototypes/Palettes/text.yml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
- type: palette
|
||||||
|
id: Material
|
||||||
|
name: Material
|
||||||
|
colors:
|
||||||
|
red: "#a91409"
|
||||||
|
red-darken-2: "#a72323"
|
||||||
|
red-accent-2: "#9b0000"
|
||||||
|
purple: "#7d1f8d"
|
||||||
|
purple-accent-2: "#8d03a5"
|
||||||
|
purple-accent-4: "#8800cc"
|
||||||
|
blue: "#0a6ab6"
|
||||||
|
blue-lighten-2: "#08528d"
|
||||||
|
blue-darken-2: "#145ea8"
|
||||||
|
cyan: "#0096aa"
|
||||||
|
cyan-lighten-2: "#198896"
|
||||||
|
cyan-darken-2: "#007986"
|
||||||
|
cyan-accent-2: "#00bebe"
|
||||||
|
cyan-accent-4: "#0093aa"
|
||||||
|
teal: "#00786d"
|
||||||
|
teal-lighten-2: "#3b8f89"
|
||||||
|
teal-accent-2: "#009076"
|
||||||
|
teal-accent-4: "#009984"
|
||||||
|
green: "#3d8c40"
|
||||||
|
green-darken-2: "#2d7230"
|
||||||
|
green-accent-2: "#0e885b"
|
||||||
|
green-accent-4: "#00a042"
|
||||||
|
lime: "#737a15"
|
||||||
|
lime-darken-2: "#8c9022"
|
||||||
|
lime-accent-2: "#737c00"
|
||||||
|
lime-accent-4: "#8bbb00"
|
||||||
|
amber: "#967000"
|
||||||
|
amber-lighten-2: "#755900"
|
||||||
|
amber-darken-2: "#cc8000"
|
||||||
|
amber-accent-2: "#7c6200"
|
||||||
|
amber-accent-4: "#996700"
|
||||||
Reference in New Issue
Block a user