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-09-30 17:32:15 +08:00
|
|
|
@export var enough: bool = true
|
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():
|
2025-09-30 17:32:15 +08:00
|
|
|
countLabel.label_settings = countLabel.label_settings.duplicate()
|
2025-08-28 06:54:08 +08:00
|
|
|
if autoFree:
|
2025-08-28 08:15:18 +08:00
|
|
|
animator.play("show")
|
|
|
|
|
await animator.animation_finished
|
2025-12-14 15:52:57 +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-09-30 17:32:15 +08:00
|
|
|
if enough:
|
|
|
|
|
countLabel.label_settings.font_color = Color.WHITE
|
|
|
|
|
else:
|
|
|
|
|
countLabel.label_settings.font_color = Color.RED
|
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 13:34:51 +08:00
|
|
|
var item = ComponentManager.getUIComponent("ItemShow").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
|