push project up sabs assets
This commit is contained in:
100
scenes/screens/lobby_screen/lobby.gd
Normal file
100
scenes/screens/lobby_screen/lobby.gd
Normal file
@@ -0,0 +1,100 @@
|
||||
class_name Lobby extends LobbyBase
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Globals.lobby_data.lobby_ui = self
|
||||
|
||||
setup_signals()
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if Globals.multiplayer_data.is_multiplayer_active: return
|
||||
|
||||
if client.peer:
|
||||
client.close_connection()
|
||||
|
||||
func setup_signals() -> void:
|
||||
rpc_signals.match_list_entries.connect(_match_list_entries)
|
||||
rpc_signals.match_list_entry_activated.connect(_on_match_list_entry_activated)
|
||||
rpc_signals.match_list_entry_added.connect(_on_match_list_entry_added)
|
||||
rpc_signals.match_list_entry_removed.connect(_on_match_list_entry_removed)
|
||||
rpc_signals.match_list_entry_load_match.connect(_on_match_list_entry_load_match)
|
||||
|
||||
func _server_host_started() -> void:
|
||||
host_connect_bttn.visible = false
|
||||
|
||||
# NOTE: 'matches_list' can be empty but so long as we get the call from the
|
||||
# server we know we are connected and thus hide respective UI elements.
|
||||
func _match_list_entries(matches_list: Array) -> void:
|
||||
push_warning("Client Joined Host: Full Match List Recieved...\n", matches_list)
|
||||
|
||||
match_create_vbox.visible = true
|
||||
search_vbox.visible = true
|
||||
host_disconnect_bttn.visible = true
|
||||
host_connect_bttn.visible = false
|
||||
|
||||
for match_entry in matches_list:
|
||||
_create_match_entry(match_entry)
|
||||
|
||||
func _on_match_list_entry_activated(match_id: String) -> void:
|
||||
for match_entry in match_list.get_children():
|
||||
match_entry.join_bttn.visible = false
|
||||
if not match_entry.match_id == match_id: continue
|
||||
|
||||
active_match = match_entry
|
||||
match_entry.join_bttn.text = "Delete"
|
||||
match_entry.join_bttn.visible = true
|
||||
match_create_vbox.visible = false
|
||||
|
||||
match_entry.join_bttn.pressed.disconnect(_join_match)
|
||||
match_entry.join_bttn.pressed.connect(
|
||||
_delete_match.bind(match_entry.match_id)
|
||||
)
|
||||
|
||||
func _on_match_list_entry_added(match_entry: Dictionary) -> void:
|
||||
push_warning("Client: Added Match List Entry...", match_entry)
|
||||
_create_match_entry(match_entry)
|
||||
|
||||
func _on_match_list_entry_removed(match_id: String) -> void:
|
||||
push_warning("Client: Removed Match List Entry...", match_id)
|
||||
|
||||
if active_match && (match_id == active_match.match_id):
|
||||
active_match = null
|
||||
match_create_vbox.visible = true
|
||||
|
||||
for match_entry in match_list.get_children():
|
||||
if not active_match:
|
||||
match_entry.join_bttn.visible = true
|
||||
|
||||
if not match_id == match_entry.match_id: continue
|
||||
match_entry.queue_free()
|
||||
|
||||
func _on_match_list_entry_load_match(match_entry: Dictionary, is_player_1: bool) -> void:
|
||||
push_warning(
|
||||
"Client: Loading Game Match...\nMatch Data: ", match_entry, "\nis_player_1: ", is_player_1
|
||||
)
|
||||
|
||||
Globals.multiplayer_data.set_multiplayer_active()
|
||||
Globals.game_data.set_game_mode(match_entry.type)
|
||||
Globals.game_data.set_player_id(is_player_1)
|
||||
Globals.game_state.set_game_scene("res://scenes/game.tscn")
|
||||
|
||||
func _create_match_entry(match_entry: Dictionary) -> void:
|
||||
var container = MATCH_ENTRY.instantiate()
|
||||
match_list.add_child(container)
|
||||
|
||||
container.name_lbl.text = match_entry.name
|
||||
container.type_lbl.text = match_entry.type
|
||||
container.match_id = match_entry.match_id
|
||||
|
||||
container.join_bttn.pressed.connect(
|
||||
_join_match.bind(match_entry.match_id)
|
||||
)
|
||||
|
||||
if active_match:
|
||||
container.join_bttn.visible = false
|
||||
|
||||
func _join_match(match_id: String) -> void:
|
||||
Globals.lobby_data.rpc_id(1, "match_list_join_entry", match_id)
|
||||
|
||||
func _delete_match(match_id: String) -> void:
|
||||
Globals.lobby_data.rpc_id(1, "match_list_remove_entry", match_id)
|
||||
Reference in New Issue
Block a user