* PR 1 * fix an error with health bar overlay (#1292) * Revert "Revert "Replace `ResourcePath` with `ResPath` (#15308)" (#155… (#15566) * [1612] change ShowHealthBarsComponent's DamageContainer field to a list (#1662) * fix build * no crit entities from not updating * cleanup * namespace * undu irrelevant changes * undo icon change * make health bar 1 px taller and icon 1 px shorter * fix medibot * fix comment * don't show health bar ratio when in crit * fix build * put the crit bar back * don't render healthbars for mobs that are in containers * draw more boxes without the background sprite * fine status icon for all bio mobs * add wacky mandatory things * attempt 2 * whoops wrong file * cool, this works too * move null check to top * only 1 init * security huds * remove shader * fix build after cleanup * slight cleanup * little more cleanup * Remove clothing grant component system * security HUD now shows a job icon on entities with a body * remove sec stuff and do similar changes to split off PR + remove unused comp * process comments * don't return * update to ComponentAddedOverlaySystemBase * no cache * colors and not rendering out of sight * touch ups * fix build & cleanup * undo * remove shader from icons * process comments * documentation * fix licence * validate prototype id * just use args * rename method and append in method * type * just fucken delete the command * space * undo * remove * don't use LocalPlayer * re-add showhealthbars command, but working * rename icon lists and conform health icon code to the others * space * undo * update command * oops --------- Co-authored-by: Rane <60792108+Elijahrane@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
112 lines
4.1 KiB
C#
112 lines
4.1 KiB
C#
using Content.Shared.StatusIcon;
|
|
using Content.Shared.StatusIcon.Components;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Enums;
|
|
using System.Numerics;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.StatusIcon;
|
|
|
|
public sealed class StatusIconOverlay : Overlay
|
|
{
|
|
[Dependency] private readonly IEntityManager _entity = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
|
|
private readonly SpriteSystem _sprite;
|
|
private readonly TransformSystem _transform;
|
|
private readonly StatusIconSystem _statusIcon;
|
|
private readonly ShaderInstance _shader;
|
|
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
|
|
|
|
internal StatusIconOverlay()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_sprite = _entity.System<SpriteSystem>();
|
|
_transform = _entity.System<TransformSystem>();
|
|
_statusIcon = _entity.System<StatusIconSystem>();
|
|
_shader = _prototype.Index<ShaderPrototype>("unshaded").Instance();
|
|
}
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
var handle = args.WorldHandle;
|
|
|
|
var eyeRot = args.Viewport.Eye?.Rotation ?? default;
|
|
|
|
var xformQuery = _entity.GetEntityQuery<TransformComponent>();
|
|
var scaleMatrix = Matrix3.CreateScale(new Vector2(1, 1));
|
|
var rotationMatrix = Matrix3.CreateRotation(-eyeRot);
|
|
|
|
handle.UseShader(_shader);
|
|
|
|
var query = _entity.AllEntityQueryEnumerator<StatusIconComponent, SpriteComponent, TransformComponent, MetaDataComponent>();
|
|
while (query.MoveNext(out var uid, out var comp, out var sprite, out var xform, out var meta))
|
|
{
|
|
if (xform.MapID != args.MapId)
|
|
continue;
|
|
|
|
var bounds = comp.Bounds ?? sprite.Bounds;
|
|
|
|
var worldPos = _transform.GetWorldPosition(xform, xformQuery);
|
|
|
|
if (!bounds.Translated(worldPos).Intersects(args.WorldAABB))
|
|
continue;
|
|
|
|
var icons = _statusIcon.GetStatusIcons(uid, meta);
|
|
if (icons.Count == 0)
|
|
continue;
|
|
|
|
var worldMatrix = Matrix3.CreateTranslation(worldPos);
|
|
Matrix3.Multiply(scaleMatrix, worldMatrix, out var scaledWorld);
|
|
Matrix3.Multiply(rotationMatrix, scaledWorld, out var matty);
|
|
handle.SetTransform(matty);
|
|
|
|
var countL = 0;
|
|
var countR = 0;
|
|
var accOffsetL = 0;
|
|
var accOffsetR = 0;
|
|
icons.Sort();
|
|
|
|
foreach (var proto in icons)
|
|
{
|
|
var texture = _sprite.Frame0(proto.Icon);
|
|
|
|
float yOffset;
|
|
float xOffset;
|
|
|
|
// the icons are ordered left to right, top to bottom.
|
|
// extra icons that don't fit are just cut off.
|
|
if (proto.LocationPreference == StatusIconLocationPreference.Left ||
|
|
proto.LocationPreference == StatusIconLocationPreference.None && countL <= countR)
|
|
{
|
|
if (accOffsetL + texture.Height > sprite.Bounds.Height * EyeManager.PixelsPerMeter)
|
|
break;
|
|
accOffsetL += texture.Height;
|
|
yOffset = (bounds.Height + sprite.Offset.Y) / 2f - (float) accOffsetL / EyeManager.PixelsPerMeter;
|
|
xOffset = -(bounds.Width + sprite.Offset.X) / 2f;
|
|
|
|
countL++;
|
|
}
|
|
else
|
|
{
|
|
if (accOffsetR + texture.Height > sprite.Bounds.Height * EyeManager.PixelsPerMeter)
|
|
break;
|
|
accOffsetR += texture.Height;
|
|
yOffset = (bounds.Height + sprite.Offset.Y) / 2f - (float) accOffsetR / EyeManager.PixelsPerMeter;
|
|
xOffset = (bounds.Width + sprite.Offset.X) / 2f - (float) texture.Width / EyeManager.PixelsPerMeter;
|
|
|
|
countR++;
|
|
}
|
|
|
|
var position = new Vector2(xOffset, yOffset);
|
|
handle.DrawTexture(texture, position);
|
|
}
|
|
}
|
|
|
|
handle.UseShader(null);
|
|
}
|
|
}
|