mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-28 19:17:53 +03:00
# Description
4 fixes:
- Fixed translators stopping to provide a language for a fraction of a
tick, causing the provided language to get de-selected when moving a
translator within your inventory (from hands to pocket or otherwise)
- Fixed translators not updating your languages when running out of
power (literally forgot to call UpdateEntityLanguages)
- Fixed language menu breaking after you reconnect to the server (the
issue is tricky, apparently all subscriptions made by ui controllers are
invalidated when the client switches from gameplay state to menu state
(the "you are disconnected" one), but never calls Initialize() for them
again, which means they can never re-create the same subscriptions...
Which explains why the ahelp menu was breaking for me after
reconnecting. All UI controllers that make event subscriptions are
affected by this bug)
- Fixed the language menu button not updating when you close the menu
manually.
# Changelog
🆑
- fix: Fixed a couple issues with the language menu UI and translators.
146 lines
4.4 KiB
C#
146 lines
4.4 KiB
C#
using Content.Client.Language.Systems;
|
|
using Content.Shared.Language.Events;
|
|
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, IEntityEventSubscriber
|
|
{
|
|
private readonly LanguageSystem _clientLanguageSystem;
|
|
private readonly List<EntryState> _entries = new();
|
|
|
|
|
|
public LanguageMenuWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
_clientLanguageSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>();
|
|
|
|
_clientLanguageSystem.OnLanguagesChanged += OnUpdateState;
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
_clientLanguageSystem.OnLanguagesChanged -= OnUpdateState;
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
|
|
private void OnUpdateState(object? sender, LanguagesUpdatedMessage args)
|
|
{
|
|
UpdateState(args.CurrentLanguage, args.Spoken);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|