From dfbacb00981ba3380eb14b34f607a4e66f5ad714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Thu, 28 Aug 2025 07:35:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(UI):=20=E4=B8=BAColorBar=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?currentValue=E5=B1=9E=E6=80=A7=E5=B9=B6=E5=AE=8C=E5=96=84boss?= =?UTF-8?q?=E8=A1=80=E6=9D=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为ColorBar组件添加currentValue属性以跟踪当前值。同时修复当设置boss时未正确更新血条显示的问题,确保boss血条在切换目标时能正确显示初始血量。 --- components/UI/ColorBar.tscn | 1 + scripts/Statemachine/BossBar.gd | 4 +--- scripts/Statemachine/EntityBase.gd | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/UI/ColorBar.tscn b/components/UI/ColorBar.tscn index 975b667..f039234 100644 --- a/components/UI/ColorBar.tscn +++ b/components/UI/ColorBar.tscn @@ -36,6 +36,7 @@ anchors_preset = 0 offset_right = 100.0 offset_bottom = 10.0 script = ExtResource("1_a106p") +currentValue = 0.0 backBox = SubResource("StyleBoxFlat_kf2fc") middleBox1 = SubResource("StyleBoxFlat_sh754") middleBox2 = SubResource("StyleBoxFlat_8n8i8") diff --git a/scripts/Statemachine/BossBar.gd b/scripts/Statemachine/BossBar.gd index 81aba49..5b43a8f 100644 --- a/scripts/Statemachine/BossBar.gd +++ b/scripts/Statemachine/BossBar.gd @@ -4,9 +4,7 @@ class_name BossBar @onready var nameLabel: Label = $"%name" @onready var valueLabel: Label = $"%value" -func _ready(): - if is_instance_valid(entity): - nameLabel.text = entity.displayName func _process(_delta): if is_instance_valid(entity): + nameLabel.text = entity.displayName valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100) diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index d97f224..bdcd512 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -202,8 +202,9 @@ func findWeaponAnchor(weaponName: String): return Vector2.ZERO func setBoss(boss: EntityBase): currentFocusedBoss = boss - if isPlayer(): + if isPlayer() and boss and UIState.bossbar.entity != boss: UIState.bossbar.entity = boss + boss.healthChanged.emit(boss.health) func playSound(type: String): var body = sounds.get_node_or_null(type) if body is AudioStreamPlayer2D: