initial commit

This commit is contained in:
2020-05-09 12:45:05 +02:00
commit a3549d357b
46 changed files with 3051 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
extends Control
func _ready():
for player_id in NetworkingSync._open_games[Player.get_game_id()][3]:
if player_id != Player.get_player_id():
rpc_id(player_id, "update_game_room_player_list")
update_game_room_player_list()
remote func update_game_room_player_list():
NetworkingSync.send_open_games_request_to_server()
yield(NetworkingSync, "updated_games")
for child in $Player_list/ScrollContainer/Player_list_container.get_children():
child.queue_free()
NetworkingSync._player_in_same_game_room_list = []
for player_id in NetworkingSync._open_games[Player.get_game_id()][3]:
add_player_entry_to_list(player_id)
func add_player_entry_to_list(player_id):
var player = load("res://Scenes/Matchmaking/Game_room/Player_entry.tscn").instance()
var player_name = str(NetworkingSync._open_games[Player.get_game_id()][3][player_id][0])
player.set_player_name(player_name)
$Player_list/ScrollContainer/Player_list_container.add_child(player)
var player_info = [player_id, player_name]
NetworkingSync._player_in_same_game_room_list.append(player_info)
func _on_Game_room_tree_entered():
if Player._is_host:
$Start_button.show()
$Ready_button.hide()
else:
$Start_button.hide()
$Ready_button.hide() # TODO: change this to .show(), if ready-feature is implemented.
func _on_Start_button_pressed():
NetworkingSync._players_ready = []
NetworkingSync.close_game()
if len(NetworkingSync._player_in_same_game_room_list) >= 2:
for player_id in NetworkingSync._player_in_same_game_room_list:
if player_id[0] != Player.get_player_id():
rpc_id(player_id[0], "start_game")
start_game()
rpc_id(1, "remove_game_from_game_list", Player.get_game_id())
remote func start_game():
get_tree().change_scene("res://Scenes/Matchmaking/Game/Game_manager.tscn")
func _on_Leave_button_pressed():
if Player.is_host():
#TODO: kick everyone out of the game
NetworkingSync.close_game()
else:
NetworkingSync.left_game()
yield(NetworkingSync, "updated_games")
for player in NetworkingSync._open_games[Player.get_game_id()][3]:
print(player)
if player != Player.get_player_id():
rpc_id(player, "update_game_room_player_list")
Player.set_game_id(0)
get_tree().change_scene("res://Scenes/Matchmaking/Lobby/Lobby.tscn")

View File

@@ -0,0 +1,88 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Scenes/Matchmaking/Game_room/Game_room.gd" type="Script" id=2]
[node name="Game_room" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Background" type="TextureRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 1 )
expand = true
stretch_mode = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Start_button" type="Button" parent="."]
margin_left = 185.965
margin_top = 324.728
margin_right = 522.965
margin_bottom = 502.728
text = "Start"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Ready_button" type="Button" parent="."]
visible = false
margin_left = 185.965
margin_top = 324.728
margin_right = 522.965
margin_bottom = 502.728
text = "Ready"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Leave_button" type="Button" parent="."]
margin_left = 179.497
margin_top = 615.335
margin_right = 526.497
margin_bottom = 810.335
text = "Leave"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_list" type="Control" parent="."]
anchor_left = 0.314583
anchor_top = 0.266667
anchor_right = 0.939583
anchor_bottom = 0.822222
margin_left = -3.99939
margin_top = 1.99963
margin_right = -3.99939
margin_bottom = 2.00024
__meta__ = {
"_edit_use_anchors_": true
}
[node name="ColorRect" type="ColorRect" parent="Player_list"]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.282353, 0.0235294, 0.0235294, 0.823529 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ScrollContainer" type="ScrollContainer" parent="Player_list"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_list_container" type="VBoxContainer" parent="Player_list/ScrollContainer"]
margin_right = 1200.0
size_flags_horizontal = 3
[connection signal="tree_entered" from="." to="." method="_on_Game_room_tree_entered"]
[connection signal="pressed" from="Start_button" to="." method="_on_Start_button_pressed"]
[connection signal="pressed" from="Leave_button" to="." method="_on_Leave_button_pressed"]

View File

@@ -0,0 +1,4 @@
extends HBoxContainer
func set_player_name(player_name):
$Player_name_label.text = player_name

View File

@@ -0,0 +1,19 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Game_room/Player_entry.gd" type="Script" id=1]
[node name="Player_entry" type="HBoxContainer"]
margin_right = 800.0
margin_bottom = 40.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Player_name_label" type="Label" parent="."]
margin_right = 800.0
margin_bottom = 40.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Player 1"
valign = 1