forked from unfa/liblast
Add rudimentary menu
parent
bf510a7c9e
commit
3b92b0fd6c
41
Game.gd
41
Game.gd
|
@ -11,48 +11,51 @@ var player_scene = preload("res://Player.tscn")
|
|||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
initialize()
|
||||
pass
|
||||
#initialize()
|
||||
|
||||
debug_connection_status()
|
||||
#debug_connection_status()
|
||||
|
||||
func _input(event):
|
||||
if event.is_action_pressed("ToggleMenu"):
|
||||
if GAME_MODE == "PLAYING":
|
||||
GAME_MODE = "MENU"
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
open_menu()
|
||||
else:
|
||||
GAME_MODE = "PLAYING"
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
close_menu()
|
||||
|
||||
func open_menu():
|
||||
GAME_MODE = "MENU"
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
$MenuContainer.show()
|
||||
|
||||
func close_menu():
|
||||
GAME_MODE = "PLAYING"
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
$MenuContainer.hide()
|
||||
|
||||
func debug_connection_status():
|
||||
if (get_tree().network_peer.get_connection_status() == NetworkedMultiplayerPeer.CONNECTION_CONNECTING):
|
||||
print("We are trying to connect")
|
||||
|
||||
func initialize():
|
||||
var peer
|
||||
|
||||
if is_server:
|
||||
peer = initialize_server()
|
||||
else:
|
||||
peer = initialize_client()
|
||||
|
||||
get_tree().network_peer = peer
|
||||
|
||||
|
||||
func initialize_server():
|
||||
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")
|
||||
add_player(1, false)
|
||||
return peer
|
||||
get_tree().network_peer = peer
|
||||
close_menu()
|
||||
|
||||
func initialize_client():
|
||||
var peer = NetworkedMultiplayerENet.new()
|
||||
peer.create_client(SERVER_IP, SERVER_PORT)
|
||||
get_tree().connect("connected_to_server", self, "on_connection_established")
|
||||
get_tree().connect("connection_failed", self, "on_connection_failed")
|
||||
return peer
|
||||
get_tree().network_peer = peer
|
||||
close_menu()
|
||||
|
||||
func quit():
|
||||
get_tree().quit()
|
||||
|
||||
func get_player_names():
|
||||
var players = $Players.get_children()
|
||||
|
|
66
Game.tscn
66
Game.tscn
|
@ -9,3 +9,69 @@ script = ExtResource( 2 )
|
|||
[node name="Level" parent="." instance=ExtResource( 3 )]
|
||||
|
||||
[node name="Players" type="Spatial" parent="."]
|
||||
|
||||
[node name="MenuContainer" type="CenterContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="MenuList" type="VBoxContainer" parent="MenuContainer"]
|
||||
margin_left = 362.0
|
||||
margin_top = 252.0
|
||||
margin_right = 662.0
|
||||
margin_bottom = 348.0
|
||||
rect_min_size = Vector2( 300, 0 )
|
||||
|
||||
[node name="AdressBook" type="MenuButton" parent="MenuContainer/MenuList"]
|
||||
margin_right = 300.0
|
||||
margin_bottom = 20.0
|
||||
text = "Select destination"
|
||||
items = [ "Unfa", null, 0, false, false, 0, 0, null, "", false, "Jan", null, 0, false, false, 1, 0, null, "", false ]
|
||||
|
||||
[node name="Destination" type="HBoxContainer" parent="MenuContainer/MenuList"]
|
||||
margin_top = 24.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 48.0
|
||||
|
||||
[node name="IPAdress" type="LineEdit" parent="MenuContainer/MenuList/Destination"]
|
||||
margin_right = 208.0
|
||||
margin_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.38
|
||||
placeholder_text = "IP address"
|
||||
|
||||
[node name="Port" type="LineEdit" parent="MenuContainer/MenuList/Destination"]
|
||||
margin_left = 212.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "port"
|
||||
|
||||
[node name="NetworkType" type="HBoxContainer" parent="MenuContainer/MenuList"]
|
||||
margin_top = 52.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 72.0
|
||||
|
||||
[node name="Host" type="Button" parent="MenuContainer/MenuList/NetworkType"]
|
||||
margin_right = 148.0
|
||||
margin_bottom = 20.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Host"
|
||||
|
||||
[node name="Join" type="Button" parent="MenuContainer/MenuList/NetworkType"]
|
||||
margin_left = 152.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 20.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Join"
|
||||
|
||||
[node name="Quit" type="Button" parent="MenuContainer/MenuList"]
|
||||
margin_top = 76.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 96.0
|
||||
text = "Quit"
|
||||
[connection signal="pressed" from="MenuContainer/MenuList/NetworkType/Host" to="." method="initialize_server"]
|
||||
[connection signal="pressed" from="MenuContainer/MenuList/NetworkType/Join" to="." method="initialize_client"]
|
||||
[connection signal="pressed" from="MenuContainer/MenuList/Quit" to="." method="quit"]
|
||||
|
|
Loading…
Reference in New Issue