Skip to content

Commit

Permalink
Update LanguageMenuUIController.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxoTrystan committed May 1, 2024
1 parent a938832 commit e66df36
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
using Robust.Shared.Input.Binding;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BaseButton;
using Robust.Client.GameObjects;

namespace Content.Client.UserInterface.Systems.Language;

[UsedImplicitly]
public sealed class LanguageMenuUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>
{
public LanguageMenuWindow? _languageWindow;
private IEntityManager _entManager;
private MenuButton? LanguageButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.LanguageButton;

/// <summary>
Expand All @@ -27,6 +29,11 @@ public sealed class LanguageMenuUIController : UIController, IOnStateEntered<Gam
/// </summary>
public Action<(string current, List<string> spoken, List<string> understood)>? LanguagesUpdatedHook;

public LanguageMenuUIController()
{
_entManager = IoCManager.Resolve<IEntityManager>();
}

public override void Initialize()
{
LanguagesUpdatedHook += (args) =>
Expand All @@ -42,8 +49,7 @@ public void OnStateEntered(GameplayState state)
{
DebugTools.Assert(_languageWindow == null);

var entManager = IoCManager.Resolve<IEntityManager>();
var clientLanguageSystem = entManager.EntitySysManager.GetEntitySystem<LanguageSystem>();
var clientLanguageSystem = _entManager.EntitySysManager.GetEntitySystem<LanguageSystem>();
clientLanguageSystem.LanguagesUpdatedHook += LanguagesUpdatedHook;

_languageWindow = UIManager.CreateWindow<LanguageMenuWindow>();
Expand All @@ -60,8 +66,7 @@ public void OnStateExited(GameplayState state)
_languageWindow = null;
}

var entManager = IoCManager.Resolve<IEntityManager>();
var clientLanguageSystem = entManager.EntitySysManager.GetEntitySystem<LanguageSystem>();
var clientLanguageSystem = _entManager.EntitySysManager.GetEntitySystem<LanguageSystem>();
clientLanguageSystem.LanguagesUpdatedHook -= LanguagesUpdatedHook;

CommandBinds.Unregister<LanguageMenuUIController>();
Expand Down

0 comments on commit e66df36

Please sign in to comment.