From ac809194e7906e943d1148e812983cb1754ff2f8 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 06:54:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(ItemShow):=20=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=9A=90=E8=97=8F=E5=8A=A8=E7=94=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加autoFree选项和动画播放逻辑,当autoFree为true时自动播放隐藏动画并释放节点 --- components/UI/ItemShow.tscn | 67 +++++++++++++++++++++++++++++++- scripts/Statemachine/ItemShow.gd | 7 ++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/components/UI/ItemShow.tscn b/components/UI/ItemShow.tscn index 9930484..e6d3f73 100644 --- a/components/UI/ItemShow.tscn +++ b/components/UI/ItemShow.tscn @@ -1,9 +1,68 @@ -[gd_scene load_steps=3 format=3 uid="uid://bbm8l3hr4ihar"] +[gd_scene load_steps=6 format=3 uid="uid://bbm8l3hr4ihar"] [ext_resource type="Script" path="res://scripts/Statemachine/ItemShow.gd" id="1_2dhsb"] [ext_resource type="Texture2D" uid="uid://bks8jmctleina" path="res://resources/items/baseball.svg" id="1_hyowb"] +[sub_resource type="Animation" id="Animation_ltvf2"] +resource_name = "hide" +length = 0.5 +tracks/0/type = "bezier" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:scale:x") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"handle_modes": PackedInt32Array(0, 0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0, 1e-05, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0, 0.5) +} +tracks/1/type = "bezier" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath(".:modulate:a") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"handle_modes": PackedInt32Array(0, 0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0, 0.5) +} + +[sub_resource type="Animation" id="Animation_6sxrr"] +length = 0.001 +tracks/0/type = "bezier" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:scale:x") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/1/type = "bezier" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath(".:modulate:a") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_xbbtb"] +_data = { +"RESET": SubResource("Animation_6sxrr"), +"hide": SubResource("Animation_ltvf2") +} + [node name="ItemShow" type="HBoxContainer"] +offset_right = 34.0 +offset_bottom = 20.0 size_flags_horizontal = 6 size_flags_vertical = 6 script = ExtResource("1_2dhsb") @@ -23,3 +82,9 @@ layout_mode = 2 size_flags_horizontal = 0 size_flags_vertical = 8 text = "0" + +[node name="animator" type="AnimationPlayer" parent="."] +unique_name_in_owner = true +libraries = { +"": SubResource("AnimationLibrary_xbbtb") +} diff --git a/scripts/Statemachine/ItemShow.gd b/scripts/Statemachine/ItemShow.gd index 7220fc6..cdda528 100644 --- a/scripts/Statemachine/ItemShow.gd +++ b/scripts/Statemachine/ItemShow.gd @@ -4,10 +4,17 @@ class_name ItemShow @export var type: ItemStore.ItemType = ItemStore.ItemType.BASEBALL @export var count: int = 0 +@export var autoFree: bool = false @onready var avatarTexture: TextureRect = $"%avatar" @onready var countLabel: Label = $"%count" +@onready var animator: AnimationPlayer = $"%animator" +func _ready(): + if autoFree: + animator.play("hide") + await animator.animation_finished + queue_free() func _physics_process(_delta): avatarTexture.texture = ItemStore.getTexture(type) countLabel.text = str(count)