Added Inventory System

This commit is contained in:
2026-08-29 23:24:04 +01:00
parent 00f9448329
commit 7df4adec93
60 changed files with 4283 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
extends Resource
class_name InventoryGD
@export var size: int = 36
@export var slots : Array[InventorySlotDataGD] = [] # Data regarding what's in each slot
+1
View File
@@ -0,0 +1 @@
uid://dila5f4tuiun1
@@ -0,0 +1,5 @@
extends Resource
class_name InventorySlotDataGD
@export var item: ItemDataGD
@export var count: int
@@ -0,0 +1 @@
uid://mv6k4s5wf52h
+64
View File
@@ -0,0 +1,64 @@
extends Panel
class_name InventorySlotGD
@onready var icon_rect: TextureRect = $Icon
@onready var count_label: Label = $CountLabel
@export var slot_data : InventorySlotDataGD # Slot data as defined in the InventoryGD class
@export var slot_index: int
@export var main_inventory: InventoryGD
# Refresh the current slot with the data of it's inventory slot
func refresh():
if (slot_index < main_inventory.slots.size()):
slot_data = main_inventory.slots[slot_index]
if slot_data == null:
icon_rect.texture = null
count_label.text = ""
else:
icon_rect.texture = slot_data.item.icon
count_label.text = str(slot_data.count) if slot_data.count > 1 else ""
# Handle Item being dragged elsewhere
func _get_drag_data(at_position: Vector2) -> Variant:
if slot_data == null:
return null
# Create a preview of the item being dragged
var preview = TextureRect.new()
preview.texture = slot_data.item.icon
preview.custom_minimum_size = Vector2(32,32)
set_drag_preview(preview)
var data = { "from_slot": slot_index, "payload": slot_data }
return data
func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
return typeof(data) == TYPE_DICTIONARY and data.has("from_slot")
# Can we drop the item where we are?
func _drop_data(_pos, data):
var from_index = data.from_slot
# Swap the 2 indexes
var temp = main_inventory.slots[slot_index]
main_inventory.slots[slot_index] = main_inventory.slots[from_index]
main_inventory.slots[from_index] = temp
# Call the refresh method for all objects that belong in the inventory_slots group
get_tree().call_group("inventory_slots", "refresh")
func initialize_slot(index: int, inventory: InventoryGD):
slot_index = index
main_inventory = inventory
if index < main_inventory.slots.size():
var inventory_slot = main_inventory.slots[slot_index]
if inventory_slot != null :
slot_data = inventory_slot
refresh()
@@ -0,0 +1 @@
uid://b0uy0my40tjsv
+7
View File
@@ -0,0 +1,7 @@
extends Resource
class_name ItemDataGD
@export var id: String
@export var display_name: String
@export var icon: Texture2D
@export var max_stack: int = 64
+1
View File
@@ -0,0 +1 @@
uid://b8cygu5gimsgi