mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
feat(武器系统): 添加武器位置交换功能
- 在ArrayTool中添加swap方法用于数组元素交换 - 为武器卡片添加左右移动按钮 - 实现武器位置交换逻辑,包括UI更新和数组同步
This commit is contained in:
@@ -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 = "→"
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user