update
This commit is contained in:
40
scripts/components/healthbar.gd
Normal file
40
scripts/components/healthbar.gd
Normal file
@@ -0,0 +1,40 @@
|
||||
extends Sprite3D
|
||||
|
||||
@onready var viewport: SubViewport = $SubViewport
|
||||
@onready var health_bar: ProgressBar = $SubViewport/HealthBar
|
||||
@onready var border: ColorRect = $SubViewport/Border
|
||||
@onready var health: Node = get_parent().get_node("Health")
|
||||
@onready var parent_node: Node = get_parent()
|
||||
|
||||
var shield: Node = null
|
||||
var shield_bar: ProgressBar = null
|
||||
var style_normal: StyleBoxFlat
|
||||
var style_aggro: StyleBoxFlat
|
||||
|
||||
func _ready() -> void:
|
||||
texture = viewport.get_texture()
|
||||
health_bar.max_value = health.max_health
|
||||
shield = get_parent().get_node_or_null("Shield")
|
||||
shield_bar = $SubViewport.get_node_or_null("ShieldBar")
|
||||
if shield and shield_bar:
|
||||
shield_bar.max_value = shield.max_shield
|
||||
elif shield_bar:
|
||||
shield_bar.visible = false
|
||||
border.visible = false
|
||||
style_normal = health_bar.get_theme_stylebox("fill").duplicate()
|
||||
style_aggro = style_normal.duplicate()
|
||||
style_aggro.bg_color = Color(0.2, 0.4, 0.9, 1)
|
||||
EventBus.target_changed.connect(_on_target_changed)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
health_bar.value = health.current_health
|
||||
if shield and shield_bar:
|
||||
shield_bar.value = shield.current_shield
|
||||
var player: Node = get_tree().get_first_node_in_group("player")
|
||||
if player and "target" in parent_node and parent_node.target == player:
|
||||
health_bar.add_theme_stylebox_override("fill", style_aggro)
|
||||
else:
|
||||
health_bar.add_theme_stylebox_override("fill", style_normal)
|
||||
|
||||
func _on_target_changed(_player: Node, target: Node) -> void:
|
||||
border.visible = (target == get_parent())
|
||||
1
scripts/components/healthbar.gd.uid
Normal file
1
scripts/components/healthbar.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d1w7vm7t3k3ts
|
||||
Reference in New Issue
Block a user