-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain_menu.gd
More file actions
51 lines (34 loc) · 1.49 KB
/
main_menu.gd
File metadata and controls
51 lines (34 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This source code is provided as reference/companion material for the Godot Multiplayer Setup tutorial
# that can be freely found at http://kehomsforge.com and should not be commercialized
# in any form. It should remain free!
#
# By Yuri Sarudiansky
extends CanvasLayer
func _ready():
network.connect("server_created", self, "_on_ready_to_play")
network.connect("join_success", self, "_on_ready_to_play")
network.connect("join_fail", self, "_on_join_fail")
func set_player_info():
if (!$PanelPlayer/txtPlayerName.text.empty()):
gamestate.player_info.name = $PanelPlayer/txtPlayerName.text
gamestate.player_info.char_color = $PanelPlayer/btColor.color
func _on_btCreate_pressed():
# Properly set the local player information
set_player_info()
# Gather values from the GUI and fill the network.server_info dictionary
if (!$PanelHost/txtServerName.text.empty()):
network.server_info.name = $PanelHost/txtServerName.text
network.server_info.max_players = int($PanelHost/txtMaxPlayers.value)
network.server_info.used_port = int($PanelHost/txtServerPort.text)
# And create the server, using the function previously added into the code
network.create_server()
func _on_btJoin_pressed():
# Properly set the local player information
set_player_info()
var port = int($PanelJoin/txtJoinPort.text)
var ip = $PanelJoin/txtJoinIP.text
network.join_server(ip, port)
func _on_ready_to_play():
get_tree().change_scene("res://game_world.tscn")
func _on_join_fail():
print("Failed to join server")