mirror of
https://github.com/D4M13N-D3V/godot_grid_inventory.git
synced 2025-03-14 08:14:55 +00:00
feat added support for multiple grids at once and being able to drag items between them
This commit is contained in:
parent
4ff0b3c25b
commit
fdf73ac404
@ -2,10 +2,10 @@
|
||||
|
||||
[ext_resource type="Script" path="res://grid_inventory_system/scripts/InventoryController.gd" id="1_hmtt6"]
|
||||
[ext_resource type="Script" path="res://grid_inventory_system/scripts/InventoryGrid.gd" id="2_8imhp"]
|
||||
[ext_resource type="Script" path="res://grid_inventory_system/scripts/ItemEquipmentSlots.gd" id="3_sri3o"]
|
||||
[ext_resource type="Script" path="res://grid_inventory_system/scripts/ItemSlot.gd" id="3_sri3o"]
|
||||
[ext_resource type="PackedScene" uid="uid://c2c7v5idagdqr" path="res://grid_inventory_system/debug/debug_ui.tscn" id="4_abx0e"]
|
||||
|
||||
[node name="Inventory" type="Control" node_paths=PackedStringArray("inventory_grid", "inventory_background", "inventory_equipment_slots")]
|
||||
[node name="Inventory" type="Control" node_paths=PackedStringArray("inventory_grid", "inventory_loot_grid", "inventory_background", "inventory_equipment_slots")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
@ -14,6 +14,7 @@ grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_hmtt6")
|
||||
inventory_grid = NodePath("UI/Background/Items")
|
||||
inventory_loot_grid = NodePath("UI/Background/ColorRect/LootItems")
|
||||
inventory_background = NodePath("UI/Background")
|
||||
inventory_equipment_slots = NodePath("UI/Background/Equipment")
|
||||
|
||||
@ -26,9 +27,9 @@ anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -473.5
|
||||
offset_top = -235.5
|
||||
offset_top = -462.0
|
||||
offset_right = 473.5
|
||||
offset_bottom = 235.5
|
||||
offset_bottom = 9.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0.121569, 0.121569, 0.121569, 1)
|
||||
@ -84,6 +85,29 @@ offset_bottom = 194.0
|
||||
grow_vertical = 2
|
||||
color = Color(0.278431, 0.278431, 0.278431, 1)
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="UI/Background"]
|
||||
offset_left = -3.0
|
||||
offset_top = 470.0
|
||||
offset_right = 711.0
|
||||
offset_bottom = 717.0
|
||||
color = Color(0.105882, 0.105882, 0.105882, 0.905882)
|
||||
|
||||
[node name="LootItems" type="ColorRect" parent="UI/Background/ColorRect"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 9
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 15.0
|
||||
offset_top = 8.0
|
||||
offset_right = 704.0
|
||||
offset_bottom = -14.0
|
||||
grow_vertical = 2
|
||||
color = Color(0.164706, 0.164706, 0.164706, 1)
|
||||
script = ExtResource("2_8imhp")
|
||||
inventory_item_grid_width = 21
|
||||
inventory_item_grid_height = 7
|
||||
inventory_grid_default_color = Color(1, 1, 1, 1)
|
||||
inventory_grid_used_color = Color(0, 1, 0, 1)
|
||||
|
||||
[node name="Items" type="ColorRect" parent="UI/Background"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 9
|
||||
|
@ -8,6 +8,7 @@ const ITEM_BASE = preload("res://grid_inventory_system/scenes/Item.tscn")
|
||||
@export var inventory_grab_input:String = "inventory_grab"
|
||||
@export var inventory_rotate_input:String = "inventory_rotate"
|
||||
@export var inventory_grid:Control
|
||||
@export var inventory_loot_grid:Control
|
||||
@export var inventory_background:Control
|
||||
@export var inventory_equipment_slots:Control
|
||||
|
||||
@ -107,6 +108,8 @@ func _get_container_mouse_over():
|
||||
|
||||
if(_is_mouse_ontop_of_control(inventory_grid)==true):
|
||||
return inventory_grid
|
||||
elif(_is_mouse_ontop_of_control(inventory_loot_grid)==true):
|
||||
return inventory_loot_grid
|
||||
elif(_is_mouse_ontop_of_control(inventory_equipment_slots)==true):
|
||||
return inventory_equipment_slots
|
||||
elif(_is_mouse_ontop_of_control(inventory_background)==true):
|
||||
|
@ -37,7 +37,7 @@ func _ready():
|
||||
|
||||
# Function to insert an item into the inventory grid
|
||||
func insert_item(item):
|
||||
var item_pos = item.position
|
||||
var item_pos = item.global_position-global_position
|
||||
var g_pos = pos_to_grid_coord(item_pos)
|
||||
var item_size = get_grid_size(item)
|
||||
|
||||
@ -45,6 +45,9 @@ func insert_item(item):
|
||||
if is_grid_space_available(g_pos.x, g_pos.y, item_size.x, item_size.y)==true:
|
||||
set_grid_space(g_pos.x, g_pos.y, item_size.x, item_size.y, true)
|
||||
item.position = Vector2(g_pos.x, g_pos.y) * inventory_item_grid_cell_size
|
||||
var parent = item.get_parent()
|
||||
if(parent!=null):
|
||||
parent.remove_child(item)
|
||||
add_child(item)
|
||||
inventory_item_grid_items.append(item)
|
||||
return true
|
||||
@ -77,7 +80,7 @@ func use_item(pos):
|
||||
item.queue_free()
|
||||
|
||||
var item_size = get_grid_size(item)
|
||||
var item_pos = item.position
|
||||
var item_pos = position-item.position
|
||||
var g_pos = pos_to_grid_coord(item_pos)
|
||||
inventory_item_grid_items.remove_at(inventory_item_grid_items.find(item))
|
||||
set_grid_space(g_pos.x, g_pos.y, item_size.x, item_size.y, false)
|
||||
@ -85,8 +88,10 @@ func use_item(pos):
|
||||
# Function to convert global position to grid coordinates
|
||||
func pos_to_grid_coord(pos):
|
||||
var results = {}
|
||||
results.x = int(pos.x / inventory_item_grid_cell_size)
|
||||
results.y = int(pos.y / inventory_item_grid_cell_size)
|
||||
var testa = int(position.x / inventory_item_grid_cell_size)
|
||||
var testb = int(position.y / inventory_item_grid_cell_size)
|
||||
results.x = int(pos.x / inventory_item_grid_cell_size)-testa
|
||||
results.y = int(pos.y / inventory_item_grid_cell_size)-testb
|
||||
return results
|
||||
|
||||
# Function to get the grid size of an item in terms of grid cells
|
||||
|
@ -1,4 +1,5 @@
|
||||
extends ColorRect
|
||||
class_name ItemSlot
|
||||
|
||||
# Reference to child slots
|
||||
@onready var slots = get_children()
|
Loading…
x
Reference in New Issue
Block a user