Skip to content

Commit

Permalink
Did what the review suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Mar 30, 2024
1 parent c61e061 commit 0b7dd07
Show file tree
Hide file tree
Showing 27 changed files with 308 additions and 292 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Language/LanguageMenuWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls"
Title="a"
Title="{Loc language-menu-window-title}"
SetSize="300 300">
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
<PanelContainer Name="CurrentLanguageContainer" Access="Public" StyleClasses="PdaBorderRect">
Expand Down
10 changes: 4 additions & 6 deletions Content.Client/Language/LanguageMenuWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ public LanguageMenuWindow()
{
RobustXamlLoader.Load(this);
_clientLanguageSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>();

Title = Loc.GetString("language-menu-window-title");
}

public void UpdateState(string currentLanguage, List<string> spokenLanguages)
{
var langName = LanguagePrototype.GetLocalizedName(currentLanguage);
CurrentLanguageLabel.Text = Loc.GetString("language-menu-current-language", ("language", langName ?? "<error>"));
var langName = Loc.GetString($"language-{currentLanguage}-name");
CurrentLanguageLabel.Text = Loc.GetString("language-menu-current-language", ("language", langName));

OptionsList.RemoveAllChildren();
_entries.Clear();
Expand Down Expand Up @@ -64,7 +62,7 @@ private void AddLanguageEntry(string language)
header.SeparationOverride = 2;

var name = new Label();
name.Text = proto?.LocalizedName ?? "<error>";
name.Text = proto?.Name ?? "<error>";
name.MinWidth = 50;
name.HorizontalExpand = true;

Expand All @@ -86,7 +84,7 @@ private void AddLanguageEntry(string language)
body.Margin = new Thickness(4f, 4f);

var description = new RichTextLabel();
description.SetMessage(proto?.LocalizedDescription ?? "<error>");
description.SetMessage(proto?.Description ?? "<error>");
description.HorizontalExpand = true;

body.AddChild(description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ public LanguageSelectorButton()
IoCManager.Resolve<IUserInterfaceManager>().GetUIController<LanguageMenuUIController>().LanguagesUpdatedHook += UpdateLanguage;
}

private void UpdateLanguage((string current, List<string> spoken, List<string> understood) args)
{
Popup.SetLanguages(args.spoken);

// Kill me please
SelectedLanguage = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>().GetLanguage(args.current);
Text = LanguageSelectorName(SelectedLanguage!);
}

protected override UIBox2 GetPopupPosition()
{
var globalLeft = GlobalPosition.X;
Expand All @@ -48,24 +39,9 @@ protected override UIBox2 GetPopupPosition()
new Vector2(SizeBox.Width, SelectorDropdownOffset));
}

public void Select(LanguagePrototype language)
{
if (Popup.Visible)
{
Popup.Close();
}

if (SelectedLanguage == language)
return;
SelectedLanguage = language;
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>().RequestSetLanguage(language);

Text = LanguageSelectorName(language);
}

public static string LanguageSelectorName(LanguagePrototype language, bool full = false)
{
var name = language.LocalizedName;
var name = language.Name;

// if the language name is short enough, just return it
if (full || name.Length < 5)
Expand All @@ -75,15 +51,39 @@ public static string LanguageSelectorName(LanguagePrototype language, bool full
if (name.Contains(' '))
{
var result = name
.Split(" ")
.Select(it => it.FirstOrNull())
.Where(it => it != null)
.Select(it => char.ToUpper(it!.Value));
.Split(" ") // split by words
.Select(it => it.FirstOrNull()) // take the first letter from each
.Where(it => it != null) // ignore empty words (double spaces)
.Select(it => char.ToUpper(it!.Value)); // capitalize

return new string(result.ToArray());
}

// Alternatively, take the first 5 letters
return name[..5];
}

public void Select(LanguagePrototype language)
{
if (Popup.Visible)
{
Popup.Close();
}

if (SelectedLanguage == language)
return;
SelectedLanguage = language;
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>().RequestSetLanguage(language);

Text = LanguageSelectorName(language);
}

private void UpdateLanguage((string current, List<string> spoken, List<string> understood) args)
{
Popup.SetLanguages(args.spoken);

// Kill me please
SelectedLanguage = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>().GetLanguage(args.current);
Text = LanguageSelectorName(SelectedLanguage!);
}
}
8 changes: 5 additions & 3 deletions Content.Client/Language/Systems/LanguageSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Language;
using Content.Shared.Language.Events;
using Content.Shared.Language.Systems;
using Content.Shared.Mind.Components;
using Robust.Shared.Console;
Expand All @@ -7,10 +8,11 @@ namespace Content.Client.Language.Systems;

/// <summary>
/// Client-side language system.
///
/// </summary>
/// <remarks>
/// Unlike the server, the client is not aware of other entities' languages; it's only notified about the entity that it posesses.
/// Due to that, this system stores such information in a static manner.
/// </summary>
/// </remarks>
public sealed class LanguageSystem : SharedLanguageSystem
{
/// <summary>
Expand Down Expand Up @@ -51,7 +53,7 @@ public void RequestSetLanguage(LanguagePrototype language)
return;

// (This is dumb. This is very dumb. It should be a message instead.)
_consoleHost.ExecuteCommand("lsselectlang " + language.ID);
_consoleHost.ExecuteCommand("languageselect " + language.ID);

// So to reduce the probability of desync, we replicate the change locally too
if (SpokenLanguages.Contains(language.ID))
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.CycleChatChannelForward);
AddButton(ContentKeyFunctions.CycleChatChannelBackward);
AddButton(ContentKeyFunctions.OpenCharacterMenu);
AddButton(ContentKeyFunctions.OpenLanguageMenu);
AddButton(ContentKeyFunctions.OpenCraftingMenu);
AddButton(ContentKeyFunctions.OpenGuidebook);
AddButton(ContentKeyFunctions.OpenInventoryMenu);
AddButton(ContentKeyFunctions.OpenLanguageMenu);
AddButton(ContentKeyFunctions.OpenAHelp);
AddButton(ContentKeyFunctions.OpenActionsMenu);
AddButton(ContentKeyFunctions.OpenEntitySpawnWindow);
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private void SendEntitySpeak(

name = FormattedMessage.EscapeText(name);
var wrappedMessage = WrapPublicMessage(source, name, message);
var obfuscated = _language.ObfuscateSpeech(source, message, language);
var obfuscated = _language.ObfuscateSpeech(message, language);
var wrappedObfuscated = WrapPublicMessage(source, name, obfuscated);

SendInVoiceRange(ChatChannel.Local, name, message, wrappedMessage, obfuscated, wrappedObfuscated, source, range, languageOverride: language);
Expand Down Expand Up @@ -488,7 +488,7 @@ private void SendEntityWhisper(
name = FormattedMessage.EscapeText(name);

var language = languageOverride ?? _language.GetLanguage(source);
var languageObfuscatedMessage = _language.ObfuscateSpeech(source, message, language);
var languageObfuscatedMessage = _language.ObfuscateSpeech(message, language);


foreach (var (session, data) in GetRecipients(source, WhisperMuffledRange))
Expand Down
17 changes: 9 additions & 8 deletions Content.Server/Chemistry/ReagentEffects/MakeSentient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
using Content.Shared.Mind.Components;
using Robust.Shared.Prototypes;
using Content.Server.Psionics; //Nyano - Summary: pulls in the ability for the sentient creature to become psionic.
using Content.Shared.Humanoid; //Delta-V - Banning humanoids from becoming ghost roles.
using Content.Shared.Humanoid;
using Content.Shared.Language.Events; //Delta-V - Banning humanoids from becoming ghost roles.

namespace Content.Server.Chemistry.ReagentEffects;

Expand All @@ -28,17 +29,17 @@ public override void Effect(ReagentEffectArgs args)
entityManager.RemoveComponent<MonkeyAccentComponent>(uid);

var speaker = entityManager.EnsureComponent<LanguageSpeakerComponent>(uid);
var gc = SharedLanguageSystem.GalacticCommon.ID;
var fallback = SharedLanguageSystem.FallbackLanguagePrototype;

if (!speaker.UnderstoodLanguages.Contains(gc))
speaker.UnderstoodLanguages.Add(gc);
if (!speaker.UnderstoodLanguages.Contains(fallback))
speaker.UnderstoodLanguages.Add(fallback);

if (!speaker.SpokenLanguages.Contains(gc))
if (!speaker.SpokenLanguages.Contains(fallback))
{
speaker.CurrentLanguage = gc;
speaker.SpokenLanguages.Add(gc);
speaker.CurrentLanguage = fallback;
speaker.SpokenLanguages.Add(fallback);

args.EntityManager.EventBus.RaiseLocalEvent(uid, new SharedLanguageSystem.LanguagesUpdateEvent(), true);
args.EntityManager.EventBus.RaiseLocalEvent(uid, new LanguagesUpdateEvent(), true);
}

// Stops from adding a ghost role to things like people who already have a mind
Expand Down
10 changes: 5 additions & 5 deletions Content.Server/Language/Commands/ListLanguagesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Content.Server.Language.Commands;
[AnyCommand]
public sealed class ListLanguagesCommand : IConsoleCommand
{
public string Command => "lslangs";
public string Description => "List languages your current entity can speak at the current moment.";
public string Help => "lslangs";
public string Command => "languagelist";
public string Description => Loc.GetString("command-list-langs-desc");
public string Help => Loc.GetString("command-list-langs-help", ("command", Command));

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
Expand All @@ -33,7 +33,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)

var (spokenLangs, knownLangs) = languages.GetAllLanguages(playerEntity);

shell.WriteLine("Spoken: " + string.Join(", ", spokenLangs));
shell.WriteLine("Understood: " + string.Join(", ", knownLangs));
shell.WriteLine("Spoken:\n" + string.Join("\n", spokenLangs));
shell.WriteLine("Understood:\n" + string.Join("\n", knownLangs));
}
}
6 changes: 3 additions & 3 deletions Content.Server/Language/Commands/SayLanguageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Content.Server.Language.Commands;
[AnyCommand]
public sealed class SayLanguageCommand : IConsoleCommand
{
public string Command => "lsay";
public string Description => "Send chat languages to the local channel or a specific chat channel, in a specific language.";
public string Help => "lsay <language id> <text>";
public string Command => "saylang";
public string Description => Loc.GetString("command-saylang-desc");
public string Help => Loc.GetString("command-saylang-help", ("command", Command));

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
Expand Down
6 changes: 3 additions & 3 deletions Content.Server/Language/Commands/SelectLanguageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Content.Server.Language.Commands;
[AnyCommand]
public sealed class SelectLanguageCommand : IConsoleCommand
{
public string Command => "lsselectlang";
public string Description => "Open a menu to select a language to speak.";
public string Help => "lsselectlang";
public string Command => "languageselect";
public string Description => Loc.GetString("command-language-select-desc");
public string Help => Loc.GetString("command-language-select-help", ("command", Command));

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
Expand Down
29 changes: 29 additions & 0 deletions Content.Server/Language/DetermineEntityLanguagesEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Content.Server.Language;

/// <summary>
/// Raised in order to determine the language an entity speaks at the current moment,
/// as well as the list of all languages the entity may speak and understand.
/// </summary>
public sealed class DetermineEntityLanguagesEvent : EntityEventArgs
{
/// <summary>
/// The default language of this entity. If empty, remain unchanged.
/// This field has no effect if the entity decides to speak in a concrete language.
/// </summary>
public string CurrentLanguage;
/// <summary>
/// The list of all languages the entity may speak. Must NOT be held as a reference!
/// </summary>
public List<string> SpokenLanguages;
/// <summary>
/// The list of all languages the entity may understand. Must NOT be held as a reference!
/// </summary>
public List<string> UnderstoodLanguages;

public DetermineEntityLanguagesEvent(string currentLanguage, List<string> spokenLanguages, List<string> understoodLanguages)
{
CurrentLanguage = currentLanguage;
SpokenLanguages = spokenLanguages;
UnderstoodLanguages = understoodLanguages;
}
}
2 changes: 2 additions & 0 deletions Content.Server/Language/LanguageSystem.Networking.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Content.Server.Mind;
using Content.Shared.Language;
using Content.Shared.Language.Events;
using Content.Shared.Language.Systems;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Robust.Shared.Player;
Expand Down
Loading

0 comments on commit 0b7dd07

Please sign in to comment.