2021-11-11 02:15:23 +13:00
|
|
|
using Content.Server.Labels.Components;
|
|
|
|
|
using Content.Shared.Containers.ItemSlots;
|
|
|
|
|
using Content.Shared.Examine;
|
|
|
|
|
using Content.Shared.Labels;
|
2024-03-05 20:33:28 -05:00
|
|
|
using Content.Shared.Labels.Components;
|
|
|
|
|
using Content.Shared.Labels.EntitySystems;
|
2024-08-04 21:23:23 -07:00
|
|
|
using Content.Shared.Paper;
|
2021-11-11 02:15:23 +13:00
|
|
|
using JetBrains.Annotations;
|
2021-11-20 18:26:01 +13:00
|
|
|
using Robust.Shared.Containers;
|
2021-11-11 02:15:23 +13:00
|
|
|
|
|
|
|
|
namespace Content.Server.Labels
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A system that lets players see the contents of a label on an object.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[UsedImplicitly]
|
2024-03-05 20:33:28 -05:00
|
|
|
public sealed class LabelSystem : SharedLabelSystem
|
2021-11-11 02:15:23 +13:00
|
|
|
{
|
2021-11-20 18:26:01 +13:00
|
|
|
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2021-11-11 02:15:23 +13:00
|
|
|
|
2022-06-12 13:29:03 +10:00
|
|
|
public const string ContainerName = "paper_label";
|
|
|
|
|
|
2021-11-11 02:15:23 +13:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2021-11-20 18:26:01 +13:00
|
|
|
SubscribeLocalEvent<PaperLabelComponent, ComponentInit>(OnComponentInit);
|
|
|
|
|
SubscribeLocalEvent<PaperLabelComponent, ComponentRemove>(OnComponentRemove);
|
|
|
|
|
SubscribeLocalEvent<PaperLabelComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
|
|
|
|
|
SubscribeLocalEvent<PaperLabelComponent, EntRemovedFromContainerMessage>(OnContainerModified);
|
2021-11-11 02:15:23 +13:00
|
|
|
SubscribeLocalEvent<PaperLabelComponent, ExaminedEvent>(OnExamined);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-14 23:27:22 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Apply or remove a label on an entity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">EntityUid to change label on</param>
|
|
|
|
|
/// <param name="text">intended label text (null to remove)</param>
|
|
|
|
|
/// <param name="label">label component for resolve</param>
|
|
|
|
|
/// <param name="metadata">metadata component for resolve</param>
|
2024-04-28 07:19:30 +03:00
|
|
|
public override void Label(EntityUid uid, string? text, MetaDataComponent? metadata = null, LabelComponent? label = null)
|
2022-09-14 23:27:22 -07:00
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref label, false))
|
|
|
|
|
label = EnsureComp<LabelComponent>(uid);
|
|
|
|
|
|
|
|
|
|
label.CurrentLabel = text;
|
2024-06-23 13:31:34 -04:00
|
|
|
NameMod.RefreshNameModifiers(uid);
|
2024-03-05 20:33:28 -05:00
|
|
|
|
2025-01-08 23:22:58 +03:00
|
|
|
|
|
|
|
|
//CP14 Events
|
|
|
|
|
var ev = new CP14LabeledEvent()
|
|
|
|
|
{
|
|
|
|
|
LabeledEntity = uid,
|
|
|
|
|
Text = text,
|
|
|
|
|
};
|
|
|
|
|
RaiseLocalEvent(uid, ev);
|
|
|
|
|
//CP14 Events end
|
|
|
|
|
|
2024-03-05 20:33:28 -05:00
|
|
|
Dirty(uid, label);
|
2022-09-14 23:27:22 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-20 18:26:01 +13:00
|
|
|
private void OnComponentInit(EntityUid uid, PaperLabelComponent component, ComponentInit args)
|
2021-11-11 02:15:23 +13:00
|
|
|
{
|
2022-06-12 13:29:03 +10:00
|
|
|
_itemSlotsSystem.AddItemSlot(uid, ContainerName, component.LabelSlot);
|
2021-11-20 18:26:01 +13:00
|
|
|
|
2024-04-13 22:39:02 -05:00
|
|
|
UpdateAppearance((uid, component));
|
2021-11-11 02:15:23 +13:00
|
|
|
}
|
|
|
|
|
|
2021-11-20 18:26:01 +13:00
|
|
|
private void OnComponentRemove(EntityUid uid, PaperLabelComponent component, ComponentRemove args)
|
|
|
|
|
{
|
|
|
|
|
_itemSlotsSystem.RemoveItemSlot(uid, component.LabelSlot);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-11 02:15:23 +13:00
|
|
|
private void OnExamined(EntityUid uid, PaperLabelComponent comp, ExaminedEvent args)
|
|
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
if (comp.LabelSlot.Item is not {Valid: true} item)
|
2021-11-11 02:15:23 +13:00
|
|
|
return;
|
|
|
|
|
|
2024-01-05 23:53:13 -07:00
|
|
|
using (args.PushGroup(nameof(PaperLabelComponent)))
|
2021-11-11 02:15:23 +13:00
|
|
|
{
|
2024-01-05 23:53:13 -07:00
|
|
|
if (!args.IsInDetailsRange)
|
|
|
|
|
{
|
|
|
|
|
args.PushMarkup(Loc.GetString("comp-paper-label-has-label-cant-read"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-11 02:15:23 +13:00
|
|
|
|
2024-01-05 23:53:13 -07:00
|
|
|
if (!EntityManager.TryGetComponent(item, out PaperComponent? paper))
|
|
|
|
|
// Assuming yaml has the correct entity whitelist, this should not happen.
|
|
|
|
|
return;
|
2021-11-11 02:15:23 +13:00
|
|
|
|
2024-01-05 23:53:13 -07:00
|
|
|
if (string.IsNullOrWhiteSpace(paper.Content))
|
|
|
|
|
{
|
|
|
|
|
args.PushMarkup(Loc.GetString("comp-paper-label-has-label-blank"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-11 02:15:23 +13:00
|
|
|
|
2024-01-05 23:53:13 -07:00
|
|
|
args.PushMarkup(Loc.GetString("comp-paper-label-has-label"));
|
|
|
|
|
var text = paper.Content;
|
|
|
|
|
args.PushMarkup(text.TrimEnd());
|
|
|
|
|
}
|
2021-11-11 02:15:23 +13:00
|
|
|
}
|
|
|
|
|
|
2021-11-20 18:26:01 +13:00
|
|
|
private void OnContainerModified(EntityUid uid, PaperLabelComponent label, ContainerModifiedMessage args)
|
2021-11-11 02:15:23 +13:00
|
|
|
{
|
2021-12-16 23:42:02 +13:00
|
|
|
if (!label.Initialized) return;
|
|
|
|
|
|
2021-11-20 18:26:01 +13:00
|
|
|
if (args.Container.ID != label.LabelSlot.ID)
|
2021-11-11 02:15:23 +13:00
|
|
|
return;
|
|
|
|
|
|
2024-04-13 22:39:02 -05:00
|
|
|
UpdateAppearance((uid, label));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateAppearance(Entity<PaperLabelComponent, AppearanceComponent?> ent)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(ent, ref ent.Comp2, false))
|
2021-11-11 02:15:23 +13:00
|
|
|
return;
|
|
|
|
|
|
2024-04-13 22:39:02 -05:00
|
|
|
var slot = ent.Comp1.LabelSlot;
|
|
|
|
|
_appearance.SetData(ent, PaperLabelVisuals.HasLabel, slot.HasItem, ent.Comp2);
|
|
|
|
|
if (TryComp<PaperLabelTypeComponent>(slot.Item, out var type))
|
|
|
|
|
_appearance.SetData(ent, PaperLabelVisuals.LabelType, type.PaperType, ent.Comp2);
|
2021-11-11 02:15:23 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|