about summary refs log tree commit diff stats
path: root/Archipelago/settings_menu.gd
blob: 0efce4017bf680c557371a6de1c1fd90235a8a0d (plain) (blame)
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
extends "res://scripts/settings_menu.gd"


func _ready():
	var level_tab = get_node("Panel/Tabs/Level")
	level_tab.get_node("ScrollContainer").queue_free()
	level_tab.get_node("upload_button").queue_free()

	var new_label = Label.new()
	new_label.text = "You must restart Lingo before playing a non-Archipelago game."
	new_label.align = Label.ALIGN_CENTER
	new_label.valign = Label.VALIGN_CENTER
	new_label.autowrap = true
	new_label.margin_left = 25
	new_label.margin_top = 25
	new_label.margin_right = 1250
	new_label.margin_bottom = 492

	var field_font = DynamicFont.new()
	field_font.font_data = load("res://fonts/Lingo2.ttf")
	field_font.size = 48

	new_label.add_font_override("font", field_font)

	level_tab.add_child(new_label)
1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
extends Spatial


func _ready():
	# Some helpful logging.
	if Steam.isSubscribed():
		global._print("Provisioning successful! Build ID: %d" % Steam.getAppBuildId())
	else:
		global._print("Provisioning failed.")

	# Undo the load screen removing our cursor
	get_tree().get_root().set_disable_input(false)
	Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

	# Increase the WebSocket input buffer size so that we can download large
	# data packages.
	ProjectSettings.set_setting("network/limits/websocket_client/max_in_buffer_kb", 8192)

	# Create the global AP client, if it doesn't already exist.
	if not global.has_node("Archipelago"):
		var apclient_script = ResourceLoader.load("user://maps/Archipelago/client.gd")
		var apclient_instance = apclient_script.new()
		apclient_instance.name = "Archipelago"
		global.add_child(apclient_instance)

		apclient_instance.SCRIPT_doorControl = load("user://maps/Archipelago/doorControl.gd")
		apclient_instance.SCRIPT_effects = load("user://maps/Archipelago/effects.gd")
		apclient_instance.SCRIPT_location = load("user://maps/Archipelago/location.gd")
		apclient_instance.SCRIPT_multiplayer = load("user://maps/Archipelago/multiplayer.gd")
		apclient_instance.SCRIPT_mypainting = load("user://maps/Archipelago/mypainting.gd")
		apclient_instance.SCRIPT_notifier = load("user://maps/Archipelago/notifier.gd")
		apclient_instance.SCRIPT_panel = load("user://maps/Archipelago/panel.gd")
		apclient_instance.SCRIPT_uuid = load("user://maps/Archipelago/vendor/uuid.gd")

		var apdata = ResourceLoader.load("user://maps/Archipelago/gamedata.gd")
		var apdata_instance = apdata.new()
		apdata_instance.name = "Gamedata"
		apclient_instance.add_child(apdata_instance)

		var extradata = ResourceLoader.load("user://maps/Archipelago/extradata.gd")
		var extradata_instance = extradata.new()
		extradata_instance.name = "Extradata"
		apclient_instance.add_child(extradata_instance)

		# Let's also inject any scripts we need to inject now.
		installScriptExtension(apclient_instance.SCRIPT_doorControl)
		installScriptExtension(ResourceLoader.load("user://maps/Archipelago/load.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/Archipelago/painting_eye.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/Archipelago/painting_scenery.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/Archipelago/panelLevelSwitch.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/Archipelago/panelEnd.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/Archipelago/panelInput.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/Archipelago/pause_menu.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/Archipelago/player.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/Archipelago/worldTransporter.gd"))

	var apclient = global.get_node("Archipelago")
	apclient.connect("client_connected", self, "connectionSuccessful")
	apclient.connect("could_not_connect", self, "connectionUnsuccessful")
	apclient.connect("connect_status", self, "connectionStatus")

	# Populate textboxes with AP settings.
	self.get_node("Panel/server_box").text = apclient.ap_server
	self.get_node("Panel/player_box").text = apclient.ap_user
	self.get_node("Panel/password_box").text = apclient.ap_pass
	self.get_node("Panel/confusing_box").pressed = apclient.confusify_world
	self.get_node("Panel/multiplayer_box").pressed = apclient.enable_multiplayer
	self.get_node("Panel/position_box").pressed = apclient.track_player

	var history_box = get_node("Panel/connection_history")
	if apclient.connection_history.empty():
		history_box.disabled = true
	else:
		history_box.disabled = false

		var i = 0
		for details in apclient.connection_history:
			history_box.get_popup().add_item("%s (%s)" % [details[1], details[0]], i)
			i += 1

	history_box.get_popup().connect("id_pressed", self, "historySelected")

	# Show client version.
	self.get_node("Panel/title").text = "ARCHIPELAGO (%s)" % apclient.my_version

	# Increase font size in text boxes.
	var field_font = DynamicFont.new()
	field_font.font_data = load("res://fonts/CutiveMono_Regular.ttf")
	field_font.size = 36

	self.get_node("Panel/server_box").add_font_override("font", field_font)
	self.get_node("Panel/player_box").add_font_override("font", field_font)
	self.get_node("Panel/password_box").add_font_override("font", field_font)


# Adapted from https://gitlab.com/Delta-V-Modding/Mods/-/blob/main/game/ModLoader.gd
func installScriptExtension(childScript: Resource):
	# Force Godot to compile the script now.
	# We need to do this here to ensure that the inheritance chain is
	# properly set up, and multiple mods can chain-extend the same
	# class multiple times.
	# This is also needed to make Godot instantiate the extended class
	# when creating singletons.
	# The actual instance is thrown away.
	childScript.new()

	var parentScript = childScript.get_base_script()
	var parentScriptPath = parentScript.resource_path
	global._print("ModLoader: Installing script extension over %s" % parentScriptPath)
	childScript.take_over_path(parentScriptPath)


func connectionStatus(message):
	var popup = self.get_node("Panel/AcceptDialog")
	popup.window_title = "Connecting to Archipelago"
	popup.dialog_text = message
	popup.popup_exclusive = true
	popup.get_ok().visible = false
	popup.popup_centered()


func connectionSuccessful():
	var apclient = global.get_node("Archipelago")

	# Save connection details
	var connection_details = [apclient.ap_server, apclient.ap_user, apclient.ap_pass]
	if apclient.connection_history.has(connection_details):
		apclient.connection_history.erase(connection_details)
	apclient.connection_history.push_front(connection_details)
	if apclient.connection_history.size() > 10:
		apclient.connection_history.resize(10)
	apclient.saveSettings()

	# Switch to LL1
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	global.save_file = apclient.getSaveFileName()

	if Directory.new().file_exists("user://level1/%s.save" % global.save_file):
		global.map = "level1"
	else:
		global.map = "level1_stable"

	var _discard = get_tree().change_scene("res://scenes/load_screen.tscn")


func connectionUnsuccessful(error_message):
	self.get_node("Panel/connect_button").disabled = false

	var popup = self.get_node("Panel/AcceptDialog")
	popup.window_title = "Could not connect to Archipelago"
	popup.dialog_text = error_message
	popup.popup_exclusive = true
	popup.get_ok().visible = true
	popup.popup_centered()


func historySelected(index):
	var apclient = global.get_node("Archipelago")
	var details = apclient.connection_history[index]

	self.get_node("Panel/server_box").text = details[0]
	self.get_node("Panel/player_box").text = details[1]
	self.get_node("Panel/password_box").text = details[2]