1
0

StatusIconSystem.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. namespace Content.Client.StatusIcon;
  12. /// <summary>
  13. /// This handles rendering gathering and rendering icons on entities.
  14. /// </summary>
  15. public sealed class StatusIconSystem : SharedStatusIconSystem
  16. {
  17. [Dependency] private readonly IConfigurationManager _configuration = default!;
  18. [Dependency] private readonly IOverlayManager _overlay = default!;
  19. [Dependency] private readonly IPlayerManager _playerManager = default!;
  20. [Dependency] private readonly EntityWhitelistSystem _entityWhitelist = default!;
  21. private bool _globalEnabled;
  22. private bool _localEnabled;
  23. /// <inheritdoc/>
  24. public override void Initialize()
  25. {
  26. Subs.CVar(_configuration, CCVars.LocalStatusIconsEnabled, OnLocalStatusIconChanged, true);
  27. Subs.CVar(_configuration, CCVars.GlobalStatusIconsEnabled, OnGlobalStatusIconChanged, true);
  28. }
  29. private void OnLocalStatusIconChanged(bool obj)
  30. {
  31. _localEnabled = obj;
  32. UpdateOverlayVisible();
  33. }
  34. private void OnGlobalStatusIconChanged(bool obj)
  35. {
  36. _globalEnabled = obj;
  37. UpdateOverlayVisible();
  38. }
  39. private void UpdateOverlayVisible()
  40. {
  41. if (_overlay.RemoveOverlay<StatusIconOverlay>())
  42. return;
  43. if (_globalEnabled && _localEnabled)
  44. _overlay.AddOverlay(new StatusIconOverlay());
  45. }
  46. public List<StatusIconData> GetStatusIcons(EntityUid uid, MetaDataComponent? meta = null)
  47. {
  48. var list = new List<StatusIconData>();
  49. if (!Resolve(uid, ref meta))
  50. return list;
  51. if (meta.EntityLifeStage >= EntityLifeStage.Terminating)
  52. return list;
  53. var ev = new GetStatusIconsEvent(list);
  54. RaiseLocalEvent(uid, ref ev);
  55. return ev.StatusIcons;
  56. }
  57. /// <summary>
  58. /// For overlay to check if an entity can be seen.
  59. /// </summary>
  60. public bool IsVisible(Entity<MetaDataComponent> ent, StatusIconData data)
  61. {
  62. var viewer = _playerManager.LocalSession?.AttachedEntity;
  63. // Always show our icons to our entity
  64. if (viewer == ent.Owner)
  65. return true;
  66. if (data.VisibleToGhosts && HasComp<GhostComponent>(viewer))
  67. return true;
  68. if (data.HideInContainer && (ent.Comp.Flags & MetaDataFlags.InContainer) != 0)
  69. return false;
  70. if (data.HideOnStealth && TryComp<StealthComponent>(ent, out var stealth) && stealth.Enabled)
  71. return false;
  72. if (TryComp<SpriteComponent>(ent, out var sprite) && !sprite.Visible)
  73. return false;
  74. //if (data.ShowTo != null && !_entityWhitelist.IsValid(data.ShowTo, viewer))
  75. // return false;
  76. return true;
  77. }
  78. }