From a083069848846b42e4ad1add25d3a700b61f8127 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: Sat, 6 Sep 2025 11:14:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=AD=A6=E5=99=A8=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=AD=A6=E5=99=A8=E6=B6=88=E8=80=97=E4=B8=BA?= =?UTF-8?q?=E5=8D=95=E4=B8=80=E6=B2=99=E6=BB=A9=E7=90=83=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=8D=87=E7=BA=A7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将武器消耗从多种资源数组简化为单一沙滩球资源 添加武器升级功能,更新武器属性时保留原始属性 修改UI显示以适配新的资源消耗系统 --- components/Abstracts/WeaponCardBase.tscn | 34 ++++++++++++++++--- project.godot | 5 +++ scripts/Structs/Weapon.gd | 43 +++++++----------------- 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/components/Abstracts/WeaponCardBase.tscn b/components/Abstracts/WeaponCardBase.tscn index c0d5f51..ea4d75f 100644 --- a/components/Abstracts/WeaponCardBase.tscn +++ b/components/Abstracts/WeaponCardBase.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=7 format=3 uid="uid://ckq2cq6m23hq3"] +[gd_scene load_steps=8 format=3 uid="uid://ckq2cq6m23hq3"] [ext_resource type="Script" path="res://scripts/Structs/Weapon.gd" id="1_g802t"] [ext_resource type="Theme" uid="uid://dhvs6urgf6jr5" path="res://themes/main.tres" id="2_fwkd3"] [ext_resource type="PackedScene" uid="uid://ch81vd3awkmhk" path="res://components/UI/WeaponName.tscn" id="3_qv0b1"] [ext_resource type="Texture2D" uid="uid://dwwpkn4q07ja2" path="res://icon.svg" id="3_vtucy"] [ext_resource type="Texture2D" uid="uid://k13cte17httt" path="res://resources/items/energy.svg" id="4_6gohw"] +[ext_resource type="Texture2D" uid="uid://dw0g7cb4skd5s" path="res://resources/items/beachball.svg" id="5_pr18h"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_n2ewr"] content_margin_left = 30.0 @@ -27,6 +28,7 @@ offset_right = 350.0 offset_bottom = 304.0 theme_override_styles/panel = SubResource("StyleBoxFlat_n2ewr") script = ExtResource("1_g802t") +costBeachball = 100 metadata/_edit_lock_ = true [node name="sounds" type="Node2D" parent="."] @@ -60,11 +62,16 @@ texture = ExtResource("3_vtucy") expand_mode = 1 stretch_mode = 5 -[node name="energyInfo" type="HBoxContainer" parent="container/info"] +[node name="infos" type="HBoxContainer" parent="container/info"] +layout_mode = 2 +theme_override_constants/separation = 20 +alignment = 1 + +[node name="energyInfo" type="HBoxContainer" parent="container/info/infos"] layout_mode = 2 alignment = 1 -[node name="icon" type="TextureRect" parent="container/info/energyInfo"] +[node name="icon" type="TextureRect" parent="container/info/infos/energyInfo"] custom_minimum_size = Vector2(15, 15) layout_mode = 2 size_flags_horizontal = 4 @@ -73,16 +80,33 @@ texture = ExtResource("4_6gohw") expand_mode = 1 stretch_mode = 5 -[node name="energy" type="Label" parent="container/info/energyInfo"] +[node name="energy" type="Label" parent="container/info/infos/energyInfo"] unique_name_in_owner = true layout_mode = 2 text = "0.0" +[node name="beachballInfo" type="HBoxContainer" parent="container/info/infos"] +layout_mode = 2 +alignment = 1 + +[node name="icon" type="TextureRect" parent="container/info/infos/beachballInfo"] +custom_minimum_size = Vector2(15, 15) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +texture = ExtResource("5_pr18h") +expand_mode = 1 +stretch_mode = 5 + +[node name="beachball" type="Label" parent="container/info/infos/beachballInfo"] +unique_name_in_owner = true +layout_mode = 2 +text = "100" + [node name="name" parent="container/info" instance=ExtResource("3_qv0b1")] unique_name_in_owner = true layout_mode = 2 displayName = "未命名饲料" -quality = 1 [node name="description" type="RichTextLabel" parent="container"] unique_name_in_owner = true diff --git a/project.godot b/project.godot index 476bdf3..2ba9343 100644 --- a/project.godot +++ b/project.godot @@ -77,6 +77,11 @@ pause={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":80,"key_label":0,"unicode":112,"location":0,"echo":false,"script":null) ] } +openWeapon={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null) +] +} [physics] diff --git a/scripts/Structs/Weapon.gd b/scripts/Structs/Weapon.gd index 14f2bde..3ac5b1a 100644 --- a/scripts/Structs/Weapon.gd +++ b/scripts/Structs/Weapon.gd @@ -2,14 +2,11 @@ extends PanelContainer class_name Weapon -signal selected(applied: bool) - @export var avatarTexture: Texture2D = preload("res://icon.svg") @export var displayName: String = "未命名饲料" @export var quality: WeaponName.Quality = WeaponName.Quality.COMMON @export var typeTopic: WeaponName.TypeTopic = WeaponName.TypeTopic.IMPACT -@export var costs: Array[ItemStore.ItemType] = [] -@export var costCounts: Array[int] = [] +@export var costBeachball: int = 0 @export var store: Dictionary = { "atk": 10 } @@ -20,18 +17,21 @@ signal selected(applied: bool) @export var needEnergy: float = 0 @export var cooldown: float = 100 @export var debugRebuild: bool = false +@export var level: int = 0 @onready var avatarRect: TextureRect = $"%avatar" @onready var nameLabel: WeaponName = $"%name" @onready var energyLabel: Label = $"%energy" +@onready var beachballLabel: Label = $"%beachball" @onready var descriptionLabel: RichTextLabel = $"%description" -@onready var costsBox: GridContainer = $"%costs" @onready var updateButton: Button = $"%updateBtn" @onready var sounds: Node2D = $"%sounds" var cooldownTimer = CooldownTimer.new() +var originalStore: Dictionary = {} func _ready(): + originalStore = store updateButton.pressed.connect( func(): apply(UIState.player) @@ -46,23 +46,12 @@ func _physics_process(_delta): rebuildInfo() func allHad(entity: EntityBase) -> bool: - var allHave = true - for i in range(min(costs.size(), costCounts.size())): - var item = costs[i] - var count = costCounts[i] * multipiler() - if entity.inventory[item] < count: - allHave = false - break - return allHave + return entity.inventory[ItemStore.ItemType.BEACHBALL] >= costBeachball func apply(entity: EntityBase): var allHave = allHad(entity) if allHave: - for i in range(min(costs.size(), costCounts.size())): - var item = costs[i] - var count = costCounts[i] * multipiler() - entity.inventory[item] -= count - hide() - selected.emit(allHave) + entity.inventory[ItemStore.ItemType.BEACHBALL] -= costBeachball + store = update(level + 1, originalStore.duplicate(), entity) return allHave func multipiler() -> float: if is_instance_valid(UIState.player): @@ -75,17 +64,9 @@ func rebuildInfo(): nameLabel.quality = quality nameLabel.typeTopic = typeTopic energyLabel.text = "%.1f" % needEnergy + beachballLabel.text = str(costBeachball) descriptionLabel.text = buildDescription() - for i in costsBox.get_children(): - i.queue_free() - for i in range(min(costs.size(), costCounts.size())): - var cost = costs[i] - var count = costCounts[i] - var costShow: ItemShow = preload("res://components/UI/ItemShow.tscn").instantiate() - costShow.type = cost - costShow.count = int(count * multipiler()) - costsBox.add_child(costShow) -func buildDescription(): +func buildDescription() -> String: var result = descriptionTemplate var i = 0 for key in store.keys(): @@ -116,7 +97,7 @@ func tryAttack(entity: EntityBase): return attack(entity) # 抽象 -func update(_to: int, _origin: Dictionary, _entity: EntityBase): - pass +func update(_to: int, origin: Dictionary, _entity: EntityBase): + return origin func attack(_entity: EntityBase): pass