Ghost sprites and a bunch of fixes
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.Observer;
|
||||
using Content.Shared.GameObjects.Components.Observer;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Observer
|
||||
namespace Content.Client.GameObjects.Components.Observer
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class GhostComponent : SharedGhostComponent
|
||||
@@ -25,6 +25,8 @@ namespace Content.Client.Observer
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IGameHud _gameHud;
|
||||
[Dependency] private readonly IPlayerManager _playerManager;
|
||||
[Dependency] private IComponentManager _componentManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
public override void OnRemove()
|
||||
@@ -34,6 +36,25 @@ namespace Content.Client.Observer
|
||||
_gui?.Dispose();
|
||||
}
|
||||
|
||||
|
||||
private void SetGhostVisibility(bool visibility)
|
||||
{
|
||||
// So, for now this is a client-side hack... Please, PLEASE someone make this work server-side.
|
||||
foreach (var ghost in _componentManager.GetAllComponents(typeof(GhostComponent)))
|
||||
{
|
||||
if (ghost.Owner.TryGetComponent(out SpriteComponent component))
|
||||
component.Visible = visibility;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (Owner.TryGetComponent(out SpriteComponent component))
|
||||
component.Visible = _playerManager.LocalPlayer.ControlledEntity?.HasComponent<GhostComponent>() ?? false;
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null,
|
||||
IComponent component = null)
|
||||
{
|
||||
@@ -52,10 +73,13 @@ namespace Content.Client.Observer
|
||||
}
|
||||
|
||||
_gameHud.HandsContainer.AddChild(_gui);
|
||||
SetGhostVisibility(true);
|
||||
|
||||
break;
|
||||
|
||||
case PlayerDetachedMsg _:
|
||||
_gui.Parent?.RemoveChild(_gui);
|
||||
SetGhostVisibility(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +93,12 @@ namespace Content.Client.Observer
|
||||
if (!(curState is GhostComponentState state)) return;
|
||||
|
||||
_canReturnToBody = state.CanReturnToBody;
|
||||
_gui?.Update();
|
||||
|
||||
if (Owner == _playerManager.LocalPlayer.ControlledEntity)
|
||||
{
|
||||
_gui?.Update();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Data;
|
||||
using Content.Client.Observer;
|
||||
using Content.Client.GameObjects.Components.Observer;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
Reference in New Issue
Block a user