diff options
author | tpart <tpart120@proton.me> | 2024-09-29 11:51:07 +0200 |
---|---|---|
committer | tpart <tpart120@proton.me> | 2024-09-29 11:51:11 +0200 |
commit | 6fbc2a8f507b43cadc8c3d954e57552204f5dbee (patch) | |
tree | 1bea750184b09e8831e21abb8a29ec0979c686d3 /client/menu/play.gd | |
parent | 1027a8c7f613e375931d59c73caa6d4f95ce4dc8 (diff) | |
download | hurrycurry-6fbc2a8f507b43cadc8c3d954e57552204f5dbee.tar hurrycurry-6fbc2a8f507b43cadc8c3d954e57552204f5dbee.tar.bz2 hurrycurry-6fbc2a8f507b43cadc8c3d954e57552204f5dbee.tar.zst |
Fix focus in play menu (Fixes #197)
Diffstat (limited to 'client/menu/play.gd')
-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 |