Files
tbd-station-14/Content.Server/GameObjects/Components/Paper/PaperComponent.cs
Remie Richards cc6acae145 Mortician's Menagerie (#2391)
* Body bags!

* Morgue Trays and the Crematorium!
Reorganised body bags to be under Morgue, not Medical

* Fix. Things outside of EntityStorageComponents now use the Try*Storage() not just *Storage() methods - Allows mobs to be trapped in a morgue/crematorium whose tray can't open.

* Fix tests. Modernise component dependency and nullability.

* Update Content.Server/GameObjects/Components/Morgue/MorgueTrayComponent.cs

Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
2020-10-28 23:51:43 +01:00

91 lines
2.7 KiB
C#

#nullable enable
using System.Threading.Tasks;
using Content.Server.Utility;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Paper
{
[RegisterComponent]
public class PaperComponent : SharedPaperComponent, IExamine, IInteractUsing, IUse
{
private PaperAction _mode;
public string Content { get; private set; } = "";
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(PaperUiKey.Key);
public override void Initialize()
{
base.Initialize();
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
}
_mode = PaperAction.Read;
UpdateUserInterface();
}
private void UpdateUserInterface()
{
UserInterface?.SetState(new PaperBoundUserInterfaceState(Content, _mode));
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
if (!inDetailsRange)
return;
message.AddMarkup(Content);
}
public bool UseEntity(UseEntityEventArgs eventArgs)
{
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor))
return false;
_mode = PaperAction.Read;
UpdateUserInterface();
UserInterface?.Toggle(actor.playerSession);
return true;
}
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
{
var msg = (PaperInputText) obj.Message;
if (string.IsNullOrEmpty(msg.Text))
return;
Content += msg.Text + '\n';
if (Owner.TryGetComponent(out SpriteComponent? sprite))
{
sprite.LayerSetState(1, "paper_words");
}
Owner.Description = "";
UpdateUserInterface();
}
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!eventArgs.Using.HasComponent<WriteComponent>())
return false;
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor))
return false;
_mode = PaperAction.Write;
UpdateUserInterface();
UserInterface?.Open(actor.playerSession);
return true;
}
}
}