PartStatusUIController.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-FileCopyrightText: 2024 Piras314 <p1r4s@proton.me>
  2. // SPDX-FileCopyrightText: 2024 gluesniffler <159397573+gluesniffler@users.noreply.github.com>
  3. // SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
  4. //
  5. // SPDX-License-Identifier: AGPL-3.0-or-later
  6. using Content.Client.Gameplay;
  7. using Content.Client._Shitmed.UserInterface.Systems.PartStatus.Widgets;
  8. using Content.Shared._Shitmed.Targeting;
  9. using Content.Client._Shitmed.Targeting;
  10. using Robust.Client.GameObjects;
  11. using Robust.Client.UserInterface.Controllers;
  12. using Robust.Shared.Utility;
  13. using Robust.Client.Graphics;
  14. namespace Content.Client._Shitmed.UserInterface.Systems.PartStatus;
  15. public sealed class PartStatusUIController : UIController, IOnStateEntered<GameplayState>, IOnSystemChanged<TargetingSystem>
  16. {
  17. [Dependency] private readonly IEntityManager _entManager = default!;
  18. [Dependency] private readonly IEntityNetworkManager _net = default!;
  19. private SpriteSystem _spriteSystem = default!;
  20. private TargetingComponent? _targetingComponent;
  21. private PartStatusControl? PartStatusControl => UIManager.GetActiveUIWidgetOrNull<PartStatusControl>();
  22. public void OnSystemLoaded(TargetingSystem system)
  23. {
  24. system.PartStatusStartup += AddPartStatusControl;
  25. system.PartStatusShutdown += RemovePartStatusControl;
  26. system.PartStatusUpdate += UpdatePartStatusControl;
  27. }
  28. public void OnSystemUnloaded(TargetingSystem system)
  29. {
  30. system.PartStatusStartup -= AddPartStatusControl;
  31. system.PartStatusShutdown -= RemovePartStatusControl;
  32. system.PartStatusUpdate -= UpdatePartStatusControl;
  33. }
  34. public void OnStateEntered(GameplayState state)
  35. {
  36. if (PartStatusControl != null)
  37. {
  38. PartStatusControl.SetVisible(_targetingComponent != null);
  39. if (_targetingComponent != null)
  40. PartStatusControl.SetTextures(_targetingComponent.BodyStatus);
  41. }
  42. }
  43. public void AddPartStatusControl(TargetingComponent component)
  44. {
  45. _targetingComponent = component;
  46. if (PartStatusControl != null)
  47. {
  48. PartStatusControl.SetVisible(_targetingComponent != null);
  49. if (_targetingComponent != null)
  50. PartStatusControl.SetTextures(_targetingComponent.BodyStatus);
  51. }
  52. }
  53. public void RemovePartStatusControl()
  54. {
  55. if (PartStatusControl != null)
  56. PartStatusControl.SetVisible(false);
  57. _targetingComponent = null;
  58. }
  59. public void UpdatePartStatusControl(TargetingComponent component)
  60. {
  61. if (PartStatusControl != null && _targetingComponent != null)
  62. PartStatusControl.SetTextures(_targetingComponent.BodyStatus);
  63. }
  64. public Texture GetTexture(SpriteSpecifier specifier)
  65. {
  66. if (_spriteSystem == null)
  67. _spriteSystem = _entManager.System<SpriteSystem>();
  68. return _spriteSystem.Frame0(specifier);
  69. }
  70. }