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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
extends Control
signal game_host_request(game_name, username, max_players, private, password)
signal game_join_request(lobby_id, password, username, args)
var lobby_name_changed : bool = false # automatically update lobby name to be based on player's name
func _ready():
$BackButton.connect("pressed", self, "back_button")
$HostMenuButton.connect("pressed", self, "host_menu_button_pressed")
$JoinMenuButton.connect("pressed", self, "join_menu_button_pressed")
$SettingsButton.connect("pressed", self, "settings_menu_button_pressed")
$HostMenu/PrivateToggle.connect("toggled", $HostMenu/Password, "set_visible")
$SettingsMenu/GameCoordinatorURL.connect("text_changed", Globals, "update_gc_url")
$PlayerInfo/Username.connect("text_changed", self, "automatically_update_lobby_name")
$HostMenu/GameName.connect("text_changed", self, "set_lobby_name_changed")
$HostMenu/HostButton.connect("pressed", self, "on_host_button_pressed")
$JoinMenu/JoinButton.connect("pressed", self, "on_join_button_pressed")
#main_menu() # in case things are incorrectly visible from editing
func open_popup(title, message, close_disabled = false):
$NotifPopup.popup_centered()
$NotifPopup/PopupControl/TitleLabel.text = title
$NotifPopup/PopupControl/MessageLabel.text = message
$NotifPopup/PopupControl/ClosePopupButton.disabled = close_disabled
func close_popup():
$NotifPopup.visible = false
func set_lobby_name_changed(_disregard_new_text):
lobby_name_changed = true
func automatically_update_lobby_name(username : String):
if lobby_name_changed: return
var suffix : String = "' Game" if username.ends_with("s") else "'s Game"
$HostMenu/GameName.set_text(username + suffix)
func main_menu():
set_menu_buttons_visible(true)
set_player_info_visible(false)
set_join_menu_visible(false)
set_host_menu_visible(false)
set_settings_menu_visible(false)
set_back_button_visible(false)
func set_menu_buttons_visible(visible : bool):
$HostMenuButton.visible = visible
$JoinMenuButton.visible = visible
$SettingsButton.visible = visible
func set_player_info_visible(visible : bool):
$PlayerInfo.visible = visible
func set_join_menu_visible(visible : bool):
$JoinMenu.visible = visible
func set_host_menu_visible(visible : bool):
$HostMenu.visible = visible
func set_settings_menu_visible(visible : bool):
$SettingsMenu.visible = visible
func set_back_button_visible(visible : bool):
$BackButton.visible = visible
$BackButton.disabled = false # reset in case left disabled by other function
## MENU CALLBACKS
# go to join game menu
func join_menu_button_pressed(lobby_id_from_url : String = "", password_from_url : String = ""):
set_menu_buttons_visible(false)
set_player_info_visible(true)
set_join_menu_visible(true)
set_back_button_visible(true)
if lobby_id_from_url:
$JoinMenu/LobbyID.text = lobby_id_from_url
if password_from_url:
$JoinMenu/Password.text = password_from_url
# go to host game menu
func host_menu_button_pressed():
set_menu_buttons_visible(false)
set_player_info_visible(true)
set_host_menu_visible(true)
set_back_button_visible(true)
# go to settings menu
func settings_menu_button_pressed():
$SettingsMenu/GameCoordinatorURL.text = Globals.GC_URL
set_menu_buttons_visible(false)
set_settings_menu_visible(true)
set_back_button_visible(true)
# return to main menu
func back_button():
main_menu()
## GAME CALLBACKS
func on_join_button_pressed():
open_popup("Connecting...", "Connecting to game coordinator...", true)
var args = { "color_pref_1" : $PlayerInfo/PlayerColor.selected, "color_pref_2" : $PlayerInfo/AltPlayerColor.selected }
emit_signal("game_join_request", $JoinMenu/LobbyID.text, $JoinMenu/Password.text, $PlayerInfo/Username.text, args)
func on_host_button_pressed():
open_popup("Connecting...", "Connecting to game coordinator...", true)
emit_signal("game_host_request", $HostMenu/GameName.text, $PlayerInfo/Username.text, $HostMenu/PlayerCount.get_selected_id(), $HostMenu/PrivateToggle.pressed, $HostMenu/Password.text)
|