aboutsummaryrefslogtreecommitdiff
path: root/client/menu/main_menu.gd
blob: 168eda7e6ed41510692365b8a5f015f3fc5f773e (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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 menu_manager: MenuManager = get_parent()

@onready var quit_button = $side/margin/options/quit
@onready var connect_uri = $side/margin/options/connect/uri
@onready var server_button = $side/margin/options/server

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

func _on_quit_pressed():
	menu_manager.transition.quit()

func _on_credits_pressed():
	menu_manager.goto("credits")

func _on_connect_pressed():
	var url = connect_uri.text
	Global.profile["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
	menu_manager.transition.transition_to("res://game.tscn")

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

func _on_settings_pressed():
	menu_manager.goto("settings")

func _on_server_pressed():
	match Server.state:
		Server.State.RUNNING: Server.stop()
		Server.State.STOPPED: Server.start()

func _process(_delta):
	server_button.disabled = Server.state != Server.State.RUNNING and Server.state != Server.State.STOPPED
	server_button.modulate = Color.AQUAMARINE if Server.state == Server.State.RUNNING else Color.WHITE
	match Server.state:
		Server.State.RUNNING: server_button.text = tr("Stop Server")
		Server.State.TESTING: server_button.text = tr("Server (Testing)")
		Server.State.STARTING: server_button.text = tr("Server is starting...")
		Server.State.STOPPED: server_button.text = tr("Start Server")
		Server.State.UNAVAILABLE: server_button.text = tr("Server (Unavailable)"); server_button.tooltip_text = tr("Server binary was not found. Please install the server seperately.")