0 votes

I am trying to design an inventory menu and have been experimenting with different GUI elements in Godot 3.0.

I notice that if I create a scene consisting of a Container and three Buttons, Godot will automatically do input processing and change the focus of the buttons depending on whether I press up or down.

Is there a way to get this kind of automatic input processing for scrolling through items in an ItemList?

I notice that items don't have a focus attribute. Rather, they can be selected or not. This leads me to believe that there is no automatic input processing I can use to scroll through them. Must I write my own input processing to allow a user to scroll through items? For example, using ItemList.select()?

in Engine by (1,597 points)

1 Answer

0 votes
Best answer

So in order to get list to scroll like buttons, add a script to your list and copy this code in. It checks if mouse enters itemlist and selects item mouse touches. If you exit list with mouse, selection is removed. This should give you ability to scroll through list.

extends ItemList

var mouse_select
var last_index

func _ready():  
    select_mode = ItemList.SELECT_SINGLE

func _input(event):
    # Check ItemList
    if InputEventMouse and mouse_select == true:
        var itm = get_item_at_position(get_local_mouse_position(),false)
        # Using select() doesn't trigger item_selected


func _on_ItemList_mouse_entered():
    mouse_select = true

func _on_ItemList_mouse_exited():
    mouse_select = false

func _on_ItemList_item_selected(index):
    if not index == last_index:
        last_index = index
by (204 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.