1
0

StatusIconSystem.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using Content.Shared.CCVar;
  2. using Content.Shared.Ghost;
  3. using Content.Shared.StatusIcon;
  4. using Content.Shared.StatusIcon.Components;
  5. using Content.Shared.Stealth.Components;
  6. using Content.Shared.Whitelist;
  7. using Robust.Client.GameObjects;
  8. using Robust.Client.Graphics;
  9. using Robust.Client.Player;
  10. using Robust.Shared.Configuration;
  11. using Content.Shared.Overlays;
  12. namespace Content.Client.StatusIcon;
  13. /// <summary>
  14. /// This handles rendering gathering and rendering icons on entities.
  15. /// </summary>
  16. public sealed class StatusIconSystem : SharedStatusIconSystem
  17. {
  18. [Dependency] private readonly IConfigurationManager _configuration = default!;
  19. [Dependency] private readonly IOverlayManager _overlay = default!;
  20. [Dependency] private readonly IPlayerManager _playerManager = default!;
  21. [Dependency] private readonly EntityWhitelistSystem _entityWhitelist = default!;
  22. private bool _globalEnabled;
  23. private bool _localEnabled;
  24. /// <inheritdoc/>
  25. public override void Initialize()
  26. {
  27. Subs.CVar(_configuration, CCVars.LocalStatusIconsEnabled, OnLocalStatusIconChanged, true);
  28. Subs.CVar(_configuration, CCVars.GlobalStatusIconsEnabled, OnGlobalStatusIconChanged, true);
  29. }
  30. private void OnLocalStatusIconChanged(bool obj)
  31. {
  32. _localEnabled = obj;
  33. UpdateOverlayVisible();
  34. }
  35. private void OnGlobalStatusIconChanged(bool obj)
  36. {
  37. _globalEnabled = obj;
  38. UpdateOverlayVisible();
  39. }
  40. private void UpdateOverlayVisible()
  41. {
  42. if (_overlay.RemoveOverlay<StatusIconOverlay>())
  43. return;
  44. if (_globalEnabled && _localEnabled)
  45. _overlay.AddOverlay(new StatusIconOverlay());
  46. }
  47. public List<StatusIconData> GetStatusIcons(EntityUid uid, MetaDataComponent? meta = null)
  48. {
  49. var list = new List<StatusIconData>();
  50. if (!Resolve(uid, ref meta))
  51. return list;
  52. if (meta.EntityLifeStage >= EntityLifeStage.Terminating)
  53. return list;
  54. var ev = new GetStatusIconsEvent(list);
  55. RaiseLocalEvent(uid, ref ev);
  56. return ev.StatusIcons;
  57. }
  58. /// <summary>
  59. /// For overlay to check if an entity can be seen.
  60. /// </summary>
  61. public bool IsVisible(Entity<MetaDataComponent> ent, StatusIconData data)
  62. {
  63. var viewer = _playerManager.LocalSession?.AttachedEntity;
  64. // Always show our icons to our entity
  65. if (viewer == ent.Owner)
  66. return true;
  67. if (data.VisibleToGhosts && HasComp<GhostComponent>(viewer))
  68. return true;
  69. if (data.HideInContainer && (ent.Comp.Flags & MetaDataFlags.InContainer) != 0)
  70. return false;
  71. if (data.HideOnStealth && TryComp<StealthComponent>(ent, out var stealth) && stealth.Enabled)
  72. return false;
  73. if (TryComp<ShowFactionIconsComponent>(ent, out var requested))
  74. {
  75. if (TryComp<ShowFactionIconsComponent>(viewer, out var requester))
  76. {
  77. //only show if on the same faction
  78. if (requester.FactionIcon != requested.FactionIcon)
  79. {
  80. return false;
  81. }
  82. }
  83. }
  84. if (TryComp<SpriteComponent>(ent, out var sprite) && !sprite.Visible)
  85. return false;
  86. //if (data.ShowTo != null && !_entityWhitelist.IsValid(data.ShowTo, viewer))
  87. // return false;
  88. return true;
  89. }
  90. }