2021-11-17 08:18:12 -06:00
|
|
|
extends Control
|
|
|
|
|
2021-11-17 13:57:45 -06:00
|
|
|
# TODO: rename to server browser
|
|
|
|
|
2021-11-17 08:18:12 -06:00
|
|
|
onready var is_loaded = false
|
|
|
|
|
2021-12-06 21:56:37 -06:00
|
|
|
onready var lobbies = $v/body/lobbies
|
|
|
|
onready var join_button = $v/head/join
|
|
|
|
onready var lobbies_label = $v/subhead/label
|
|
|
|
|
2021-11-17 08:18:12 -06:00
|
|
|
func _ready():
|
2021-12-06 21:56:37 -06:00
|
|
|
join_button.disabled = true
|
2021-11-17 13:57:45 -06:00
|
|
|
Global.client.signaller.connect("lobby_new", self, "_lobby_new")
|
|
|
|
Global.client.signaller.connect("lobby_delete", self, "_lobby_delete")
|
|
|
|
Global.client.signaller.connect("lobby_joined", self, "_lobby_joined")
|
|
|
|
Global.client.signaller.connect("lobby_left", self, "_lobby_left")
|
2021-11-17 16:24:00 -06:00
|
|
|
Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected")
|
|
|
|
Global.client.signaller.request_lobby_list()
|
2021-12-03 17:05:31 -06:00
|
|
|
|
2021-12-06 21:56:37 -06:00
|
|
|
if Global.create_lobby:
|
|
|
|
Global.create_lobby = false
|
|
|
|
Global.client.signaller.create_lobby()
|
2021-11-17 16:24:00 -06:00
|
|
|
|
|
|
|
func _signaller_disconnected():
|
|
|
|
Global.main_menu()
|
2021-11-17 08:18:12 -06:00
|
|
|
|
2021-11-17 16:24:00 -06:00
|
|
|
func _lobby_joined(_id, _peerId):
|
2021-11-17 13:57:45 -06:00
|
|
|
Global.lobby()
|
|
|
|
|
|
|
|
func _lobby_left(_id):
|
|
|
|
Global.lobby_browser()
|
|
|
|
|
2021-11-17 08:18:12 -06:00
|
|
|
func _on_back_pressed():
|
2021-11-17 13:57:45 -06:00
|
|
|
Global.main_menu()
|
|
|
|
|
|
|
|
func _on_create_lobby_pressed():
|
|
|
|
Global.client.signaller.create_lobby()
|
|
|
|
|
|
|
|
func _on_join_pressed():
|
2021-12-06 21:56:37 -06:00
|
|
|
var items = lobbies.get_selected_items()
|
2021-11-17 13:57:45 -06:00
|
|
|
if len(items) > 0:
|
2021-12-06 21:56:37 -06:00
|
|
|
Global.client.signaller.join_lobby(lobbies.get_item_metadata(items[0])["id"])
|
2021-11-17 13:57:45 -06:00
|
|
|
|
2021-12-06 21:56:37 -06:00
|
|
|
func _lobby_new(new_lobbies):
|
|
|
|
for i in range(len(new_lobbies)):
|
|
|
|
var id = new_lobbies[i]["id"]
|
|
|
|
var name = new_lobbies[i]["name"]
|
2021-11-17 13:57:45 -06:00
|
|
|
print("New Lobby ", id, name)
|
|
|
|
# TODO: could keep an index of IDs and indexes
|
2021-12-06 21:56:37 -06:00
|
|
|
lobbies.add_item(name)
|
|
|
|
lobbies.set_item_metadata(lobbies.get_item_count() - 1, { "id": id })
|
|
|
|
|
|
|
|
if Global.join_first_available_lobby:
|
|
|
|
Global.join_first_available_lobby = false
|
|
|
|
Global.client.signaller.join_lobby(id)
|
|
|
|
lobbies_label.text = "Active Lobbies: %d" % lobbies.get_item_count()
|
2021-11-17 13:57:45 -06:00
|
|
|
|
|
|
|
func _lobby_delete(id):
|
2021-12-06 21:56:37 -06:00
|
|
|
for i in range(lobbies.get_item_count()):
|
|
|
|
if id == lobbies.get_item_metadata(i)["id"]:
|
|
|
|
lobbies.remove_item(i)
|
2021-11-17 13:57:45 -06:00
|
|
|
return
|
2021-12-06 21:56:37 -06:00
|
|
|
lobbies_label.text = "Active Lobbies: %d" % lobbies.get_item_count()
|
2021-12-02 16:30:24 -06:00
|
|
|
|
2021-12-06 21:56:37 -06:00
|
|
|
func _on_lobbies_item_activated(_index):
|
2021-12-02 16:30:24 -06:00
|
|
|
_on_join_pressed()
|
2021-12-06 21:56:37 -06:00
|
|
|
|
|
|
|
func _on_lobbies_item_selected(_index):
|
|
|
|
join_button.disabled = false
|