EscapeContextUIController.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Content.Client.UserInterface.Systems.Info;
  2. using Content.Shared.Input;
  3. using JetBrains.Annotations;
  4. using Robust.Client.Input;
  5. using Robust.Client.UserInterface;
  6. using Robust.Client.UserInterface.Controllers;
  7. using Robust.Shared.Input;
  8. using Robust.Shared.Input.Binding;
  9. namespace Content.Client.UserInterface.Systems.EscapeMenu;
  10. [UsedImplicitly]
  11. public sealed class EscapeContextUIController : UIController
  12. {
  13. [Dependency] private readonly IInputManager _inputManager = default!;
  14. [Dependency] private readonly CloseRecentWindowUIController _closeRecentWindowUIController = default!;
  15. [Dependency] private readonly EscapeUIController _escapeUIController = default!;
  16. public override void Initialize()
  17. {
  18. _inputManager.SetInputCommand(ContentKeyFunctions.EscapeContext,
  19. InputCmdHandler.FromDelegate(_ => CloseWindowOrOpenGameMenu()));
  20. }
  21. private void CloseWindowOrOpenGameMenu()
  22. {
  23. if (_closeRecentWindowUIController.HasClosableWindow())
  24. {
  25. _closeRecentWindowUIController.CloseMostRecentWindow();
  26. }
  27. else
  28. {
  29. _escapeUIController.ToggleWindow();
  30. }
  31. }
  32. }