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:
@@ -38,6 +38,10 @@ namespace Content.Client.Input
|
|||||||
ghost.AddFunction(EngineKeyFunctions.MoveRight);
|
ghost.AddFunction(EngineKeyFunctions.MoveRight);
|
||||||
ghost.AddFunction(EngineKeyFunctions.Run);
|
ghost.AddFunction(EngineKeyFunctions.Run);
|
||||||
ghost.AddFunction(ContentKeyFunctions.OpenContextMenu);
|
ghost.AddFunction(ContentKeyFunctions.OpenContextMenu);
|
||||||
|
|
||||||
|
common.AddFunction(ContentKeyFunctions.OpenEntitySpawnWindow);
|
||||||
|
common.AddFunction(ContentKeyFunctions.OpenSandboxWindow);
|
||||||
|
common.AddFunction(ContentKeyFunctions.OpenTileSpawnWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
using Content.Client.UserInterface;
|
using Content.Client.UserInterface;
|
||||||
|
using Content.Shared.Input;
|
||||||
using Content.Shared.Sandbox;
|
using Content.Shared.Sandbox;
|
||||||
|
using Robust.Client.Interfaces.Input;
|
||||||
using Robust.Client.Interfaces.Placement;
|
using Robust.Client.Interfaces.Placement;
|
||||||
using Robust.Client.Interfaces.ResourceManagement;
|
using Robust.Client.Interfaces.ResourceManagement;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
|
using Robust.Shared.Input;
|
||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
using Robust.Shared.Interfaces.Network;
|
using Robust.Shared.Interfaces.Network;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -22,32 +25,48 @@ namespace Content.Client.Sandbox
|
|||||||
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
||||||
[Dependency] private readonly IResourceCache _resourceCache;
|
[Dependency] private readonly IResourceCache _resourceCache;
|
||||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
|
||||||
|
[Dependency] private readonly IInputManager _inputManager;
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
private bool _sandboxAllowed;
|
private bool _sandboxAllowed;
|
||||||
private SandboxWindow _window;
|
private SandboxWindow _window;
|
||||||
|
private EntitySpawnWindow _spawnWindow;
|
||||||
|
private TileSpawnWindow _tilesSpawnWindow;
|
||||||
|
private bool _sandboxWindowToggled = false;
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
_netManager.RegisterNetMessage<MsgSandboxStatus>(nameof(MsgSandboxStatus),
|
_netManager.RegisterNetMessage<MsgSandboxStatus>(nameof(MsgSandboxStatus),
|
||||||
message => SetAllowed(message.SandboxAllowed));
|
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)
|
_sandboxWindowToggled = newValue;
|
||||||
{
|
UpdateSandboxWindowVisibility();
|
||||||
if (_sandboxAllowed)
|
}
|
||||||
{
|
|
||||||
OpenWindow();
|
private void ToggleSandboxWindow()
|
||||||
}
|
{
|
||||||
}
|
_sandboxWindowToggled = !_sandboxWindowToggled;
|
||||||
|
UpdateSandboxWindowVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateSandboxWindowVisibility()
|
||||||
|
{
|
||||||
|
if (_sandboxWindowToggled && _sandboxAllowed)
|
||||||
|
OpenWindow();
|
||||||
else
|
else
|
||||||
{
|
|
||||||
_window?.Close();
|
_window?.Close();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetAllowed(bool newAllowed)
|
private void SetAllowed(bool newAllowed)
|
||||||
@@ -82,7 +101,7 @@ namespace Content.Client.Sandbox
|
|||||||
_window.SpawnTilesButton.OnPressed += OnSpawnTilesButtonClicked;
|
_window.SpawnTilesButton.OnPressed += OnSpawnTilesButtonClicked;
|
||||||
_window.SpawnEntitiesButton.OnPressed += OnSpawnEntitiesButtonClicked;
|
_window.SpawnEntitiesButton.OnPressed += OnSpawnEntitiesButtonClicked;
|
||||||
|
|
||||||
_window.Open();
|
_window.OpenCentered();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WindowOnOnClose()
|
private void WindowOnOnClose()
|
||||||
@@ -98,14 +117,44 @@ namespace Content.Client.Sandbox
|
|||||||
|
|
||||||
private void OnSpawnEntitiesButtonClicked(BaseButton.ButtonEventArgs args)
|
private void OnSpawnEntitiesButtonClicked(BaseButton.ButtonEventArgs args)
|
||||||
{
|
{
|
||||||
var window = new EntitySpawnWindow(_placementManager, _prototypeManager, _resourceCache, _localization);
|
ToggleEntitySpawnWindow();
|
||||||
window.OpenToLeft();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSpawnTilesButtonClicked(BaseButton.ButtonEventArgs args)
|
private void OnSpawnTilesButtonClicked(BaseButton.ButtonEventArgs args)
|
||||||
{
|
{
|
||||||
var window = new TileSpawnWindow(_tileDefinitionManager, _placementManager, _resourceCache);
|
ToggleTilesWindow();
|
||||||
window.OpenToLeft();
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,8 @@ namespace Content.Shared.Input
|
|||||||
public static readonly BoundKeyFunction ThrowItemInHand = "ThrowItemInHand";
|
public static readonly BoundKeyFunction ThrowItemInHand = "ThrowItemInHand";
|
||||||
public static readonly BoundKeyFunction ToggleCombatMode = "ToggleCombatMode";
|
public static readonly BoundKeyFunction ToggleCombatMode = "ToggleCombatMode";
|
||||||
public static readonly BoundKeyFunction MouseMiddle = "MouseMiddle";
|
public static readonly BoundKeyFunction MouseMiddle = "MouseMiddle";
|
||||||
|
public static readonly BoundKeyFunction OpenEntitySpawnWindow = "OpenEntitySpawnWindow";
|
||||||
|
public static readonly BoundKeyFunction OpenSandboxWindow = "OpenSandboxWindow";
|
||||||
|
public static readonly BoundKeyFunction OpenTileSpawnWindow = "OpenTileSpawnWindow";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,3 +146,12 @@ binds:
|
|||||||
type: state
|
type: state
|
||||||
key: Delete
|
key: Delete
|
||||||
canRepeat: true
|
canRepeat: true
|
||||||
|
- function: OpenEntitySpawnWindow
|
||||||
|
type: state
|
||||||
|
key: F5
|
||||||
|
- function: OpenTileSpawnWindow
|
||||||
|
type: state
|
||||||
|
key: F6
|
||||||
|
- function: OpenSandboxWindow
|
||||||
|
type: state
|
||||||
|
key: B
|
||||||
|
|||||||
Reference in New Issue
Block a user