diff options
Diffstat (limited to 'client/menu')
-rw-r--r-- | client/menu/play.gd | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/client/menu/play.gd b/client/menu/play.gd index 0c482abc..1abd0bbc 100644 --- a/client/menu/play.gd +++ b/client/menu/play.gd @@ -38,12 +38,21 @@ func _ready(): update_server_list(ServerList.current_list) update_server_list_loading(ServerList.loading) - ServerList.start() super() + ServerList.start() func update_server_list(lists: Array[Array]): + # Find out the index of the currently focused server in the list + var prev_selected_idx := -1 + for i in range(server_list.get_children().size()): + if server_list.get_child(i).has_focus(): + prev_selected_idx = i + break + for c in server_list.get_children(): c.queue_free() + + var idx := 0 for l in lists: for i in l: var b := Button.new() @@ -54,6 +63,17 @@ func update_server_list(lists: Array[Array]): b.disabled = true b.pressed.connect(connect_to.bind(i.address[0])) server_list.add_child(b) + # Focus the same server with the same index as the previously focused one + if idx == prev_selected_idx: + b.grab_focus() + idx += 1 + + if prev_selected_idx > idx: + # Same index cannot be focused, since number of servers decreased + if idx - 1 < 0: + connect_uri.grab_focus() + else: + server_list.get_child(idx - 1).grab_focus() func update_server_list_loading(status: bool): server_list_loading.visible = status |