Revert "Hunger and thirst HUDs" (#18125)
This commit is contained in:
@@ -1,115 +0,0 @@
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Player;
|
||||
|
||||
namespace Content.Client.Overlays
|
||||
{
|
||||
public abstract class ComponentAddedOverlaySystemBase<T> : EntitySystem where T : IComponent
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
private InventorySystem _invSystem = default!;
|
||||
|
||||
protected bool IsActive = false;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<T, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<T, ComponentRemove>(OnRemove);
|
||||
|
||||
SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttached);
|
||||
SubscribeLocalEvent<PlayerDetachedEvent>(OnPlayerDetached);
|
||||
|
||||
SubscribeLocalEvent<T, GotEquippedEvent>(OnCompEquip);
|
||||
SubscribeLocalEvent<T, GotUnequippedEvent>(OnCompUnequip);
|
||||
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
|
||||
|
||||
_invSystem = _entityManager.System<InventorySystem>();
|
||||
}
|
||||
|
||||
public void ApplyOverlay(T component)
|
||||
{
|
||||
IsActive = true;
|
||||
OnApplyOverlay(component);
|
||||
}
|
||||
|
||||
public void RemoveOverlay()
|
||||
{
|
||||
IsActive = false;
|
||||
OnRemoveOverlay();
|
||||
}
|
||||
|
||||
protected virtual void OnApplyOverlay(T component) { }
|
||||
|
||||
protected virtual void OnRemoveOverlay() { }
|
||||
|
||||
private void OnInit(EntityUid uid, T component, ComponentInit args)
|
||||
{
|
||||
if (_player.LocalPlayer?.ControlledEntity == uid)
|
||||
{
|
||||
ApplyOverlay(component);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, T component, ComponentRemove args)
|
||||
{
|
||||
if (_player.LocalPlayer?.ControlledEntity == uid)
|
||||
{
|
||||
RemoveOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(PlayerAttachedEvent args)
|
||||
{
|
||||
if (TryComp<T>(args.Entity, out var component))
|
||||
ApplyOverlay(component);
|
||||
|
||||
if (TryComp(args.Entity, out InventoryComponent? inventoryComponent)
|
||||
&& _invSystem.TryGetSlots(args.Entity, out var slotDefinitions, inventoryComponent))
|
||||
{
|
||||
foreach (var slot in slotDefinitions)
|
||||
{
|
||||
if (_invSystem.TryGetSlotEntity(args.Entity, slot.Name, out var itemUid)
|
||||
&& TryComp(itemUid.Value, out component))
|
||||
{
|
||||
OnCompEquip(itemUid.Value, component, new GotEquippedEvent(args.Entity, itemUid.Value, slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerDetached(PlayerDetachedEvent args)
|
||||
{
|
||||
RemoveOverlay();
|
||||
}
|
||||
|
||||
private void OnCompEquip(EntityUid uid, T component, GotEquippedEvent args)
|
||||
{
|
||||
if (!TryComp<ClothingComponent>(uid, out var clothing)) return;
|
||||
|
||||
if (args.Equipee != _player.LocalPlayer?.ControlledEntity) return;
|
||||
|
||||
if (!clothing.Slots.HasFlag(args.SlotFlags)) return;
|
||||
|
||||
ApplyOverlay(component);
|
||||
}
|
||||
|
||||
private void OnCompUnequip(EntityUid uid, T component, GotUnequippedEvent args)
|
||||
{
|
||||
if (args.Equipee != _player.LocalPlayer?.ControlledEntity) return;
|
||||
|
||||
RemoveOverlay();
|
||||
}
|
||||
|
||||
private void OnRoundRestart(RoundRestartCleanupEvent args)
|
||||
{
|
||||
RemoveOverlay();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Overlays;
|
||||
using Content.Shared.StatusIcon;
|
||||
using Content.Shared.StatusIcon.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Overlays
|
||||
{
|
||||
public sealed class ShowHungerIconsSystem : ComponentAddedOverlaySystemBase<ShowHungerIconsComponent>
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeMan = default!;
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
private StatusIconPrototype? _overfed;
|
||||
private StatusIconPrototype? _peckish;
|
||||
private StatusIconPrototype? _starving;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<HungerComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent);
|
||||
|
||||
}
|
||||
|
||||
private void OnGetStatusIconsEvent(EntityUid uid, HungerComponent hungerComponent, ref GetStatusIconsEvent @event)
|
||||
{
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
var healthIcons = DecideHungerIcon(uid, hungerComponent);
|
||||
|
||||
@event.StatusIcons.AddRange(healthIcons);
|
||||
}
|
||||
|
||||
private IReadOnlyList<StatusIconPrototype> DecideHungerIcon(EntityUid uid, HungerComponent hungerComponent)
|
||||
{
|
||||
var result = new List<StatusIconPrototype>();
|
||||
|
||||
if (_entManager.TryGetComponent<MetaDataComponent>(uid, out var metaDataComponent) &&
|
||||
metaDataComponent.Flags.HasFlag(MetaDataFlags.InContainer))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
switch (hungerComponent.CurrentThreshold)
|
||||
{
|
||||
case HungerThreshold.Overfed:
|
||||
if (_overfed != null ||
|
||||
_prototypeMan.TryIndex("HungerIcon_Overfed", out _overfed))
|
||||
{
|
||||
result.Add(_overfed);
|
||||
}
|
||||
break;
|
||||
case HungerThreshold.Peckish:
|
||||
if (_peckish != null ||
|
||||
_prototypeMan.TryIndex("HungerIcon_Peckish", out _peckish))
|
||||
{
|
||||
result.Add(_peckish);
|
||||
}
|
||||
break;
|
||||
case HungerThreshold.Starving:
|
||||
if (_starving != null ||
|
||||
_prototypeMan.TryIndex("HungerIcon_Starving", out _starving))
|
||||
{
|
||||
result.Add(_starving);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Overlays;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.StatusIcon;
|
||||
using Content.Shared.StatusIcon.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Overlays
|
||||
{
|
||||
public sealed class ShowSecurityIconsSystem : ComponentAddedOverlaySystemBase<ShowSecurityIconsComponent>
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeMan = default!;
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
||||
|
||||
private Dictionary<string, StatusIconPrototype> _jobIcons = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BodyComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent);
|
||||
}
|
||||
|
||||
private void OnGetStatusIconsEvent(EntityUid uid, BodyComponent _, ref GetStatusIconsEvent @event)
|
||||
{
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
var healthIcons = DecideSecurityIcon(uid);
|
||||
|
||||
@event.StatusIcons.AddRange(healthIcons);
|
||||
}
|
||||
|
||||
private IReadOnlyList<StatusIconPrototype> DecideSecurityIcon(EntityUid uid)
|
||||
{
|
||||
var result = new List<StatusIconPrototype>();
|
||||
if (_entManager.TryGetComponent<MetaDataComponent>(uid, out var metaDataComponent) &&
|
||||
metaDataComponent.Flags.HasFlag(MetaDataFlags.InContainer))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var iconToGet = "NoId";
|
||||
if (_inventorySystem.TryGetSlotEntity(uid, "id", out var idUid))
|
||||
{
|
||||
// PDA
|
||||
if (EntityManager.TryGetComponent(idUid, out PdaComponent? pda))
|
||||
{
|
||||
iconToGet = pda.ContainedId?.JobTitle ?? string.Empty;
|
||||
}
|
||||
// ID Card
|
||||
else if (EntityManager.TryGetComponent(idUid, out IdCardComponent? id))
|
||||
{
|
||||
iconToGet = id.JobTitle ?? string.Empty;
|
||||
}
|
||||
|
||||
iconToGet = iconToGet.Replace(" ", "");
|
||||
}
|
||||
|
||||
iconToGet = EnsureIcon(iconToGet, _jobIcons);
|
||||
result.Add(_jobIcons[iconToGet]);
|
||||
|
||||
// Add arrest icons here, WYCI.
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private string EnsureIcon(string iconKey, Dictionary<string, StatusIconPrototype> icons)
|
||||
{
|
||||
if (!icons.ContainsKey(iconKey))
|
||||
{
|
||||
if (_prototypeMan.TryIndex<StatusIconPrototype>($"JobIcon_{iconKey}", out var securityIcon))
|
||||
{
|
||||
icons.Add(iconKey, securityIcon);
|
||||
return iconKey;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return iconKey;
|
||||
}
|
||||
|
||||
iconKey = "Unknown";
|
||||
return EnsureIcon(iconKey, icons);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Overlays;
|
||||
using Content.Shared.StatusIcon;
|
||||
using Content.Shared.StatusIcon.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Overlays
|
||||
{
|
||||
public sealed class ShowThirstIconsSystem : ComponentAddedOverlaySystemBase<ShowThirstIconsComponent>
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeMan = default!;
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
private StatusIconPrototype? _overhydrated;
|
||||
private StatusIconPrototype? _thirsty;
|
||||
private StatusIconPrototype? _parched;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ThirstComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent);
|
||||
}
|
||||
|
||||
private void OnGetStatusIconsEvent(EntityUid uid, ThirstComponent thirstComponent, ref GetStatusIconsEvent @event)
|
||||
{
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
var healthIcons = DecideThirstIcon(uid, thirstComponent);
|
||||
|
||||
@event.StatusIcons.AddRange(healthIcons);
|
||||
}
|
||||
|
||||
private IReadOnlyList<StatusIconPrototype> DecideThirstIcon(EntityUid uid, ThirstComponent thirstComponent)
|
||||
{
|
||||
var result = new List<StatusIconPrototype>();
|
||||
|
||||
if (_entManager.TryGetComponent<MetaDataComponent>(uid, out var metaDataComponent) &&
|
||||
metaDataComponent.Flags.HasFlag(MetaDataFlags.InContainer))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
switch (thirstComponent.CurrentThirstThreshold)
|
||||
{
|
||||
case ThirstThreshold.OverHydrated:
|
||||
if (_overhydrated != null ||
|
||||
_prototypeMan.TryIndex("ThirstIcon_Overhydrated", out _overhydrated))
|
||||
{
|
||||
result.Add(_overhydrated);
|
||||
}
|
||||
break;
|
||||
case ThirstThreshold.Thirsty:
|
||||
if (_thirsty != null ||
|
||||
_prototypeMan.TryIndex("ThirstIcon_Thirsty", out _thirsty))
|
||||
{
|
||||
result.Add(_thirsty);
|
||||
}
|
||||
break;
|
||||
case ThirstThreshold.Parched:
|
||||
if (_parched != null ||
|
||||
_prototypeMan.TryIndex("ThirstIcon_Parched", out _parched))
|
||||
{
|
||||
result.Add(_parched);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user