-
Notifications
You must be signed in to change notification settings - Fork 1
/
join_game.gd
60 lines (46 loc) · 1.57 KB
/
join_game.gd
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
51
52
53
54
55
56
57
58
59
60
extends Node2D
onready var lobby = $lobby
onready var game_id = $GUI/game_id
onready var join_button = $GUI/join_button
onready var error_panel = $GUI/error_panel
onready var wait_panel = $GUI/wait_panel
# HACK(Richo): We can't handle the textchanged event because the
# experimental virtual keyboard doesn't support it so instead we
# just check the value on the process event
onready var previous_game_id = game_id.text
func _process(delta):
if game_id.text != previous_game_id:
# Only uppercase
var pos = game_id.caret_position
game_id.text = game_id.text.to_upper()
game_id.caret_position = pos
# Enable join button if not empty
join_button.disabled = game_id.text.strip_edges().empty()
previous_game_id = game_id.text
func _on_join_button_pressed():
join()
func _on_game_id_text_entered(new_text):
join()
func join():
if error_panel.visible: return
if join_button.disabled: return
var id = game_id.text.strip_edges()
if id.empty(): return
join_button.disabled = true
game_id.editable = false
lobby.game_id = id
lobby.start()
wait_panel.set_game_code(id)
wait_panel.visible = true
# If, for some reason, the connection cannot be made we wait 15 seconds
# before giving up
yield(get_tree().create_timer(15), "timeout")
lobby.stop()
func _on_back_button_pressed():
get_tree().change_scene("res://menu.tscn")
func _on_lobby_connection_failed(reason):
if reason.empty(): reason = "Unknown"
error_panel.show_message("CONNECTION FAILED!", "Reason: %s" % reason)
wait_panel.visible = false
func _on_error_panel_closed():
get_tree().reload_current_scene()