2024-02-22 06:22:22 +11:00
|
|
|
class_name HealthBar extends TextureProgressBar
|
2023-12-10 12:05:41 +11:00
|
|
|
|
|
|
|
@export var health_bar_gradient: Gradient
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
@onready var prev_bar: TextureProgressBar = $PreviousHealthBar
|
2023-12-10 12:05:41 +11:00
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func setup(health: float) -> void:
|
2023-12-10 12:05:41 +11:00
|
|
|
max_value = health
|
|
|
|
value = health
|
|
|
|
prev_bar.max_value = health
|
|
|
|
prev_bar.value = health
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func on_health_changed(health: float) -> void:
|
2023-12-10 12:05:41 +11:00
|
|
|
set_visible(true)
|
2024-02-22 06:22:22 +11:00
|
|
|
var health_went_down: bool = true if health < value else false
|
2023-12-10 12:05:41 +11:00
|
|
|
value = health
|
|
|
|
tint_progress = health_bar_gradient.sample(value / max_value)
|
|
|
|
if health_went_down:
|
2024-02-22 06:22:22 +11:00
|
|
|
var tween: Tween = create_tween()
|
2023-12-10 12:05:41 +11:00
|
|
|
tween.set_ease(Tween.EASE_OUT)
|
|
|
|
tween.set_trans(Tween.TRANS_QUINT)
|
|
|
|
tween.tween_interval(0.3)
|
|
|
|
tween.tween_property(prev_bar, "value", value, 0.7)
|
|
|
|
else:
|
|
|
|
prev_bar.value = value
|