Sandbox window improvements (#578)

* Several sandbox manager improvements

- Bound sandbox manager to B key as it lists on the UI
- Bound entity spawner to F5
- Bound tile spawner to F6
- Made entity spawner and tile spawner toggle instead of repeated spawning new windows from the sandbox panel

* Move relevant keyfunctions from engine to content

Turns out it was unnecessary to have the key functions in the engine as all code using the ones added here are in content.
This commit is contained in:
moneyl
2020-02-02 16:38:51 -05:00
committed by GitHub
parent e72a78fc87
commit 33cf29978a
4 changed files with 82 additions and 17 deletions

View File

@@ -1,9 +1,12 @@
using Content.Client.UserInterface;
using Content.Client.UserInterface;
using Content.Shared.Input;
using Content.Shared.Sandbox;
using Robust.Client.Interfaces.Input;
using Robust.Client.Interfaces.Placement;
using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Input;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
@@ -22,32 +25,48 @@ namespace Content.Client.Sandbox
[Dependency] private readonly IPrototypeManager _prototypeManager;
[Dependency] private readonly IResourceCache _resourceCache;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
[Dependency] private readonly IInputManager _inputManager;
#pragma warning restore 649
private bool _sandboxAllowed;
private SandboxWindow _window;
private EntitySpawnWindow _spawnWindow;
private TileSpawnWindow _tilesSpawnWindow;
private bool _sandboxWindowToggled = false;
public void Initialize()
{
_netManager.RegisterNetMessage<MsgSandboxStatus>(nameof(MsgSandboxStatus),
message => SetAllowed(message.SandboxAllowed));
_gameHud.SandboxButtonToggled = SandboxButtonToggled;
_gameHud.SandboxButtonToggled = SandboxButtonPressed;
_inputManager.SetInputCommand(ContentKeyFunctions.OpenEntitySpawnWindow,
InputCmdHandler.FromDelegate(session => ToggleEntitySpawnWindow()));
_inputManager.SetInputCommand(ContentKeyFunctions.OpenSandboxWindow,
InputCmdHandler.FromDelegate(session => ToggleSandboxWindow()));
_inputManager.SetInputCommand(ContentKeyFunctions.OpenTileSpawnWindow,
InputCmdHandler.FromDelegate(session => ToggleTilesWindow()));
}
private void SandboxButtonToggled(bool newValue)
private void SandboxButtonPressed(bool newValue)
{
if (newValue)
{
if (_sandboxAllowed)
{
OpenWindow();
}
}
_sandboxWindowToggled = newValue;
UpdateSandboxWindowVisibility();
}
private void ToggleSandboxWindow()
{
_sandboxWindowToggled = !_sandboxWindowToggled;
UpdateSandboxWindowVisibility();
}
private void UpdateSandboxWindowVisibility()
{
if (_sandboxWindowToggled && _sandboxAllowed)
OpenWindow();
else
{
_window?.Close();
}
}
private void SetAllowed(bool newAllowed)
@@ -82,7 +101,7 @@ namespace Content.Client.Sandbox
_window.SpawnTilesButton.OnPressed += OnSpawnTilesButtonClicked;
_window.SpawnEntitiesButton.OnPressed += OnSpawnEntitiesButtonClicked;
_window.Open();
_window.OpenCentered();
}
private void WindowOnOnClose()
@@ -98,14 +117,44 @@ namespace Content.Client.Sandbox
private void OnSpawnEntitiesButtonClicked(BaseButton.ButtonEventArgs args)
{
var window = new EntitySpawnWindow(_placementManager, _prototypeManager, _resourceCache, _localization);
window.OpenToLeft();
ToggleEntitySpawnWindow();
}
private void OnSpawnTilesButtonClicked(BaseButton.ButtonEventArgs args)
{
var window = new TileSpawnWindow(_tileDefinitionManager, _placementManager, _resourceCache);
window.OpenToLeft();
ToggleTilesWindow();
}
private void ToggleEntitySpawnWindow()
{
if(_spawnWindow == null)
_spawnWindow = new EntitySpawnWindow(_placementManager, _prototypeManager, _resourceCache, _localization);
if (_spawnWindow.IsOpen)
{
_spawnWindow.Close();
}
else
{
_spawnWindow = new EntitySpawnWindow(_placementManager, _prototypeManager, _resourceCache, _localization);
_spawnWindow.OpenToLeft();
}
}
private void ToggleTilesWindow()
{
if(_tilesSpawnWindow == null)
_tilesSpawnWindow = new TileSpawnWindow(_tileDefinitionManager, _placementManager, _resourceCache);
if (_tilesSpawnWindow.IsOpen)
{
_tilesSpawnWindow.Close();
}
else
{
_tilesSpawnWindow = new TileSpawnWindow(_tileDefinitionManager, _placementManager, _resourceCache);
_tilesSpawnWindow.OpenToLeft();
}
}
}
}