2023-09-23 15:14:06 +02:00
|
|
|
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 : EquipmentHudSystem<ShowHungerIconsComponent>
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeMan = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<HungerComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnGetStatusIconsEvent(EntityUid uid, HungerComponent hungerComponent, ref GetStatusIconsEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!IsActive || args.InContainer)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-04 17:48:57 +01:00
|
|
|
var hungerIcons = DecideHungerIcon(uid, hungerComponent);
|
2023-09-23 15:14:06 +02:00
|
|
|
|
2024-01-04 17:48:57 +01:00
|
|
|
args.StatusIcons.AddRange(hungerIcons);
|
2023-09-23 15:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IReadOnlyList<StatusIconPrototype> DecideHungerIcon(EntityUid uid, HungerComponent hungerComponent)
|
|
|
|
|
{
|
|
|
|
|
var result = new List<StatusIconPrototype>();
|
|
|
|
|
|
|
|
|
|
switch (hungerComponent.CurrentThreshold)
|
|
|
|
|
{
|
|
|
|
|
case HungerThreshold.Overfed:
|
|
|
|
|
if (_prototypeMan.TryIndex<StatusIconPrototype>("HungerIconOverfed", out var overfed))
|
|
|
|
|
{
|
|
|
|
|
result.Add(overfed);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case HungerThreshold.Peckish:
|
|
|
|
|
if (_prototypeMan.TryIndex<StatusIconPrototype>("HungerIconPeckish", out var peckish))
|
|
|
|
|
{
|
|
|
|
|
result.Add(peckish);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case HungerThreshold.Starving:
|
|
|
|
|
if (_prototypeMan.TryIndex<StatusIconPrototype>("HungerIconStarving", out var starving))
|
|
|
|
|
{
|
|
|
|
|
result.Add(starving);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|