Files
tbd-station-14/Content.Shared/Labels/EntitySystems/SharedLabelSystem.cs
Tayrtahn ac1bdd2c84 Fix unlabeled jugs in ChemVend (#29178)
* Spawn dummy entities on client for vending machine UI

* Asked sloth, and we kinda need this pr

---------

Co-authored-by: Vasilis <vasilis@pikachu.systems>
2024-06-23 19:31:34 +02:00

52 lines
1.8 KiB
C#

using Content.Shared.Examine;
using Content.Shared.Labels.Components;
using Content.Shared.NameModifier.EntitySystems;
using Robust.Shared.Utility;
namespace Content.Shared.Labels.EntitySystems;
public abstract partial class SharedLabelSystem : EntitySystem
{
[Dependency] protected readonly NameModifierSystem NameMod = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<LabelComponent, MapInitEvent>(OnLabelCompMapInit);
SubscribeLocalEvent<LabelComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<LabelComponent, RefreshNameModifiersEvent>(OnRefreshNameModifiers);
}
private void OnLabelCompMapInit(EntityUid uid, LabelComponent component, MapInitEvent args)
{
if (!string.IsNullOrEmpty(component.CurrentLabel))
{
component.CurrentLabel = Loc.GetString(component.CurrentLabel);
Dirty(uid, component);
}
NameMod.RefreshNameModifiers(uid);
}
public virtual void Label(EntityUid uid, string? text, MetaDataComponent? metadata = null, LabelComponent? label = null){}
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 OnRefreshNameModifiers(Entity<LabelComponent> entity, ref RefreshNameModifiersEvent args)
{
if (!string.IsNullOrEmpty(entity.Comp.CurrentLabel))
args.AddModifier("comp-label-format", extraArgs: ("label", entity.Comp.CurrentLabel));
}
}