2025-08-26 18:09:04 +08:00
|
|
|
@tool
|
|
|
|
|
extends HBoxContainer
|
2025-08-26 18:44:28 +08:00
|
|
|
class_name ItemShow
|
2025-08-26 18:09:04 +08:00
|
|
|
|
|
|
|
|
@export var type: ItemStore.ItemType = ItemStore.ItemType.BASEBALL
|
|
|
|
|
@export var count: int = 0
|
2025-08-28 06:54:08 +08:00
|
|
|
@export var autoFree: bool = false
|
2025-08-26 18:09:04 +08:00
|
|
|
|
|
|
|
|
@onready var avatarTexture: TextureRect = $"%avatar"
|
|
|
|
|
@onready var countLabel: Label = $"%count"
|
2025-08-28 06:54:08 +08:00
|
|
|
@onready var animator: AnimationPlayer = $"%animator"
|
2025-08-26 18:09:04 +08:00
|
|
|
|
2025-08-28 06:54:08 +08:00
|
|
|
func _ready():
|
|
|
|
|
if autoFree:
|
2025-08-28 08:15:18 +08:00
|
|
|
animator.play("show")
|
|
|
|
|
await animator.animation_finished
|
2025-08-28 15:03:12 +08:00
|
|
|
await TickTool.millseconds(GameRule.itemShowLifetime) # 等待几秒后自动隐藏
|
2025-08-28 06:54:08 +08:00
|
|
|
animator.play("hide")
|
|
|
|
|
await animator.animation_finished
|
|
|
|
|
queue_free()
|
2025-08-27 08:09:47 +08:00
|
|
|
func _physics_process(_delta):
|
2025-08-26 20:46:02 +08:00
|
|
|
avatarTexture.texture = ItemStore.getTexture(type)
|
2025-08-26 18:09:04 +08:00
|
|
|
countLabel.text = str(count)
|
2025-08-28 06:49:50 +08:00
|
|
|
|
2025-08-28 06:55:18 +08:00
|
|
|
static func generate(itemType: ItemStore.ItemType, itemCount: int = 1, isAutoFree: bool = false):
|
2025-09-21 12:53:15 +08:00
|
|
|
var item = load("res://components/UI/ItemShow.tscn").instantiate()
|
2025-08-28 06:49:50 +08:00
|
|
|
item.type = itemType
|
|
|
|
|
item.count = itemCount
|
2025-08-28 06:55:18 +08:00
|
|
|
item.autoFree = isAutoFree
|
2025-08-28 06:49:50 +08:00
|
|
|
return item
|