Add EscapeContext keybind (#15301)
* Add EscapeContext Escape context input closes windows if there are any open. If there are not any windows it opens the game menu. * Add fluent for Escape Context * Move EngineContext keybind to content * Readd WindowCloseAll * Fix EscapeContext not opening the game menu after using WindowCloseAll WindowCloseAll does not clear the CloseRecentWindowUIController.recentlyInteractedWindows, which caused HasClosableWindow to return true because the list still had items. Changed HasClosableWindow to check if windows in the list are still open and clear them if they aren't. * Clean up EscapeContextUIController
This commit is contained in:
@@ -32,7 +32,10 @@ public sealed class CloseRecentWindowUIController : UIController
|
||||
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--)
|
||||
@@ -118,5 +121,23 @@ public sealed class CloseRecentWindowUIController : UIController
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,10 @@ public sealed class EscapeUIController : UIController, IOnStateEntered<GameplayS
|
||||
_escapeWindow?.Close();
|
||||
}
|
||||
|
||||
private void ToggleWindow()
|
||||
/// <summary>
|
||||
/// Toggles the game menu.
|
||||
/// </summary>
|
||||
public void ToggleWindow()
|
||||
{
|
||||
if (_escapeWindow == null)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user