mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
# Description The language PR was merged early and OH GOD I ALREADY REGRET IT This PR is intended to provide the missing refactors and address the issues that were missed due to the early merge. --- # TODO - [X] Introduced a polymorphic obfuscation property to the LanguagePrototype - now it supports more than just 2 hardcoded methods, and each method can be configured per-language. Currently there are 3 obfuscation methods: replacement (same as replacement accent), obuscation by syllables and obfuscation by phrases. - [X] Refactored the existing obfuscation methods to not be a big hardcoded mess. - [X] Updated the existing languages accordingly: animalistic languages are now less of an unreadable mess and include less syllables. Certain languages like binary and snake seriously benefit from that. - [X] Refactored the existing commands in response to the never-addressed review (it got lost among hundreds of others) - [X] Refactored the commands to be more user-friendly (you can now use the number of the language in saylang and languageselect which can allow using keybinds to switch between languages) - [X] Moved a lot of obfuscation-related stuff from server to shared. The actual obfuscation process, however, is still done on the server. That may or may not be subject to change, too. - [X] Refactored the entire process of resolution of entities' languages. Instead of raising an event every time it's required to learn what languages an entity knows, the lists of ALL languages available to the entity (including via translators) is stored in LanguageSpeakerComponent and only updated when necessary (e.g. when a translator gets toggled). The list of languages the entity knows on its own is now stored in LanguageKnowledgeComponent. - [X] Made handheld translators automatically change your current language when activated. - [X] Rewrote the translator implanter system, now using the real implants and implanters - [ ] Rebalance science stuff (translators are incredibly expensive for what they're worth) - [ ] Uhhh stuff --- <details><summary><h1>Media</h1></summary> <p> N/A for now </p> </details> --- # Changelog 🆑 - tweak: Translator implants are now proper implants that can be removed. - tweak: Animalistic languages should now look less messy. - fix: Hopefully fixed language menu desync and other issues. --------- Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com>
132 lines
3.9 KiB
C#
132 lines
3.9 KiB
C#
using Content.Client.Language.Systems;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
namespace Content.Client.Language;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class LanguageMenuWindow : DefaultWindow
|
|
{
|
|
private readonly LanguageSystem _clientLanguageSystem;
|
|
private readonly List<EntryState> _entries = new();
|
|
|
|
|
|
public LanguageMenuWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
_clientLanguageSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>();
|
|
}
|
|
|
|
protected override void Opened()
|
|
{
|
|
// Refresh the window when it gets opened.
|
|
// This actually causes two refreshes: one immediately, and one after the server sends a state message.
|
|
UpdateState(_clientLanguageSystem.CurrentLanguage, _clientLanguageSystem.SpokenLanguages);
|
|
_clientLanguageSystem.RequestStateUpdate();
|
|
}
|
|
|
|
|
|
public void UpdateState(string currentLanguage, List<string> spokenLanguages)
|
|
{
|
|
var langName = Loc.GetString($"language-{currentLanguage}-name");
|
|
CurrentLanguageLabel.Text = Loc.GetString("language-menu-current-language", ("language", langName));
|
|
|
|
OptionsList.RemoveAllChildren();
|
|
_entries.Clear();
|
|
|
|
foreach (var language in spokenLanguages)
|
|
{
|
|
AddLanguageEntry(language);
|
|
}
|
|
|
|
// Disable the button for the currently chosen language
|
|
foreach (var entry in _entries)
|
|
{
|
|
if (entry.button != null)
|
|
entry.button.Disabled = entry.language == currentLanguage;
|
|
}
|
|
}
|
|
|
|
private void AddLanguageEntry(string language)
|
|
{
|
|
var proto = _clientLanguageSystem.GetLanguagePrototype(language);
|
|
var state = new EntryState { language = language };
|
|
|
|
var container = new BoxContainer { Orientation = BoxContainer.LayoutOrientation.Vertical };
|
|
|
|
#region Header
|
|
var header = new BoxContainer
|
|
{
|
|
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
|
HorizontalExpand = true,
|
|
SeparationOverride = 2
|
|
};
|
|
|
|
var name = new Label
|
|
{
|
|
Text = proto?.Name ?? Loc.GetString("generic-error"),
|
|
MinWidth = 50,
|
|
HorizontalExpand = true
|
|
};
|
|
|
|
var button = new Button { Text = "Choose" };
|
|
button.OnPressed += _ => OnLanguageChosen(language);
|
|
state.button = button;
|
|
|
|
header.AddChild(name);
|
|
header.AddChild(button);
|
|
|
|
container.AddChild(header);
|
|
#endregion
|
|
|
|
#region Collapsible description
|
|
var body = new CollapsibleBody
|
|
{
|
|
HorizontalExpand = true,
|
|
Margin = new Thickness(4f, 4f)
|
|
};
|
|
|
|
var description = new RichTextLabel { HorizontalExpand = true };
|
|
description.SetMessage(proto?.Description ?? Loc.GetString("generic-error"));
|
|
body.AddChild(description);
|
|
|
|
var collapser = new Collapsible(Loc.GetString("language-menu-description-header"), body)
|
|
{
|
|
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
|
HorizontalExpand = true
|
|
};
|
|
|
|
container.AddChild(collapser);
|
|
#endregion
|
|
|
|
// Before adding, wrap the new container in a PanelContainer to give it a distinct look
|
|
var wrapper = new PanelContainer();
|
|
wrapper.StyleClasses.Add("PdaBorderRect");
|
|
|
|
wrapper.AddChild(container);
|
|
OptionsList.AddChild(wrapper);
|
|
|
|
_entries.Add(state);
|
|
}
|
|
|
|
|
|
private void OnLanguageChosen(string id)
|
|
{
|
|
var proto = _clientLanguageSystem.GetLanguagePrototype(id);
|
|
if (proto == null)
|
|
return;
|
|
|
|
_clientLanguageSystem.RequestSetLanguage(proto);
|
|
UpdateState(id, _clientLanguageSystem.SpokenLanguages);
|
|
}
|
|
|
|
|
|
private struct EntryState
|
|
{
|
|
public string language;
|
|
public Button? button;
|
|
}
|
|
}
|