Sandbox panel

This commit is contained in:
Pieter-Jan Briers
2019-10-02 10:45:06 +02:00
parent 18392610c9
commit a2d8fc1ef9
11 changed files with 320 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ using Content.Client.Interfaces;
using Content.Client.Interfaces.Chat;
using Content.Client.Interfaces.Parallax;
using Content.Client.Parallax;
using Content.Client.Sandbox;
using Content.Client.UserInterface;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Chemistry;
@@ -134,6 +135,8 @@ namespace Content.Client
IoCManager.Register<IParallaxManager, ParallaxManager>();
IoCManager.Register<IChatManager, ChatManager>();
IoCManager.Register<IEscapeMenuOwner, EscapeMenuOwner>();
IoCManager.Register<ISandboxManager, SandboxManager>();
if (TestingCallbacks != null)
{
var cast = (ClientModuleTestingCallbacks) TestingCallbacks;
@@ -195,6 +198,7 @@ namespace Content.Client
IoCManager.Resolve<IClientGameTicker>().Initialize();
IoCManager.Resolve<IOverlayManager>().AddOverlay(new ParallaxOverlay());
IoCManager.Resolve<IChatManager>().Initialize();
IoCManager.Resolve<ISandboxManager>().Initialize();
}
public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs)

View File

@@ -0,0 +1,7 @@
namespace Content.Client.Sandbox
{
public interface ISandboxManager
{
void Initialize();
}
}

View File

@@ -0,0 +1,111 @@
using Content.Client.UserInterface;
using Content.Shared.Sandbox;
using Robust.Client.Interfaces.Placement;
using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
namespace Content.Client.Sandbox
{
internal sealed class SandboxManager : SharedSandboxManager, ISandboxManager
{
#pragma warning disable 649
[Dependency] private readonly IGameHud _gameHud;
[Dependency] private readonly IClientNetManager _netManager;
[Dependency] private readonly ILocalizationManager _localization;
[Dependency] private readonly IPlacementManager _placementManager;
[Dependency] private readonly IPrototypeManager _prototypeManager;
[Dependency] private readonly IResourceCache _resourceCache;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
#pragma warning restore 649
private bool _sandboxAllowed;
private SandboxWindow _window;
public void Initialize()
{
_netManager.RegisterNetMessage<MsgSandboxStatus>(nameof(MsgSandboxStatus),
message => SetAllowed(message.SandboxAllowed));
_gameHud.SandboxButtonToggled = SandboxButtonToggled;
}
private void SandboxButtonToggled(bool newValue)
{
if (newValue)
{
if (_sandboxAllowed)
{
OpenWindow();
}
}
else
{
_window?.Close();
}
}
private void SetAllowed(bool newAllowed)
{
if (newAllowed == _sandboxAllowed)
{
return;
}
_sandboxAllowed = newAllowed;
_gameHud.SandboxButtonVisible = newAllowed;
if (!newAllowed)
{
// Sandbox permission revoked, close window.
_window?.Close();
}
}
private void OpenWindow()
{
if (_window != null)
{
return;
}
_window = new SandboxWindow(_localization);
_window.OnClose += WindowOnOnClose;
_window.RespawnButton.OnPressed += OnRespawnButtonOnOnPressed;
_window.SpawnTilesButton.OnPressed += OnSpawnTilesButtonClicked;
_window.SpawnEntitiesButton.OnPressed += OnSpawnEntitiesButtonClicked;
_window.Open();
}
private void WindowOnOnClose()
{
_window = null;
_gameHud.SandboxButtonDown = false;
}
private void OnRespawnButtonOnOnPressed(BaseButton.ButtonEventArgs args)
{
_netManager.ClientSendMessage(_netManager.CreateNetMessage<MsgSandboxRespawn>());
}
private void OnSpawnEntitiesButtonClicked(BaseButton.ButtonEventArgs args)
{
var window = new EntitySpawnWindow(_placementManager, _prototypeManager, _resourceCache, _localization);
window.OpenToLeft();
}
private void OnSpawnTilesButtonClicked(BaseButton.ButtonEventArgs args)
{
var window = new TileSpawnWindow(_tileDefinitionManager, _placementManager, _resourceCache);
window.OpenToLeft();
}
}
}

View File

@@ -0,0 +1,45 @@
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Localization;
namespace Content.Client.Sandbox
{
public sealed class SandboxWindow : SS14Window
{
public Button RespawnButton { get; }
public Button SpawnEntitiesButton { get; }
public Button SpawnTilesButton { get; }
public SandboxWindow(ILocalizationManager loc)
{
Title = loc.GetString("Sandbox Panel");
RespawnButton = new Button
{
Text = loc.GetString("Respawn")
};
SpawnEntitiesButton = new Button
{
Text = loc.GetString("Spawn Entities")
};
SpawnTilesButton = new Button
{
Text = loc.GetString("Spawn Tiles")
};
Contents.AddChild(new VBoxContainer
{
Children =
{
RespawnButton,
SpawnEntitiesButton,
SpawnTilesButton
}
});
Size = CombinedMinimumSize;
}
}
}

View File

@@ -182,7 +182,7 @@ namespace Content.Client.UserInterface
_buttonSandboxMenu = new TopButton(sandboxTexture, "B")
{
ToolTip = _loc.GetString("Open sandbox menu."),
Visible = true
Visible = false
};
_topButtonsContainer.AddChild(_buttonSandboxMenu);