Files
brotato/scenes/ui/health_bar/health_bar.gd
T
2026-05-18 15:46:44 +08:00

37 lines
1.0 KiB
GDScript

extends Control
class_name HealthBar
@export var back_color: Color
@export var fill_color: Color
@onready var progress_bar: ProgressBar = $ProgressBar
@onready var health_amount: Label = $HealthAmount
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var back_style := progress_bar.get_theme_stylebox("background").duplicate()
back_style.bg_color = back_color
var fill_style := progress_bar.get_theme_stylebox("fill").duplicate()
fill_style.bg_color = fill_color
progress_bar.add_theme_stylebox_override("background", back_style)
progress_bar.add_theme_stylebox_override("fill", fill_style)
func update_bar(value: float, health: float) -> void:
progress_bar.value = value
health_amount.text = str(health)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_health_component_on_health_changed(current: float, max: float) -> void:
var value = current / max
update_bar(value, current)