FunkPanion/scripts/xmle/load.gd

35 lines
1.1 KiB
GDScript

extends MenuButton
signal load_xml(path: String)
signal load_image(path: String)
@onready var root = get_tree().root
func _ready() -> void:
var popup = self.get_popup()
popup.index_pressed.connect(func(idx: int):
if idx < 0: return
var file_dialog = FileDialog.new()
file_dialog.use_native_dialog = true
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
if idx == 0:
file_dialog.add_filter("*.xml", "Sparrow spritesheet")
elif idx == 1:
file_dialog.add_filter("*.png", "Image")
file_dialog.access = FileDialog.ACCESS_FILESYSTEM
file_dialog.current_path = OS.get_data_dir().path_join("FunkPanion/")
file_dialog.file_selected.connect(func(path_string: String):
var localized = path_string.simplify_path().replace(OS.get_data_dir().path_join("FunkPanion/"), "user://")
if idx == 0:
load_xml.emit(localized)
elif idx == 1:
load_image.emit(localized)
file_dialog.queue_free()
)
file_dialog.canceled.connect(func(path_string: String):
root.remove_child(file_dialog)
file_dialog.queue_free()
)
root.add_child(file_dialog)
file_dialog.popup()
)