update lobby for online players

This commit is contained in:
2020-05-15 21:16:48 +02:00
parent ccdbf5b158
commit d84fdd4d00
7 changed files with 94 additions and 15 deletions

View File

@ -5,6 +5,9 @@ const MAX_PLAYERS = 8
const MIN_GAME_NAME_LENGTH = 1
const MAX_GAME_NAME_LENGTH = 20
func _ready():
$Lobby/Auto_refresh_timer.start()
func _on_Refresh_button_pressed():
refresh_game_list()
@ -38,10 +41,17 @@ func _on_Cancel_button_pressed():
$Lobby.show()
func _on_Exit_button_pressed():
get_tree().set_network_peer(null)
get_tree().change_scene("res://Scenes/Matchmaking/Menu/Menu.tscn")
func _on_Lobby_controller_tree_entered():
refresh_game_list()
update_online_players()
func update_online_players():
NetworkingSync.update_players_online()
yield(NetworkingSync, "update_players_online")
$Lobby/Online_players/HBoxContainer/Number_of_player.text = str(NetworkingSync.get_number_of_online_players())
func _on_Game_name_line_edit_text_changed(new_text):
check_input_fields()
@ -78,3 +88,8 @@ func create_game_room():
var max_players = int($Lobby_game_creation_panel/HBoxContainer2/Number_of_players_line_edit.text)
var game_id = get_tree().get_network_unique_id()
NetworkingSync.create_game([game_id, game_name, max_players, {}], Player)
func _on_Auto_refresh_timer_timeout():
update_online_players()
refresh_game_list()

View File

@ -117,6 +117,48 @@ __meta__ = {
[node name="Auto_refresh_timer" type="Timer" parent="Lobby"]
[node name="Online_players" type="Control" parent="Lobby"]
margin_left = 902.145
margin_top = 965.807
margin_right = 1857.14
margin_bottom = 1012.81
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Background" type="ColorRect" parent="Lobby/Online_players"]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.196078, 0.254902, 0.352941, 0.843137 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="Lobby/Online_players"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Number_of_player" type="Label" parent="Lobby/Online_players/HBoxContainer"]
margin_right = 475.0
margin_bottom = 47.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "0"
align = 2
valign = 1
[node name="Player_label" type="Label" parent="Lobby/Online_players/HBoxContainer"]
margin_left = 479.0
margin_right = 955.0
margin_bottom = 47.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Player"
valign = 1
[node name="Lobby_game_creation_panel" type="Control" parent="."]
visible = false
anchor_left = 0.183854
@ -215,6 +257,7 @@ __meta__ = {
[connection signal="pressed" from="Lobby/Lobby_buttons/Create_game_button" to="." method="_on_Create_game_button_pressed"]
[connection signal="pressed" from="Lobby/Lobby_buttons/Refresh_button" to="." method="_on_Refresh_button_pressed"]
[connection signal="pressed" from="Lobby/Lobby_buttons/Exit_button" to="." method="_on_Exit_button_pressed"]
[connection signal="timeout" from="Lobby/Auto_refresh_timer" to="." method="_on_Auto_refresh_timer_timeout"]
[connection signal="text_changed" from="Lobby_game_creation_panel/HBoxContainer/Game_name_line_edit" to="." method="_on_Game_name_line_edit_text_changed"]
[connection signal="text_changed" from="Lobby_game_creation_panel/HBoxContainer2/Number_of_players_line_edit" to="." method="_on_Number_of_players_line_edit_text_changed"]
[connection signal="pressed" from="Lobby_game_creation_panel/Ok_button" to="." method="_on_Ok_button_pressed"]