89 lines
2.5 KiB
GDScript
89 lines
2.5 KiB
GDScript
extends Control
|
|
|
|
|
|
@export var items:Array = []
|
|
|
|
|
|
@export var active_item:Dictionary = {}
|
|
|
|
@onready var old_slot:int = 0
|
|
@onready var current_slot:int = 0
|
|
@onready var slot_container = $Panel/HBoxContainer
|
|
|
|
signal active_item_changed(active_item)
|
|
|
|
func _process(_delta):
|
|
if current_slot == 0:
|
|
return
|
|
if Input.is_action_just_pressed("drop_item"):
|
|
drop_item()
|
|
if Input.is_action_just_released("cycle_down"):
|
|
var new_slot = current_slot + 1
|
|
if new_slot == 6:
|
|
new_slot = 1
|
|
if new_slot > len(items):
|
|
new_slot = 1
|
|
set_active_slot(new_slot)
|
|
if Input.is_action_just_released("cycle_up"):
|
|
var new_slot = current_slot - 1
|
|
if new_slot == 0:
|
|
new_slot = len(items)
|
|
set_active_slot(new_slot)
|
|
|
|
|
|
func add_inventory_item(new_item: Dictionary):
|
|
if len(items) == 6:
|
|
drop_item(true)
|
|
items.append(new_item)
|
|
var slot = get_node("Panel/HBoxContainer/InventorySlot" + str(len(items)))
|
|
slot.setup_slot(new_item)
|
|
if len(items) == 1:
|
|
set_active_slot(len(items))
|
|
|
|
|
|
func drop_item(replace: bool = false):
|
|
print("CURRENT SLOT: ", current_slot)
|
|
var clear_slot = current_slot
|
|
if items[clear_slot]:
|
|
# TODO: Here we would spawn the item in
|
|
items.remove_at(clear_slot)
|
|
print("NEW ITEM ARRAY! ", items)
|
|
if not replace:
|
|
# old_slot = current_slot
|
|
# current_slot = current_slot - 1
|
|
# if current_slot > -1:
|
|
# active_item = items[current_slot]
|
|
# else:
|
|
# active_item = {}
|
|
var slot = get_node("$Panel/HBoxContainer/InventorySlot" + str(current_slot))
|
|
slot.clear_slot()
|
|
set_active_slot(clear_slot)
|
|
|
|
func set_active_slot(slot_index: int):
|
|
print("CURRENT SLOT: ", current_slot, " SLOT INDEX: ", slot_index)
|
|
if current_slot != slot_index and current_slot != 0:
|
|
var old_slot = get_node("Panel/HBoxContainer/InventorySlot" + str(current_slot))
|
|
old_slot.slot_deselected()
|
|
#old_slot.slot_deselected.rpc_id(multiplayer.get_unique_id())
|
|
if len(items) == 0:
|
|
active_item = {}
|
|
current_slot = 0
|
|
else:
|
|
var slot = get_node("Panel/HBoxContainer/InventorySlot" + str(slot_index))
|
|
slot.slot_selected()
|
|
#slot.slot_selected.rpc_id(multiplayer.get_unique_id())
|
|
current_slot = slot_index
|
|
active_item = items[current_slot - 1]
|
|
emit_signal("active_item_changed", active_item)
|
|
|
|
|
|
|
|
#func set_active_slot():
|
|
# if current_slot == -1:
|
|
# return
|
|
# var old_slot = get_node("Panel/HBoxContainer/InventorySlot" + str(old_slot))
|
|
# old_slot.slot_deselected.rpc_id(get_multiplayer_authority())
|
|
# var slot = get_node("Panel/HBoxContainer/InventorySlot" + str(current_slot))
|
|
# slot.slot_selected.rpc_id(get_multiplayer_authority())
|
|
|