diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/But_ChangeScene.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/But_ChangeScene.gd new file mode 100644 index 0000000..f8a43ac --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/But_ChangeScene.gd @@ -0,0 +1,18 @@ +#BUT_CHANGESCENE: +# Generic template script allowing GUI linking of scenes by button press. + +tool +extends Button + +#Creates param usable in the UI; and the params next to export make it string and file browser +export(String, FILE) var next_scene_path: = "" + +var tempToggle = 0 + +func _on_But_NewGame_button_up(): + get_tree().change_scene(next_scene_path) + + +func _get_configuration_warning() -> String: + return "next_scene_path must be set for this button to work" if next_scene_path == "" else "" + diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd index 052b427..7782a71 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd @@ -7,6 +7,8 @@ var server = null var client = null var ip_address = "" +var room_name = "" +var room_password = "" func _ready() -> void: ip_address = IP.get_local_addresses()[3] @@ -33,3 +35,7 @@ func _connected_to_server() -> void: func _server_disconnected() -> void: print("Disconnected from the server") + +func _set_server_info(name, password) -> void: + room_name = name + room_password = password diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd index f1bee1b..1b2737d 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd @@ -1,53 +1,55 @@ extends Control -var playerCounter = 1 -var player = load("res://Player.tscn") - -onready var multiplayer_config_ui = $Multiplayer_Configure -onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address -onready var device_ip_address = $CanvasLayer/Device_IP_Address +#var playerCounter = 1 +#var player = load("res://Player.tscn") +# +#onready var multiplayer_config_ui = $Multiplayer_Configure +#onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address +#onready var device_ip_address = $CanvasLayer/Device_IP_Address +# +# +# +## Called when the node enters the scene tree for the first time. +#func _ready(): +# get_tree().connect("network_peer_connected", self, "_player_connected") +# get_tree().connect("network_peer_disconnected", self, "_player_disconnected") +# get_tree().connect("connected_to_server", self, "_connected_to_server") +# +# device_ip_address.text = Network.ip_address +# +#func _player_connected(id) -> void: +# print("Player " + str(id) + "connected") +# instance_player(id) +# +#func _player_disconnected(id) -> void: +# print("Player " + str(id) + "disconnected") +# +# if Players.has_node(str(id)): +# Players.get_node(str(id)).queue_free() +# +#func _on_Create_Server_pressed(): +# multiplayer_config_ui.hide() +# Network._create_server() +# instance_player(get_tree().get_network_unique_id()) +# +#func _on_Join_Server_pressed(): +# if server_ip_address.text != "": +# multiplayer_config_ui.hide() +# Network.ip_address = server_ip_address.text +# Network._join_server() +# +#func _connected_to_server() -> void: +# yield(get_tree().create_timer(0.1), "timeout") +# instance_player(get_tree().get_network_unique_id()) +# +#func instance_player(id) -> void: +# var player_instance = Global.instance_node(player, Players) +# player_instance.name = str(id) +# var player_name = "Player " + str(playerCounter) +# player_instance._set_name(player_name) +# player_instance._set_name_position(playerCounter) +# player_instance.set_network_master(id) +# playerCounter += 1 - -# Called when the node enters the scene tree for the first time. -func _ready(): - get_tree().connect("network_peer_connected", self, "_player_connected") - get_tree().connect("network_peer_disconnected", self, "_player_disconnected") - get_tree().connect("connected_to_server", self, "_connected_to_server") - - device_ip_address.text = Network.ip_address - -func _player_connected(id) -> void: - print("Player " + str(id) + "connected") - instance_player(id) - -func _player_disconnected(id) -> void: - print("Player " + str(id) + "disconnected") - - if Players.has_node(str(id)): - Players.get_node(str(id)).queue_free() - -func _on_Create_Server_pressed(): - multiplayer_config_ui.hide() - Network._create_server() - instance_player(get_tree().get_network_unique_id()) - -func _on_Join_Server_pressed(): - if server_ip_address.text != "": - multiplayer_config_ui.hide() - Network.ip_address = server_ip_address.text - Network._join_server() - -func _connected_to_server() -> void: - yield(get_tree().create_timer(0.1), "timeout") - instance_player(get_tree().get_network_unique_id()) - -func instance_player(id) -> void: - var player_instance = Global.instance_node(player, Players) - player_instance.name = str(id) - var player_name = "Player " + str(playerCounter) - player_instance._set_name(player_name) - player_instance._set_name_position(playerCounter) - player_instance.set_network_master(id) - playerCounter += 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn index 49caf72..82e64be 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://Network_Setup.gd" type="Script" id=1] +[ext_resource path="res://But_ChangeScene.gd" type="Script" id=2] [node name="Network_Setup" type="Control"] anchor_right = 1.0 @@ -21,6 +22,8 @@ margin_top = 21.0 margin_right = 125.0 margin_bottom = 121.0 text = "Create Server" +script = ExtResource( 2 ) +next_scene_path = "res://Room_Creation.tscn" [node name="Join_Server" type="Button" parent="Multiplayer_Configure"] anchor_left = 0.5 @@ -32,6 +35,7 @@ margin_top = -129.0 margin_right = 125.0 margin_bottom = -29.0 text = "Join Server" +script = ExtResource( 2 ) [node name="Server_IP_Address" type="LineEdit" parent="Multiplayer_Configure"] margin_left = 389.0 @@ -54,5 +58,4 @@ margin_bottom = -26.0 align = 1 valign = 1 -[connection signal="pressed" from="Multiplayer_Configure/Create_Server" to="." method="_on_Create_Server_pressed"] -[connection signal="pressed" from="Multiplayer_Configure/Join_Server" to="." method="_on_Join_Server_pressed"] +[connection signal="button_up" from="Multiplayer_Configure/Create_Server" to="Multiplayer_Configure/Create_Server" method="_on_But_NewGame_button_up"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd new file mode 100644 index 0000000..e2ac87e --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd @@ -0,0 +1,59 @@ +extends Control + + +var playerCounter = 1 +var player = load("res://Player.tscn") + +onready var multiplayer_config_ui = $Multiplayer_Configure +#onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address +onready var device_ip_address = $CanvasLayer/Device_IP_Address +onready var player_name = $Multiplayer_Configure/Player_Name +onready var room_name = $Multiplayer_Configure/Room_Name +onready var room_password = $Multiplayer_Configure/Room_Password +onready var room_ui = $Room_UI + + + +# Called when the node enters the scene tree for the first time. +func _ready(): + get_tree().connect("network_peer_connected", self, "_player_connected") + get_tree().connect("network_peer_disconnected", self, "_player_disconnected") + get_tree().connect("connected_to_server", self, "_connected_to_server") + + device_ip_address.text = Network.ip_address + +func _player_connected(id) -> void: + print("Player " + str(id) + "connected") + instance_player(id) + +func _player_disconnected(id) -> void: + print("Player " + str(id) + "disconnected") + + if Players.has_node(str(id)): + Players.get_node(str(id)).queue_free() + +func _on_Create_Server_pressed(): + multiplayer_config_ui.hide() + Network._create_server() + instance_player(get_tree().get_network_unique_id()) + Network._set_server_info(room_name.text, room_password.text) + $Room_UI/Room_Name.text = room_name.text + room_ui.show() + +#func _on_Join_Server_pressed(): +# if server_ip_address.text != "": +# multiplayer_config_ui.hide() +# Network.ip_address = server_ip_address.text +# Network._join_server() + +func _connected_to_server() -> void: + yield(get_tree().create_timer(0.1), "timeout") + instance_player(get_tree().get_network_unique_id()) + +func instance_player(id) -> void: + var player_instance = Global.instance_node(player, Players) + player_instance.name = str(id) + player_instance._set_name(player_name.text) + player_instance._set_name_position(playerCounter) + player_instance.set_network_master(id) + playerCounter += 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn new file mode 100644 index 0000000..2543f5f --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn @@ -0,0 +1,86 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Room_Creation.gd" type="Script" id=1] + +[node name="Room_Creation" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="Back" type="Button" parent="."] +margin_left = 312.0 +margin_top = 419.0 +margin_right = 474.0 +margin_bottom = 493.0 +text = "Back" + +[node name="Multiplayer_Configure" type="Control" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="Create_Server" type="Button" parent="Multiplayer_Configure"] +margin_left = 592.0 +margin_top = 419.0 +margin_right = 754.0 +margin_bottom = 493.0 +text = "Create" + +[node name="Room_Name" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 452.0 +margin_top = 250.0 +margin_right = 619.0 +margin_bottom = 274.0 +text = "Room Name" +align = 1 + +[node name="Room_Password" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 452.0 +margin_top = 315.0 +margin_right = 619.0 +margin_bottom = 339.0 +text = "Room Password" +align = 1 + +[node name="Player_Name" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 451.0 +margin_top = 188.0 +margin_right = 618.0 +margin_bottom = 212.0 +text = "Player Name" +align = 1 + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Device_IP_Address" type="Label" parent="CanvasLayer"] +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = -1.0 +margin_top = -76.0 +margin_right = -1.0 +margin_bottom = -26.0 +align = 1 +valign = 1 + +[node name="Room_UI" type="Control" parent="."] +visible = false +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="Room_Name" type="Label" parent="Room_UI"] +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -20.0 +margin_right = 20.0 +margin_bottom = 14.0 + +[node name="Players" type="Label" parent="Room_UI"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_top = -225.0 +margin_bottom = -225.0 +text = "Players:" +align = 1 +valign = 1 + +[connection signal="pressed" from="Multiplayer_Configure/Create_Server" to="." method="_on_Create_Server_pressed"]