common.AddFunction(ContentKeyFunctions.FocusDeadChat);
common.AddFunction(ContentKeyFunctions.CycleChatChannelForward);
common.AddFunction(ContentKeyFunctions.CycleChatChannelBackward);
+ common.AddFunction(ContentKeyFunctions.EscapeContext);
common.AddFunction(ContentKeyFunctions.ExamineEntity);
common.AddFunction(ContentKeyFunctions.OpenAHelp);
common.AddFunction(ContentKeyFunctions.TakeScreenshot);
AddButton(EngineKeyFunctions.WindowCloseAll);
AddButton(EngineKeyFunctions.WindowCloseRecent);
AddButton(EngineKeyFunctions.EscapeMenu);
+ AddButton(ContentKeyFunctions.EscapeContext);
AddHeader("ui-options-header-misc");
AddButton(ContentKeyFunctions.TakeScreenshot);
InputCmdHandler.FromDelegate(session => CloseMostRecentWindow()));
}
- private void CloseMostRecentWindow()
+ /// <summary>
+ /// Closes the most recently focused window.
+ /// </summary>
+ public void CloseMostRecentWindow()
{
// Search backwards through the recency list to find a still open window and close it
for (int i=recentlyInteractedWindows.Count-1; i>=0; i--)
SetMostRecentlyInteractedWindow((BaseWindow) control);
}
}
-}
+ /// <summary>
+ /// Checks whether there are any windows that can be closed.
+ /// </summary>
+ /// <returns></returns>
+ public bool HasClosableWindow()
+ {
+ for (var i = recentlyInteractedWindows.Count - 1; i >= 0; i--)
+ {
+ var window = recentlyInteractedWindows[i];
+ if (window.IsOpen)
+ return true;
+
+ recentlyInteractedWindows.RemoveAt(i);
+ // continue going down the list, hoping to find a still-open window
+ }
+
+ return false;
+ }
+}
--- /dev/null
+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();
+ }
+ }
+}
_escapeWindow?.Close();
}
- private void ToggleWindow()
+ /// <summary>
+ /// Toggles the game menu.
+ /// </summary>
+ public void ToggleWindow()
{
if (_escapeWindow == null)
return;
public static readonly BoundKeyFunction FocusConsoleChat = "FocusConsoleChatWindow";
public static readonly BoundKeyFunction CycleChatChannelForward = "CycleChatChannelForward";
public static readonly BoundKeyFunction CycleChatChannelBackward = "CycleChatChannelBackward";
+ public static readonly BoundKeyFunction EscapeContext = "EscapeContext";
public static readonly BoundKeyFunction OpenCharacterMenu = "OpenCharacterMenu";
public static readonly BoundKeyFunction OpenCraftingMenu = "OpenCraftingMenu";
public static readonly BoundKeyFunction OpenGuidebook = "OpenGuidebook";
ui-options-function-window-close-all = Close all windows
ui-options-function-window-close-recent = Close recent window
ui-options-function-show-escape-menu = Toggle game menu
+ui-options-function-escape-context = Close recent window or toggle game menu
ui-options-function-take-screenshot = Take screenshot
ui-options-function-take-screenshot-no-ui = Take screenshot (without UI)
type: State
key: Tab
mod1: Shift
-- function: WindowCloseRecent
+- function: EscapeContext
type: State
key: Escape
- function: WindowCloseAll