tblext.gd 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. @tool
  2. extends EditorPlugin
  3. func _enter_tree() -> void:
  4. var helper := preload('tblext.gd')
  5. var base_dir: String = helper.resource_path.get_base_dir()
  6. var tools_dir := base_dir.path_join('editor/tools')
  7. var dir := DirAccess.open(tools_dir)
  8. for file in dir.get_files():
  9. if file.get_extension() == 'tres':
  10. make_panel(load(tools_dir.path_join(file)))
  11. func make_panel(dev_tool:DevTool) -> VBoxContainer:
  12. var panel := VBoxContainer.new()
  13. var options := JSON.parse_string(FileAccess.get_file_as_string(dev_tool.tool_config))
  14. for option in options:
  15. if option.value is String:
  16. var comment := Label.new()
  17. var line_edit := LineEdit.new()
  18. comment.text = option.comment
  19. line_edit.text = option.value
  20. panel.add_child(comment)
  21. panel.add_child(line_edit)
  22. panel.tree_exiting.connect(func():
  23. option.value = line_edit.text
  24. )
  25. elif option.value is bool:
  26. var check_box := CheckBox.new()
  27. check_box.text = option.comment
  28. check_box.button_pressed = option.value
  29. panel.add_child(check_box)
  30. panel.tree_exiting.connect(func():
  31. option.value = check_box.button_pressed
  32. )
  33. var command := Button.new()
  34. command.text = dev_tool.tool_command_name
  35. command.button_up.connect(func():
  36. OS.execute('ruby', [ProjectSettings.globalize_path(dev_tool.tool_script)])
  37. )
  38. panel.add_child(command)
  39. panel.name = dev_tool.tool_name
  40. add_control_to_dock(dev_tool.tool_dock, panel)
  41. panel.tree_exited.connect(func():
  42. var json := FileAccess.open(dev_tool.tool_config, FileAccess.WRITE)
  43. json.store_string(JSON.stringify(options, "\t"))
  44. )
  45. tree_exiting.connect(func():
  46. remove_control_from_docks(panel)
  47. panel.queue_free()
  48. )
  49. return panel