55 lines
1.5 KiB
GDScript
55 lines
1.5 KiB
GDScript
extends Control
|
|
|
|
# TODO: rename to server browser
|
|
|
|
onready var is_loaded = false
|
|
|
|
func _ready():
|
|
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")
|
|
Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected")
|
|
Global.client.signaller.request_lobby_list()
|
|
|
|
func _draw():
|
|
$join.disabled = len($lobbies.get_selected_items()) <= 1
|
|
|
|
func _signaller_disconnected():
|
|
Global.main_menu()
|
|
|
|
func _lobby_joined(_id, _peerId):
|
|
Global.lobby()
|
|
|
|
func _lobby_left(_id):
|
|
Global.lobby_browser()
|
|
|
|
func _on_back_pressed():
|
|
Global.main_menu()
|
|
|
|
func _on_create_lobby_pressed():
|
|
Global.client.signaller.create_lobby()
|
|
|
|
func _on_join_pressed():
|
|
var items = $lobbies.get_selected_items()
|
|
if len(items) > 0:
|
|
Global.client.signaller.join_lobby($lobbies.get_item_metadata(items[0])["id"])
|
|
|
|
func _lobby_new(lobbies):
|
|
for i in range(len(lobbies)):
|
|
var id = lobbies[i]["id"]
|
|
var name = lobbies[i]["name"]
|
|
print("New Lobby ", id, name)
|
|
# TODO: could keep an index of IDs and indexes
|
|
$lobbies.add_item("%s" % name)
|
|
$lobbies.set_item_metadata($lobbies.get_item_count() - 1, { "id": id })
|
|
|
|
func _lobby_delete(id):
|
|
for i in range($lobbies.get_item_count()):
|
|
if id == $lobbies.get_item_metadata(i)["id"]:
|
|
$lobbies.remove_item(i)
|
|
return
|
|
|
|
func _on_lobbies_item_activated(index):
|
|
_on_join_pressed()
|