]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Ports colored chat names (#24478)
authorike709 <ike709@users.noreply.github.com>
Thu, 25 Jan 2024 08:39:00 +0000 (01:39 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Jan 2024 08:39:00 +0000 (01:39 -0700)
* Ports colored chat names

* Update name color on every message

---------

Co-authored-by: ike709 <ike709@github.com>
Content.Server/Chat/Systems/ChatSystem.cs
Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs
Resources/Prototypes/Palettes/text.yml [new file with mode: 0644]

index 7a8446be8a2d041bf241919269bd8c745e304f8b..1b5c8b83fa461bd489eaf52d9e389f34b6ca5648 100644 (file)
@@ -13,7 +13,9 @@ 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;
 using Content.Shared.Interaction;
 using Content.Shared.Mobs.Systems;
@@ -25,6 +27,7 @@ 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;
@@ -67,6 +70,10 @@ public sealed partial class ChatSystem : SharedChatSystem
     private bool _critLoocEnabled;
     private readonly bool _adminLoocEnabled = true;
 
+    [ValidatePrototypeId<ColorPalettePrototype>]
+    private const string _chatNamePalette = "Material";
+    private string[] _chatNameColors = default!;
+
     public override void Initialize()
     {
         base.Initialize();
@@ -76,6 +83,13 @@ 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()
@@ -409,6 +423,11 @@ 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(speech.Bold ? "chat-manager-entity-say-bold-wrap-message" : "chat-manager-entity-say-wrap-message",
             ("entityName", name),
             ("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))),
@@ -479,6 +498,10 @@ 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)));
 
@@ -619,6 +642,17 @@ 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,
index 02e29549d4883ad19b44dcd819bf6d5d2762633a..597afcbda2ae1987357d9fe6d6fe4a09b7104772 100644 (file)
@@ -1,4 +1,5 @@
 using System.Linq;
+using Content.Shared.Decals;
 using Content.Shared.Humanoid.Markings;
 using Content.Shared.Humanoid.Prototypes;
 using Content.Shared.Preferences;
diff --git a/Resources/Prototypes/Palettes/text.yml b/Resources/Prototypes/Palettes/text.yml
new file mode 100644 (file)
index 0000000..de0a9fb
--- /dev/null
@@ -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"
\ No newline at end of file