CloseAllWindowsUIController.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Content.Client.Gameplay;
  2. using Content.Client.Info;
  3. using Robust.Client.Input;
  4. using Robust.Client.UserInterface;
  5. using Robust.Client.UserInterface.Controllers;
  6. using Robust.Client.UserInterface.CustomControls;
  7. using Robust.Shared.Input;
  8. using Robust.Shared.Input.Binding;
  9. namespace Content.Client.UserInterface.Systems.Info;
  10. public sealed class CloseAllWindowsUIController : UIController
  11. {
  12. [Dependency] private readonly IInputManager _inputManager = default!;
  13. [Dependency] private readonly IUserInterfaceManager _uiManager = default!;
  14. public override void Initialize()
  15. {
  16. _inputManager.SetInputCommand(EngineKeyFunctions.WindowCloseAll,
  17. InputCmdHandler.FromDelegate(session => CloseAllWindows()));
  18. }
  19. private void CloseAllWindows()
  20. {
  21. foreach (var childControl in new List<Control>(_uiManager.WindowRoot.Children)) // Copy children list as it will be modified on Close()
  22. {
  23. if (childControl is BaseWindow)
  24. {
  25. ((BaseWindow) childControl).Close();
  26. }
  27. }
  28. }
  29. }