aboutsummaryrefslogtreecommitdiff
path: root/client/menu/main_menu.gd
blob: 31ca5462a9a91981ffc666e7ac3254ec6d82d0e8 (plain)
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
# Undercooked - a game about cooking
# Copyright 2024 metamuffin
# Copyright 2024 tpart
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
extends Control

@onready var transition = $SceneTransition
@onready var quick_connect = $side/margin/options/quick_connect
@onready var quit_button = $side/margin/options/quit
@onready var connect_uri = $side/margin/options/connect/uri

func _ready():
	quick_connect.grab_focus()
	if OS.has_feature("web"):
		quit_button.hide()
	connect_uri.text = Global.settings["last_server_url"]

func _on_quit_pressed():
	transition.quit()

func _on_credits_pressed():
	transition.transition_to("res://menu/credits_menu.tscn")

func _on_connect_pressed():
	var url = $side/margin/options/connect/uri.text
	Global.settings["last_server_url"] = url
	Global.save_profile()
	connect_to(url)

func _on_quick_connect_pressed():
	if OS.has_feature("JavaScript"):
		connect_to(JavaScriptBridge.eval("""
			window.location.protocol.endsWith("s:")
			? `wss://${window.location.host}/`
			: `ws://${window.location.hostname}:27032/`
		"""))
	else:
		connect_to("wss://undercooked.metamuffin.org/")

func connect_to(url):
	print("Connecting to %s" % url)
	Global.server_url = url
	transition.transition_to("res://game.tscn")

func _on_change_character_pressed():
	transition.transition_to("res://menu/character_menu.tscn")

func _on_settings_pressed():
	transition.transition_to("res://menu/settings_menu.tscn")