Hi everyone!
I seem to be in a pattern of asking a sorta difficult question followed by a really simple one. This time, I'm trying to make a simple 6-item inventory list you can scroll through with the mouse wheel and select with the middle mouse button. If possible, I'm also trying to make the menu loop. (As in, scrolling up from slot 6 will highlight slot 1, and scrolling down from slot 1 will highlight slot 6.)
I have an inventory of 6 instantiated panels as you can see below. Here's the scene tree and code for my UI scene:
`extends Control
@onready var inv: Inv = preload("res://inventory/inventory.tres")
@onready var slots: Array = $TextureRect/GridContainer.get_children()
func _ready():
updateSlots() #this function updates what items appear in each slot. it only happening at the start of the game is WIP
func updateSlots():
for i in range(min(inv.items.size(), slots.size())):
slots.update(inv.items)
`
And the scene and code for each individual panel object:
`extends Panel
@onready var item_visual: Sprite2D = $CenterContainer/Panel/display
func update(item: InvItem): #this is for showing the item in the slot
if !item:
item_visual.visible = false
else:
item_visual.visible = true
item_visual.texture = item.texture
`
I can store info in these panels no problem, but I'm stumped on how to highlight, scroll through or select them. What kind of code would I need to write to be able to do this? Please let me know if you can help!! Thank you once again!!