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:
@@ -214,4 +214,31 @@ public abstract class SharedChatSystem : EntitySystem
|
||||
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
public static string InjectTagInsideTag(ChatMessage message, string outerTag, string innerTag, string? tagParameter)
|
||||
{
|
||||
var rawmsg = message.WrappedMessage;
|
||||
var tagStart = rawmsg.IndexOf($"[{outerTag}]");
|
||||
var tagEnd = rawmsg.IndexOf($"[/{outerTag}]");
|
||||
if (tagStart < 0 || tagEnd < 0) //If the outer tag is not found, the injection is not performed
|
||||
return rawmsg;
|
||||
tagStart += outerTag.Length + 2;
|
||||
|
||||
string innerTagProcessed = tagParameter != null ? $"[{innerTag}={tagParameter}]" : $"[{innerTag}]";
|
||||
|
||||
rawmsg = rawmsg.Insert(tagEnd, $"[/{innerTag}]");
|
||||
rawmsg = rawmsg.Insert(tagStart, innerTagProcessed);
|
||||
|
||||
return rawmsg;
|
||||
}
|
||||
public static string GetStringInsideTag(ChatMessage message, string tag)
|
||||
{
|
||||
var rawmsg = message.WrappedMessage;
|
||||
var tagStart = rawmsg.IndexOf($"[{tag}]");
|
||||
var tagEnd = rawmsg.IndexOf($"[/{tag}]");
|
||||
if (tagStart < 0 || tagEnd < 0)
|
||||
return "";
|
||||
tagStart += tag.Length + 2;
|
||||
return rawmsg.Substring(tagStart, tagEnd - tagStart);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user