1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-06-06 19:57:12 +08:00

feat(武器系统): 添加武器位置交换功能

- 在ArrayTool中添加swap方法用于数组元素交换
- 为武器卡片添加左右移动按钮
- 实现武器位置交换逻辑,包括UI更新和数组同步
This commit is contained in:
2025-09-21 21:58:57 +08:00
parent cc75192e2e
commit a12c201880
3 changed files with 38 additions and 4 deletions
+16
View File
@@ -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()
+6 -1
View File
@@ -5,4 +5,9 @@ static func removeAll(array: Array, value) -> Array:
for item in array:
if item != value:
result.append(item)
return result
return result
static func swap(array: Array, a: int, b: int):
var temp = array[a]
array[a] = array[b]
array[b] = temp
return array