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,33 @@
extends Node
var _game_id
var _game_name
var _max_players
var _player_list
func _init(game_id, game_name, max_players):
_game_id = game_id
_game_name = game_name
_max_players = max_players
_player_list = {}
func get_parsable_game_information():
return [_game_id, _game_name, _max_players, _player_list]
func add_player_to_game(player):
_player_list.append(player)
func remove_player_from_game():
pass
func set_game_id(game_id):
_game_id = game_id
func set_game_name(game_name):
_game_name = game_name
func set_max_players(max_players):
_max_players = max_players
func is_full():
return _max_players <= len(_player_list)

View File

@ -0,0 +1,28 @@
extends Button
var _game_name
var _max_players
var _game_id
func set_game_id(game_id):
_game_id = game_id
func set_game_name(game_name):
_game_name = game_name
func set_max_players(max_players):
_max_players = max_players
func update_gui():
$HBoxContainer/Game_name.text = _game_name
$HBoxContainer/Number_of_player.text = str(len(NetworkingSync._open_games[_game_id][3])) + "/" + str(_max_players)
func _on_Games_entry_pressed():
NetworkingSync.send_open_games_request_to_server()
yield(NetworkingSync, "updated_games")
if _game_id in NetworkingSync._open_games and !is_full():
NetworkingSync.join_game(_game_id)
func is_full():
var number_of_players = len(NetworkingSync._open_games[_game_id][3])
return number_of_players >= _max_players

View File

@ -0,0 +1,36 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Lobby/Games_entry.gd" type="Script" id=1]
[node name="Games_entry" type="Button"]
margin_right = 661.0
margin_bottom = 77.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Game_name" type="Label" parent="HBoxContainer"]
margin_right = 80.0
margin_bottom = 77.0
size_flags_vertical = 1
text = "Game_name"
valign = 1
[node name="Number_of_player" type="Label" parent="HBoxContainer"]
margin_left = 84.0
margin_right = 661.0
margin_bottom = 77.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "2/2"
align = 2
valign = 1
[connection signal="pressed" from="." to="." method="_on_Games_entry_pressed"]

View File

@ -0,0 +1,80 @@
extends Control
const MIN_PLAYERS = 2
const MAX_PLAYERS = 8
const MIN_GAME_NAME_LENGTH = 1
const MAX_GAME_NAME_LENGTH = 20
func _on_Refresh_button_pressed():
refresh_game_list()
func refresh_game_list():
NetworkingSync.send_open_games_request_to_server()
yield(NetworkingSync, "updated_games")
for child in $Lobby/Games_list/Open_games/VBoxContainer.get_children():
child.queue_free()
for game in NetworkingSync.get_open_games().values():
add_entry_to_lobby(game[0], game[1], game[2])
func add_entry_to_lobby(game_id, game_name, max_players):
var new_game = load("res://Scenes/Matchmaking/Lobby/Games_entry.tscn").instance()
new_game.set_game_id(game_id)
new_game.set_game_name(game_name)
new_game.set_max_players(max_players)
new_game.name = "Game_entry_" + game_name
new_game.update_gui()
$Lobby/Games_list/Open_games/VBoxContainer.add_child(new_game)
func _on_Create_game_button_pressed():
$Lobby.hide()
$Lobby_game_creation_panel.show()
func _on_Ok_button_pressed():
create_game_room()
func _on_Cancel_button_pressed():
$Lobby_game_creation_panel.hide()
$Lobby.show()
func _on_Exit_button_pressed():
get_tree().change_scene("res://Scenes/Matchmaking/Menu/Menu.tscn")
func _on_Lobby_controller_tree_entered():
refresh_game_list()
func _on_Game_name_line_edit_text_changed(new_text):
check_input_fields()
func _on_Number_of_players_line_edit_text_changed(new_text):
check_input_fields()
func is_number_of_players_text_field_ok():
var result = false
var text_field = $Lobby_game_creation_panel/HBoxContainer2/Number_of_players_line_edit.text
if int(text_field) >= MIN_PLAYERS and int(text_field) <= MAX_PLAYERS:
result = true
return result
func is_game_name_text_field_ok():
var result = false
var text_field = $Lobby_game_creation_panel/HBoxContainer/Game_name_line_edit.text
if len(text_field) <= MAX_GAME_NAME_LENGTH and len(text_field) >= MIN_GAME_NAME_LENGTH:
result = true
return result
func check_input_fields():
if is_number_of_players_text_field_ok() and is_game_name_text_field_ok():
$Lobby_game_creation_panel/Ok_button.disabled = false
else:
$Lobby_game_creation_panel/Ok_button.disabled = true
func _input(ev):
if Input.is_key_pressed(KEY_ENTER) and not $Lobby_game_creation_panel/Ok_button.disabled:
create_game_room()
func create_game_room():
var game_name = $Lobby_game_creation_panel/HBoxContainer/Game_name_line_edit.text
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)

View File

@ -0,0 +1,221 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Scenes/Matchmaking/Lobby/Lobby.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[node name="Lobby_controller" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Lobby_background" type="TextureRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 2 )
stretch_mode = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Lobby" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Games_list" type="Control" parent="Lobby"]
anchor_left = 0.31283
anchor_top = 0.147956
anchor_right = 0.965434
anchor_bottom = 0.834067
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Background" type="ColorRect" parent="Lobby/Games_list"]
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="Open_games" type="ScrollContainer" parent="Lobby/Games_list"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="Lobby/Games_list/Open_games"]
margin_right = 1253.0
size_flags_horizontal = 3
[node name="Lobby_buttons" type="Control" parent="Lobby"]
anchor_left = 0.0234375
anchor_top = 0.407407
anchor_right = 0.283854
anchor_bottom = 0.796296
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Background" type="ColorRect" parent="Lobby/Lobby_buttons"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -3.05176e-05
margin_bottom = -20.0
color = Color( 0.196078, 0.254902, 0.352941, 0.843137 )
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Create_game_button" type="Button" parent="Lobby/Lobby_buttons"]
margin_left = 20.0
margin_top = 20.0
margin_right = 480.0
margin_bottom = 80.0
text = "Create Game"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Search_game_button" type="Button" parent="Lobby/Lobby_buttons"]
margin_left = 20.0
margin_top = 120.0
margin_right = 480.0
margin_bottom = 180.0
disabled = true
text = "Search Game"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Refresh_button" type="Button" parent="Lobby/Lobby_buttons"]
margin_left = 20.0
margin_top = 220.0
margin_right = 480.0
margin_bottom = 280.0
text = "Refresh"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Exit_button" type="Button" parent="Lobby/Lobby_buttons"]
margin_left = 20.0
margin_top = 320.0
margin_right = 480.0
margin_bottom = 380.0
text = "Exit"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Auto_refresh_timer" type="Timer" parent="Lobby"]
[node name="Lobby_game_creation_panel" type="Control" parent="."]
visible = false
anchor_left = 0.183854
anchor_top = 0.200463
anchor_right = 0.816146
anchor_bottom = 0.799537
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Background" type="ColorRect" parent="Lobby_game_creation_panel"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = 1.75809
margin_bottom = 1.75806
color = Color( 0.360784, 0.360784, 0.360784, 0.823529 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="Lobby_game_creation_panel"]
anchor_left = 0.0881384
anchor_top = 0.0772798
anchor_right = 0.911862
anchor_bottom = 0.200927
margin_bottom = -40.0
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Game_name_label" type="Label" parent="Lobby_game_creation_panel/HBoxContainer"]
margin_right = 78.0
margin_bottom = 39.0
size_flags_vertical = 3
text = "Gamename:"
valign = 1
[node name="Game_name_line_edit" type="LineEdit" parent="Lobby_game_creation_panel/HBoxContainer"]
margin_left = 82.0
margin_right = 1000.0
margin_bottom = 39.0
size_flags_horizontal = 3
[node name="HBoxContainer2" type="HBoxContainer" parent="Lobby_game_creation_panel"]
anchor_left = 0.0881384
anchor_top = 0.278207
anchor_right = 0.911862
anchor_bottom = 0.401855
margin_bottom = -40.0
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Max_player_label" type="Label" parent="Lobby_game_creation_panel/HBoxContainer2"]
margin_right = 80.0
margin_bottom = 40.0
size_flags_vertical = 3
text = "Max Players:"
valign = 1
[node name="Number_of_players_line_edit" type="LineEdit" parent="Lobby_game_creation_panel/HBoxContainer2"]
margin_left = 84.0
margin_right = 1000.0
margin_bottom = 40.0
size_flags_horizontal = 3
[node name="Ok_button" type="Button" parent="Lobby_game_creation_panel"]
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -457.0
margin_top = -247.0
margin_right = -57.0
margin_bottom = -147.0
disabled = true
text = "Ok"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Cancel_button" type="Button" parent="Lobby_game_creation_panel"]
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = 43.0001
margin_top = -247.0
margin_right = 443.0
margin_bottom = -147.0
text = "Cancel"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="tree_entered" from="." to="." method="_on_Lobby_controller_tree_entered"]
[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="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"]
[connection signal="pressed" from="Lobby_game_creation_panel/Cancel_button" to="." method="_on_Cancel_button_pressed"]