Files
MovementTests/player_controller/PlayerUi.cs
Minimata ddf1bd019b
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 42s
Create tag and build when new code gets to main / Test (push) Successful in 6m13s
Create tag and build when new code gets to main / Export (push) Successful in 7m5s
better healthbars and one for the player as well
2026-01-26 18:09:29 +01:00

77 lines
2.1 KiB
C#

using Godot;
using System;
using Movementtests.interfaces;
public partial class PlayerUi : Control
{
private TextureRect[] _dashIcons = new TextureRect[3];
private TextureRect _enemyTarget;
private Healthbar _healthbar;
public enum TargetState
{
NoTarget,
TargetTooFar,
TargetInRange,
TargetDashThrough
}
public record TargetProperties(TargetState State, Vector2 Position);
[Export]
public Color DashThroughColor { get; set; } = new Color("009c8f");
[Export]
public Color DashBlockedColor { get; set; } = new Color("fc001c");
[Export]
public Color DashOutOfRangeColor { get; set; } = new Color("ffffff");
public override void _Ready()
{
_dashIcons[0] = GetNode<TextureRect>("%Dash1");
_dashIcons[1] = GetNode<TextureRect>("%Dash2");
_dashIcons[2] = GetNode<TextureRect>("%Dash3");
_enemyTarget = GetNode<TextureRect>("%EnemyTarget");
_healthbar = GetNode<Healthbar>("%Healthbar");
}
public void Initialize(float initialHealth)
{
_healthbar.Initialize(initialHealth);
}
public void SetEnemyTargetProperties(TargetProperties targetProperties)
{
var (state, position) = targetProperties;
var visible = state != TargetState.NoTarget;
var modulation = state switch
{
TargetState.TargetTooFar => DashOutOfRangeColor,
TargetState.TargetInRange => DashBlockedColor,
TargetState.TargetDashThrough => DashThroughColor,
_ => DashOutOfRangeColor
};
_enemyTarget.SetVisible(visible);
_enemyTarget.SetPosition(position - _enemyTarget.Size / 2);
_enemyTarget.SetModulate(modulation);
}
public void SetNumberOfDashesLeft(int numberOfDashes)
{
int index = 1;
foreach (var dashIcon in _dashIcons)
{
dashIcon.SetVisible(index <= numberOfDashes);
index++;
}
}
public void OnHealthChanged(IHealthable healthable, HealthChangedRecord healthChanged)
{
_healthbar.CurrentHealth = healthChanged.CurrentHealth;
}
}