Add chat.max_announcement_length cvar (#23571)
* Add announce message length to UI and make a cvar for it * Update comm console server-side trim to use the cvar * Rely on the new OnTextChanged event Because OnKeyBindUp only works for keys that have binds * Add a similar indicator to nukies' war declaration UI * Remove message length indicators for now cuz it requires the engine update * Rename cvar slightly * Refactor duplicated code to a helper method * Remove message trimming from *Window class as it's better to live in the BoundUserInterface where the other message handling happens * Rename to chat.max_announcement_length
This commit is contained in:
@@ -184,4 +184,34 @@ public abstract class SharedChatSystem : EntitySystem
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public static string SanitizeAnnouncement(string message, int maxLength = 0, int maxNewlines = 2)
|
||||
{
|
||||
var trimmed = message.Trim();
|
||||
if (maxLength > 0 && trimmed.Length > maxLength)
|
||||
{
|
||||
trimmed = $"{message[..maxLength]}...";
|
||||
}
|
||||
|
||||
// No more than max newlines, other replaced to spaces
|
||||
if (maxNewlines > 0)
|
||||
{
|
||||
var chars = trimmed.ToCharArray();
|
||||
var newlines = 0;
|
||||
for (var i = 0; i < chars.Length; i++)
|
||||
{
|
||||
if (chars[i] != '\n')
|
||||
continue;
|
||||
|
||||
if (newlines >= maxNewlines)
|
||||
chars[i] = ' ';
|
||||
|
||||
newlines++;
|
||||
}
|
||||
|
||||
return new string(chars);
|
||||
}
|
||||
|
||||
return trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user