Cargo: pizza & bureaucracy (#5123)
* add paper label component * git mv * rename namespace * add cargo printouts * more crates * directly attach paper * comment typo
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Server.Inventory.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.PDA;
|
||||
using Content.Shared.Access;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Inventory;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Server.Access.Systems
|
||||
{
|
||||
@@ -74,5 +80,53 @@ namespace Content.Server.Access.Systems
|
||||
("fullName", id.FullName),
|
||||
("jobSuffix", jobSuffix));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to find an ID card on an entity. This will look in the entity itself, in the entity's hands, and
|
||||
/// in the entity's inventory.
|
||||
/// </summary>
|
||||
public bool TryFindIdCard(EntityUid uid, [NotNullWhen(true)] out IdCardComponent? idCard)
|
||||
{
|
||||
// check held item?
|
||||
if (EntityManager.TryGetComponent(uid, out SharedHandsComponent? hands) &&
|
||||
hands.TryGetActiveHeldEntity(out var heldItem) &&
|
||||
TryGetIdCard(heldItem.Uid, out idCard))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// check entity itself
|
||||
if (TryGetIdCard(uid, out idCard))
|
||||
return true;
|
||||
|
||||
// check inventory slot?
|
||||
if (EntityManager.TryGetComponent(uid, out InventoryComponent? inventoryComponent) &&
|
||||
inventoryComponent.HasSlot(EquipmentSlotDefines.Slots.IDCARD) &&
|
||||
inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent? item) &&
|
||||
TryGetIdCard(item.Owner.Uid, out idCard))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to get an id card component from an entity, either by getting it directly from the entity, or by
|
||||
/// getting the contained id from a <see cref="PDAComponent"/>.
|
||||
/// </summary>
|
||||
private bool TryGetIdCard(EntityUid uid, [NotNullWhen(true)] out IdCardComponent? idCard)
|
||||
{
|
||||
if (EntityManager.TryGetComponent(uid, out idCard))
|
||||
return true;
|
||||
|
||||
if (EntityManager.TryGetComponent(uid, out PDAComponent? pda) && pda.ContainedID != null)
|
||||
{
|
||||
idCard = pda.ContainedID;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.Cargo.Components;
|
||||
using Content.Shared.Cargo;
|
||||
using Content.Shared.GameTicking;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Cargo
|
||||
{
|
||||
@@ -43,6 +46,9 @@ namespace Content.Server.Cargo
|
||||
|
||||
public CargoOrderDatabase StationOrderDatabase => GetOrderDatabase(0);
|
||||
|
||||
[Dependency] private readonly IdCardSystem _idCardSystem = default!;
|
||||
[Dependency] private readonly AccessReaderSystem _accessReaderSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||
@@ -171,12 +177,25 @@ namespace Content.Server.Cargo
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ApproveOrder(int id, int orderNumber)
|
||||
public bool ApproveOrder(EntityUid uid, EntityUid approver, int id, int orderNumber, AccessReader? reader = null)
|
||||
{
|
||||
// does the approver have permission to approve orders?
|
||||
if (Resolve(uid, ref reader) && !_accessReaderSystem.IsAllowed(reader, approver))
|
||||
return false;
|
||||
|
||||
// get the approver's name
|
||||
_idCardSystem.TryFindIdCard(approver, out var idCard);
|
||||
var approverName = idCard?.FullName ?? string.Empty;
|
||||
|
||||
if (!TryGetOrderDatabase(id, out var database))
|
||||
return false;
|
||||
if (!database.ApproveOrder(orderNumber))
|
||||
|
||||
if (!database.TryGetOrder(orderNumber, out var order))
|
||||
return false;
|
||||
|
||||
if (!database.ApproveOrder(approverName, orderNumber))
|
||||
return false;
|
||||
|
||||
SyncComponentsWithId(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Shared.Cargo;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Cargo
|
||||
@@ -84,7 +86,7 @@ namespace Content.Server.Cargo
|
||||
/// Approves an order in the database.
|
||||
/// </summary>
|
||||
/// <param name="order">The order to be approved.</param>
|
||||
public bool ApproveOrder(int orderNumber)
|
||||
public bool ApproveOrder(string approver, int orderNumber)
|
||||
{
|
||||
if (CurrentOrderSize == MaxOrderSize ||
|
||||
!_orders.TryGetValue(orderNumber, out var order) ||
|
||||
@@ -104,6 +106,8 @@ namespace Content.Server.Cargo
|
||||
}
|
||||
|
||||
order.Approved = true;
|
||||
order.Approver = approver;
|
||||
|
||||
CurrentOrderSize += order.Amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -135,6 +135,10 @@ namespace Content.Server.Cargo.Components
|
||||
break;
|
||||
}
|
||||
|
||||
var uid = msg.Session.AttachedEntityUid;
|
||||
if (uid == null)
|
||||
break;
|
||||
|
||||
PrototypeManager.TryIndex(order.ProductId, out CargoProductPrototype? product);
|
||||
if (product == null!)
|
||||
break;
|
||||
@@ -143,13 +147,14 @@ namespace Content.Server.Cargo.Components
|
||||
(capacity.CurrentCapacity == capacity.MaxCapacity
|
||||
|| capacity.CurrentCapacity + order.Amount > capacity.MaxCapacity
|
||||
|| !_cargoConsoleSystem.CheckBalance(_bankAccount.Id, (-product.PointCost) * order.Amount)
|
||||
|| !_cargoConsoleSystem.ApproveOrder(orders.Database.Id, msg.OrderNumber)
|
||||
|| !_cargoConsoleSystem.ApproveOrder(Owner.Uid, uid.Value, orders.Database.Id, msg.OrderNumber)
|
||||
|| !_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount))
|
||||
)
|
||||
{
|
||||
SoundSystem.Play(Filter.Local(), _errorSound.GetSound(), Owner, AudioParams.Default);
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateUIState();
|
||||
break;
|
||||
}
|
||||
@@ -189,12 +194,7 @@ namespace Content.Server.Cargo.Components
|
||||
orders.Database.ClearOrderCapacity();
|
||||
foreach (var order in approvedOrders)
|
||||
{
|
||||
if (!PrototypeManager.TryIndex(order.ProductId, out CargoProductPrototype? product))
|
||||
continue;
|
||||
for (var i = 0; i < order.Amount; i++)
|
||||
{
|
||||
telepadComponent.QueueTeleport(product);
|
||||
}
|
||||
telepadComponent.QueueTeleport(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Labels.Components;
|
||||
using Content.Server.Paper;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Cargo;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Cargo.Components
|
||||
{
|
||||
@@ -17,14 +24,23 @@ namespace Content.Server.Cargo.Components
|
||||
[RegisterComponent]
|
||||
public class CargoTelepadComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
public override string Name => "CargoTelepad";
|
||||
|
||||
private const float TeleportDuration = 0.5f;
|
||||
private const float TeleportDelay = 15f;
|
||||
private List<CargoProductPrototype> _teleportQueue = new List<CargoProductPrototype>();
|
||||
private List<CargoOrderData> _teleportQueue = new();
|
||||
private CargoTelepadState _currentState = CargoTelepadState.Unpowered;
|
||||
[DataField("teleportSound")] private SoundSpecifier _teleportSound = new SoundPathSpecifier("/Audio/Machines/phasein.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// The paper-type prototype to spawn with the order information.
|
||||
/// </summary>
|
||||
[DataField("printerOutput", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string PrinterOutput = "Paper";
|
||||
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
@@ -39,9 +55,12 @@ namespace Content.Server.Cargo.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void QueueTeleport(CargoProductPrototype product)
|
||||
public void QueueTeleport(CargoOrderData order)
|
||||
{
|
||||
_teleportQueue.Add(product);
|
||||
for (var i = 0; i < order.Amount; i++)
|
||||
{
|
||||
_teleportQueue.Add(order);
|
||||
}
|
||||
TeleportLoop();
|
||||
}
|
||||
|
||||
@@ -79,7 +98,7 @@ namespace Content.Server.Cargo.Components
|
||||
if (!Deleted && !Owner.Deleted && _currentState == CargoTelepadState.Teleporting && _teleportQueue.Count > 0)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _teleportSound.GetSound(), Owner, AudioParams.Default.WithVolume(-8f));
|
||||
Owner.EntityManager.SpawnEntity(_teleportQueue[0].Product, Owner.Transform.Coordinates);
|
||||
SpawnProduct(_teleportQueue[0]);
|
||||
_teleportQueue.RemoveAt(0);
|
||||
if (Owner.TryGetComponent<SpriteComponent>(out var spriteComponent) && spriteComponent.LayerCount > 0)
|
||||
spriteComponent.LayerSetState(0, "idle");
|
||||
@@ -92,6 +111,38 @@ namespace Content.Server.Cargo.Components
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawn the product and a piece of paper. Attempt to attach the paper to the product.
|
||||
/// </summary>
|
||||
private void SpawnProduct(CargoOrderData data)
|
||||
{
|
||||
// spawn the order
|
||||
if (!_prototypeManager.TryIndex(data.ProductId, out CargoProductPrototype? prototype))
|
||||
return;
|
||||
var product = Owner.EntityManager.SpawnEntity(prototype.Product, Owner.Transform.Coordinates);
|
||||
|
||||
// spawn a piece of paper.
|
||||
var printed = Owner.EntityManager.SpawnEntity(PrinterOutput, Owner.Transform.Coordinates);
|
||||
if (!_entityManager.TryGetComponent(printed.Uid, out PaperComponent paper))
|
||||
return;
|
||||
|
||||
// fill in the order data
|
||||
printed.Name = Loc.GetString("cargo-console-paper-print-name", ("orderNumber", data.OrderNumber));
|
||||
paper.SetContent(Loc.GetString(
|
||||
"cargo-console-paper-print-text",
|
||||
("orderNumber", data.OrderNumber),
|
||||
("requester", data.Requester),
|
||||
("reason", data.Reason),
|
||||
("approver", data.Approver)));
|
||||
|
||||
// attempt to attach the label
|
||||
if (_entityManager.TryGetComponent(product.Uid, out PaperLabelComponent label) &&
|
||||
_entityManager.TryGetComponent(product.Uid, out SharedItemSlotsComponent slots))
|
||||
{
|
||||
EntitySystem.Get<SharedItemSlotsSystem>().TryInsertContent(slots, printed, label.LabelSlot);
|
||||
}
|
||||
}
|
||||
|
||||
private enum CargoTelepadState { Unpowered, Idle, Charging, Teleporting };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using Content.Server.HandLabeler.Components;
|
||||
using Content.Shared.Examine;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.HandLabeler
|
||||
{
|
||||
/// <summary>
|
||||
/// A system that lets players see the contents of a label on an object.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public class LabelSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<LabelComponent, ExaminedEvent>(OnExamine);
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, LabelComponent? label, ExaminedEvent args)
|
||||
{
|
||||
if (!Resolve(uid, ref label))
|
||||
return;
|
||||
|
||||
if (label.CurrentLabel == null)
|
||||
return;
|
||||
|
||||
var message = new FormattedMessage();
|
||||
message.AddText(Loc.GetString("hand-labeler-has-label", ("label", label.CurrentLabel)));
|
||||
args.PushMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.HandLabeler.Components
|
||||
namespace Content.Server.Labels.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class HandLabelerComponent : Component
|
||||
@@ -2,7 +2,7 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.HandLabeler.Components
|
||||
namespace Content.Server.Labels.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class LabelComponent : Component
|
||||
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Labels.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// This component allows you to attach and remove a piece of paper to an entity.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class PaperLabelComponent : Component
|
||||
{
|
||||
public override string Name => "PaperLabel";
|
||||
|
||||
[DataField("labelSlot")]
|
||||
public string LabelSlot = "labelSlot";
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.HandLabeler.Components;
|
||||
using Content.Server.Labels.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.HandLabeler;
|
||||
using Content.Shared.Labels;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -12,7 +12,7 @@ using Robust.Shared.Localization;
|
||||
using Content.Shared.Popups;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.HandLabeler
|
||||
namespace Content.Server.Labels
|
||||
{
|
||||
/// <summary>
|
||||
/// A hand labeler system that lets an object apply labels to objects with the <see cref="LabelComponent"/> .
|
||||
97
Content.Server/Labels/Label/LabelSystem.cs
Normal file
97
Content.Server/Labels/Label/LabelSystem.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Content.Server.Labels.Components;
|
||||
using Content.Server.Paper;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Labels;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Utility;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.Labels
|
||||
{
|
||||
/// <summary>
|
||||
/// A system that lets players see the contents of a label on an object.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public class LabelSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedItemSlotsSystem _itemSlotsSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<LabelComponent, ExaminedEvent>(OnExamine);
|
||||
SubscribeLocalEvent<PaperLabelComponent, ComponentInit>(InitializePaperLabel);
|
||||
SubscribeLocalEvent<PaperLabelComponent, ItemSlotChangedEvent>(OnItemSlotChanged);
|
||||
SubscribeLocalEvent<PaperLabelComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
|
||||
private void InitializePaperLabel(EntityUid uid, PaperLabelComponent component, ComponentInit args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out SharedAppearanceComponent appearance))
|
||||
return;
|
||||
|
||||
appearance.SetData(PaperLabelVisuals.HasLabel, false);
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, LabelComponent? label, ExaminedEvent args)
|
||||
{
|
||||
if (!Resolve(uid, ref label))
|
||||
return;
|
||||
|
||||
if (label.CurrentLabel == null)
|
||||
return;
|
||||
|
||||
var message = new FormattedMessage();
|
||||
message.AddText(Loc.GetString("hand-labeler-has-label", ("label", label.CurrentLabel)));
|
||||
args.PushMessage(message);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, PaperLabelComponent comp, ExaminedEvent args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out SharedItemSlotsComponent slots))
|
||||
return;
|
||||
|
||||
var label = _itemSlotsSystem.PeekItemInSlot(slots, comp.LabelSlot);
|
||||
|
||||
if (label == null)
|
||||
return;
|
||||
|
||||
if (!args.IsInDetailsRange)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("comp-paper-label-has-label-cant-read"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EntityManager.TryGetComponent(label.Uid, out PaperComponent paper))
|
||||
// should never happen
|
||||
return;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(paper.Content))
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("comp-paper-label-has-label-blank"));
|
||||
return;
|
||||
}
|
||||
|
||||
args.PushMarkup(Loc.GetString("comp-paper-label-has-label"));
|
||||
var text = paper.Content;
|
||||
args.PushMarkup(text.TrimEnd());
|
||||
}
|
||||
|
||||
|
||||
private void OnItemSlotChanged(EntityUid uid, PaperLabelComponent component, ItemSlotChangedEvent args)
|
||||
{
|
||||
if (args.SlotName != component.LabelSlot)
|
||||
return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(uid, out SharedAppearanceComponent appearance))
|
||||
return;
|
||||
|
||||
appearance.SetData(PaperLabelVisuals.HasLabel, args.ContainedItem != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,81 +22,14 @@ namespace Content.Server.Morgue.Components
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
#pragma warning disable 618
|
||||
public class BodyBagEntityStorageComponent : EntityStorageComponent, IExamine, IInteractUsing
|
||||
#pragma warning restore 618
|
||||
public class BodyBagEntityStorageComponent : EntityStorageComponent
|
||||
{
|
||||
public override string Name => "BodyBagEntityStorage";
|
||||
|
||||
[ViewVariables]
|
||||
[ComponentDependency] private readonly AppearanceComponent? _appearance = null;
|
||||
|
||||
[ViewVariables] public ContainerSlot? LabelContainer { get; private set; }
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_appearance?.SetData(BodyBagVisuals.Label, false);
|
||||
LabelContainer = Owner.EnsureContainer<ContainerSlot>("body_bag_label", out _);
|
||||
}
|
||||
|
||||
protected override bool AddToContents(IEntity entity)
|
||||
{
|
||||
if (entity.HasComponent<SharedBodyComponent>() && !EntitySystem.Get<StandingStateSystem>().IsDown(entity.Uid)) return false;
|
||||
return base.AddToContents(entity);
|
||||
}
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (inDetailsRange)
|
||||
{
|
||||
if (LabelContainer?.ContainedEntity != null && LabelContainer.ContainedEntity.TryGetComponent<PaperComponent>(out var paper))
|
||||
{
|
||||
message.AddText(Loc.GetString("body-bag-entity-storage-component-on-examine-details", ("paper", paper.Content)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (LabelContainer == null) return false;
|
||||
|
||||
if (LabelContainer.ContainedEntity != null)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("body-bag-entity-storage-component-interact-using-already-attached"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var handsComponent = eventArgs.User.GetComponent<HandsComponent>();
|
||||
if (!handsComponent.Drop(eventArgs.Using, LabelContainer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_appearance?.SetData(BodyBagVisuals.Label, true);
|
||||
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("body-bag-entity-storage-component-interact-using-success",("entity", eventArgs.Using)));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RemoveLabel(IEntity user)
|
||||
{
|
||||
if (LabelContainer == null) return;
|
||||
|
||||
var ent = LabelContainer.ContainedEntity;
|
||||
if(ent is null)
|
||||
return;
|
||||
|
||||
if (user.TryGetComponent(out HandsComponent? hands))
|
||||
{
|
||||
hands.PutInHandOrDrop(ent.GetComponent<ItemComponent>());
|
||||
_appearance?.SetData(BodyBagVisuals.Label, false);
|
||||
}
|
||||
else if (LabelContainer.Remove(ent))
|
||||
{
|
||||
ent.Transform.Coordinates = Owner.Transform.Coordinates;
|
||||
_appearance?.SetData(BodyBagVisuals.Label, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace Content.Server.Morgue
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CrematoriumEntityStorageComponent, GetAlternativeVerbsEvent>(AddCremateVerb);
|
||||
SubscribeLocalEvent<BodyBagEntityStorageComponent, GetAlternativeVerbsEvent>(AddRemoveLabelVerb);
|
||||
}
|
||||
|
||||
private void AddCremateVerb(EntityUid uid, CrematoriumEntityStorageComponent component, GetAlternativeVerbsEvent args)
|
||||
@@ -32,22 +31,6 @@ namespace Content.Server.Morgue
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This adds the "remove label" verb to the list of verbs. Yes, this is a stupid function name, but it's
|
||||
/// consistent with other get-verb event handlers.
|
||||
/// </summary>
|
||||
private void AddRemoveLabelVerb(EntityUid uid, BodyBagEntityStorageComponent component, GetAlternativeVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null || !args.CanAccess || !args.CanInteract || component.LabelContainer?.ContainedEntity == null)
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("remove-label-verb-get-data-text");
|
||||
// TODO VERB ICON Add cancel/X icon? or maybe just use the pick-up or eject icon?
|
||||
verb.Act = () => component.RemoveLabel(args.User);
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
_accumulatedFrameTime += frameTime;
|
||||
|
||||
@@ -36,6 +36,22 @@ namespace Content.Server.Paper
|
||||
_mode = PaperAction.Read;
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
public void SetContent(string content)
|
||||
{
|
||||
Content = content + '\n';
|
||||
UpdateUserInterface();
|
||||
|
||||
if (!Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
return;
|
||||
|
||||
var status = string.IsNullOrWhiteSpace(content)
|
||||
? PaperStatus.Blank
|
||||
: PaperStatus.Written;
|
||||
|
||||
appearance.SetData(PaperVisuals.Status, status);
|
||||
}
|
||||
|
||||
private void UpdateUserInterface()
|
||||
{
|
||||
UserInterface?.SetState(new PaperBoundUserInterfaceState(Content, _mode));
|
||||
|
||||
Reference in New Issue
Block a user