Added host as spectator option. Fix #15

remotes/1705382094874458415/tmp_refs/heads/godot4-port
Jan 2020-09-21 15:17:29 +02:00
parent cf13adf1e1
commit 0882c770f4
2 changed files with 19 additions and 6 deletions

View File

@ -1,4 +1,4 @@
extends Spatial
extends Node
export var SERVER_PORT = 9999 setget , get_port
export(String, "172.28.162.191", "172.28.166.24", "127.0.0.1") var SERVER_IP = "172.28.162.191" setget , get_ip
@ -136,14 +136,15 @@ func get_ip():
func get_port():
return SERVER_PORT
func initialize_server():
func initialize_server(join=true):
var peer = NetworkedMultiplayerENet.new()
peer.create_server(SERVER_PORT, MAX_PLAYERS)
get_tree().connect("network_peer_connected", self, "on_peer_connected")
get_tree().connect("network_peer_disconnected", self, "on_peer_disconnected")
get_tree().network_peer = peer
close_menus()
add_player(1, false)
if join:
add_player(1, false)
func initialize_client():
var peer = NetworkedMultiplayerENet.new()

View File

@ -26,7 +26,7 @@ glow_blend_mode = 0
glow_hdr_threshold = 1.5
glow_bicubic_upscale = true
[node name="Game" type="Spatial"]
[node name="Game" type="Node"]
script = ExtResource( 2 )
SERVER_IP = "127.0.0.1"
@ -68,6 +68,8 @@ margin_bottom = 24.0
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.38
placeholder_text = "IP address"
caret_blink = true
caret_blink_speed = 0.5
[node name="Port" type="LineEdit" parent="MenuContainer/MainMenu/Destination"]
margin_left = 282.0
@ -75,6 +77,8 @@ margin_right = 400.0
margin_bottom = 24.0
size_flags_horizontal = 3
placeholder_text = "port"
caret_blink = true
caret_blink_speed = 0.5
[node name="NetworkType" type="HBoxContainer" parent="MenuContainer/MainMenu"]
margin_top = 52.0
@ -82,13 +86,20 @@ margin_right = 400.0
margin_bottom = 72.0
[node name="Host" type="Button" parent="MenuContainer/MainMenu/NetworkType"]
margin_right = 198.0
margin_right = 130.0
margin_bottom = 20.0
size_flags_horizontal = 3
text = "Host"
[node name="HostAsSpectator" type="Button" parent="MenuContainer/MainMenu/NetworkType"]
margin_left = 134.0
margin_right = 265.0
margin_bottom = 20.0
size_flags_horizontal = 3
text = "Host As Spectator"
[node name="Join" type="Button" parent="MenuContainer/MainMenu/NetworkType"]
margin_left = 202.0
margin_left = 269.0
margin_right = 400.0
margin_bottom = 20.0
size_flags_horizontal = 3
@ -221,6 +232,7 @@ text = "Fullscreen"
[connection signal="pressed" from="MenuContainer/MainMenu/QuickJoin" to="." method="open_menu" binds= [ "QuickJoinMenu" ]]
[connection signal="text_changed" from="MenuContainer/MainMenu/Destination/IPAdress" to="." method="set_ip"]
[connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/Host" to="." method="initialize_server"]
[connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/HostAsSpectator" to="." method="initialize_server" binds= [ false ]]
[connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/Join" to="." method="initialize_client"]
[connection signal="pressed" from="MenuContainer/MainMenu/Options" to="." method="open_menu" binds= [ "OptionsMenu" ]]
[connection signal="pressed" from="MenuContainer/MainMenu/Quit" to="." method="quit"]