From a12c2018806c39c4a275abe6b50adc1b2ff28a77 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 21:58:57 +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=E4=BD=8D=E7=BD=AE=E4=BA=A4?= =?UTF-8?q?=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在ArrayTool中添加swap方法用于数组元素交换 - 为武器卡片添加左右移动按钮 - 实现武器位置交换逻辑,包括UI更新和数组同步 --- components/Abstracts/WeaponCardBase.tscn | 19 ++++++++++++++++--- scripts/Structs/Weapon.gd | 16 ++++++++++++++++ scripts/Tools/ArrayTool.gd | 7 ++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/components/Abstracts/WeaponCardBase.tscn b/components/Abstracts/WeaponCardBase.tscn index 07312ff..d988704 100644 --- a/components/Abstracts/WeaponCardBase.tscn +++ b/components/Abstracts/WeaponCardBase.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=9 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"] [ext_resource type="Texture2D" uid="uid://7jhhyoinptns" path="res://resources/items/soul.svg" id="6_tygah"] @@ -78,7 +77,6 @@ custom_minimum_size = Vector2(75, 75) layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 0 -texture = ExtResource("3_vtucy") expand_mode = 1 stretch_mode = 5 @@ -167,3 +165,18 @@ size_flags_vertical = 10 theme_override_constants/h_separation = 10 theme_override_constants/v_separation = 10 columns = 2 + +[node name="control" type="HBoxContainer" parent="container"] +layout_mode = 2 + +[node name="moveleft" type="Button" parent="container/control"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +text = "←" + +[node name="moveright" type="Button" parent="container/control"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +text = "→" diff --git a/scripts/Structs/Weapon.gd b/scripts/Structs/Weapon.gd index be76bf9..3336b34 100644 --- a/scripts/Structs/Weapon.gd +++ b/scripts/Structs/Weapon.gd @@ -30,6 +30,8 @@ class_name Weapon @onready var extractBtn: Button = $"%extractBtn" @onready var inlayBtn: Button = $"%inlayBtn" @onready var sounds: Node2D = $"%sounds" +@onready var moveLeftBtn: Button = $"%moveleft" +@onready var moveRightBtn: Button = $"%moveright" var cooldownTimer: CooldownTimer = null var originalStore: Dictionary = {} @@ -62,6 +64,20 @@ func _ready(): updateStore(level, UIState.player) rebuildInfo() ) + moveLeftBtn.pressed.connect( + func(): + var myIndex = get_index() + var leftIndex = max(myIndex - 1, 0) + get_parent().move_child(self, leftIndex) + ArrayTool.swap(UIState.player.weapons, myIndex, leftIndex) + UIState.player.rebuildWeaponIcons() + ) + moveRightBtn.pressed.connect( + func(): + var myIndex = get_index() + var rightIndex = min(myIndex + 1, get_parent().get_child_count() - 1) + get_parent().move_child(self, rightIndex) + ) for i in sounds.get_children(): i.process_mode = ProcessMode.PROCESS_MODE_ALWAYS rebuildInfo() diff --git a/scripts/Tools/ArrayTool.gd b/scripts/Tools/ArrayTool.gd index aa49d2a..793ad20 100644 --- a/scripts/Tools/ArrayTool.gd +++ b/scripts/Tools/ArrayTool.gd @@ -5,4 +5,9 @@ static func removeAll(array: Array, value) -> Array: for item in array: if item != value: result.append(item) - return result \ No newline at end of file + return result +static func swap(array: Array, a: int, b: int): + var temp = array[a] + array[a] = array[b] + array[b] = temp + return array