| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- // 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.Targeting.Widgets;
- using Content.Shared._Shitmed.Targeting;
- using Content.Client._Shitmed.Targeting;
- using Content.Shared._Shitmed.Targeting.Events;
- using Robust.Client.UserInterface.Controllers;
- using Robust.Client.Player;
- namespace Content.Client._Shitmed.UserInterface.Systems.Targeting;
- public sealed class TargetingUIController : UIController, IOnStateEntered<GameplayState>, IOnSystemChanged<TargetingSystem>
- {
- [Dependency] private readonly IEntityManager _entManager = default!;
- [Dependency] private readonly IEntityNetworkManager _net = default!;
- [Dependency] private readonly IPlayerManager _playerManager = default!;
- private TargetingComponent? _targetingComponent;
- private TargetingControl? TargetingControl => UIManager.GetActiveUIWidgetOrNull<TargetingControl>();
- public void OnSystemLoaded(TargetingSystem system)
- {
- system.TargetingStartup += AddTargetingControl;
- system.TargetingShutdown += RemoveTargetingControl;
- system.TargetChange += CycleTarget;
- }
- public void OnSystemUnloaded(TargetingSystem system)
- {
- system.TargetingStartup -= AddTargetingControl;
- system.TargetingShutdown -= RemoveTargetingControl;
- system.TargetChange -= CycleTarget;
- }
- public void OnStateEntered(GameplayState state)
- {
- if (TargetingControl == null)
- return;
- TargetingControl.SetTargetDollVisible(_targetingComponent != null);
- if (_targetingComponent != null)
- TargetingControl.SetBodyPartsVisible(_targetingComponent.Target);
- }
- public void AddTargetingControl(TargetingComponent component)
- {
- _targetingComponent = component;
- if (TargetingControl != null)
- {
- TargetingControl.SetTargetDollVisible(_targetingComponent != null);
- if (_targetingComponent != null)
- TargetingControl.SetBodyPartsVisible(_targetingComponent.Target);
- }
- }
- public void RemoveTargetingControl()
- {
- if (TargetingControl != null)
- TargetingControl.SetTargetDollVisible(false);
- _targetingComponent = null;
- }
- public void CycleTarget(TargetBodyPart bodyPart)
- {
- if (_playerManager.LocalEntity is not { } user
- || _entManager.GetComponent<TargetingComponent>(user) is not { } targetingComponent
- || TargetingControl == null)
- return;
- var player = _entManager.GetNetEntity(user);
- if (bodyPart != targetingComponent.Target)
- {
- var msg = new TargetChangeEvent(player, bodyPart);
- _net.SendSystemNetworkMessage(msg);
- TargetingControl?.SetBodyPartsVisible(bodyPart);
- }
- }
- }
|