Button to return to body
This commit is contained in:
@@ -5,6 +5,8 @@ using Robust.Shared.GameObjects;
|
|||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Network;
|
using Robust.Shared.Interfaces.Network;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Log;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
namespace Content.Client.Observer
|
namespace Content.Client.Observer
|
||||||
{
|
{
|
||||||
@@ -12,6 +14,14 @@ namespace Content.Client.Observer
|
|||||||
public class GhostComponent : SharedGhostComponent
|
public class GhostComponent : SharedGhostComponent
|
||||||
{
|
{
|
||||||
private GhostGui _gui;
|
private GhostGui _gui;
|
||||||
|
private bool _canReturnToBody = true;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
|
public override bool CanReturnToBody
|
||||||
|
{
|
||||||
|
get => _canReturnToBody;
|
||||||
|
set {}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
[Dependency] private readonly IGameHud _gameHud;
|
[Dependency] private readonly IGameHud _gameHud;
|
||||||
@@ -34,7 +44,7 @@ namespace Content.Client.Observer
|
|||||||
case PlayerAttachedMsg _:
|
case PlayerAttachedMsg _:
|
||||||
if (_gui == null)
|
if (_gui == null)
|
||||||
{
|
{
|
||||||
_gui = new GhostGui();
|
_gui = new GhostGui(this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -49,5 +59,18 @@ namespace Content.Client.Observer
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendReturnToBodyMessage() => SendNetworkMessage(new ReturnToBodyComponentMessage());
|
||||||
|
|
||||||
|
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
||||||
|
{
|
||||||
|
base.HandleComponentState(curState, nextState);
|
||||||
|
|
||||||
|
if (!(curState is GhostComponentState state)) return;
|
||||||
|
|
||||||
|
_canReturnToBody = state.CanReturnToBody;
|
||||||
|
if (_gui == null) return;
|
||||||
|
_gui.ReturnToBody.Disabled = !_canReturnToBody;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Content.Client.Observer;
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -6,13 +7,20 @@ namespace Content.Client.UserInterface
|
|||||||
{
|
{
|
||||||
public class GhostGui : Control
|
public class GhostGui : Control
|
||||||
{
|
{
|
||||||
public GhostGui()
|
public Button ReturnToBody = new Button(){Text = "Return to body"};
|
||||||
|
private GhostComponent _owner;
|
||||||
|
|
||||||
|
public GhostGui(GhostComponent owner)
|
||||||
{
|
{
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
|
|
||||||
|
_owner = owner;
|
||||||
|
|
||||||
MouseFilter = MouseFilterMode.Ignore;
|
MouseFilter = MouseFilterMode.Ignore;
|
||||||
|
|
||||||
AddChild(new Label(){Text = "YES THIS IS GHOST WHOOOOOO"});
|
ReturnToBody.OnPressed += (args) => { owner.SendReturnToBodyMessage(); };
|
||||||
|
|
||||||
|
AddChild(ReturnToBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
56
Content.Server/Observer/GhostComponent.cs
Normal file
56
Content.Server/Observer/GhostComponent.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using Content.Server.Players;
|
||||||
|
using Content.Shared.Observer;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Network;
|
||||||
|
using Robust.Shared.Log;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
using Timer = Robust.Shared.Timers.Timer;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Content.Server.Observer
|
||||||
|
{
|
||||||
|
[RegisterComponent]
|
||||||
|
public class GhostComponent : SharedGhostComponent
|
||||||
|
{
|
||||||
|
private bool _canReturnToBody = true;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public override bool CanReturnToBody
|
||||||
|
{
|
||||||
|
get => _canReturnToBody;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_canReturnToBody = value;
|
||||||
|
Dirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ComponentState GetComponentState() => new GhostComponentState(CanReturnToBody);
|
||||||
|
|
||||||
|
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null,
|
||||||
|
IComponent component = null)
|
||||||
|
{
|
||||||
|
base.HandleMessage(message, netChannel, component);
|
||||||
|
|
||||||
|
switch (message)
|
||||||
|
{
|
||||||
|
case ReturnToBodyComponentMessage reenter:
|
||||||
|
if (!Owner.TryGetComponent(out IActorComponent actor) || !CanReturnToBody) break;
|
||||||
|
if (netChannel == null || netChannel == actor.playerSession.ConnectedClient)
|
||||||
|
{
|
||||||
|
actor.playerSession.ContentData().Mind.UnVisit();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PlayerDetachedMsg _:
|
||||||
|
Timer.Spawn(100, Owner.Delete);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,5 +41,6 @@
|
|||||||
public const uint HANDHELD_LIGHT = 1036;
|
public const uint HANDHELD_LIGHT = 1036;
|
||||||
public const uint PAPER = 1037;
|
public const uint PAPER = 1037;
|
||||||
public const uint REAGENT_INJECTOR = 1038;
|
public const uint REAGENT_INJECTOR = 1038;
|
||||||
|
public const uint GHOST = 1039;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Observer
|
namespace Content.Shared.Observer
|
||||||
{
|
{
|
||||||
public class SharedGhostComponent : Component
|
public class SharedGhostComponent : Component
|
||||||
{
|
{
|
||||||
public override string Name => "Ghost";
|
public override string Name => "Ghost";
|
||||||
|
public override uint? NetID => ContentNetIDs.GHOST;
|
||||||
|
|
||||||
|
public virtual bool CanReturnToBody { get; set; } = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public class GhostComponentState : ComponentState
|
||||||
|
{
|
||||||
|
public bool CanReturnToBody { get; }
|
||||||
|
|
||||||
|
public GhostComponentState(bool canReturnToBody) : base(ContentNetIDs.GHOST)
|
||||||
|
{
|
||||||
|
CanReturnToBody = canReturnToBody;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public class ReturnToBodyComponentMessage : ComponentMessage
|
||||||
|
{
|
||||||
|
public ReturnToBodyComponentMessage() => Directed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user