-
Notifications
You must be signed in to change notification settings - Fork 0
/
current_next_health_bar.gd
53 lines (45 loc) · 1.25 KB
/
current_next_health_bar.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
extends HBoxContainer
class_name CurrentNextHealthBar
@export var next_hp: Control
@export var current_hp: Control
@export var missing_hp: Control
@export var hide_full = false
var current_health = 20
var max_health = 40
var next_health = 10
var is_ready = false
var tween: Tween
func _ready():
is_ready = true
update_health()
func set_health(current_hp: int, max_hp: int, next_hp: int):
current_health = current_hp
max_health = max_hp
next_health = next_hp
if next_health < 0:
next_health = 0
update_health()
func update_health():
if not is_ready:
return
if hide_full and current_health == max_health and current_health == next_health:
hide()
return
show()
next_hp.size_flags_stretch_ratio = next_health
current_hp.size_flags_stretch_ratio = (current_health - next_health)
missing_hp.size_flags_stretch_ratio = (max_health - current_health)
if next_health > 0:
if tween:
tween.kill()
tween = create_tween()
tween.set_loops()
tween.tween_property(current_hp, "modulate:a", 0.5, 1.0)
tween.tween_property(current_hp, "modulate:a", 1, 1.0)
else:
if tween:
tween.kill()
tween = create_tween()
tween.set_loops()
tween.tween_property(current_hp, "modulate:a", 0.5, 0.25)
tween.tween_property(current_hp, "modulate:a", 1, 0.25)