Teams in lobby
This commit is contained in:
parent
6d34205ba2
commit
787de0ab09
6 changed files with 210 additions and 43 deletions
|
|
@ -1,28 +0,0 @@
|
|||
extends Node
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
multiplayer.peer_connected.connect(on_peer_connected)
|
||||
multiplayer.peer_disconnected.connect(on_peer_disconnected)
|
||||
Lobby.lobby_created.emit(add_self)
|
||||
Lobby.lobby_joined.emit(add_self)
|
||||
Lobby.lobby_closed.emit(clear)
|
||||
|
||||
func on_peer_connected(id: int) -> void:
|
||||
var label = Label.new()
|
||||
label.text = str(id)
|
||||
label.name = str(id)
|
||||
add_child(label,true)
|
||||
|
||||
func on_peer_disconnected(id: int) -> void:
|
||||
get_node(str(id)).queue_free()
|
||||
|
||||
func add_self() -> void:
|
||||
var label = Label.new()
|
||||
label.text = str(multiplayer.get_unique_id())
|
||||
label.name = str(multiplayer.get_unique_id())
|
||||
add_child(label,true)
|
||||
|
||||
func clear() -> void:
|
||||
for child in get_children():
|
||||
child.queue_free()
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://cl3hhmw5666sj
|
||||
|
|
@ -1,13 +1,38 @@
|
|||
extends Node
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Lobby.lobby_joined.connect(hide_host_buttons)
|
||||
Lobby.lobby_created.connect(show_host_buttons)
|
||||
Lobby.lobby_closed.connect(cleanup_lobby)
|
||||
Lobby.update_teams_state.connect(on_player_switched_team)
|
||||
|
||||
func _on_leave_button_pressed() -> void:
|
||||
Lobby.leave()
|
||||
cleanup_lobby()
|
||||
|
||||
func cleanup_lobby() -> void:
|
||||
$Lobby.hide()
|
||||
$MainMenu.show()
|
||||
%JoinAttackButton.show()
|
||||
%JoinDefenceButton.show()
|
||||
%JoinSpectatorsButton.hide()
|
||||
|
||||
|
||||
func _on_start_button_pressed() -> void:
|
||||
Lobby.start_game.rpc()
|
||||
|
||||
func hide_host_buttons() -> void:
|
||||
%StartButton.hide()
|
||||
|
||||
func show_host_buttons() -> void:
|
||||
%StartButton.show()
|
||||
|
||||
func _on_host_button_pressed() -> void:
|
||||
Lobby.host()
|
||||
$MainMenu.hide()
|
||||
$Lobby.show()
|
||||
|
||||
|
||||
func _on_connect_button_pressed() -> void:
|
||||
var ip = $MainMenu/VBoxContainer/LineEdit.text
|
||||
if ip == "":
|
||||
|
|
@ -17,3 +42,53 @@ func _on_connect_button_pressed() -> void:
|
|||
return
|
||||
$MainMenu.hide()
|
||||
$Lobby.show()
|
||||
|
||||
func on_player_switched_team():
|
||||
%JoinAttackButton.hide()
|
||||
%JoinDefenceButton.hide()
|
||||
%JoinSpectatorsButton.visible = Lobby.specators_team.has(multiplayer.get_unique_id()) == false
|
||||
if Lobby.attack_team.size() < 5 and not Lobby.attack_team.has(multiplayer.get_unique_id()):
|
||||
%JoinAttackButton.show()
|
||||
if Lobby.defence_team.size() < 5 and not Lobby.defence_team.has(multiplayer.get_unique_id()):
|
||||
%JoinDefenceButton.show()
|
||||
|
||||
for child in %AttackTeam.get_children():
|
||||
if child.name == "TeamName":
|
||||
continue
|
||||
child.queue_free()
|
||||
|
||||
for child in %DefenceTeam.get_children():
|
||||
if child.name == "TeamName":
|
||||
continue
|
||||
child.queue_free()
|
||||
|
||||
for child in %SpectatorsTeam.get_children():
|
||||
if child.name == "TeamName":
|
||||
continue
|
||||
child.queue_free()
|
||||
|
||||
for attacker in Lobby.attack_team:
|
||||
var label = Label.new()
|
||||
label.text = str(attacker)
|
||||
%AttackTeam.add_child(label)
|
||||
|
||||
for defender in Lobby.defence_team:
|
||||
var label = Label.new()
|
||||
label.text = str(defender)
|
||||
%DefenceTeam.add_child(label)
|
||||
|
||||
for spectator in Lobby.specators_team:
|
||||
var label = Label.new()
|
||||
label.text = str(spectator)
|
||||
%SpectatorsTeam.add_child(label)
|
||||
|
||||
func _on_join_attack_button_pressed() -> void:
|
||||
Lobby.switch_team(Session.TEAMS.ATTACK)
|
||||
|
||||
|
||||
func _on_join_defence_button_pressed() -> void:
|
||||
Lobby.switch_team(Session.TEAMS.DEFENCE)
|
||||
|
||||
|
||||
func _on_join_spectators_button_pressed() -> void:
|
||||
Lobby.switch_team(Session.TEAMS.SPECTATE)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue