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