make RefreshOverlay default to the player session (#32354)

This commit is contained in:
Milon
2025-01-30 06:09:25 +01:00
committed by GitHub
parent f4c648f316
commit 3a51f11cb2
5 changed files with 31 additions and 34 deletions

View File

@@ -56,35 +56,35 @@ public abstract class EquipmentHudSystem<T> : EntitySystem where T : IComponent
protected virtual void DeactivateInternal() { } protected virtual void DeactivateInternal() { }
private void OnStartup(EntityUid uid, T component, ComponentStartup args) private void OnStartup(Entity<T> ent, ref ComponentStartup args)
{ {
RefreshOverlay(uid); RefreshOverlay();
} }
private void OnRemove(EntityUid uid, T component, ComponentRemove args) private void OnRemove(Entity<T> ent, ref ComponentRemove args)
{ {
RefreshOverlay(uid); RefreshOverlay();
} }
private void OnPlayerAttached(LocalPlayerAttachedEvent args) private void OnPlayerAttached(LocalPlayerAttachedEvent args)
{ {
RefreshOverlay(args.Entity); RefreshOverlay();
} }
private void OnPlayerDetached(LocalPlayerDetachedEvent args) private void OnPlayerDetached(LocalPlayerDetachedEvent args)
{ {
if (_player.LocalSession?.AttachedEntity == null) if (_player.LocalSession?.AttachedEntity is null)
Deactivate(); Deactivate();
} }
private void OnCompEquip(EntityUid uid, T component, GotEquippedEvent args) private void OnCompEquip(Entity<T> ent, ref GotEquippedEvent args)
{ {
RefreshOverlay(args.Equipee); RefreshOverlay();
} }
private void OnCompUnequip(EntityUid uid, T component, GotUnequippedEvent args) private void OnCompUnequip(Entity<T> ent, ref GotUnequippedEvent args)
{ {
RefreshOverlay(args.Equipee); RefreshOverlay();
} }
private void OnRoundRestart(RoundRestartCleanupEvent args) private void OnRoundRestart(RoundRestartCleanupEvent args)
@@ -92,24 +92,24 @@ public abstract class EquipmentHudSystem<T> : EntitySystem where T : IComponent
Deactivate(); Deactivate();
} }
protected virtual void OnRefreshEquipmentHud(EntityUid uid, T component, InventoryRelayedEvent<RefreshEquipmentHudEvent<T>> args) protected virtual void OnRefreshEquipmentHud(Entity<T> ent, ref InventoryRelayedEvent<RefreshEquipmentHudEvent<T>> args)
{ {
OnRefreshComponentHud(uid, component, args.Args); OnRefreshComponentHud(ent, ref args.Args);
} }
protected virtual void OnRefreshComponentHud(EntityUid uid, T component, RefreshEquipmentHudEvent<T> args) protected virtual void OnRefreshComponentHud(Entity<T> ent, ref RefreshEquipmentHudEvent<T> args)
{ {
args.Active = true; args.Active = true;
args.Components.Add(component); args.Components.Add(ent.Comp);
} }
protected void RefreshOverlay(EntityUid uid) protected void RefreshOverlay()
{ {
if (uid != _player.LocalSession?.AttachedEntity) if (_player.LocalSession?.AttachedEntity is not { } entity)
return; return;
var ev = new RefreshEquipmentHudEvent<T>(TargetSlots); var ev = new RefreshEquipmentHudEvent<T>(TargetSlots);
RaiseLocalEvent(uid, ev); RaiseLocalEvent(entity, ref ev);
if (ev.Active) if (ev.Active)
Update(ev); Update(ev);

View File

@@ -28,7 +28,7 @@ public sealed class ShowHealthBarsSystem : EquipmentHudSystem<ShowHealthBarsComp
private void OnHandleState(Entity<ShowHealthBarsComponent> ent, ref AfterAutoHandleStateEvent args) private void OnHandleState(Entity<ShowHealthBarsComponent> ent, ref AfterAutoHandleStateEvent args)
{ {
RefreshOverlay(ent); RefreshOverlay();
} }
protected override void UpdateInternal(RefreshEquipmentHudEvent<ShowHealthBarsComponent> component) protected override void UpdateInternal(RefreshEquipmentHudEvent<ShowHealthBarsComponent> component)

View File

@@ -47,7 +47,7 @@ public sealed class ShowHealthIconsSystem : EquipmentHudSystem<ShowHealthIconsCo
private void OnHandleState(Entity<ShowHealthIconsComponent> ent, ref AfterAutoHandleStateEvent args) private void OnHandleState(Entity<ShowHealthIconsComponent> ent, ref AfterAutoHandleStateEvent args)
{ {
RefreshOverlay(ent); RefreshOverlay();
} }
private void OnGetStatusIconsEvent(Entity<DamageableComponent> entity, ref GetStatusIconsEvent args) private void OnGetStatusIconsEvent(Entity<DamageableComponent> entity, ref GetStatusIconsEvent args)

View File

@@ -1,13 +1,10 @@
namespace Content.Shared.Inventory.Events; namespace Content.Shared.Inventory.Events;
public sealed class RefreshEquipmentHudEvent<T> : EntityEventArgs, IInventoryRelayEvent where T : IComponent [ByRefEvent]
public record struct RefreshEquipmentHudEvent<T>(SlotFlags TargetSlots) : IInventoryRelayEvent
where T : IComponent
{ {
public SlotFlags TargetSlots { get; init; } public SlotFlags TargetSlots { get; } = TargetSlots;
public bool Active = false; public bool Active = false;
public List<T> Components = new(); public List<T> Components = new();
public RefreshEquipmentHudEvent(SlotFlags targetSlots)
{
TargetSlots = targetSlots;
}
} }

View File

@@ -55,14 +55,14 @@ public partial class InventorySystem
SubscribeLocalEvent<InventoryComponent, SolutionScanEvent>(RelayInventoryEvent); SubscribeLocalEvent<InventoryComponent, SolutionScanEvent>(RelayInventoryEvent);
// ComponentActivatedClientSystems // ComponentActivatedClientSystems
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowJobIconsComponent>>(RelayInventoryEvent); SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowJobIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthBarsComponent>>(RelayInventoryEvent); SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthBarsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthIconsComponent>>(RelayInventoryEvent); SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHungerIconsComponent>>(RelayInventoryEvent); SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHungerIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowThirstIconsComponent>>(RelayInventoryEvent); SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowThirstIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowMindShieldIconsComponent>>(RelayInventoryEvent); SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowMindShieldIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowSyndicateIconsComponent>>(RelayInventoryEvent); SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowSyndicateIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowCriminalRecordIconsComponent>>(RelayInventoryEvent); SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowCriminalRecordIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetEquipmentVerbs); SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetEquipmentVerbs);
} }