82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
using Content.Shared.Access.Components;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.PDA;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.Access.Systems;
|
|
|
|
public sealed class IdExaminableSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly ExamineSystemShared _examineSystem = default!;
|
|
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<IdExaminableComponent, GetVerbsEvent<ExamineVerb>>(OnGetExamineVerbs);
|
|
}
|
|
|
|
private void OnGetExamineVerbs(EntityUid uid, IdExaminableComponent component, GetVerbsEvent<ExamineVerb> args)
|
|
{
|
|
var detailsRange = _examineSystem.IsInDetailsRange(args.User, uid);
|
|
var info = GetMessage(uid);
|
|
|
|
var verb = new ExamineVerb()
|
|
{
|
|
Act = () =>
|
|
{
|
|
var markup = FormattedMessage.FromMarkupOrThrow(info);
|
|
|
|
_examineSystem.SendExamineTooltip(args.User, uid, markup, false, false);
|
|
},
|
|
Text = Loc.GetString("id-examinable-component-verb-text"),
|
|
Category = VerbCategory.Examine,
|
|
Disabled = !detailsRange,
|
|
Message = detailsRange ? null : Loc.GetString("id-examinable-component-verb-disabled"),
|
|
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/character.svg.192dpi.png"))
|
|
};
|
|
|
|
args.Verbs.Add(verb);
|
|
}
|
|
|
|
public string GetMessage(EntityUid uid)
|
|
{
|
|
return GetInfo(uid) ?? Loc.GetString("id-examinable-component-verb-no-id");
|
|
}
|
|
|
|
public string? GetInfo(EntityUid uid)
|
|
{
|
|
if (_inventorySystem.TryGetSlotEntity(uid, "id", out var idUid))
|
|
{
|
|
// PDA
|
|
if (EntityManager.TryGetComponent(idUid, out PdaComponent? pda) &&
|
|
TryComp<IdCardComponent>(pda.ContainedId, out var id))
|
|
{
|
|
return GetNameAndJob(id);
|
|
}
|
|
// ID Card
|
|
if (EntityManager.TryGetComponent(idUid, out id))
|
|
{
|
|
return GetNameAndJob(id);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private string GetNameAndJob(IdCardComponent id)
|
|
{
|
|
var jobSuffix = string.IsNullOrWhiteSpace(id.LocalizedJobTitle) ? string.Empty : $" ({id.LocalizedJobTitle})";
|
|
|
|
var val = string.IsNullOrWhiteSpace(id.FullName)
|
|
? Loc.GetString(id.NameLocId,
|
|
("jobSuffix", jobSuffix))
|
|
: Loc.GetString(id.FullNameLocId,
|
|
("fullName", id.FullName),
|
|
("jobSuffix", jobSuffix));
|
|
|
|
return val;
|
|
}
|
|
}
|