Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Improved language colors #156

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Content.Client/Chat/UI/SpeechBubble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public static SpeechBubble CreateSpeechBubble(SpeechType type, ChatMessage messa
return new TextSpeechBubble(message, senderEntity, "emoteBox");

case SpeechType.Say:
return new FancyTextSpeechBubble(message, senderEntity, "sayBox", message.MessageColorOverride);
return new FancyTextSpeechBubble(message, senderEntity, "sayBox");

case SpeechType.Whisper:
return new FancyTextSpeechBubble(message, senderEntity, "whisperBox", message.MessageColorOverride);
return new FancyTextSpeechBubble(message, senderEntity, "whisperBox");

case SpeechType.Looc:
return new TextSpeechBubble(message, senderEntity, "emoteBox", Color.FromHex("#48d1cc"));
Expand Down
26 changes: 18 additions & 8 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ private void SendEntitySpeak(
("fontSize", speech.FontSize),
("message", FormattedMessage.EscapeText(msg.OriginalMessage)));

var color = LanguageSystem.GetLanguageColor(msg);

if (color is not null)
wrappedMessage = InjectTagInsideTag(wrappedMessage, "Message", "color", color.Value.ToHex());

var wrappedLanguageMessage = 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))),
Expand All @@ -451,9 +456,7 @@ private void SendEntitySpeak(

var understand = _language.IsUnderstandLanguage(session, msg);

var color = understand ? LanguageSystem.GetLanguageColor(msg) : null;

_chatManager.ChatMessageToOne(ChatChannel.Local, understand ? msg.OriginalMessage : msg.Message, understand ? wrappedMessage : wrappedLanguageMessage, source, entRange == MessageRangeCheckResult.HideChat, session.Channel, color);
_chatManager.ChatMessageToOne(ChatChannel.Local, understand ? msg.OriginalMessage : msg.Message, understand ? wrappedMessage : wrappedLanguageMessage, source, entRange == MessageRangeCheckResult.HideChat, session.Channel);
}

_replay.RecordServerMessage(new ChatMessage(ChatChannel.Local, msg.OriginalMessage, wrappedMessage, GetNetEntity(source), null, MessageRangeHideChatForReplay(range)));
Expand Down Expand Up @@ -534,6 +537,15 @@ private void SendEntityWhisper(
var wrappedUnknownMessage = Loc.GetString("chat-manager-entity-whisper-unknown-wrap-message",
("message", FormattedMessage.EscapeText(obfuscatedMessage)));

var color = LanguageSystem.GetLanguageColor(msg);

if (color is not null)
{
wrappedMessage = InjectTagInsideTag(wrappedMessage, "Message", "color", color.Value.ToHex());
wrappedObfuscatedMessage = InjectTagInsideTag(wrappedObfuscatedMessage, "Message", "color", color.Value.ToHex());
wrappedUnknownMessage = InjectTagInsideTag(wrappedUnknownMessage, "Message", "color", color.Value.ToHex());
}

var wrappedLanguageMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("entityName", name), ("message", FormattedMessage.EscapeText(msg.Message)));

Expand All @@ -557,17 +569,15 @@ private void SendEntityWhisper(

var understand = _language.IsUnderstandLanguage(session, msg);

var color = understand ? LanguageSystem.GetLanguageColor(msg) : null;

if (data.Range <= WhisperClearRange)
_chatManager.ChatMessageToOne(ChatChannel.Whisper, understand ? msg.OriginalMessage : msg.Message, understand ? wrappedMessage : wrappedLanguageMessage, source, false, session.Channel, color);
_chatManager.ChatMessageToOne(ChatChannel.Whisper, understand ? msg.OriginalMessage : msg.Message, understand ? wrappedMessage : wrappedLanguageMessage, source, false, session.Channel);
//If listener is too far, they only hear fragments of the message
//Collisiongroup.Opaque is not ideal for this use. Preferably, there should be a check specifically with "Can Ent1 see Ent2" in mind
else if (_interactionSystem.InRangeUnobstructed(source, listener, WhisperMuffledRange, Shared.Physics.CollisionGroup.Opaque)) //Shared.Physics.CollisionGroup.Opaque
_chatManager.ChatMessageToOne(ChatChannel.Whisper, understand ? obfuscatedMessage : obfuscatedLanguageMessage, understand ? wrappedObfuscatedMessage : wrappedObfuscatedLanguageMessage, source, false, session.Channel, color);
_chatManager.ChatMessageToOne(ChatChannel.Whisper, understand ? obfuscatedMessage : obfuscatedLanguageMessage, understand ? wrappedObfuscatedMessage : wrappedObfuscatedLanguageMessage, source, false, session.Channel);
//If listener is too far and has no line of sight, they can't identify the whisperer's identity
else
_chatManager.ChatMessageToOne(ChatChannel.Whisper, understand ? obfuscatedMessage : obfuscatedLanguageMessage, understand ? wrappedUnknownMessage : wrappedUnknownLanguageMessage, source, false, session.Channel, color);
_chatManager.ChatMessageToOne(ChatChannel.Whisper, understand ? obfuscatedMessage : obfuscatedLanguageMessage, understand ? wrappedUnknownMessage : wrappedUnknownLanguageMessage, source, false, session.Channel);
}

_replay.RecordServerMessage(new ChatMessage(ChatChannel.Whisper, msg.OriginalMessage, wrappedMessage, GetNetEntity(source), null, MessageRangeHideChatForReplay(range)));
Expand Down
5 changes: 5 additions & 0 deletions Content.Server/Radio/EntitySystems/RadioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public void SendRadioMessage(EntityUid messageSource, LanguageMessage message, R
("name", name),
("message", content));

var color = LanguageSystem.GetLanguageColor(message);

if (color is not null)
wrappedMessage = SharedChatSystem.InjectTagInsideTag(wrappedMessage, "Message", "color", color.Value.ToHex());

var wrappedLanguageMessage = languageContent is not null ? Loc.GetString(speech!.Bold ? "chat-radio-message-wrap-bold" : "chat-radio-message-wrap",
("color", channel.Color),
("fontType", speech.FontId),
Expand Down
21 changes: 13 additions & 8 deletions Content.Shared/Chat/SharedChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,25 @@ public static string SanitizeAnnouncement(string message, int maxLength = 0, int

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}]");
return InjectTagInsideTag(message.WrappedMessage, outerTag, innerTag, tagParameter);
}

public static string InjectTagInsideTag(string message, string outerTag, string innerTag, string? tagParameter)
{
var tagStart = message.IndexOf($"[{outerTag}]");
var tagEnd = message.IndexOf($"[/{outerTag}]");
if (tagStart < 0 || tagEnd < 0) //If the outer tag is not found, the injection is not performed
return rawmsg;
return message;
tagStart += outerTag.Length + 2;

string innerTagProcessed = tagParameter != null ? $"[{innerTag}={tagParameter}]" : $"[{innerTag}]";
var innerTagProcessed = tagParameter != null ? $"[{innerTag}={tagParameter}]" : $"[{innerTag}]";

rawmsg = rawmsg.Insert(tagEnd, $"[/{innerTag}]");
rawmsg = rawmsg.Insert(tagStart, innerTagProcessed);
message = message.Insert(tagEnd, $"[/{innerTag}]");
message = message.Insert(tagStart, innerTagProcessed);

return rawmsg;
return message;
}

public static string GetStringInsideTag(ChatMessage message, string tag)
{
var rawmsg = message.WrappedMessage;
Expand Down
4 changes: 2 additions & 2 deletions Resources/Locale/en-US/chat/managers/chat-manager.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ chat-manager-whisper-headset-on-message = You can't whisper on the radio!
chat-manager-server-wrap-message = [bold]{$message}[/bold]
chat-manager-sender-announcement-wrap-message = [font size=14][bold]{$sender} Announcement:[/font][font size=12]
{$message}[/bold][/font]
chat-manager-entity-say-wrap-message = [BubbleHeader][bold][Name]{$entityName}[/Name][/bold][/BubbleHeader] {$verb}, [font={$fontType} size={$fontSize}]"[BubbleContent]{$message}[/BubbleContent]"[/font]
chat-manager-entity-say-bold-wrap-message = [BubbleHeader][bold][Name]{$entityName}[/Name][/bold][/BubbleHeader] {$verb}, [font={$fontType} size={$fontSize}]"[BubbleContent][bold]{$message}[/bold][/BubbleContent]"[/font]
chat-manager-entity-say-wrap-message = [BubbleHeader][bold][Name]{$entityName}[/Name][/bold][/BubbleHeader] {$verb}, [font={$fontType} size={$fontSize}]"[BubbleContent][Message]{$message}[/Message][/BubbleContent]"[/font]
chat-manager-entity-say-bold-wrap-message = [BubbleHeader][bold][Name]{$entityName}[/Name][/bold][/BubbleHeader] {$verb}, [font={$fontType} size={$fontSize}]"[BubbleContent][bold][Message]{$message}[/Message][/bold][/BubbleContent]"[/font]

chat-manager-entity-whisper-wrap-message = [font size=11][italic][BubbleHeader][Name]{$entityName}[/Name][/BubbleHeader] whispers,"[BubbleContent]{$message}[/BubbleContent]"[/italic][/font]
chat-manager-entity-whisper-unknown-wrap-message = [font size=11][italic][BubbleHeader]Someone[/BubbleHeader] whispers, "[BubbleContent]{$message}[/BubbleContent]"[/italic][/font]
Expand Down
4 changes: 2 additions & 2 deletions Resources/Locale/en-US/headset/headset-component.ftl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Chat window radio wrap (prefix and postfix)
chat-radio-message-wrap = [color={$color}]{$channel} [bold]{$name}[/bold] {$verb}, [font={$fontType} size={$fontSize}]"{$message}"[/font][/color]
chat-radio-message-wrap-bold = [color={$color}]{$channel} [bold]{$name}[/bold] {$verb}, [font={$fontType} size={$fontSize}][bold]"{$message}"[/bold][/font][/color]
chat-radio-message-wrap = [color={$color}]{$channel} [bold]{$name}[/bold] {$verb}, [font={$fontType} size={$fontSize}]"[Message]{$message}[/Message]"[/font][/color]
chat-radio-message-wrap-bold = [color={$color}]{$channel} [bold]{$name}[/bold] {$verb}, [font={$fontType} size={$fontSize}][bold]"[Message]{$message}[/Message]"[/bold][/font][/color]

examine-headset-default-channel = Use {$prefix} for the default channel ([color={$color}]{$channel}[/color]).

Expand Down
4 changes: 2 additions & 2 deletions Resources/Locale/ru-RU/chat/managers/chat-manager.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ chat-manager-whisper-headset-on-message = Вы не можете шептать
chat-manager-server-wrap-message = [bold]{ $message }[/bold]
chat-manager-sender-announcement-wrap-message = [font size=14][bold]Объявление { $sender }:[/font][font size=12]
{ $message }[/bold][/font]
chat-manager-entity-say-wrap-message = [BubbleHeader][bold][Name]{ $entityName }[/Name][/bold][/BubbleHeader] { $verb }, [font={ $fontType } size={ $fontSize } ]"[BubbleContent]{ $message }[/BubbleContent]"[/font]
chat-manager-entity-say-bold-wrap-message = [BubbleHeader][bold][Name]{ $entityName }[/Name][/bold][/BubbleHeader] { $verb }, [font={ $fontType } size={ $fontSize }]"[BubbleContent][bold]{ $message }[/bold][/BubbleContent]"[/font]
chat-manager-entity-say-wrap-message = [BubbleHeader][bold][Name]{ $entityName }[/Name][/bold][/BubbleHeader] { $verb }, [font={ $fontType } size={ $fontSize } ]"[BubbleContent][Message]{ $message }[/Message][/BubbleContent]"[/font]
chat-manager-entity-say-bold-wrap-message = [BubbleHeader][bold][Name]{ $entityName }[/Name][/bold][/BubbleHeader] { $verb }, [font={ $fontType } size={ $fontSize }]"[BubbleContent][bold][Message]{ $message }[/Message][/bold][/BubbleContent]"[/font]
chat-manager-entity-whisper-wrap-message = [font size=11][italic][BubbleHeader][Name]{ $entityName }[/Name][/BubbleHeader] шепчет,"[BubbleContent]{ $message }[/BubbleContent]"[/italic][/font]
chat-manager-entity-whisper-unknown-wrap-message = [font size=11][italic][BubbleHeader]Кто-то[/BubbleHeader] шепчет, "[BubbleContent]{ $message }[/BubbleContent]"[/italic][/font]
chat-manager-entity-me-wrap-message = [italic]{ $entityName } { $message }[/italic]
Expand Down
4 changes: 2 additions & 2 deletions Resources/Locale/ru-RU/headset/headset-component.ftl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Chat window radio wrap (prefix and postfix)
chat-radio-message-wrap = [color={ $color }]{ $channel } [bold]{ $name }[/bold] { $verb }, [font={ $fontType } size={ $fontSize }]"{ $message }"[/font][/color]
chat-radio-message-wrap-bold = [color={ $color }]{ $channel } [bold]{ $name }[/bold] { $verb }, [font={ $fontType } size={ $fontSize }][bold]"{ $message }"[/bold][/font][/color]
chat-radio-message-wrap = [color={ $color }]{ $channel } [bold]{ $name }[/bold] { $verb }, [font={ $fontType } size={ $fontSize }]"[Message]{ $message }[/Message]"[/font][/color]
chat-radio-message-wrap-bold = [color={ $color }]{ $channel } [bold]{ $name }[/bold] { $verb }, [font={ $fontType } size={ $fontSize }]"[bold][Message]{ $message }[/Message][/bold]"[/font][/color]
examine-headset-default-channel = Отображается, что каналом по умолчанию этой гарнитуры является [color={ $color }]{ $channel }[/color].
chat-radio-common = Общий
chat-radio-centcom = Центком
Expand Down
Loading