mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +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.
82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
using Content.Shared.Language;
|
|
using Content.Shared.Language.Events;
|
|
using Content.Shared.Language.Systems;
|
|
using Robust.Client;
|
|
|
|
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.
|
|
/// </remarks>
|
|
public sealed class LanguageSystem : SharedLanguageSystem
|
|
{
|
|
[Dependency] private readonly IBaseClient _client = default!;
|
|
|
|
/// <summary>
|
|
/// The current language of the entity currently possessed by the player.
|
|
/// </summary>
|
|
public string CurrentLanguage { get; private set; } = default!;
|
|
/// <summary>
|
|
/// The list of languages the currently possessed entity can speak.
|
|
/// </summary>
|
|
public List<string> SpokenLanguages { get; private set; } = new();
|
|
/// <summary>
|
|
/// The list of languages the currently possessed entity can understand.
|
|
/// </summary>
|
|
public List<string> UnderstoodLanguages { get; private set; } = new();
|
|
|
|
public event EventHandler<LanguagesUpdatedMessage>? OnLanguagesChanged;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeNetworkEvent<LanguagesUpdatedMessage>(OnLanguagesUpdated);
|
|
_client.RunLevelChanged += OnRunLevelChanged;
|
|
}
|
|
|
|
private void OnLanguagesUpdated(LanguagesUpdatedMessage message)
|
|
{
|
|
// TODO this entire thing is horrible. If someone is willing to refactor this, LanguageSpeakerComponent should become shared with SendOnlyToOwner = true
|
|
// That way, this system will be able to use the existing networking infrastructure instead of relying on this makeshift... whatever this is.
|
|
CurrentLanguage = message.CurrentLanguage;
|
|
SpokenLanguages = message.Spoken;
|
|
UnderstoodLanguages = message.Understood;
|
|
|
|
OnLanguagesChanged?.Invoke(this, message);
|
|
}
|
|
|
|
private void OnRunLevelChanged(object? sender, RunLevelChangedEventArgs args)
|
|
{
|
|
// Request an update when entering a game
|
|
if (args.NewLevel == ClientRunLevel.InGame)
|
|
RequestStateUpdate();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends a network request to the server to update this system's state.
|
|
/// The server may ignore the said request if the player is not possessing an entity.
|
|
/// </summary>
|
|
public void RequestStateUpdate()
|
|
{
|
|
RaiseNetworkEvent(new RequestLanguagesMessage());
|
|
}
|
|
|
|
public void RequestSetLanguage(LanguagePrototype language)
|
|
{
|
|
if (language.ID == CurrentLanguage)
|
|
return;
|
|
|
|
RaiseNetworkEvent(new LanguagesSetMessage(language.ID));
|
|
|
|
// May cause some minor desync...
|
|
// So to reduce the probability of desync, we replicate the change locally too
|
|
if (SpokenLanguages.Contains(language.ID))
|
|
CurrentLanguage = language.ID;
|
|
}
|
|
}
|