1
0

ShowJobIconsSystem.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Content.Shared.Access.Components;
  2. using Content.Shared.Access.Systems;
  3. using Content.Shared.Overlays;
  4. using Content.Shared.PDA;
  5. using Content.Shared.StatusIcon;
  6. using Content.Shared.StatusIcon.Components;
  7. using Robust.Shared.Prototypes;
  8. namespace Content.Client.Overlays;
  9. public sealed class ShowJobIconsSystem : EquipmentHudSystem<ShowJobIconsComponent>
  10. {
  11. [Dependency] private readonly IPrototypeManager _prototype = default!;
  12. [Dependency] private readonly AccessReaderSystem _accessReader = default!;
  13. [ValidatePrototypeId<JobIconPrototype>]
  14. private const string JobIconForNoId = "JobIconNoId";
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. SubscribeLocalEvent<StatusIconComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent);
  19. }
  20. private void OnGetStatusIconsEvent(EntityUid uid, StatusIconComponent _, ref GetStatusIconsEvent ev)
  21. {
  22. if (!IsActive)
  23. return;
  24. var iconId = JobIconForNoId;
  25. if (_accessReader.FindAccessItemsInventory(uid, out var items))
  26. {
  27. foreach (var item in items)
  28. {
  29. // ID Card
  30. if (TryComp<IdCardComponent>(item, out var id))
  31. {
  32. iconId = id.JobIcon;
  33. break;
  34. }
  35. // PDA
  36. if (TryComp<PdaComponent>(item, out var pda)
  37. && pda.ContainedId != null
  38. && TryComp(pda.ContainedId, out id))
  39. {
  40. iconId = id.JobIcon;
  41. break;
  42. }
  43. }
  44. }
  45. if (_prototype.TryIndex<JobIconPrototype>(iconId, out var iconPrototype))
  46. ev.StatusIcons.Add(iconPrototype);
  47. else
  48. Log.Error($"Invalid job icon prototype: {iconPrototype}");
  49. }
  50. }