CatStation/Content.Shared/Damage/Systems/DamagePopupSystem.cs
Whatstone a88d2c5164
Cleanup: Resolve remaining PopupSystem warnings in Content.Shared (#44685)
* PopupClient to PopupEntity/Coordinates

* PopupPredictedX to PopupEntity/Cursor/Coordinates

* The rest of the damn owl

* nullability fixes

* Buckle cleanup

* cleanup, address PR comments

* ExecutionSystem: one popup method

* correct my filthy lies

* Apply most of ajcm's suggestions

* return user to SharedItemRecallSystem.cs

* Fix lingering Ensnarable broadcast popups

* targeted drain popups

* fix lingering untargeted Guardian popups

I read the comment on GuardianHostRecall.  Oops.

* target stethoscope popups

* fix the PDA vibration popup

* Fix target for encryption key removal popup

* anomaly scanner: args.User, not uid

* disposal unit comment, bcast pda vibration popup
2026-07-16 21:54:33 +00:00

49 lines
1.7 KiB
C#

using Content.Shared.Damage.Components;
using Content.Shared.Interaction;
using Content.Shared.Popups;
namespace Content.Shared.Damage.Systems;
public sealed partial class DamagePopupSystem : EntitySystem
{
[Dependency] private SharedPopupSystem _popupSystem = default!;
[Dependency] private DamageableSystem _damageable = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DamagePopupComponent, DamageChangedEvent>(OnDamageChange);
SubscribeLocalEvent<DamagePopupComponent, InteractHandEvent>(OnInteractHand);
}
private void OnDamageChange(Entity<DamagePopupComponent> ent, ref DamageChangedEvent args)
{
if (args.DamageDelta != null)
{
var damageTotal = _damageable.GetTotalDamage((ent, args.Damageable));
var damageDelta = args.DamageDelta.GetTotal();
var msg = ent.Comp.Type switch
{
DamagePopupType.Delta => damageDelta.ToString(),
DamagePopupType.Total => damageTotal.ToString(),
DamagePopupType.Combined => damageDelta + " | " + damageTotal,
DamagePopupType.Hit => "!",
_ => "Invalid type",
};
_popupSystem.PopupEntity(msg, ent.Owner);
}
}
private void OnInteractHand(Entity<DamagePopupComponent> ent, ref InteractHandEvent args)
{
if (ent.Comp.AllowTypeChange)
{
var next = (DamagePopupType)(((int)ent.Comp.Type + 1) % Enum.GetValues<DamagePopupType>().Length);
ent.Comp.Type = next;
Dirty(ent);
_popupSystem.PopupEntity(Loc.GetString("damage-popup-component-switched", ("setting", ent.Comp.Type)), ent.Owner);
}
}
}