mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-21 07:28:31 +03:00
82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
using Content.Client.Gameplay;
|
|
using Content.Client.UserInterface.Systems.PartStatus.Widgets;
|
|
using Content.Shared.Targeting;
|
|
using Content.Client.Targeting;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.UserInterface.Controllers;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Utility;
|
|
using Robust.Client.Graphics;
|
|
|
|
|
|
namespace Content.Client.UserInterface.Systems.PartStatus;
|
|
|
|
public sealed class PartStatusUIController : UIController, IOnStateEntered<GameplayState>, IOnSystemChanged<TargetingSystem>
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
[Dependency] private readonly IEntityNetworkManager _net = default!;
|
|
private SpriteSystem _spriteSystem = default!;
|
|
private TargetingComponent? _targetingComponent;
|
|
private PartStatusControl? PartStatusControl => UIManager.GetActiveUIWidgetOrNull<PartStatusControl>();
|
|
|
|
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<SpriteSystem>();
|
|
|
|
return _spriteSystem.Frame0(specifier);
|
|
}
|
|
} |