SubFloorHideSystem.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using Content.Client.UserInterface.Systems.Sandbox;
  2. using Content.Shared.SubFloor;
  3. using Robust.Client.GameObjects;
  4. using Robust.Client.UserInterface;
  5. using Robust.Shared.Player;
  6. namespace Content.Client.SubFloor;
  7. public sealed class SubFloorHideSystem : SharedSubFloorHideSystem
  8. {
  9. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  10. [Dependency] private readonly IUserInterfaceManager _ui = default!;
  11. private bool _showAll;
  12. [ViewVariables(VVAccess.ReadWrite)]
  13. public bool ShowAll
  14. {
  15. get => _showAll;
  16. set
  17. {
  18. if (_showAll == value) return;
  19. _showAll = value;
  20. _ui.GetUIController<SandboxUIController>().SetToggleSubfloors(value);
  21. var ev = new ShowSubfloorRequestEvent()
  22. {
  23. Value = value,
  24. };
  25. RaiseNetworkEvent(ev);
  26. }
  27. }
  28. public override void Initialize()
  29. {
  30. base.Initialize();
  31. SubscribeLocalEvent<SubFloorHideComponent, AppearanceChangeEvent>(OnAppearanceChanged);
  32. SubscribeNetworkEvent<ShowSubfloorRequestEvent>(OnRequestReceived);
  33. SubscribeLocalEvent<LocalPlayerDetachedEvent>(OnPlayerDetached);
  34. }
  35. private void OnPlayerDetached(LocalPlayerDetachedEvent ev)
  36. {
  37. // Vismask resets so need to reset this.
  38. ShowAll = false;
  39. }
  40. private void OnRequestReceived(ShowSubfloorRequestEvent ev)
  41. {
  42. // When client receives request Queue an update on all vis.
  43. UpdateAll();
  44. }
  45. private void OnAppearanceChanged(EntityUid uid, SubFloorHideComponent component, ref AppearanceChangeEvent args)
  46. {
  47. if (args.Sprite == null)
  48. return;
  49. _appearance.TryGetData<bool>(uid, SubFloorVisuals.Covered, out var covered, args.Component);
  50. _appearance.TryGetData<bool>(uid, SubFloorVisuals.ScannerRevealed, out var scannerRevealed, args.Component);
  51. scannerRevealed &= !ShowAll; // no transparency for show-subfloor mode.
  52. var revealed = !covered || ShowAll || scannerRevealed;
  53. // set visibility & color of each layer
  54. foreach (var layer in args.Sprite.AllLayers)
  55. {
  56. // pipe connection visuals are updated AFTER this, and may re-hide some layers
  57. layer.Visible = revealed;
  58. }
  59. // Is there some layer that is always visible?
  60. var hasVisibleLayer = false;
  61. foreach (var layerKey in component.VisibleLayers)
  62. {
  63. if (!args.Sprite.LayerMapTryGet(layerKey, out var layerIndex))
  64. continue;
  65. var layer = args.Sprite[layerIndex];
  66. layer.Visible = true;
  67. layer.Color = layer.Color.WithAlpha(1f);
  68. hasVisibleLayer = true;
  69. }
  70. args.Sprite.Visible = hasVisibleLayer || revealed;
  71. if (ShowAll)
  72. {
  73. // Allows sandbox mode to make wires visible over other stuff.
  74. component.OriginalDrawDepth ??= args.Sprite.DrawDepth;
  75. args.Sprite.DrawDepth = (int)Shared.DrawDepth.DrawDepth.Overdoors;
  76. }
  77. else if (scannerRevealed)
  78. {
  79. // Allows a t-ray to show wires/pipes above carpets/puddles.
  80. if (component.OriginalDrawDepth is not null)
  81. return;
  82. component.OriginalDrawDepth = args.Sprite.DrawDepth;
  83. var drawDepthDifference = Shared.DrawDepth.DrawDepth.ThickPipe - Shared.DrawDepth.DrawDepth.Puddles;
  84. args.Sprite.DrawDepth -= drawDepthDifference - 1;
  85. }
  86. else if (component.OriginalDrawDepth.HasValue)
  87. {
  88. args.Sprite.DrawDepth = component.OriginalDrawDepth.Value;
  89. component.OriginalDrawDepth = null;
  90. }
  91. }
  92. private void UpdateAll()
  93. {
  94. var query = AllEntityQuery<SubFloorHideComponent, AppearanceComponent>();
  95. while (query.MoveNext(out var uid, out _, out var appearance))
  96. {
  97. _appearance.QueueUpdate(uid, appearance);
  98. }
  99. }
  100. }