forked from peter-kish/gloot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory_transfer.gd
53 lines (38 loc) · 1.82 KB
/
inventory_transfer.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
extends Control
@onready var inventory_left: Inventory = $Inventory
@onready var inventory_right: Inventory = $Inventory2
@onready var btn_left_to_right: Button = $VBoxContainer/HBoxContainer2/BtnLToR
@onready var btn_right_to_left: Button = $VBoxContainer/HBoxContainer2/BtnRToL
@onready var btn_equip: Button = $VBoxContainer/HBoxContainer3/HBoxContainer/BtnEquipL
@onready var btn_unequip: Button = $VBoxContainer/HBoxContainer3/HBoxContainer/BtnUnequipL
@onready var ctrl_inventory_left: CtrlInventory = $VBoxContainer/HBoxContainer/CtrlInventory
@onready var ctrl_inventory_right: CtrlInventory = $VBoxContainer/HBoxContainer/CtrlInventory2
@onready var slot: ItemSlot = $ItemSlot
func _ready() -> void:
btn_left_to_right.pressed.connect(_on_ltor_pressed)
btn_right_to_left.pressed.connect(_on_rtol_pressed)
btn_equip.pressed.connect(_on_equip_pressed)
btn_unequip.pressed.connect(_on_unequip_pressed)
func _on_ltor_pressed() -> void:
var selected_items: Array[InventoryItem] = ctrl_inventory_left.get_selected_inventory_items()
if selected_items.is_empty():
return
for selected_item in selected_items:
inventory_left.transfer(selected_item, inventory_right)
func _on_rtol_pressed() -> void:
var selected_items: Array[InventoryItem] = ctrl_inventory_right.get_selected_inventory_items()
if selected_items.is_empty():
return
for selected_item in selected_items:
inventory_right.transfer(selected_item, inventory_left)
func _on_equip_pressed() -> void:
if slot.get_item() != null:
return
var item: InventoryItem = ctrl_inventory_left.get_selected_inventory_item()
if item == null:
return
slot.equip(item)
func _on_unequip_pressed() -> void:
if slot.get_item() != null:
inventory_left.add_item(slot.get_item())
slot.clear()