0 votes

On new game screen I have an ItemList for selecting language. When I click on any of the items it gets selected and previously selected item gets deselected, but if I click on empty area of the ItemList, all items get deselected. I would like to prevent that.

Additionally, when I select an item via code in _ready function it gets styled incorrectly. Though I managed to work around it, by moving selecting code to fixed_process.

in Engine by (53 points)

1 Answer

0 votes

I figured a workaround for the problem, I can store last selected item value in a variable, connect an input event to the ItemList and when user clicks on the list and no item is selected, reselect the last selected item.

More or less this:

func _on_LanguageList_item_selected( index ):
    last_selected_language = index
    pass

func _on_LanguageList_input_event( event ):
if (event.type == InputEvent.MOUSE_BUTTON):
    if (event.is_pressed()):
        if (!clicked):
            if (language_list.get_selected_items().size() == 0):
                language_list.select(last_selected_language)
                pass
            clicked = true
        pass
    else:
        clicked = false;
        pass
    pass
pass
by (53 points)
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 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 webmaster@godotengine.org with your username.