2025-08-26 13:56:12 +08:00
|
|
|
extends Node2D
|
|
|
|
|
class_name DamageLabel
|
|
|
|
|
|
|
|
|
|
@export var damage: float = 0
|
|
|
|
|
@export var crit: bool = false
|
2025-08-27 10:23:57 +08:00
|
|
|
@export var color1: Color = Color(1, 0, 0, 1)
|
|
|
|
|
@export var color2: Color = Color(0, 1, 0, 1)
|
|
|
|
|
@export var color3: Color = Color(0.5, 0.5, 0.5, 1)
|
2025-09-07 14:23:58 +08:00
|
|
|
@export var color4: Color = Color.YELLOW
|
2025-08-26 14:26:45 +08:00
|
|
|
|
|
|
|
|
@onready var label: Label = $"%label"
|
|
|
|
|
@onready var animator: AnimationPlayer = $"%animator"
|
|
|
|
|
|
2025-08-26 13:56:12 +08:00
|
|
|
func _ready():
|
2025-08-28 13:59:01 +08:00
|
|
|
label.label_settings = label.label_settings.duplicate()
|
2025-09-17 06:44:12 +08:00
|
|
|
var damageValue = ceil(abs(damage))
|
2025-08-27 10:23:57 +08:00
|
|
|
var damageSign = sign(damage)
|
|
|
|
|
if damageSign > 0:
|
|
|
|
|
label.label_settings.font_color = color1
|
2025-11-09 10:56:13 +08:00
|
|
|
label.text = "%d%s" % [damageValue, "!!!" if crit else ""]
|
2025-08-27 10:23:57 +08:00
|
|
|
elif damageSign < 0:
|
|
|
|
|
label.label_settings.font_color = color2
|
2025-11-09 10:56:13 +08:00
|
|
|
label.text = "+%d%s" % [damageValue, "!!!" if crit else ""]
|
2025-08-26 14:26:45 +08:00
|
|
|
else:
|
2025-09-07 14:23:58 +08:00
|
|
|
if crit:
|
|
|
|
|
label.label_settings.font_color = color4
|
2025-09-07 14:29:11 +08:00
|
|
|
label.text = "完美闪避"
|
2025-09-07 14:23:58 +08:00
|
|
|
else:
|
|
|
|
|
label.label_settings.font_color = color3
|
2025-09-07 14:29:11 +08:00
|
|
|
label.text = "闪避"
|
2025-08-26 14:26:45 +08:00
|
|
|
animator.play("show")
|
|
|
|
|
await animator.animation_finished
|
|
|
|
|
queue_free()
|
2025-08-26 13:56:12 +08:00
|
|
|
|
|
|
|
|
static func create(spawnDamage: float, spawnCrit: bool, spawnPosition: Vector2, addToWorld: bool = true) -> DamageLabel:
|
2025-09-21 13:34:51 +08:00
|
|
|
var instance = ComponentManager.getUIComponent("DamageLabel").instantiate()
|
2025-08-26 13:56:12 +08:00
|
|
|
instance.damage = spawnDamage
|
|
|
|
|
instance.crit = spawnCrit
|
|
|
|
|
instance.position = spawnPosition
|
|
|
|
|
if addToWorld:
|
2025-08-26 17:28:20 +08:00
|
|
|
WorldManager.rootNode.add_child(instance)
|
2025-08-26 13:56:12 +08:00
|
|
|
return instance
|