Created a basic Lobby system, to further test networking features

This commit is contained in:
PersonGuyGit
2023-07-23 12:55:33 -06:00
parent bd6acd0611
commit 80787c9f2a
8 changed files with 214 additions and 10 deletions

View File

@ -1,5 +1,33 @@
extends Control
onready var player_name = $CenterContainer/VBoxContainer/GridContainer/NameLineEdit
func _on_Button_pressed():
onready var selected_IP = $CenterContainer/VBoxContainer/GridContainer/IPLineEdit
onready var selected_port = $CenterContainer/VBoxContainer/GridContainer/PortLineEdit
onready var waiting_room = $WaitingRoom
onready var ready_btn = $WaitingRoom/CenterContainer/VBoxContainer/ReadyButton
func _ready():
player_name.text = Save.save_data["player_name"]
selected_IP.text = Server.DEFAULT_IP
selected_port.text = str(Server.DEFAULT_PORT)
func show_waiting_room():
waiting_room.popup_centered()
func _on_ReadyBtn_pressed():
ready_btn.disabled = true
func _on_NameLineEdit_text_changed(_new_text):
Save.save_data["Player_name"] = player_name.text
Save.save_game()
func _on_JoinButton_pressed():
Server.selected_IP = selected_IP.text
Server.selected_port = int(selected_port.text)
Server._connect_to_server()
show_waiting_room()

View File

@ -1,21 +1,89 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Lobby/Lobby.gd" type="Script" id=1]
[ext_resource path="res://Lobby/WatingRoom.tscn" type="PackedScene" id=2]
[node name="Control" type="Control"]
[node name="Lobby" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
[node name="ColorRect" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.231373, 0.231373, 0.258824, 1 )
[node name="CenterContainer" type="CenterContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="Button" type="Button" parent="CenterContainer"]
margin_left = 468.0
margin_top = 290.0
margin_right = 556.0
margin_bottom = 310.0
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
margin_left = 338.0
margin_top = 207.0
margin_right = 685.0
margin_bottom = 393.0
custom_constants/separation = 20
[node name="LobbyLabel" type="Label" parent="CenterContainer/VBoxContainer"]
margin_right = 347.0
margin_bottom = 14.0
text = "Lobby"
align = 1
[node name="GridContainer" type="GridContainer" parent="CenterContainer/VBoxContainer"]
margin_top = 34.0
margin_right = 347.0
margin_bottom = 146.0
custom_constants/vseparation = 20
custom_constants/hseparation = 20
columns = 2
[node name="NameLabel" type="Label" parent="CenterContainer/VBoxContainer/GridContainer"]
margin_top = 5.0
margin_right = 77.0
margin_bottom = 19.0
text = "Name:"
[node name="NameLineEdit" type="LineEdit" parent="CenterContainer/VBoxContainer/GridContainer"]
margin_left = 97.0
margin_right = 347.0
margin_bottom = 24.0
rect_min_size = Vector2( 250, 0 )
[node name="IPLabel" type="Label" parent="CenterContainer/VBoxContainer/GridContainer"]
margin_top = 49.0
margin_right = 77.0
margin_bottom = 63.0
text = "IP Address:"
[node name="IPLineEdit" type="LineEdit" parent="CenterContainer/VBoxContainer/GridContainer"]
margin_left = 97.0
margin_top = 44.0
margin_right = 347.0
margin_bottom = 68.0
rect_min_size = Vector2( 250, 0 )
[node name="PortLabel" type="Label" parent="CenterContainer/VBoxContainer/GridContainer"]
margin_top = 93.0
margin_right = 77.0
margin_bottom = 107.0
text = "Port:"
[node name="PortLineEdit" type="LineEdit" parent="CenterContainer/VBoxContainer/GridContainer"]
margin_left = 97.0
margin_top = 88.0
margin_right = 347.0
margin_bottom = 112.0
rect_min_size = Vector2( 250, 0 )
[node name="JoinButton" type="Button" parent="CenterContainer/VBoxContainer"]
margin_top = 166.0
margin_right = 347.0
margin_bottom = 186.0
text = "Join Session"
[connection signal="pressed" from="CenterContainer/Button" to="." method="_on_Button_pressed"]
[node name="WaitingRoom" parent="." instance=ExtResource( 2 )]
visible = false
[connection signal="text_changed" from="CenterContainer/VBoxContainer/GridContainer/NameLineEdit" to="." method="_on_NameLineEdit_text_changed"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/JoinButton" to="." method="_on_JoinButton_pressed"]

View File

@ -0,0 +1,12 @@
extends Popup
onready var player_list = $CenterContainer/VBoxContainer/ItemList
func _ready():
player_list.clear()
func refresh_players(players):
player_list.clear()
for player_id in players:
var player = players[player_id]["Player_name"]
player_list.add_item(player, null, false)

View File

@ -0,0 +1,47 @@
[gd_scene format=2]
[node name="WatingRoom" type="Popup" groups=["WaitingRoom"]]
visible = true
anchor_right = 1.0
anchor_bottom = 1.0
[node name="ColorRect" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.109804, 0.129412, 0.243137, 1 )
[node name="CenterContainer" type="CenterContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
margin_left = 412.0
margin_top = 194.0
margin_right = 612.0
margin_bottom = 406.0
[node name="Label" type="Label" parent="CenterContainer/VBoxContainer"]
margin_right = 200.0
margin_bottom = 31.0
text = "Waiting Room
"
align = 1
valign = 1
[node name="ItemList" type="ItemList" parent="CenterContainer/VBoxContainer"]
margin_top = 35.0
margin_right = 200.0
margin_bottom = 188.0
rect_min_size = Vector2( 200, 0 )
custom_constants/vseparation = 10
items = [ "Player 1", null, false, "Player 2", null, false, "Player 3", null, false, "Player 4", null, false ]
auto_height = true
same_column_width = true
fixed_column_width = 200
icon_mode = 0
[node name="ReadyButton" type="Button" parent="CenterContainer/VBoxContainer"]
margin_top = 192.0
margin_right = 200.0
margin_bottom = 212.0
text = "Ready"