material_dialog.gd 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. tool
  2. extends ConfirmationDialog
  3. var src_fs
  4. var dst_fs
  5. var import_plugin
  6. func configure(p_import_plugin,path,metadata):
  7. import_plugin=p_import_plugin
  8. if (metadata):
  9. # metadata from previous import exists, fill in fields
  10. assert( metadata.get_source_count() > 0 )
  11. # Always expand the source paths
  12. var src_path = import_plugin.expand_source_path( metadata.get_source_path(0) )
  13. get_node("src_file").set_text(src_path)
  14. get_node("dst_file").set_text(path)
  15. # Fill in from metadata options
  16. get_node("use_red_anyway").set_pressed( metadata.get_option("use_red_anyway") )
  17. func _ready():
  18. src_fs = FileDialog.new()
  19. src_fs.set_mode(FileDialog.MODE_OPEN_FILE)
  20. src_fs.set_access(FileDialog.ACCESS_FILESYSTEM) #access all filesystem, not only res://
  21. src_fs.add_filter("*.mtxt")
  22. src_fs.connect("file_selected",self,"_on_src_selected")
  23. add_child(src_fs)
  24. dst_fs = EditorFileDialog.new()
  25. dst_fs.set_mode(EditorFileDialog.MODE_SAVE_FILE)
  26. dst_fs.add_filter("*.mtl") # Use binary extension always, text can't save metadata
  27. dst_fs.connect("file_selected",self,"_on_dst_selected")
  28. add_child(dst_fs)
  29. set_hide_on_ok(true)
  30. get_ok().set_text("Import!")
  31. func _on_src_browse_pressed():
  32. src_fs.popup_centered_ratio()
  33. func _on_dst_browse_pressed():
  34. dst_fs.popup_centered_ratio()
  35. func _on_src_selected(path):
  36. get_node("src_file").set_text(path)
  37. func _on_dst_selected(path):
  38. get_node("dst_file").set_text(path)
  39. func _on_MaterialImport_confirmed():
  40. # Create an import metadata
  41. var imd = ResourceImportMetadata.new()
  42. # Add the source files, always validate the source path
  43. imd.add_source( import_plugin.validate_source_path( get_node("src_file").get_text() ))
  44. # Add the options
  45. imd.set_option( "use_red_anyway", get_node("use_red_anyway").is_pressed() )
  46. # Perform regular import
  47. var err = import_plugin.import( get_node("dst_file").get_text(), imd )
  48. # Warn if error
  49. if (err!=OK):
  50. get_node("error").set_text("Error Importing!")
  51. get_node("error").popup_centered_minsize()