ShowFactionIconsSystem.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Content.Shared.Overlays;
  2. using Content.Shared.StatusIcon;
  3. using Content.Shared.StatusIcon.Components;
  4. using Robust.Shared.Prototypes;
  5. namespace Content.Client.Overlays;
  6. public sealed class ShowFactionIconsSystem : EquipmentHudSystem<ShowFactionIconsComponent>
  7. {
  8. [Dependency] private readonly IPrototypeManager _prototype = default!;
  9. public override void Initialize()
  10. {
  11. base.Initialize();
  12. SubscribeLocalEvent<ShowFactionIconsComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent);
  13. }
  14. /// <summary>
  15. /// Adds faction and job icons to the status icon list for an entity if their prototypes are found.
  16. /// </summary>
  17. /// <param name="uid">The entity requesting status icons.</param>
  18. /// <param name="component">The component specifying faction and job icon identifiers.</param>
  19. /// <param name="ev">The event containing the status icon list to update.</param>
  20. private void OnGetStatusIconsEvent(EntityUid uid, ShowFactionIconsComponent component, ref GetStatusIconsEvent ev)
  21. {
  22. if (!IsActive)
  23. return;
  24. // Display regular faction icon
  25. if (_prototype.TryIndex<FactionIconPrototype>(component.FactionIcon, out var iconPrototype))
  26. ev.StatusIcons.Add(iconPrototype);
  27. // Display squad-specific icon if assigned by the server
  28. if (component.AssignSquad && component.SquadIcon != null)
  29. {
  30. if (_prototype.TryIndex<JobIconPrototype>(component.SquadIcon, out var squadIconPrototype))
  31. ev.StatusIcons.Add(squadIconPrototype);
  32. }
  33. // Otherwise, display the general job icon if no squad icon is present or if not part of a squad
  34. if (component.JobIcon != null && component.JobIcon != "JobIconSoldier" && component.JobIcon != "JobIconRifleman" && component.JobIcon != "JobIconMG")
  35. {
  36. if (_prototype.TryIndex<JobIconPrototype>(component.JobIcon, out var jobIconPrototype))
  37. ev.StatusIcons.Add(jobIconPrototype);
  38. }
  39. }
  40. }