Health and shield gauges

This commit is contained in:
Marco 2025-02-11 17:55:50 +01:00
commit 3682de18d5
14 changed files with 188 additions and 22 deletions

View file

@ -19,7 +19,14 @@ public partial class Hud : CanvasLayer
private Node2D _selector;
[Export] private Label _healthLabel;
[Export] private ProgressBar _healthBar;
[Export] private Label _shieldLabel;
[Export] private ProgressBar _shieldBar;
[Export] private Container _itemsContainer;
[Export] private LabelSettings _labelSettings;
private Dictionary<string, HudItem> _items = new();
@ -56,6 +63,19 @@ public partial class Hud : CanvasLayer
public void UpdateHealth(float newHealth, float maxHealth)
{
_healthLabel.Text = $"{newHealth}/{maxHealth}";
if (_healthBar != null)
{
_healthBar.Value = newHealth;
}
}
public void UpdateShield(float newValue, float maxValue)
{
_shieldLabel.Text = $"{newValue}/{maxValue}";
if (_shieldBar != null)
{
_shieldBar.Value = newValue;
}
}
public void UpdateInteractable(Interactable interactable) {
@ -109,11 +129,8 @@ public partial class Hud : CanvasLayer
// {
// label.Text = currentAmount.ToString();
// }
label.LabelSettings = new LabelSettings()
{
FontSize = 8
};
label.LabelSettings = _labelSettings;
hbox.AddChild(label);
hudItem.Label = label;