// SPDX-FileCopyrightText: 2024 Piras314 // SPDX-FileCopyrightText: 2024 gluesniffler <159397573+gluesniffler@users.noreply.github.com> // SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com> // // SPDX-License-Identifier: AGPL-3.0-or-later using Content.Client.Gameplay; using Content.Client._Shitmed.UserInterface.Systems.PartStatus.Widgets; using Content.Shared._Shitmed.Targeting; using Content.Client._Shitmed.Targeting; using Robust.Client.GameObjects; using Robust.Client.UserInterface.Controllers; using Robust.Shared.Utility; using Robust.Client.Graphics; namespace Content.Client._Shitmed.UserInterface.Systems.PartStatus; public sealed class PartStatusUIController : UIController, IOnStateEntered, IOnSystemChanged { [Dependency] private readonly IEntityManager _entManager = default!; [Dependency] private readonly IEntityNetworkManager _net = default!; private SpriteSystem _spriteSystem = default!; private TargetingComponent? _targetingComponent; private PartStatusControl? PartStatusControl => UIManager.GetActiveUIWidgetOrNull(); public void OnSystemLoaded(TargetingSystem system) { system.PartStatusStartup += AddPartStatusControl; system.PartStatusShutdown += RemovePartStatusControl; system.PartStatusUpdate += UpdatePartStatusControl; } public void OnSystemUnloaded(TargetingSystem system) { system.PartStatusStartup -= AddPartStatusControl; system.PartStatusShutdown -= RemovePartStatusControl; system.PartStatusUpdate -= UpdatePartStatusControl; } public void OnStateEntered(GameplayState state) { if (PartStatusControl != null) { PartStatusControl.SetVisible(_targetingComponent != null); if (_targetingComponent != null) PartStatusControl.SetTextures(_targetingComponent.BodyStatus); } } public void AddPartStatusControl(TargetingComponent component) { _targetingComponent = component; if (PartStatusControl != null) { PartStatusControl.SetVisible(_targetingComponent != null); if (_targetingComponent != null) PartStatusControl.SetTextures(_targetingComponent.BodyStatus); } } public void RemovePartStatusControl() { if (PartStatusControl != null) PartStatusControl.SetVisible(false); _targetingComponent = null; } public void UpdatePartStatusControl(TargetingComponent component) { if (PartStatusControl != null && _targetingComponent != null) PartStatusControl.SetTextures(_targetingComponent.BodyStatus); } public Texture GetTexture(SpriteSpecifier specifier) { if (_spriteSystem == null) _spriteSystem = _entManager.System(); return _spriteSystem.Frame0(specifier); } }