mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-20 23:17:43 +03:00
## Mirror of PR #26027: [Improves Medical Hud interface and functionality](https://github.com/space-wizards/space-station-14/pull/26027) from <img src="https://avatars.githubusercontent.com/u/10567778?v=4" alt="space-wizards" width="22"/> [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `8d40bc36a93d3d5c6d3ece6c662ac9747f7837ae` PR opened by <img src="https://avatars.githubusercontent.com/u/68350815?v=4" width="16"/><a href="https://github.com/DoutorWhite"> DoutorWhite</a> at 2024-03-12 07:00:06 UTC --- PR changed 8 files with 78 additions and 13 deletions. The PR had the following labels: - Changes: Sprites - Status: Awaiting Changes --- <details open="true"><summary><h1>Original Body</h1></summary> > ## About the PR > > There are some changes to the Medical Hud interface: The icon has been changed and now there is one for each mob state, making it easier to recognize whether the mob is rotting, dead or crit. > > ## Why / Balance > > It's more visually pleasing and helps with discerning mob states. > > ## Technical details > > There is a decision structure for determining which icon is appropriate for the mob's state. It's the only relevant code change. > > ## Media > >  > > - [X] I have added screenshots/videos to this PR showcasing its changes ingame, **or** this PR does not require an ingame showcase > > > **Changelog** > > 🆑 > - add: Introduce new health status icons. > - tweak: Enhance the Medical HUD to display the health status of players and mobs using the newly added icons. </details> Co-authored-by: SimpleStation14 <Unknown>
85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
using Content.Shared.Atmos.Rotting;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Inventory.Events;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Overlays;
|
|
using Content.Shared.StatusIcon;
|
|
using Content.Shared.StatusIcon.Components;
|
|
using Robust.Shared.Prototypes;
|
|
using System.Linq;
|
|
|
|
namespace Content.Client.Overlays;
|
|
|
|
/// <summary>
|
|
/// Shows a healthy icon on mobs.
|
|
/// </summary>
|
|
public sealed class ShowHealthIconsSystem : EquipmentHudSystem<ShowHealthIconsComponent>
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeMan = default!;
|
|
|
|
public HashSet<string> DamageContainers = new();
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<DamageableComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent);
|
|
|
|
}
|
|
|
|
protected override void UpdateInternal(RefreshEquipmentHudEvent<ShowHealthIconsComponent> component)
|
|
{
|
|
base.UpdateInternal(component);
|
|
|
|
foreach (var damageContainerId in component.Components.SelectMany(x => x.DamageContainers))
|
|
{
|
|
DamageContainers.Add(damageContainerId);
|
|
}
|
|
}
|
|
|
|
protected override void DeactivateInternal()
|
|
{
|
|
base.DeactivateInternal();
|
|
|
|
DamageContainers.Clear();
|
|
}
|
|
|
|
private void OnGetStatusIconsEvent(Entity<DamageableComponent> entity, ref GetStatusIconsEvent args)
|
|
{
|
|
if (!IsActive || args.InContainer)
|
|
return;
|
|
|
|
var healthIcons = DecideHealthIcons(entity);
|
|
|
|
args.StatusIcons.AddRange(healthIcons);
|
|
}
|
|
|
|
private IReadOnlyList<StatusIconPrototype> DecideHealthIcons(Entity<DamageableComponent> entity)
|
|
{
|
|
var damageableComponent = entity.Comp;
|
|
|
|
if (damageableComponent.DamageContainerID == null ||
|
|
!DamageContainers.Contains(damageableComponent.DamageContainerID))
|
|
{
|
|
return Array.Empty<StatusIconPrototype>();
|
|
}
|
|
|
|
var result = new List<StatusIconPrototype>();
|
|
|
|
// Here you could check health status, diseases, mind status, etc. and pick a good icon, or multiple depending on whatever.
|
|
if (damageableComponent?.DamageContainerID == "Biological")
|
|
{
|
|
if (TryComp<MobStateComponent>(entity, out var state))
|
|
{
|
|
// Since there is no MobState for a rotting mob, we have to deal with this case first.
|
|
if (HasComp<RottingComponent>(entity) && _prototypeMan.TryIndex(damageableComponent.RottingIcon, out var rottingIcon))
|
|
result.Add(rottingIcon);
|
|
else if (damageableComponent.HealthIcons.TryGetValue(state.CurrentState, out var value) && _prototypeMan.TryIndex(value, out var icon))
|
|
result.Add(icon);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|