29 lines
1.0 KiB
GDScript
29 lines
1.0 KiB
GDScript
extends CanvasLayer
|
|
|
|
|
|
## Minimal HUD showing the player's special attack charge.
|
|
##
|
|
## Expects to be a child of a Player that exposes a `special_charge_changed`
|
|
## signal, just like PlayerHealthHUD expects `health_changed`.
|
|
|
|
|
|
@onready var special_bar: ProgressBar = $HUD/SpecialBar
|
|
@onready var special_label: Label = $HUD/SpecialBar/SpecialLabel
|
|
|
|
|
|
func _ready() -> void:
|
|
var player: Node = get_parent()
|
|
if player == null or not player.has_signal(&"special_charge_changed"):
|
|
push_error("SpecialChargeHUD must be a child of a Player with special_charge_changed signal.")
|
|
return
|
|
|
|
# Child _ready() runs before Player._ready(). We connect here first and the
|
|
# Player will emit its initial charge a moment later during its _ready().
|
|
player.connect(&"special_charge_changed", _on_special_charge_changed)
|
|
|
|
|
|
func _on_special_charge_changed(current_charge: int, max_charge: int) -> void:
|
|
special_bar.max_value = float(max_charge)
|
|
special_bar.value = float(current_charge)
|
|
special_label.text = "SPECIAL %d%%" % [current_charge]
|