Forward progress on joining sessions. Pre-game lobby created.
This commit is contained in:
parent
f9a788d7db
commit
f298ca909c
2 changed files with 125 additions and 32 deletions
104
scenes/menu.tscn
104
scenes/menu.tscn
|
@ -27,6 +27,12 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
anchor_mode = 0
|
||||||
|
current = true
|
||||||
|
smoothing_enabled = true
|
||||||
|
smoothing_speed = 10.0
|
||||||
|
|
||||||
[node name="Header2" type="Label" parent="."]
|
[node name="Header2" type="Label" parent="."]
|
||||||
margin_right = 158.0
|
margin_right = 158.0
|
||||||
margin_bottom = 11.0
|
margin_bottom = 11.0
|
||||||
|
@ -163,6 +169,89 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="Game Lobby" type="Panel" parent="."]
|
||||||
|
anchor_left = 0.0125
|
||||||
|
anchor_top = 0.0888889
|
||||||
|
anchor_right = 0.0125
|
||||||
|
anchor_bottom = 0.0888889
|
||||||
|
margin_left = 648.0
|
||||||
|
margin_top = 17.0
|
||||||
|
margin_right = 1256.0
|
||||||
|
margin_bottom = 318.0
|
||||||
|
custom_styles/panel = ExtResource( 7 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Header4" type="Label" parent="Game Lobby"]
|
||||||
|
margin_left = -7.38599
|
||||||
|
margin_top = -48.0
|
||||||
|
margin_right = 150.614
|
||||||
|
margin_bottom = -37.0
|
||||||
|
rect_scale = Vector2( 4, 4 )
|
||||||
|
custom_fonts/font = ExtResource( 2 )
|
||||||
|
text = "pregame lobby"
|
||||||
|
align = 1
|
||||||
|
valign = 1
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="PlayersPanel" type="Panel" parent="Game Lobby"]
|
||||||
|
anchor_left = 0.0125
|
||||||
|
anchor_top = 0.0888889
|
||||||
|
anchor_right = 0.0125
|
||||||
|
anchor_bottom = 0.0888889
|
||||||
|
margin_left = 352.4
|
||||||
|
margin_top = 4.24444
|
||||||
|
margin_right = 584.4
|
||||||
|
margin_bottom = 228.244
|
||||||
|
custom_styles/panel = ExtResource( 7 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="Game Lobby/PlayersPanel"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
margin_top = 8.0
|
||||||
|
margin_bottom = 19.0
|
||||||
|
custom_fonts/font = ExtResource( 2 )
|
||||||
|
text = "connected Players"
|
||||||
|
align = 1
|
||||||
|
valign = 1
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="Game Lobby"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
margin_top = 7.0
|
||||||
|
margin_bottom = 18.0
|
||||||
|
custom_fonts/font = ExtResource( 2 )
|
||||||
|
text = "General"
|
||||||
|
align = 1
|
||||||
|
valign = 1
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Btn_Disconnect" type="Button" parent="Game Lobby"]
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
margin_left = -288.0
|
||||||
|
margin_top = -38.0
|
||||||
|
margin_right = -206.0
|
||||||
|
margin_bottom = -17.0
|
||||||
|
hint_tooltip = "Join an online game with above parameters"
|
||||||
|
mouse_default_cursor_shape = 2
|
||||||
|
custom_fonts/font = ExtResource( 1 )
|
||||||
|
text = "Disconnect"
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
[node name="HostPanel" type="Panel" parent="."]
|
[node name="HostPanel" type="Panel" parent="."]
|
||||||
anchor_left = 0.0125
|
anchor_left = 0.0125
|
||||||
anchor_top = 0.0888889
|
anchor_top = 0.0888889
|
||||||
|
@ -262,21 +351,6 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="CheckBox" type="CheckBox" parent="HostPanel"]
|
|
||||||
margin_left = 88.0
|
|
||||||
margin_top = 104.0
|
|
||||||
margin_right = 264.0
|
|
||||||
margin_bottom = 128.0
|
|
||||||
hint_tooltip = "Tonytins mode! Duh!"
|
|
||||||
custom_fonts/font = ExtResource( 3 )
|
|
||||||
disabled = true
|
|
||||||
toggle_mode = false
|
|
||||||
shortcut_in_tooltip = false
|
|
||||||
text = "Tonytins Mode"
|
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="HostGameBtn" type="Button" parent="HostPanel"]
|
[node name="HostGameBtn" type="Button" parent="HostPanel"]
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
var host_port = 2675
|
var host_port = 2675
|
||||||
var host_playermax = 2
|
var maxplayers
|
||||||
var ip = "127.0.0.1"
|
var ip = "127.0.0.1"
|
||||||
var port = 2670
|
var port = 2670
|
||||||
|
var players = {}
|
||||||
|
var playername
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
get_tree().connect("connected_to_server", self, "_connected_ok")
|
||||||
|
get_tree().connect("connection_failed", self, "_connected_fail")
|
||||||
|
get_tree().connect("server_disconnected", self, "_server_disconnect")
|
||||||
if OS.has_environment("USERNAME"):
|
if OS.has_environment("USERNAME"):
|
||||||
$GeneralPanel/player_name.text = OS.get_environment("USERNAME")
|
$GeneralPanel/player_name.text = OS.get_environment("USERNAME")
|
||||||
else:
|
else:
|
||||||
|
@ -19,8 +23,8 @@ func _on_singleplayer_button_up():
|
||||||
|
|
||||||
|
|
||||||
func _on_JoinGameBtn_button_up():
|
func _on_JoinGameBtn_button_up():
|
||||||
ip = $JoinPanel/join_ip
|
ip = $JoinPanel/join_ip.text
|
||||||
port = $JoinPanel/join_port
|
port = $JoinPanel/join_port.value
|
||||||
print("Netplay - Attempting to join game at IP ",ip," via port ",port)
|
print("Netplay - Attempting to join game at IP ",ip," via port ",port)
|
||||||
join_game()
|
join_game()
|
||||||
|
|
||||||
|
@ -30,21 +34,36 @@ func _on_HostGameBtn_button_up():
|
||||||
host_game(host_port)
|
host_game(host_port)
|
||||||
|
|
||||||
func host_game(port):
|
func host_game(port):
|
||||||
var maxplayers = $HostPanel/playercount.value
|
playername = $GeneralPanel/player_name.text
|
||||||
|
maxplayers = $HostPanel/playercount.value
|
||||||
var host = NetworkedMultiplayerENet.new()
|
var host = NetworkedMultiplayerENet.new()
|
||||||
print("Netplay - Returned: ",host)
|
var hostresult = host.create_server(port, maxplayers) # ports, maxplayers
|
||||||
host.create_server(port, maxplayers) # ports, maxplayers
|
if (hostresult==OK):
|
||||||
get_tree().set_network_peer(host)
|
print("Netplay - No conflicts. Starting Server")
|
||||||
print("Netplay - Hosting on port ",port,". Max players: ",maxplayers)
|
get_tree().set_network_peer(host)
|
||||||
print("Netplay - Are you the server ... ",get_tree().is_network_server())
|
print("Netplay - Hosting on port ",port,". Max players: ",maxplayers)
|
||||||
$HostPanel/HostGameBtn.disabled = 1
|
print("Netplay - Are you the server ... ",get_tree().is_network_server())
|
||||||
$HostPanel/HostGameBtn.hint_tooltip = "Cannot start another server, Server already started."
|
$HostPanel/HostGameBtn.disabled = 1
|
||||||
$JoinPanel/JoinGameBtn.disabled = 1
|
$HostPanel/HostGameBtn.hint_tooltip = "Cannot start another server, Server already started."
|
||||||
$JoinPanel/JoinGameBtn.hint_tooltip = "Cannot join another server, Server already started."
|
$JoinPanel/JoinGameBtn.disabled = 1
|
||||||
|
$JoinPanel/JoinGameBtn.hint_tooltip = "Cannot join another server, Server already started."
|
||||||
|
$Camera2D.position.x += 640
|
||||||
|
else:
|
||||||
|
print("Netplay - Cant start server")
|
||||||
#Goto a lobby instance
|
#Goto a lobby instance
|
||||||
|
|
||||||
func join_game():
|
func join_game():
|
||||||
|
playername = $GeneralPanel/player_name.text
|
||||||
var host = NetworkedMultiplayerENet.new()
|
var host = NetworkedMultiplayerENet.new()
|
||||||
host.create_client(ip, port)
|
var joinresult = host.create_client(ip, port)
|
||||||
get_tree().set_network_peer(host)
|
if (joinresult==OK):
|
||||||
print("Maybe it joined...?")
|
get_tree().set_network_peer(host)
|
||||||
|
print("Netplay - It worked! I should be connecting...")
|
||||||
|
else:
|
||||||
|
print("Netplay - I was unable to connect to the server.")
|
||||||
|
|
||||||
|
func _connected_ok():
|
||||||
|
print("Netplay - Built-in Signal - It worked! Im connected!")
|
||||||
|
|
||||||
|
func _connected_fail():
|
||||||
|
print("Netplay - Built-in Signal - It failed")
|
||||||
|
|
Loading…
Add table
Reference in a new issue