update
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
extends CanvasLayer
|
||||
|
||||
const GCD_TIME := 1.0
|
||||
|
||||
@onready var health_bar: ProgressBar = $HealthBar
|
||||
@onready var shield_bar: ProgressBar = $ShieldBar
|
||||
@onready var respawn_label: Label = $RespawnTimer
|
||||
@onready var class_icon: Label = $AbilityBar/ClassIcon/Label
|
||||
@onready var ability_panels: Array = [
|
||||
$AbilityBar/Ability1,
|
||||
$AbilityBar/Ability2,
|
||||
$AbilityBar/Ability3,
|
||||
$AbilityBar/Ability4,
|
||||
$AbilityBar/Ability5,
|
||||
]
|
||||
|
||||
var player_node: Node = null
|
||||
var ability_labels: Array[String] = ["1", "2", "3", "4", "P"]
|
||||
|
||||
func _ready() -> void:
|
||||
respawn_label.visible = false
|
||||
@@ -15,6 +24,7 @@ func _ready() -> void:
|
||||
EventBus.player_respawned.connect(_on_player_respawned)
|
||||
EventBus.class_changed.connect(_on_class_changed)
|
||||
EventBus.respawn_tick.connect(_on_respawn_tick)
|
||||
EventBus.cooldown_tick.connect(_on_cooldown_tick)
|
||||
|
||||
func _on_health_changed(entity: Node, current: float, max_val: float) -> void:
|
||||
if entity.name == "Player":
|
||||
@@ -41,3 +51,22 @@ func _on_class_changed(_player: Node, class_type: int) -> void:
|
||||
0: class_icon.text = "T"
|
||||
1: class_icon.text = "D"
|
||||
2: class_icon.text = "H"
|
||||
|
||||
func _on_cooldown_tick(cooldowns: Array, max_cooldowns: Array, gcd_timer: float) -> void:
|
||||
for i in range(min(ability_panels.size(), cooldowns.size())):
|
||||
var panel: Panel = ability_panels[i]
|
||||
var label: Label = panel.get_node("Label")
|
||||
var overlay: ColorRect = panel.get_node("CooldownOverlay")
|
||||
var cd: float = cooldowns[i]
|
||||
var gcd: float = gcd_timer if i != 2 and i != 4 else 0.0
|
||||
var active_cd: float = max(cd, gcd)
|
||||
var max_cd: float = max_cooldowns[i] if max_cooldowns[i] > 0 else GCD_TIME
|
||||
|
||||
if active_cd > 0:
|
||||
var ratio: float = clamp(active_cd / max_cd, 0.0, 1.0)
|
||||
overlay.visible = true
|
||||
overlay.anchor_bottom = ratio
|
||||
label.text = str(ceil(active_cd))
|
||||
else:
|
||||
overlay.visible = false
|
||||
label.text = ability_labels[i]
|
||||
|
||||
Reference in New Issue
Block a user