Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make RefreshOverlay default to the player session #32354

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions Content.Client/Overlays/EquipmentHudSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,60 +56,60 @@ protected virtual void UpdateInternal(RefreshEquipmentHudEvent<T> args) { }

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)
{
RefreshOverlay(args.Entity);
RefreshOverlay();
}

private void OnPlayerDetached(LocalPlayerDetachedEvent args)
{
if (_player.LocalSession?.AttachedEntity == null)
if (_player.LocalSession?.AttachedEntity is null)
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)
{
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.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;

var ev = new RefreshEquipmentHudEvent<T>(TargetSlots);
RaiseLocalEvent(uid, ev);
RaiseLocalEvent(entity, ref ev);

if (ev.Active)
Update(ev);
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Overlays/ShowHealthBarsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override void Initialize()

private void OnHandleState(Entity<ShowHealthBarsComponent> ent, ref AfterAutoHandleStateEvent args)
{
RefreshOverlay(ent);
RefreshOverlay();
}

protected override void UpdateInternal(RefreshEquipmentHudEvent<ShowHealthBarsComponent> component)
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Overlays/ShowHealthIconsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void DeactivateInternal()

private void OnHandleState(Entity<ShowHealthIconsComponent> ent, ref AfterAutoHandleStateEvent args)
{
RefreshOverlay(ent);
RefreshOverlay();
}

private void OnGetStatusIconsEvent(Entity<DamageableComponent> entity, ref GetStatusIconsEvent args)
Expand Down
11 changes: 4 additions & 7 deletions Content.Shared/Inventory/Events/RefreshEquipmentHudEvent.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
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 List<T> Components = new();

public RefreshEquipmentHudEvent(SlotFlags targetSlots)
{
TargetSlots = targetSlots;
}
}
16 changes: 8 additions & 8 deletions Content.Shared/Inventory/InventorySystem.Relay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public void InitializeRelay()
SubscribeLocalEvent<InventoryComponent, SolutionScanEvent>(RelayInventoryEvent);

// ComponentActivatedClientSystems
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowJobIconsComponent>>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthBarsComponent>>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthIconsComponent>>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHungerIconsComponent>>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowThirstIconsComponent>>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowMindShieldIconsComponent>>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowSyndicateIconsComponent>>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowCriminalRecordIconsComponent>>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowJobIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthBarsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHungerIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowThirstIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowMindShieldIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowSyndicateIconsComponent>>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowCriminalRecordIconsComponent>>(RefRelayInventoryEvent);

SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetEquipmentVerbs);
}
Expand Down
Loading