From 86a87b882be20825af21bd09225aaa35ca793777 Mon Sep 17 00:00:00 2001
From: Star Rauchenberger <fefferburbia@gmail.com>
Date: Thu, 20 Apr 2023 22:48:41 -0400
Subject: Disable connect button while connecting

Pressing back now also halts the connection.
---
 Archipelago/client.gd           | 13 ++++++++++++-
 Archipelago/settings_buttons.gd |  5 +++++
 Archipelago/settings_screen.gd  |  2 ++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/Archipelago/client.gd b/Archipelago/client.gd
index a6a78e2..bb6d0a2 100644
--- a/Archipelago/client.gd
+++ b/Archipelago/client.gd
@@ -124,6 +124,11 @@ func _connected(_proto = ""):
 	global._print("Connected!")
 
 
+func disconnect_from_ap():
+	_initiated_disconnect = true
+	_client.disconnect_from_host()
+
+
 func _on_data():
 	var packet = _client.get_peer(1).get_packet()
 	global._print("Got data from server: " + packet.get_string_from_utf8())
@@ -388,7 +393,13 @@ func connectToServer():
 	var url = "ws://" + ap_server
 	var err = _client.connect_to_url(url)
 	if err != OK:
-		emit_signal("could_not_connect", "Could not connect to Archipelago. Error code: %d." % err)
+		emit_signal(
+			"could_not_connect",
+			(
+				"Could not connect to Archipelago. Check that your server and port are correct. See the error log for more information. Error code: %d."
+				% err
+			)
+		)
 		global._print("Could not connect to AP: " + err)
 		return
 	_should_process = true
diff --git a/Archipelago/settings_buttons.gd b/Archipelago/settings_buttons.gd
index 735f944..0050504 100644
--- a/Archipelago/settings_buttons.gd
+++ b/Archipelago/settings_buttons.gd
@@ -6,6 +6,8 @@ func _ready():
 
 
 func _connect_pressed():
+	self.disabled = true
+
 	var apclient = global.get_node("Archipelago")
 	apclient.ap_server = self.get_parent().get_node("server_box").text
 	apclient.ap_user = self.get_parent().get_node("player_box").text
@@ -16,4 +18,7 @@ func _connect_pressed():
 
 
 func _back_pressed():
+	var apclient = global.get_node("Archipelago")
+	apclient.disconnect_from_ap()
+
 	fader._fade_start("main_menu")
diff --git a/Archipelago/settings_screen.gd b/Archipelago/settings_screen.gd
index 0eb68cf..b74617b 100644
--- a/Archipelago/settings_screen.gd
+++ b/Archipelago/settings_screen.gd
@@ -66,6 +66,8 @@ func connectionSuccessful():
 
 
 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
-- 
cgit 1.4.1