mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description <!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> Port from WWDP. Refactor from [Goob](https://github.com/Goob-Station/Goob-Station/pull/1251) --- <!-- This is default collapsed, readers click to expand it and see all your media The PR media section can get very large at times, so this is a good way to keep it clean The title is written using HTML tags The title must be within the <summary> tags or you won't see it --> <details><summary><h1>Media</h1></summary> <p>  Night vision goggles:  Zealot's blindfold:  Animal vision:  Thermal vision goggles:  Deathsquad helmet:  Xeno vision:  </p> </details> --- # Changelog <!-- You can add an author after the `🆑` to change the name that appears in the changelog (ex: `🆑 Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> 🆑 @Aviu00, Spatison, @PuroSlavKing - add: Added night vision goggle - add: Added thermal vision goggle - add: Deathsquad helmet now grants night and thermal vision. - add: Ninja visor now grants night vision. - tweak: Some animals have gained night vision. - tweak: Xenos have gained night vision. --------- Signed-off-by: Spatison <137375981+Spatison@users.noreply.github.com> Co-authored-by: PuroSlavKing <103608145+puroslavking@users.noreply.github.com> (cherry picked from commit 0f481422a54a197923f4bf03db1b5733e481965f)
119 lines
3.3 KiB
C#
119 lines
3.3 KiB
C#
using Content.Shared.GameTicking;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Inventory.Events;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Client.Overlays;
|
|
|
|
/// <summary>
|
|
/// This is a base system to make it easier to enable or disabling UI elements based on whether or not the player has
|
|
/// some component, either on their controlled entity on some worn piece of equipment.
|
|
/// </summary>
|
|
public abstract class EquipmentHudSystem<T> : EntitySystem where T : IComponent
|
|
{
|
|
[Dependency] private readonly IPlayerManager _player = default!;
|
|
|
|
protected bool IsActive;
|
|
protected virtual SlotFlags TargetSlots => ~SlotFlags.POCKET;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<T, ComponentStartup>(OnStartup);
|
|
SubscribeLocalEvent<T, ComponentRemove>(OnRemove);
|
|
|
|
SubscribeLocalEvent<LocalPlayerAttachedEvent>(OnPlayerAttached);
|
|
SubscribeLocalEvent<LocalPlayerDetachedEvent>(OnPlayerDetached);
|
|
|
|
SubscribeLocalEvent<T, GotEquippedEvent>(OnCompEquip);
|
|
SubscribeLocalEvent<T, GotUnequippedEvent>(OnCompUnequip);
|
|
|
|
SubscribeLocalEvent<T, RefreshEquipmentHudEvent<T>>(OnRefreshComponentHud);
|
|
SubscribeLocalEvent<T, InventoryRelayedEvent<RefreshEquipmentHudEvent<T>>>(OnRefreshEquipmentHud);
|
|
|
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
|
|
}
|
|
|
|
private void Update(RefreshEquipmentHudEvent<T> ev)
|
|
{
|
|
IsActive = true;
|
|
UpdateInternal(ev);
|
|
}
|
|
|
|
public void Deactivate()
|
|
{
|
|
if (!IsActive)
|
|
return;
|
|
|
|
IsActive = false;
|
|
DeactivateInternal();
|
|
}
|
|
|
|
protected virtual void UpdateInternal(RefreshEquipmentHudEvent<T> args) { }
|
|
|
|
protected virtual void DeactivateInternal() { }
|
|
|
|
private void OnStartup(EntityUid uid, T component, ComponentStartup args)
|
|
{
|
|
RefreshOverlay(uid);
|
|
}
|
|
|
|
private void OnRemove(EntityUid uid, T component, ComponentRemove args)
|
|
{
|
|
RefreshOverlay(uid);
|
|
}
|
|
|
|
private void OnPlayerAttached(LocalPlayerAttachedEvent args)
|
|
{
|
|
RefreshOverlay(args.Entity);
|
|
}
|
|
|
|
private void OnPlayerDetached(LocalPlayerDetachedEvent args)
|
|
{
|
|
if (_player.LocalSession?.AttachedEntity == null)
|
|
Deactivate();
|
|
}
|
|
|
|
private void OnCompEquip(EntityUid uid, T component, GotEquippedEvent args)
|
|
{
|
|
RefreshOverlay(args.Equipee);
|
|
}
|
|
|
|
private void OnCompUnequip(EntityUid uid, T component, GotUnequippedEvent args)
|
|
{
|
|
RefreshOverlay(args.Equipee);
|
|
}
|
|
|
|
private void OnRoundRestart(RoundRestartCleanupEvent args)
|
|
{
|
|
Deactivate();
|
|
}
|
|
|
|
protected virtual void OnRefreshEquipmentHud(EntityUid uid, T component, InventoryRelayedEvent<RefreshEquipmentHudEvent<T>> args)
|
|
{
|
|
OnRefreshComponentHud(uid, component, args.Args);
|
|
}
|
|
|
|
protected virtual void OnRefreshComponentHud(EntityUid uid, T component, RefreshEquipmentHudEvent<T> args)
|
|
{
|
|
args.Active = true;
|
|
args.Components.Add(component);
|
|
}
|
|
|
|
protected void RefreshOverlay(EntityUid uid)
|
|
{
|
|
if (uid != _player.LocalSession?.AttachedEntity)
|
|
return;
|
|
|
|
var ev = new RefreshEquipmentHudEvent<T>(TargetSlots);
|
|
RaiseLocalEvent(uid, ev);
|
|
|
|
if (ev.Active)
|
|
Update(ev);
|
|
else
|
|
Deactivate();
|
|
}
|
|
}
|