Sandbox panel
This commit is contained in:
@@ -7,6 +7,7 @@ using Content.Client.Interfaces;
|
|||||||
using Content.Client.Interfaces.Chat;
|
using Content.Client.Interfaces.Chat;
|
||||||
using Content.Client.Interfaces.Parallax;
|
using Content.Client.Interfaces.Parallax;
|
||||||
using Content.Client.Parallax;
|
using Content.Client.Parallax;
|
||||||
|
using Content.Client.Sandbox;
|
||||||
using Content.Client.UserInterface;
|
using Content.Client.UserInterface;
|
||||||
using Content.Shared.GameObjects.Components;
|
using Content.Shared.GameObjects.Components;
|
||||||
using Content.Shared.GameObjects.Components.Chemistry;
|
using Content.Shared.GameObjects.Components.Chemistry;
|
||||||
@@ -134,6 +135,8 @@ namespace Content.Client
|
|||||||
IoCManager.Register<IParallaxManager, ParallaxManager>();
|
IoCManager.Register<IParallaxManager, ParallaxManager>();
|
||||||
IoCManager.Register<IChatManager, ChatManager>();
|
IoCManager.Register<IChatManager, ChatManager>();
|
||||||
IoCManager.Register<IEscapeMenuOwner, EscapeMenuOwner>();
|
IoCManager.Register<IEscapeMenuOwner, EscapeMenuOwner>();
|
||||||
|
IoCManager.Register<ISandboxManager, SandboxManager>();
|
||||||
|
|
||||||
if (TestingCallbacks != null)
|
if (TestingCallbacks != null)
|
||||||
{
|
{
|
||||||
var cast = (ClientModuleTestingCallbacks) TestingCallbacks;
|
var cast = (ClientModuleTestingCallbacks) TestingCallbacks;
|
||||||
@@ -195,6 +198,7 @@ namespace Content.Client
|
|||||||
IoCManager.Resolve<IClientGameTicker>().Initialize();
|
IoCManager.Resolve<IClientGameTicker>().Initialize();
|
||||||
IoCManager.Resolve<IOverlayManager>().AddOverlay(new ParallaxOverlay());
|
IoCManager.Resolve<IOverlayManager>().AddOverlay(new ParallaxOverlay());
|
||||||
IoCManager.Resolve<IChatManager>().Initialize();
|
IoCManager.Resolve<IChatManager>().Initialize();
|
||||||
|
IoCManager.Resolve<ISandboxManager>().Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs)
|
public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs)
|
||||||
|
|||||||
7
Content.Client/Sandbox/ISandboxManager.cs
Normal file
7
Content.Client/Sandbox/ISandboxManager.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Content.Client.Sandbox
|
||||||
|
{
|
||||||
|
public interface ISandboxManager
|
||||||
|
{
|
||||||
|
void Initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
111
Content.Client/Sandbox/SandboxManager.cs
Normal file
111
Content.Client/Sandbox/SandboxManager.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
Content.Client/Sandbox/SandboxWindow.cs
Normal file
45
Content.Client/Sandbox/SandboxWindow.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -182,7 +182,7 @@ namespace Content.Client.UserInterface
|
|||||||
_buttonSandboxMenu = new TopButton(sandboxTexture, "B")
|
_buttonSandboxMenu = new TopButton(sandboxTexture, "B")
|
||||||
{
|
{
|
||||||
ToolTip = _loc.GetString("Open sandbox menu."),
|
ToolTip = _loc.GetString("Open sandbox menu."),
|
||||||
Visible = true
|
Visible = false
|
||||||
};
|
};
|
||||||
|
|
||||||
_topButtonsContainer.AddChild(_buttonSandboxMenu);
|
_topButtonsContainer.AddChild(_buttonSandboxMenu);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Content.Server.GameTicking;
|
|||||||
using Content.Server.Interfaces;
|
using Content.Server.Interfaces;
|
||||||
using Content.Server.Interfaces.Chat;
|
using Content.Server.Interfaces.Chat;
|
||||||
using Content.Server.Interfaces.GameTicking;
|
using Content.Server.Interfaces.GameTicking;
|
||||||
|
using Content.Server.Sandbox;
|
||||||
using Content.Shared.Interfaces;
|
using Content.Shared.Interfaces;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.ContentPack;
|
using Robust.Shared.ContentPack;
|
||||||
@@ -48,6 +49,7 @@ namespace Content.Server
|
|||||||
IoCManager.Register<IGameTicker, GameTicker>();
|
IoCManager.Register<IGameTicker, GameTicker>();
|
||||||
IoCManager.Register<IChatManager, ChatManager>();
|
IoCManager.Register<IChatManager, ChatManager>();
|
||||||
IoCManager.Register<IMoMMILink, MoMMILink>();
|
IoCManager.Register<IMoMMILink, MoMMILink>();
|
||||||
|
IoCManager.Register<ISandboxManager, SandboxManager>();
|
||||||
if (TestingCallbacks != null)
|
if (TestingCallbacks != null)
|
||||||
{
|
{
|
||||||
var cast = (ServerModuleTestingCallbacks) TestingCallbacks;
|
var cast = (ServerModuleTestingCallbacks) TestingCallbacks;
|
||||||
@@ -73,6 +75,7 @@ namespace Content.Server
|
|||||||
base.PostInit();
|
base.PostInit();
|
||||||
|
|
||||||
_gameTicker.Initialize();
|
_gameTicker.Initialize();
|
||||||
|
IoCManager.Resolve<ISandboxManager>().Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs)
|
public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs)
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
|
using Content.Server.Interfaces.GameTicking;
|
||||||
|
using Content.Server.Sandbox;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
|
||||||
namespace Content.Server.GameTicking.GamePresets
|
namespace Content.Server.GameTicking.GamePresets
|
||||||
{
|
{
|
||||||
public sealed class PresetSandbox : GamePreset
|
public sealed class PresetSandbox : GamePreset
|
||||||
{
|
{
|
||||||
|
#pragma warning disable 649
|
||||||
|
[Dependency] private readonly ISandboxManager _sandboxManager;
|
||||||
|
#pragma warning restore 649
|
||||||
|
|
||||||
public override void Start()
|
public override void Start()
|
||||||
{
|
{
|
||||||
// Nothing yet.
|
_sandboxManager.IsSandboxEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,8 +156,7 @@ namespace Content.Server.GameTicking
|
|||||||
|
|
||||||
RunLevel = GameRunLevel.InRound;
|
RunLevel = GameRunLevel.InRound;
|
||||||
|
|
||||||
// TODO: Allow other presets to be selected.
|
var preset = _dynamicTypeFactory.CreateInstance<GamePreset>(_presetType ?? typeof(PresetSandbox));
|
||||||
var preset = (GamePreset)_dynamicTypeFactory.CreateInstance(_presetType ?? typeof(PresetSandbox));
|
|
||||||
preset.Start();
|
preset.Start();
|
||||||
|
|
||||||
foreach (var (playerSession, ready) in _playersInLobby.ToList())
|
foreach (var (playerSession, ready) in _playersInLobby.ToList())
|
||||||
|
|||||||
8
Content.Server/Sandbox/ISandboxManager.cs
Normal file
8
Content.Server/Sandbox/ISandboxManager.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Content.Server.Sandbox
|
||||||
|
{
|
||||||
|
public interface ISandboxManager
|
||||||
|
{
|
||||||
|
bool IsSandboxEnabled { get; set; }
|
||||||
|
void Initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
80
Content.Server/Sandbox/SandboxManager.cs
Normal file
80
Content.Server/Sandbox/SandboxManager.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
using Content.Server.GameTicking;
|
||||||
|
using Content.Server.Interfaces.GameTicking;
|
||||||
|
using Content.Shared.Sandbox;
|
||||||
|
using Robust.Server.Interfaces.Player;
|
||||||
|
using Robust.Server.Player;
|
||||||
|
using Robust.Shared.Enums;
|
||||||
|
using Robust.Shared.Interfaces.Network;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
|
||||||
|
namespace Content.Server.Sandbox
|
||||||
|
{
|
||||||
|
internal sealed class SandboxManager : SharedSandboxManager, ISandboxManager
|
||||||
|
{
|
||||||
|
#pragma warning disable 649
|
||||||
|
[Dependency] private readonly IPlayerManager _playerManager;
|
||||||
|
[Dependency] private readonly IServerNetManager _netManager;
|
||||||
|
[Dependency] private readonly IGameTicker _gameTicker;
|
||||||
|
#pragma warning restore 649
|
||||||
|
|
||||||
|
private bool _isSandboxEnabled;
|
||||||
|
|
||||||
|
public bool IsSandboxEnabled
|
||||||
|
{
|
||||||
|
get => _isSandboxEnabled;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_isSandboxEnabled = value;
|
||||||
|
UpdateSandboxStatusForAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
_netManager.RegisterNetMessage<MsgSandboxStatus>(nameof(MsgSandboxStatus));
|
||||||
|
_netManager.RegisterNetMessage<MsgSandboxRespawn>(nameof(MsgSandboxRespawn), SandboxRespawnReceived);
|
||||||
|
|
||||||
|
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||||
|
_gameTicker.OnRunLevelChanged += GameTickerOnOnRunLevelChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GameTickerOnOnRunLevelChanged(GameRunLevelChangedEventArgs obj)
|
||||||
|
{
|
||||||
|
// Automatically clear sandbox state when round resets.
|
||||||
|
if (obj.NewRunLevel == GameRunLevel.PreRoundLobby)
|
||||||
|
{
|
||||||
|
IsSandboxEnabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPlayerStatusChanged(object sender, SessionStatusEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.NewStatus != SessionStatus.Connected || e.OldStatus != SessionStatus.Connecting)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var msg = _netManager.CreateNetMessage<MsgSandboxStatus>();
|
||||||
|
msg.SandboxAllowed = IsSandboxEnabled;
|
||||||
|
_netManager.ServerSendMessage(msg, e.Session.ConnectedClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SandboxRespawnReceived(MsgSandboxRespawn message)
|
||||||
|
{
|
||||||
|
if (!IsSandboxEnabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
||||||
|
_gameTicker.Respawn(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateSandboxStatusForAll()
|
||||||
|
{
|
||||||
|
var msg = _netManager.CreateNetMessage<MsgSandboxStatus>();
|
||||||
|
msg.SandboxAllowed = IsSandboxEnabled;
|
||||||
|
_netManager.ServerSendToAll(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
Content.Shared/Sandbox/SharedSandboxManager.cs
Normal file
51
Content.Shared/Sandbox/SharedSandboxManager.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using Lidgren.Network;
|
||||||
|
using Robust.Shared.Interfaces.Network;
|
||||||
|
using Robust.Shared.Network;
|
||||||
|
|
||||||
|
namespace Content.Shared.Sandbox
|
||||||
|
{
|
||||||
|
public abstract class SharedSandboxManager
|
||||||
|
{
|
||||||
|
protected sealed class MsgSandboxStatus : NetMessage
|
||||||
|
{
|
||||||
|
#region REQUIRED
|
||||||
|
|
||||||
|
public const MsgGroups GROUP = MsgGroups.Command;
|
||||||
|
public const string NAME = nameof(MsgSandboxStatus);
|
||||||
|
public MsgSandboxStatus(INetChannel channel) : base(NAME, GROUP) { }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public bool SandboxAllowed { get; set; }
|
||||||
|
|
||||||
|
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||||
|
{
|
||||||
|
SandboxAllowed = buffer.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||||
|
{
|
||||||
|
buffer.Write(SandboxAllowed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected sealed class MsgSandboxRespawn : NetMessage
|
||||||
|
{
|
||||||
|
#region REQUIRED
|
||||||
|
|
||||||
|
public const MsgGroups GROUP = MsgGroups.Command;
|
||||||
|
public const string NAME = nameof(MsgSandboxRespawn);
|
||||||
|
public MsgSandboxRespawn(INetChannel channel) : base(NAME, GROUP) { }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user