116 lines
2.7 KiB
GDScript
116 lines
2.7 KiB
GDScript
extends Control
|
|
|
|
|
|
func _ready() -> void:
|
|
Lobby.lobby_joined.connect(hide_host_buttons)
|
|
Session.session_started.connect(hide)
|
|
Lobby.lobby_created.connect(show_host_buttons)
|
|
Lobby.lobby_closed.connect(cleanup_lobby)
|
|
Lobby.update_teams_state.connect(on_player_switched_team)
|
|
Session.session_ended.connect(on_session_ended)
|
|
|
|
$Lobby.hide()
|
|
$MainMenu.show()
|
|
%NicknameEdit.text = ClientSettings.NICKNAME
|
|
|
|
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 hide_host_buttons() -> void:
|
|
%HostMenu.hide()
|
|
|
|
func show_host_buttons() -> void:
|
|
%HostMenu.show()
|
|
|
|
func _on_host_button_pressed() -> void:
|
|
Lobby.host()
|
|
$MainMenu.hide()
|
|
$Lobby.show()
|
|
|
|
func _on_connect_button_pressed() -> void:
|
|
var ip = %IpEdit.text
|
|
if ip == "":
|
|
ip = "localhost"
|
|
var joined = Lobby.join(ip)
|
|
if joined != Error.OK:
|
|
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 = PlayerLabel.new()
|
|
label.id = attacker
|
|
%AttackTeam.add_child(label)
|
|
|
|
for defender in Lobby.defence_team:
|
|
var label = PlayerLabel.new()
|
|
label.id = defender
|
|
%DefenceTeam.add_child(label)
|
|
|
|
for spectator in Lobby.specators_team:
|
|
var label = PlayerLabel.new()
|
|
label.id = 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)
|
|
|
|
func on_session_ended() -> void:
|
|
show()
|
|
if Lobby.in_lobby:
|
|
$MainMenu.hide()
|
|
$Lobby.show()
|
|
else:
|
|
$MainMenu.show()
|
|
$Lobby.hide()
|
|
|
|
|
|
func _on_nickname_edit_text_changed(new_text: String) -> void:
|
|
if new_text == "":
|
|
ClientSettings.NICKNAME = "MyNameIs"
|
|
else:
|
|
ClientSettings.NICKNAME = new_text
|
|
|
|
|
|
func _on_exit_button_pressed() -> void:
|
|
get_tree().quit()
|