Skip to content

Commit

Permalink
part 5
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuSai committed Aug 9, 2022
1 parent 9caad3d commit 94013f7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
5 changes: 5 additions & 0 deletions JoinDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ func connected_ok() -> void:
connect_button.disabled = false

wait_container.show()


func _on_JoinDialog_popup_hide() -> void:
wait_container.hide()
connect_container.show()
23 changes: 23 additions & 0 deletions Menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,26 @@ func _on_JoinButton_pressed() -> void:
func _on_popup_hide() -> void:
if get_tree().network_peer != null:
Client.stop()


func add_player_to_ui(name: String) -> void:
if Client.is_creator:
create_dialog_player_list.add_player(name)
else:
join_player_list.add_player(name)


func remove_player(index: int) -> void:
if Client.is_creator:
create_dialog_player_list.remove_player(index)
else:
join_player_list.remove_player(index)


func remove_all_players() -> void:
if Client.is_creator:
create_dialog_player_list.remove_all()
create_dialog.hide()
else:
join_player_list.remove_all()
join_dialog.hide()
7 changes: 6 additions & 1 deletion Menu.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Menu.gd" type="Script" id=1]
[ext_resource path="res://JoinDialog.gd" type="Script" id=2]
[ext_resource path="res://PlayerList.gd" type="Script" id=3]

[node name="Menu" type="Control"]
anchor_right = 1.0
Expand Down Expand Up @@ -50,6 +51,7 @@ margin_bottom = 14.0
text = "Loading..."

[node name="PlayerList" type="VBoxContainer" parent="CreateDialog/ScrollContainer/VBoxContainer"]
script = ExtResource( 3 )

[node name="JoinDialog" type="WindowDialog" parent="."]
visible = true
Expand Down Expand Up @@ -96,8 +98,11 @@ margin_bottom = 14.0
[node name="PlayerList" type="VBoxContainer" parent="JoinDialog/WaitScrollContainer/VBoxContainer"]
margin_top = 18.0
margin_bottom = 18.0
script = ExtResource( 3 )

[connection signal="pressed" from="VBoxContainer/CreateButton" to="." method="_on_CreateButton_pressed"]
[connection signal="pressed" from="VBoxContainer/JoinButton" to="." method="_on_JoinButton_pressed"]
[connection signal="popup_hide" from="CreateDialog" to="." method="_on_popup_hide"]
[connection signal="popup_hide" from="JoinDialog" to="." method="_on_popup_hide"]
[connection signal="popup_hide" from="JoinDialog" to="JoinDialog" method="_on_JoinDialog_popup_hide"]
[connection signal="pressed" from="JoinDialog/ConnectVBoxContainer/ConnectButton" to="JoinDialog" method="_on_ConnectButton_pressed"]
16 changes: 16 additions & 0 deletions PlayerList.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends VBoxContainer


func add_player(name: String) -> void:
var label: Label = Label.new()
label.text = name
add_child(label)


func remove_player(index: int) -> void:
get_child(index).queue_free()


func remove_all() -> void:
for child in get_children():
child.queue_free()
20 changes: 20 additions & 0 deletions autoloads/Client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ func stop() -> void:
get_tree().disconnect("server_disconnected", self, "_server_disconnected")

get_tree().network_peer = null

_remove_all_players()


remote func register_player(id: int, info: Dictionary) -> void:
player_info[id] = info
get_tree().current_scene.add_player_to_ui(info.name)


remote func remove_player(id: int) -> void:
get_tree().current_scene.remove_player(player_info.keys().find(id))

if not player_info.erase(id):
printerr("Error removing player from dictionary")


func _remove_all_players() -> void:
get_tree().current_scene.remove_all_players()

player_info = {}


func _connected_ok() -> void:
Expand Down

0 comments on commit 94013f7

Please sign in to comment.