mirror of
https://github.com/D4M13N-D3V/godot_grid_inventory.git
synced 2025-03-14 08:14:55 +00:00
fix the inventory grid class to account for global position not being 0,0 when autofilling
This commit is contained in:
parent
ace5d094bc
commit
25231836b0
@ -92,6 +92,7 @@ func show_context_menu(mouse_pos: Vector2, item):
|
||||
# Function to hide the context menu
|
||||
func hide_context_menu():
|
||||
if(inventory_context_menu!=null):
|
||||
inventory_context_menu_item=null
|
||||
inventory_context_menu.queue_free()
|
||||
|
||||
func context_menu_open():
|
||||
|
@ -135,13 +135,15 @@ func get_item_under_pos(pos):
|
||||
if item.get_global_rect().has_point(pos):
|
||||
return item
|
||||
return null
|
||||
|
||||
# Function to insert an item at the first available spot in the grid
|
||||
# Function to insert an item at the first available spot in the grid
|
||||
func insert_item_at_first_available_spot(item):
|
||||
for x in inventory_item_grid_width:
|
||||
for y in inventory_item_grid_height:
|
||||
if not inventory_item_grid[x][y]["used"]:
|
||||
item.global_position = Vector2(x* inventory_item_grid_cell_size, (y)* inventory_item_grid_cell_size)
|
||||
for x in range(inventory_item_grid_width):
|
||||
for y in range(inventory_item_grid_height):
|
||||
if inventory_item_grid[x][y]["used"] == false:
|
||||
item.global_position = global_position+ Vector2(x * inventory_item_grid_cell_size, y * inventory_item_grid_cell_size)
|
||||
if insert_item(item) == true:
|
||||
print("Item inserted at:", item.position)
|
||||
return true
|
||||
return false
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user