Skip to content

Commit

Permalink
Languages Markers (#510)
Browse files Browse the repository at this point in the history
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

Require #459 

Add 3 optional settings for LanguagePrototypes to play with richtext
tags to they could be reconized as Makings

color - Set a specefic color to the text.
fontId - Set a font to the text by using the Id.
fontSize - Set the size of the text

All 3 are optional if not set message will be handeled like normal.

This should be mostly used to know what language your currently speaking
and assist with markings.
Take note those changes happent only in the TextBox chat, bubblechat is
left unchanged.

---

# TODO

<!--
A list of everything you have to do before this PR is "complete"
You probably won't have to complete everything before merging but it's
good to leave future references
-->

- [x] Add Markings
- [x] Add Fonts

---

<!--
This is default collapsed, readers click to expand it and see all your
media
The PR media section can get very large at times, so this is a good way
to keep it clean
The title is written using HTML tags
The title must be within the <summary> tags or you won't see it
-->

<details><summary><h1>Media</h1></summary>
<p>


![image](https://github.com/Simple-Station/Einstein-Engines/assets/45297731/10c3956b-c964-41af-ba0e-37ad1be8119e)

![image](https://github.com/Simple-Station/Einstein-Engines/assets/45297731/4377bdd8-a52e-4b62-bd70-fa9ba36c8d8b)

</p>
</details>

---

# Changelog

<!--
You can add an author after the `:cl:` to change the name that appears
in the changelog (ex: `:cl: Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

:cl: FoxxoTrystan
- add: Languages are now marked in the chat!

---------

Signed-off-by: Mnemotechnican <[email protected]>
Signed-off-by: FoxxoTrystan <[email protected]>
Co-authored-by: fox <[email protected]>
Co-authored-by: Mnemotechnican <[email protected]>
  • Loading branch information
3 people committed Jul 9, 2024
1 parent 78e33b3 commit 849b330
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 20 deletions.
20 changes: 12 additions & 8 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,11 @@ private void SendEntitySpeak(

name = FormattedMessage.EscapeText(name);
// The chat message wrapped in a "x says y" string
var wrappedMessage = WrapPublicMessage(source, name, message);
var wrappedMessage = WrapPublicMessage(source, name, message, languageOverride: language);
// The chat message obfuscated via language obfuscation
var obfuscated = SanitizeInGameICMessage(source, _language.ObfuscateSpeech(message, language), out var emoteStr, true, _configurationManager.GetCVar(CCVars.ChatPunctuation), (!CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Parent.Name == "en") || (CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Name == "en"));
// The language-obfuscated message wrapped in a "x says y" string
var wrappedObfuscated = WrapPublicMessage(source, name, obfuscated);
var wrappedObfuscated = WrapPublicMessage(source, name, obfuscated, languageOverride: language);

SendInVoiceRange(ChatChannel.Local, name, message, wrappedMessage, obfuscated, wrappedObfuscated, source, range, languageOverride: language);

Expand Down Expand Up @@ -514,6 +514,7 @@ private void SendEntityWhisper(
// Scenario 1: the listener can clearly understand the message
result = perceivedMessage;
wrappedMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("color", language.Color ?? Color.Gray),
("entityName", name),
("message", FormattedMessage.EscapeText(result)));
}
Expand All @@ -523,20 +524,22 @@ private void SendEntityWhisper(
// Collisiongroup.Opaque is not ideal for this use. Preferably, there should be a check specifically with "Can Ent1 see Ent2" in mind
result = ObfuscateMessageReadability(perceivedMessage);
wrappedMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("entityName", nameIdentity), ("message", FormattedMessage.EscapeText(result)));
("entityName", nameIdentity), ("color", language.Color ?? Color.Gray), ("message", FormattedMessage.EscapeText(result)));
}
else
{
// Scenario 3: If listener is too far and has no line of sight, they can't identify the whisperer's identity
result = ObfuscateMessageReadability(perceivedMessage);
wrappedMessage = Loc.GetString("chat-manager-entity-whisper-unknown-wrap-message",
("color", language.Color ?? Color.Gray),
("message", FormattedMessage.EscapeText(result)));
}

_chatManager.ChatMessageToOne(ChatChannel.Whisper, result, wrappedMessage, source, false, session.Channel);
}

var replayWrap = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("color", language.Color ?? Color.Gray),
("entityName", name),
("message", FormattedMessage.EscapeText(message)));
_replay.RecordServerMessage(new ChatMessage(ChatChannel.Whisper, message, replayWrap, GetNetEntity(source), null, MessageRangeHideChatForReplay(range)));
Expand Down Expand Up @@ -837,15 +840,16 @@ public string SanitizeMessageReplaceWords(string message)
/// <summary>
/// Wraps a message sent by the specified entity into an "x says y" string.
/// </summary>
public string WrapPublicMessage(EntityUid source, string name, string message)
public string WrapPublicMessage(EntityUid source, string name, string message, LanguagePrototype? languageOverride = null)
{
var language = languageOverride ?? _language.GetLanguage(source);
var speech = GetSpeechVerb(source, message);
var verbName = Loc.GetString(_random.Pick(speech.SpeechVerbStrings));
return Loc.GetString(speech.Bold ? "chat-manager-entity-say-bold-wrap-message" : "chat-manager-entity-say-wrap-message",
("color", language.Color ?? Color.White),
("entityName", name),
("verb", verbName),
("fontType", speech.FontId),
("fontSize", speech.FontSize),
("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))),
("fontType", language.FontId ?? speech.FontId),
("fontSize", language.FontSize ?? speech.FontSize),
("message", message));
}

Expand Down
11 changes: 6 additions & 5 deletions Content.Server/Radio/EntitySystems/RadioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ public void SendRadioMessage(EntityUid messageSource, string message, RadioChann
? FormattedMessage.EscapeText(message)
: message;

var wrappedMessage = WrapRadioMessage(messageSource, channel, name, content);
var wrappedMessage = WrapRadioMessage(messageSource, channel, name, content, language);
var msg = new ChatMessage(ChatChannel.Radio, content, wrappedMessage, NetEntity.Invalid, null);

// ... you guess it
var obfuscated = _language.ObfuscateSpeech(content, language);
var obfuscatedWrapped = WrapRadioMessage(messageSource, channel, name, obfuscated);
var obfuscatedWrapped = WrapRadioMessage(messageSource, channel, name, obfuscated, language);
var notUdsMsg = new ChatMessage(ChatChannel.Radio, obfuscated, obfuscatedWrapped, NetEntity.Invalid, null);

var ev = new RadioReceiveEvent(messageSource, channel, msg, notUdsMsg, language);
Expand Down Expand Up @@ -173,13 +173,14 @@ public void SendRadioMessage(EntityUid messageSource, string message, RadioChann
_messages.Remove(message);
}

private string WrapRadioMessage(EntityUid source, RadioChannelPrototype channel, string name, string message)
private string WrapRadioMessage(EntityUid source, RadioChannelPrototype channel, string name, string message, LanguagePrototype language)
{
var speech = _chat.GetSpeechVerb(source, message);
return Loc.GetString(speech.Bold ? "chat-radio-message-wrap-bold" : "chat-radio-message-wrap",
("color", channel.Color),
("fontType", speech.FontId),
("fontSize", speech.FontSize),
("languageColor", language.Color ?? channel.Color),
("fontType", language.FontId ?? speech.FontId),
("fontSize", language.FontSize ?? speech.FontSize),
("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))),
("channel", $"\\[{channel.LocalizedName}\\]"),
("name", name),
Expand Down
9 changes: 9 additions & 0 deletions Content.Shared/Language/LanguagePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ public sealed class LanguagePrototype : IPrototype
[IdDataField]
public string ID { get; private set; } = default!;

[DataField("color")]
public Color? Color;

[DataField("fontId")]
public string? FontId;

[DataField("fontSize")]
public int? FontSize;

/// <summary>
/// Obfuscation method used by this language. By default, uses <see cref="ObfuscationMethod.Default"/>
/// </summary>
Expand Down
Binary file added Resources/Fonts/Copperplate.otf
Binary file not shown.
Binary file added Resources/Fonts/Mangat.ttf
Binary file not shown.
Binary file added Resources/Fonts/Noganas.ttf
Binary file not shown.
Binary file added Resources/Fonts/RubikBubbles.ttf
Binary file not shown.
8 changes: 4 additions & 4 deletions Resources/Locale/en-US/chat/managers/chat-manager.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ 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][Name]{$entityName}[/Name][/BubbleHeader] {$verb}, [font={$fontType} size={$fontSize}]"[BubbleContent]{$message}[/BubbleContent]"[/font]
chat-manager-entity-say-bold-wrap-message = [BubbleHeader][Name]{$entityName}[/Name][/BubbleHeader] {$verb}, [font={$fontType} size={$fontSize}]"[BubbleContent][bold]{$message}[/bold][/BubbleContent]"[/font]
chat-manager-entity-say-wrap-message = [BubbleHeader][Name]{$entityName}[/Name][/BubbleHeader] {$verb}, [font="{$fontType}" size={$fontSize}]"[color={$color}][BubbleContent]{$message}[/BubbleContent][/color]"[/font]
chat-manager-entity-say-bold-wrap-message = [BubbleHeader][Name]{$entityName}[/Name][/BubbleHeader] {$verb}, [font="{$fontType}" size={$fontSize}]"[color={$color}][BubbleContent][bold]{$message}[/bold][/BubbleContent][/color]"[/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]
chat-manager-entity-whisper-wrap-message = [font size=11][italic][BubbleHeader][Name]{$entityName}[/Name][/BubbleHeader] whispers,"[color={$color}][BubbleContent]{$message}[/BubbleContent][/color]"[/italic][/font]
chat-manager-entity-whisper-unknown-wrap-message = [font size=11][italic][BubbleHeader]Someone[/BubbleHeader] whispers, "[color={$color}][BubbleContent]{$message}[/BubbleContent][/color]"[/italic][/font]
# THE() is not used here because the entity and its name can technically be disconnected if a nameOverride is passed...
chat-manager-entity-me-wrap-message = [italic]{ PROPER($entity) ->
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} {$name} {$verb}, [font={$fontType} size={$fontSize}]"{$message}"[/font][/color]
chat-radio-message-wrap-bold = [color={$color}]{$channel} {$name} {$verb}, [font={$fontType} size={$fontSize}][bold]"{$message}"[/bold][/font][/color]
chat-radio-message-wrap = [color={$color}]{$channel} {$name} {$verb}, [font="{$fontType}" size={$fontSize}]"[/color][color={$languageColor}]{$message}[/color][color={$color}]"[/font][/color]
chat-radio-message-wrap-bold = [color={$color}]{$channel} {$name} {$verb}, [font="{$fontType}" size={$fontSize}][bold]"[/color][color={$languageColor}]{$message}[/color][color={$color}]"[/bold][/font][/color]
examine-headset-default-channel = Use {$prefix} for the default channel ([color={$color}]{$channel}[/color]).
Expand Down
13 changes: 12 additions & 1 deletion Resources/Prototypes/Language/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
# Spoken by slimes.
- type: language
id: Bubblish
color: "#0077aa"
fontId: RubikBubbles
obfuscation:
!type:SyllableObfuscation
minSyllables: 1
Expand All @@ -52,6 +54,8 @@
# Spoken by moths.
- type: language
id: Moffic
color: "#869b29"
fontId: Copperplate
obfuscation:
!type:SyllableObfuscation
minSyllables: 2 # Replacements are really short
Expand Down Expand Up @@ -118,6 +122,8 @@
# Spoken by dionas.
- type: language
id: RootSpeak
color: "#804000"
fontId: Noganas
obfuscation:
!type:SyllableObfuscation
minSyllables: 1
Expand All @@ -132,6 +138,8 @@
# A mess of broken Japanese, spoken by Felinds and Oni
- type: language
id: Nekomimetic
color: "#803B56"
fontId: Manga
obfuscation:
!type:SyllableObfuscation
minSyllables: 1
Expand Down Expand Up @@ -189,6 +197,7 @@
# Spoken by the Lizard race.
- type: language
id: Draconic
color: "#228b22"
obfuscation:
!type:SyllableObfuscation
minSyllables: 2
Expand Down Expand Up @@ -282,6 +291,7 @@
# Spoken by the Vulpkanin race.
- type: language
id: Canilunzt
color: "#b97a57"
obfuscation:
!type:SyllableObfuscation
minSyllables: 1
Expand Down Expand Up @@ -314,7 +324,6 @@
- vor
- nic
- gro
# - lll
- enem
- zandt
- tzch
Expand Down Expand Up @@ -349,6 +358,7 @@
# The common language of the Sol system.
- type: language
id: SolCommon
color: "#8282fb"
obfuscation:
!type:SyllableObfuscation
minSyllables: 1
Expand All @@ -374,6 +384,7 @@

- type: language
id: RobotTalk
fontId: Monospace
obfuscation:
!type:SyllableObfuscation
minSyllables: 1
Expand Down
16 changes: 16 additions & 0 deletions Resources/Prototypes/fonts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,19 @@
- type: font
id: Emoji
path: /Fonts/NotoEmoji.ttf

- type: font
id: RubikBubbles
path: /Fonts/RubikBubbles.ttf

- type: font
id: Copperplate
path: /Fonts/Copperplate.otf

- type: font
id: Manga
path: /Fonts/Mangat.ttf

- type: font
id: Noganas
path: /Fonts/Noganas.ttf

0 comments on commit 849b330

Please sign in to comment.