update lobby for online players

This commit is contained in:
Thorben 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"]

View File

@ -2,10 +2,12 @@ extends Node
signal updated_games
signal all_ready
signal update_players_online
var _open_games = {}
var _player_in_same_game_room_list = []
var _players_ready = []
var _number_of_online_players
func send_open_games_request_to_server():
rpc_id(1, "get_open_games_from_server", get_tree().get_network_unique_id())
@ -47,3 +49,14 @@ remote func send_host_ready_signal(id):
_players_ready.append(id)
if len(_players_ready) == len(_player_in_same_game_room_list):
emit_signal("all_ready")
func update_players_online():
rpc_id(1, "get_online_players", Player.get_player_id())
remote func update_online_players(number_of_players):
_number_of_online_players = number_of_players
emit_signal("update_players_online")
func get_number_of_online_players():
return _number_of_online_players

View File

@ -75,7 +75,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../../Godot_Executables/Godot_client_web/Client_project.html"
export_path="../../Godot_Executables/Client_web/Client_project.html"
patch_list=PoolStringArray( )
script_export_mode=1
script_encryption_key=""

View File

@ -4,6 +4,13 @@ extends Node
var _open_games = {}
var _players_online = []
var _number_of_online_players
func get_number_of_online_players():
return len(get_tree().get_network_connected_peers())
remote func get_online_players(id):
rpc_id(id, "update_online_players", _number_of_online_players)
remote func get_open_games_from_server(id):
rpc_id(id, "update_open_games", _open_games)
@ -29,17 +36,17 @@ remote func remove_game_from_game_list(game_id):
var _queue = []
var _hidden_games = {}
func _process(delta):
if _queue.empty():
print("Nothing to do.")
else:
var player_id = dequeue()
if _hidden_games.empty():
create_game(player_id)
else:
join_next_hidden_game(player_id)
#func _process(delta):
# if _queue.empty():
# print("Nothing to do.")
# else:
# var player_id = dequeue()
#
# if _hidden_games.empty():
# create_game(player_id)
# else:
# join_next_hidden_game(player_id)
#
func create_game(player_id):
pass

View File

@ -22,11 +22,12 @@ func start_server():
get_tree().set_network_peer(peer)
func _player_connected(id):
print(str(id) + " connected to server.")
NetworkingSync._players_online.append(id)
NetworkingSync._number_of_online_players = len(get_tree().get_network_connected_peers())
func _player_disconnected(id):
print(str(id) + " left the game.")
NetworkingSync._players_online.erase(id)
NetworkingSync._number_of_online_players = len(get_tree().get_network_connected_peers())
if id in NetworkingSync._open_games:
NetworkingSync.remove_game_from_game_list(id)

View File

@ -7,7 +7,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../Executables/Server.x86_64"
export_path="../../Godot_Executables/Server_linux/Server.x86_64"
patch_list=PoolStringArray( )
script_export_mode=1
script_encryption_key=""