diff --git a/grid_inventory_system/scripts/InventoryController.gd b/grid_inventory_system/scripts/InventoryController.gd index c339572..a07d890 100644 --- a/grid_inventory_system/scripts/InventoryController.gd +++ b/grid_inventory_system/scripts/InventoryController.gd @@ -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(): diff --git a/grid_inventory_system/scripts/InventoryGrid.gd b/grid_inventory_system/scripts/InventoryGrid.gd index 357346c..bfcb8e0 100644 --- a/grid_inventory_system/scripts/InventoryGrid.gd +++ b/grid_inventory_system/scripts/InventoryGrid.gd @@ -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 +