fix the inventory grid class to account for global position not being 0,0 when autofilling

This commit is contained in:
Damien Ostler 2024-01-09 00:25:38 -05:00
parent ace5d094bc
commit 25231836b0
2 changed files with 10 additions and 7 deletions

View File

@ -53,7 +53,7 @@ func _process(delta):
var cursor_pos = get_global_mouse_position()
if Input.is_action_just_pressed("inventory_grab"):
if Input.is_action_just_pressed("inventory_grab"):
grab(cursor_pos)
if Input.is_action_just_released("inventory_grab"):
@ -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():

View File

@ -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)
if insert_item(item)==true:
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