From e5b23e7715326ca997df410a5ebcfaee6b8ac9e8 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: Sun, 21 Sep 2025 16:49:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=AD=A6=E5=99=A8=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=AD=A6=E5=99=A8=E8=83=8C=E5=8C=85=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=8F=8A=E6=AD=A6=E5=99=A8=E5=B1=95=E7=A4=BA=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现武器背包功能,用于存储已获得的武器名称。新增WeaponShow组件,根据操作类型显示不同的武器信息。修改Feed.gd以支持武器展示逻辑,包括获取和提炼两种操作状态。 --- components/UI/WeaponShow.tscn | 25 +++++++++++++++++++---- scripts/Statemachine/EntityBase.gd | 2 ++ scripts/Statemachine/WeaponShow.gd | 32 ++++++++++++++++++++++++++++++ scripts/Structs/Feed.gd | 9 +++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 scripts/Statemachine/WeaponShow.gd diff --git a/components/UI/WeaponShow.tscn b/components/UI/WeaponShow.tscn index 2cc4a9b..9d31994 100644 --- a/components/UI/WeaponShow.tscn +++ b/components/UI/WeaponShow.tscn @@ -1,26 +1,43 @@ -[gd_scene load_steps=3 format=3 uid="uid://c7747qr83iojj"] +[gd_scene load_steps=6 format=3 uid="uid://c7747qr83iojj"] [ext_resource type="Theme" uid="uid://b6nox1qqh50ub" path="res://themes/smallText.tres" id="1_ua7kx"] +[ext_resource type="Script" path="res://scripts/Statemachine/WeaponShow.gd" id="2_cojxr"] [ext_resource type="PackedScene" uid="uid://bbm8l3hr4ihar" path="res://components/UI/ItemShow.tscn" id="2_yqc2h"] +[ext_resource type="PackedScene" uid="uid://b2qhes4apaxsj" path="res://components/Weapons/NuclearBomb.tscn" id="3_gh1wm"] +[ext_resource type="Texture2D" uid="uid://cp57lmeohvo3o" path="res://resources/weapons/nuclear-bomb.png" id="4_yyc4p"] [node name="WeaponShow" type="HBoxContainer"] offset_right = 189.0 offset_bottom = 22.0 theme = ExtResource("1_ua7kx") +script = ExtResource("2_cojxr") +weapon = ExtResource("3_gh1wm") [node name="operation" type="Label" parent="."] unique_name_in_owner = true layout_mode = 2 -text = "获得/提炼" +text = "提炼" + +[node name="avatar" type="TextureRect" parent="."] +unique_name_in_owner = true +visible = false +custom_minimum_size = Vector2(20, 20) +layout_mode = 2 +size_flags_horizontal = 10 +size_flags_vertical = 4 +texture = ExtResource("4_yyc4p") +expand_mode = 1 +stretch_mode = 5 [node name="name" type="Label" parent="."] unique_name_in_owner = true +visible = false layout_mode = 2 -size_flags_horizontal = 10 -text = "武器名称" +text = "核弹控制器" [node name="soul" parent="." instance=ExtResource("2_yqc2h")] unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 10 type = 4 +count = 1 diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index f948d73..c7f062f 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -98,6 +98,7 @@ var lastDirection: int = 1 var currentFocusedBoss: EntityBase = null var charginup: bool = false var weapons: Array[Weapon] = [] +var weaponBag: Array[String] = [] var canRunAi: bool = true var currentStage: int = 0 var spawnTime: float = 0 @@ -115,6 +116,7 @@ func _ready(): for i in weaponStore.get_children(): i.hide() weapons.append(i) + weaponBag.append(i.displayName) statebar.levelLabels.hide() UIState.player = self energyChanged.connect( diff --git a/scripts/Statemachine/WeaponShow.gd b/scripts/Statemachine/WeaponShow.gd new file mode 100644 index 0000000..38eed6b --- /dev/null +++ b/scripts/Statemachine/WeaponShow.gd @@ -0,0 +1,32 @@ +@tool +extends HBoxContainer +class_name WeaponShow + +enum Operation { + GET, + EXTRACT, +} + +@export var weapon: PackedScene = null +@export var operation: Operation = Operation.GET + +@onready var operationLabel: Label = $"%operation" +@onready var avatarRect: TextureRect = $"%avatar" +@onready var nameLabel: Label = $"%name" +@onready var soulShow: ItemShow = $"%soul" + +func _ready(): + var weaponInstance = weapon.instantiate() as Weapon + avatarRect.texture = weaponInstance.avatarTexture + nameLabel.text = weaponInstance.displayName + soulShow.count = weaponInstance.soulLevel + if operation == Operation.GET: + operationLabel.text = "获得" + avatarRect.visible = true + nameLabel.visible = true + soulShow.visible = false + else: + operationLabel.text = "提炼" + avatarRect.visible = false + nameLabel.visible = false + soulShow.visible = true diff --git a/scripts/Structs/Feed.gd b/scripts/Structs/Feed.gd index 648cff0..e04b146 100644 --- a/scripts/Structs/Feed.gd +++ b/scripts/Structs/Feed.gd @@ -79,6 +79,15 @@ func rebuildInfo(): fieldsBox.add_child(fieldShow) if noField: fieldsBox.add_child(QuickUI.smallText("无词条")) + for i in weaponsBox.get_children(): + i.queue_free() + for weapon in weapons: + var weaponShow: WeaponShow = ComponentManager.getUIComponent("WeaponShow").instantiate() + weaponShow.weapon = weapon + if is_instance_valid(UIState.player): + weaponShow.operation = WeaponShow.Operation.EXTRACT if UIState.player.weaponBag.has(weapon.instantiate().displayName) else WeaponShow.Operation.GET + weaponShow.visible = true + weaponsBox.add_child(weaponShow) for i in costsBox.get_children(): i.queue_free() for i in range(min(costs.size(), costCounts.size())):