diff options
Diffstat (limited to 'client/Archipelago/settings_screen.gd')
| -rw-r--r-- | client/Archipelago/settings_screen.gd | 173 |
1 files changed, 173 insertions, 0 deletions
| diff --git a/client/Archipelago/settings_screen.gd b/client/Archipelago/settings_screen.gd new file mode 100644 index 0000000..90d5437 --- /dev/null +++ b/client/Archipelago/settings_screen.gd | |||
| @@ -0,0 +1,173 @@ | |||
| 1 | extends Node2D | ||
| 2 | |||
| 3 | |||
| 4 | func _ready(): | ||
| 5 | # Some helpful logging. | ||
| 6 | if Steam.isSubscribed(): | ||
| 7 | global._print("Provisioning successful! Build ID: %d" % Steam.getAppBuildId()) | ||
| 8 | else: | ||
| 9 | global._print("Provisioning failed.") | ||
| 10 | |||
| 11 | # Undo the load screen removing our cursor | ||
| 12 | get_tree().get_root().set_disable_input(false) | ||
| 13 | Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) | ||
| 14 | |||
| 15 | # Increase the WebSocket input buffer size so that we can download large | ||
| 16 | # data packages. | ||
| 17 | ProjectSettings.set_setting("network/limits/websocket_client/max_in_buffer_kb", 8192) | ||
| 18 | |||
| 19 | # Create the global AP manager, if it doesn't already exist. | ||
| 20 | if not global.has_node("Archipelago"): | ||
| 21 | var ap_script = ResourceLoader.load("user://maps/Archipelago/manager.gd") | ||
| 22 | var ap_instance = ap_script.new() | ||
| 23 | ap_instance.name = "Archipelago" | ||
| 24 | |||
| 25 | #apclient_instance.SCRIPT_doorControl = load("user://maps/Archipelago/doorControl.gd") | ||
| 26 | #apclient_instance.SCRIPT_effects = load("user://maps/Archipelago/effects.gd") | ||
| 27 | #apclient_instance.SCRIPT_location = load("user://maps/Archipelago/location.gd") | ||
| 28 | #apclient_instance.SCRIPT_mypainting = load("user://maps/Archipelago/mypainting.gd") | ||
| 29 | #apclient_instance.SCRIPT_panel = load("user://maps/Archipelago/panel.gd") | ||
| 30 | #apclient_instance.SCRIPT_textclient = load("user://maps/Archipelago/textclient.gd") | ||
| 31 | |||
| 32 | ap_instance.SCRIPT_client = load("user://maps/Archipelago/client.gd") | ||
| 33 | ap_instance.SCRIPT_locationListener = load("user://maps/Archipelago/locationListener.gd") | ||
| 34 | ap_instance.SCRIPT_uuid = load("user://maps/Archipelago/vendor/uuid.gd") | ||
| 35 | |||
| 36 | global.add_child(ap_instance) | ||
| 37 | |||
| 38 | # Let's also inject any scripts we need to inject now. | ||
| 39 | installScriptExtension(ResourceLoader.load("user://maps/Archipelago/door.gd")) | ||
| 40 | installScriptExtension(ResourceLoader.load("user://maps/Archipelago/painting.gd")) | ||
| 41 | installScriptExtension(ResourceLoader.load("user://maps/Archipelago/player.gd")) | ||
| 42 | |||
| 43 | var proto_script = load("user://maps/Archipelago/generated/proto.gd") | ||
| 44 | var gamedata_script = load("user://maps/Archipelago/gamedata.gd") | ||
| 45 | var gamedata_instance = gamedata_script.new(proto_script) | ||
| 46 | gamedata_instance.load( | ||
| 47 | FileAccess.get_file_as_bytes("user://maps/Archipelago/generated/data.binpb") | ||
| 48 | ) | ||
| 49 | gamedata_instance.name = "Gamedata" | ||
| 50 | global.add_child(gamedata_instance) | ||
| 51 | |||
| 52 | var ap = global.get_node("Archipelago") | ||
| 53 | ap.connect("ap_connected", connectionSuccessful) | ||
| 54 | ap.connect("could_not_connect", connectionUnsuccessful) | ||
| 55 | ap.connect("connect_status", connectionStatus) | ||
| 56 | |||
| 57 | # Populate textboxes with AP settings. | ||
| 58 | $Panel/server_box.text = ap.ap_server | ||
| 59 | $Panel/player_box.text = ap.ap_user | ||
| 60 | $Panel/password_box.text = ap.ap_pass | ||
| 61 | |||
| 62 | var history_box = $Panel/connection_history | ||
| 63 | if ap.connection_history.is_empty(): | ||
| 64 | history_box.disabled = true | ||
| 65 | else: | ||
| 66 | history_box.disabled = false | ||
| 67 | |||
| 68 | var i = 0 | ||
| 69 | for details in ap.connection_history: | ||
| 70 | history_box.get_popup().add_item("%s (%s)" % [details[1], details[0]], i) | ||
| 71 | i += 1 | ||
| 72 | |||
| 73 | history_box.get_popup().connect("id_pressed", historySelected) | ||
| 74 | |||
| 75 | # Show client version. | ||
| 76 | $Panel/title.text = "ARCHIPELAGO (%s)" % ap.my_version | ||
| 77 | |||
| 78 | # Increase font size in text boxes. | ||
| 79 | $Panel/server_box.add_theme_font_size_override("font_size", 36) | ||
| 80 | $Panel/player_box.add_theme_font_size_override("font_size", 36) | ||
| 81 | $Panel/password_box.add_theme_font_size_override("font_size", 36) | ||
| 82 | |||
| 83 | |||
| 84 | # Adapted from https://gitlab.com/Delta-V-Modding/Mods/-/blob/main/game/ModLoader.gd | ||
| 85 | func installScriptExtension(childScript: Resource): | ||
| 86 | # Force Godot to compile the script now. | ||
| 87 | # We need to do this here to ensure that the inheritance chain is | ||
| 88 | # properly set up, and multiple mods can chain-extend the same | ||
| 89 | # class multiple times. | ||
| 90 | # This is also needed to make Godot instantiate the extended class | ||
| 91 | # when creating singletons. | ||
| 92 | # The actual instance is thrown away. | ||
| 93 | childScript.new() | ||
| 94 | |||
| 95 | var parentScript = childScript.get_base_script() | ||
| 96 | var parentScriptPath = parentScript.resource_path | ||
| 97 | global._print("ModLoader: Installing script extension over %s" % parentScriptPath) | ||
| 98 | childScript.take_over_path(parentScriptPath) | ||
| 99 | |||
| 100 | |||
| 101 | func connectionStatus(message): | ||
| 102 | var popup = self.get_node("Panel/AcceptDialog") | ||
| 103 | popup.title = "Connecting to Archipelago" | ||
| 104 | popup.dialog_text = message | ||
| 105 | popup.exclusive = true | ||
| 106 | popup.get_ok_button().visible = false | ||
| 107 | popup.popup_centered() | ||
| 108 | |||
| 109 | |||
| 110 | func connectionSuccessful(): | ||
| 111 | var ap = global.get_node("Archipelago") | ||
| 112 | |||
| 113 | # Save connection details | ||
| 114 | var connection_details = [ap.ap_server, ap.ap_user, ap.ap_pass] | ||
| 115 | if ap.connection_history.has(connection_details): | ||
| 116 | ap.connection_history.erase(connection_details) | ||
| 117 | ap.connection_history.push_front(connection_details) | ||
| 118 | if ap.connection_history.size() > 10: | ||
| 119 | ap.connection_history.resize(10) | ||
| 120 | ap.saveSettings() | ||
| 121 | |||
| 122 | # Switch to the_entry | ||
| 123 | Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) | ||
| 124 | global.user = ap.getSaveFileName() | ||
| 125 | global.universe = "lingo" | ||
| 126 | global.map = "the_entry" | ||
| 127 | |||
| 128 | unlocks.resetKeys() | ||
| 129 | unlocks.resetCollectables() | ||
| 130 | unlocks.resetData() | ||
| 131 | unlocks.loadKeys() | ||
| 132 | unlocks.loadCollectables() | ||
| 133 | unlocks.loadData() | ||
| 134 | unlocks.unlockKey("capslock", 1) | ||
| 135 | |||
| 136 | clearResourceCache("res://objects/nodes/door.tscn") | ||
| 137 | clearResourceCache("res://objects/nodes/player.tscn") | ||
| 138 | |||
| 139 | var paintings_dir = DirAccess.open("res://objects/meshes/paintings") | ||
| 140 | if paintings_dir: | ||
| 141 | paintings_dir.list_dir_begin() | ||
| 142 | var file_name = paintings_dir.get_next() | ||
| 143 | while file_name != "": | ||
| 144 | if not paintings_dir.current_is_dir() and file_name.ends_with(".tscn"): | ||
| 145 | clearResourceCache("res://objects/meshes/paintings/" + file_name) | ||
| 146 | file_name = paintings_dir.get_next() | ||
| 147 | |||
| 148 | switcher.switch_map("res://objects/scenes/the_entry.tscn") | ||
| 149 | |||
| 150 | |||
| 151 | func connectionUnsuccessful(error_message): | ||
| 152 | $Panel/connect_button.disabled = false | ||
| 153 | |||
| 154 | var popup = $Panel/AcceptDialog | ||
| 155 | popup.title = "Could not connect to Archipelago" | ||
| 156 | popup.dialog_text = error_message | ||
| 157 | popup.exclusive = true | ||
| 158 | popup.get_ok_button().visible = true | ||
| 159 | popup.popup_centered() | ||
| 160 | |||
| 161 | |||
| 162 | func historySelected(index): | ||
| 163 | var ap = global.get_node("Archipelago") | ||
| 164 | var details = ap.connection_history[index] | ||
| 165 | |||
| 166 | $Panel/server_box.text = details[0] | ||
| 167 | $Panel/player_box.text = details[1] | ||
| 168 | $Panel/password_box.text = details[2] | ||
| 169 | |||
| 170 | |||
| 171 | func clearResourceCache(path): | ||
| 172 | ResourceLoader.load_threaded_request(path, "", false, ResourceLoader.CACHE_MODE_REPLACE) | ||
| 173 | ResourceLoader.load_threaded_get(path) | ||
