extends MenuButton const menu_items: Array = [ { label = "IMPORT OPTION SETS", action = "_menu_import_option_sets_action" }, { label = "EXPORT OPTION SETS", action = "_menu_export_option_sets_action" }, { label = "CLEAR OPTION SETS", action = "_menu_clear_option_sets_action" }, { label = "EXPORT DATA", action = "_menu_export_data_action" }, { label = "CLEAR DATA", action = "_menu_clear_data_action" }, { label = "ABOUT", action = "_menu_about_action" }, { label = "FAKE_DB", action = "_menu_fake_db_action" }, ] const license_font_b612: String = "res://licenses/font_b612.txt" const license_godot: String = "res://licenses/godot.txt" onready var popup := get_popup() as PopupMenu onready var confirm_action := get_node("/root/main/confirm_action") as ConfirmationDialog onready var file_picker := get_node("/root/main/file_picker") as FileDialog onready var database := get_node("/root/main/database") as Database onready var stage := get_node("/root/main/stage") as Stage func _ready(): for idx in range(menu_items.size()): popup.add_item(menu_items[idx].label, idx) popup.connect("id_pressed", self, "id_pressed") file_picker.get_cancel().connect("pressed", self, "dialog_cancelled", ["file_selected"]) confirm_action.get_cancel().connect("pressed", self, "dialog_cancelled", ["confirmed"]) func id_pressed(id: int): self.call_deferred(menu_items[id].action) func dialog_cancelled(confirmation_signal_name: String): var confirmation_handlers = confirm_action.get_signal_connection_list(confirmation_signal_name) for it in confirmation_handlers: confirm_action.disconnect(it.signal, it.target, it.method) func _menu_import_option_sets_action(): file_picker.window_title = "IMPORT OPTION SETS" file_picker.mode = FileDialog.MODE_OPEN_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.connect("file_selected", stage, "load_option_sets", [], CONNECT_ONESHOT) file_picker.show_modal(true) file_picker.invalidate() func _menu_export_option_sets_action(): file_picker.window_title = "EXPORT OPTION SETS" file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.connect("file_selected", stage, "store_option_sets", [], CONNECT_ONESHOT) file_picker.show_modal(true) file_picker.invalidate() func _menu_clear_option_sets_action(): confirm_action.window_title = "CLEAR OPTION SETS" confirm_action.dialog_text = "Do you want to delete all option sets?" confirm_action.connect("confirmed", stage, "clear_option_sets", [true], CONNECT_ONESHOT) confirm_action.show_modal(true) func _menu_export_data_action(): file_picker.window_title = "EXPORT DATA" file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.connect("file_selected", database, "store_database", [], CONNECT_ONESHOT) file_picker.show_modal(true) file_picker.invalidate() func _menu_clear_data_action(): confirm_action.window_title = "CLEAR DATA" confirm_action.dialog_text = "Do you want to delete all entries from the database?" confirm_action.connect("confirmed", database, "clear_database", [true], CONNECT_ONESHOT) confirm_action.show_modal(true) func _menu_about_action(): confirm_action.window_title = "FAKE DB" confirm_action.dialog_text = "About text here!" confirm_action.show_modal(true) # @DAM Hide this debug method before release. func _menu_fake_db_action(): confirm_action.window_title = "FAKE DB" confirm_action.dialog_text = "Do you want to delete all entries from the database and replace by fake entries?" confirm_action.connect("confirmed", database, "fake_database", [true], CONNECT_ONESHOT) confirm_action.show_modal(true)