From f0555579cd462b27c71c486bd7456265cc827937 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 9 Dec 2023 13:14:25 -0500 Subject: Starting to work --- randomizer/settings_screen.gd | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 randomizer/settings_screen.gd (limited to 'randomizer/settings_screen.gd') diff --git a/randomizer/settings_screen.gd b/randomizer/settings_screen.gd new file mode 100644 index 0000000..708b4ef --- /dev/null +++ b/randomizer/settings_screen.gd @@ -0,0 +1,78 @@ +extends Spatial + + +func _ready(): + # Undo the load screen removing our cursor + get_tree().get_root().set_disable_input(false) + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + + # Create the global Randomizer node, if it doesn't already exist. + if not global.has_node("Randomizer"): + var randomizer_script = ResourceLoader.load("user://maps/randomizer/randomizer.gd") + var randomizer_instance = randomizer_script.new() + randomizer_instance.name = "Randomizer" + global.add_child(randomizer_instance) + + randomizer_instance.SCRIPT_generator = load("user://maps/randomizer/generator.gd") + + var generated_puzzles = ResourceLoader.load("user://maps/randomizer/generated_puzzles.gd") + var generated_puzzles_instance = generated_puzzles.new() + generated_puzzles_instance.name = "GeneratedPuzzles" + randomizer_instance.add_child(generated_puzzles_instance) + + # Let's also inject any scripts we need to inject now. + installScriptExtension(ResourceLoader.load("user://maps/randomizer/load.gd")) + installScriptExtension(ResourceLoader.load("user://maps/randomizer/panelEnd.gd")) + installScriptExtension(ResourceLoader.load("user://maps/randomizer/panelInput.gd")) + installScriptExtension(ResourceLoader.load("user://maps/randomizer/panelLevelSwitch.gd")) + installScriptExtension(ResourceLoader.load("user://maps/randomizer/worldTransporter.gd")) + + var randomizer = global.get_node("Randomizer") + randomizer.connect("finished_randomizing", self, "randomizationSuccessful") + randomizer.connect("randomizer_status", self, "randomizationStatus") + + # Show client version. + self.get_node("Panel/title").text = "RANDOMIZER (%s)" % randomizer.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/seed_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 randomizationStatus(message): + var popup = self.get_node("Panel/AcceptDialog") + popup.window_title = "Randomizing..." + popup.dialog_text = message + popup.popup_exclusive = true + popup.get_ok().visible = false + popup.popup_centered() + + +func randomizationSuccessful(): + var randomizer = global.get_node("Randomizer") + + # Switch to LL1 + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + global.map = "level1" + global.save_file = randomizer.getSaveFileName() + var _discard = get_tree().change_scene("res://scenes/load_screen.tscn") -- cgit 1.4.1