Make ghost component ECS (#4159)

* Make ghost component ECS

* Remove players and locations properties from ghost component

* Address reviews

* One more doc

* Fix client ghost component state method error
This commit is contained in:
DrSmugleaf
2021-06-18 09:56:23 +02:00
committed by GitHub
parent 86ff812428
commit 4f4d203d2e
10 changed files with 481 additions and 401 deletions

View File

@@ -1,8 +1,12 @@
#nullable enable
using System.Collections.Generic;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Ghost;
using Robust.Client.Console;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
@@ -17,19 +21,29 @@ namespace Content.Client.Ghost
public GhostTargetWindow? TargetWindow { get; }
public GhostGui(GhostComponent owner)
public GhostGui(GhostComponent owner, IEntityNetworkManager eventBus)
{
IoCManager.InjectDependencies(this);
_owner = owner;
TargetWindow = new GhostTargetWindow(owner);
TargetWindow = new GhostTargetWindow(owner, eventBus);
MouseFilter = MouseFilterMode.Ignore;
_ghostWarp.OnPressed += _ => TargetWindow.Populate();
_returnToBody.OnPressed += _ => owner.SendReturnToBodyMessage();
_ghostRoles.OnPressed += _ => IoCManager.Resolve<IClientConsoleHost>().RemoteExecuteCommand(null, "ghostroles");
_ghostWarp.OnPressed += _ =>
{
eventBus.SendSystemNetworkMessage(new GhostWarpsRequestEvent());
TargetWindow.Populate();
TargetWindow.OpenCentered();
};
_returnToBody.OnPressed += _ =>
{
var msg = new GhostReturnToBodyRequest();
eventBus.SendSystemNetworkMessage(msg);
};
_ghostRoles.OnPressed += _ => IoCManager.Resolve<IClientConsoleHost>()
.RemoteExecuteCommand(null, "ghostroles");
AddChild(new HBoxContainer
{
@@ -40,28 +54,42 @@ namespace Content.Client.Ghost
_ghostRoles,
}
});
Update();
}
public void Update()
{
_returnToBody.Disabled = !_owner.CanReturnToBody;
TargetWindow?.Populate();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
TargetWindow?.Dispose();
}
}
}
public class GhostTargetWindow : SS14Window
{
private readonly GhostComponent _owner;
private readonly IEntityNetworkManager _netManager;
private readonly VBoxContainer _buttonContainer;
public GhostTargetWindow(GhostComponent owner)
public List<string> Locations { get; set; } = new();
public Dictionary<EntityUid, string> Players { get; set; } = new();
public GhostTargetWindow(GhostComponent owner, IEntityNetworkManager netManager)
{
MinSize = SetSize = (300, 450);
Title = "Ghost Warp";
_owner = owner;
_owner.GhostRequestWarpPoint();
_owner.GhostRequestPlayerNames();
_netManager = netManager;
_buttonContainer = new VBoxContainer()
{
@@ -86,12 +114,11 @@ namespace Content.Client.Ghost
_buttonContainer.DisposeAllChildren();
AddButtonPlayers();
AddButtonLocations();
OpenCentered();
}
private void AddButtonPlayers()
{
foreach (var (key, value) in _owner.PlayerNames)
foreach (var (key, value) in Players)
{
var currentButtonRef = new Button
{
@@ -106,7 +133,8 @@ namespace Content.Client.Ghost
currentButtonRef.OnPressed += (_) =>
{
_owner.SendGhostWarpRequestMessage(key);
var msg = new GhostWarpToTargetRequestEvent(key);
_netManager.SendSystemNetworkMessage(msg);
};
_buttonContainer.AddChild(currentButtonRef);
@@ -115,7 +143,7 @@ namespace Content.Client.Ghost
private void AddButtonLocations()
{
foreach (var name in _owner.WarpNames)
foreach (var name in Locations)
{
var currentButtonRef = new Button
{
@@ -130,7 +158,8 @@ namespace Content.Client.Ghost
currentButtonRef.OnPressed += (_) =>
{
_owner.SendGhostWarpRequestMessage(name);
var msg = new GhostWarpToLocationRequestEvent(name);
_netManager.SendSystemNetworkMessage(msg);
};
_buttonContainer.AddChild(currentButtonRef);