Topic was automatically imported from the old Question2Answer platform.
Asked By
jahu00
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.
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