Files
tbd-station-14/Content.Client/GameObjects/EntitySystems/HealthOverlay/HealthOverlayBar.cs
DrSmugleaf 0ae4a6792f Add health overlay and a command to toggle it (#3278)
* Add health overlay bar and a command to toggle it

* Remove empty line
2021-02-19 19:31:25 +01:00

47 lines
1.2 KiB
C#

using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Client.GameObjects.EntitySystems.HealthOverlay
{
public class HealthOverlayBar : Control
{
public const byte HealthBarScale = 2;
private const int XPixelDiff = 20 * HealthBarScale;
public HealthOverlayBar()
{
IoCManager.InjectDependencies(this);
Shader = IoCManager.Resolve<IPrototypeManager>().Index<ShaderPrototype>("unshaded").Instance();
}
private ShaderInstance Shader { get; }
/// <summary>
/// From -1 (dead) to 0 (crit) and 1 (alive)
/// </summary>
public float Ratio { get; set; }
public Color Color { get; set; }
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
handle.UseShader(Shader);
var leftOffset = 2 * HealthBarScale;
var box = new UIBox2i(
leftOffset,
-2 + 2 * HealthBarScale,
leftOffset + (int) (XPixelDiff * Ratio * UIScale),
-2);
handle.DrawRect(box, Color);
}
}
}