59 lines
1.8 KiB
GDScript
59 lines
1.8 KiB
GDScript
extends Window
|
|
|
|
@onready var inventoryItemDisplayer = %Inventory
|
|
|
|
var itemTransitionScene = preload("res://UI/Sugaring/ItemFadeTransition.tscn")
|
|
|
|
var fallingAnimPositions = []
|
|
var fallingAnimPosIndex = 0
|
|
var playerInventory:Inventory
|
|
|
|
func _ready():
|
|
fallingAnimPositions.append(Vector2(444, 280))
|
|
fallingAnimPositions.append(Vector2(414, 260))
|
|
fallingAnimPositions.append(Vector2(470, 265))
|
|
|
|
inventoryItemDisplayer.fiveButtons = true
|
|
inventoryItemDisplayer.allButtons = true
|
|
|
|
inventoryItemDisplayer.buttonPressed.connect(drop_item)
|
|
inventoryItemDisplayer.fiveButtonPressed.connect(drop_item.bind(5))
|
|
inventoryItemDisplayer.allButtonPressed.connect(drop_item.bind(999999))
|
|
|
|
func opened():
|
|
get_tree().paused = true
|
|
playerInventory = InventoryManager.get_inventory()
|
|
inventoryItemDisplayer.inventory = filter_inventory(playerInventory)
|
|
inventoryItemDisplayer.update_display()
|
|
|
|
func drop_item(item:Item, quantity:int = 1):
|
|
var itemsInInv = InventoryManager.get_item_count(item)
|
|
if itemsInInv < quantity:
|
|
quantity = itemsInInv
|
|
|
|
InventoryManager.remove_item_from_inventory(item, quantity)
|
|
InventoryManager.add_item_to_inventory(item, quantity, "HoleInventory")
|
|
|
|
drop_item_animation(item)
|
|
|
|
inventoryItemDisplayer.inventory = filter_inventory(playerInventory)
|
|
inventoryItemDisplayer.update_display()
|
|
|
|
func drop_item_animation(item):
|
|
var fallAnimation = preload("res://UI/Hole/ItemFallingTransition.tscn").instantiate()
|
|
fallAnimation.start_transition(item.get_sprite())
|
|
fallAnimation.position = fallingAnimPositions[fallingAnimPosIndex]
|
|
|
|
fallingAnimPosIndex += 1
|
|
if fallingAnimPosIndex >= fallingAnimPositions.size():
|
|
fallingAnimPosIndex = 0
|
|
add_child(fallAnimation)
|
|
|
|
func filter_inventory(inventory):
|
|
var filteredInv:Inventory = inventory.duplicate()
|
|
return filteredInv
|
|
|
|
func _on_leave_button_pressed():
|
|
get_tree().paused = false
|
|
hide()
|