6
2026-01-24 12:49:55 +03:00

38 lines
1.2 KiB
C#

using Content.Client.UserInterface.Systems.Info;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
namespace Content.Client.UserInterface.Systems.EscapeMenu;
[UsedImplicitly]
public sealed class EscapeContextUIController : UIController
{
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly CloseRecentWindowUIController _closeRecentWindowUIController = default!;
[Dependency] private readonly EscapeUIController _escapeUIController = default!;
public override void Initialize()
{
_inputManager.SetInputCommand(ContentKeyFunctions.EscapeContext,
InputCmdHandler.FromDelegate(_ => CloseWindowOrOpenGameMenu()));
}
private void CloseWindowOrOpenGameMenu()
{
if (_closeRecentWindowUIController.HasClosableWindow())
{
_closeRecentWindowUIController.CloseMostRecentWindow();
}
else
{
_escapeUIController.ToggleWindow();
}
}
}