tblext.gd 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 int:
  26. var comment := Label.new()
  27. var range := SpinBox.new()
  28. comment.text = option.comment
  29. range.value = option.value
  30. range.step = 1
  31. range.min_value = -65535
  32. range.max_value = 65535
  33. panel.add_child(comment)
  34. panel.add_child(range)
  35. panel.tree_exiting.connect(func():
  36. option.value = int(range.value)
  37. )
  38. elif option.value is float:
  39. var comment := Label.new()
  40. var range := SpinBox.new()
  41. comment.text = option.comment
  42. range.value = option.value
  43. panel.add_child(comment)
  44. panel.add_child(range)
  45. panel.tree_exiting.connect(func():
  46. option.value = range.value
  47. )
  48. elif option.value is bool:
  49. var check_box := CheckBox.new()
  50. check_box.text = option.comment
  51. check_box.button_pressed = option.value
  52. panel.add_child(check_box)
  53. panel.tree_exiting.connect(func():
  54. option.value = check_box.button_pressed
  55. )
  56. else:
  57. print("unsupported option value({0}): {1}".format([option.name, typeof(option.value)]))
  58. var command := Button.new()
  59. command.text = dev_tool.tool_command_name
  60. command.button_up.connect(func():
  61. OS.execute('ruby', [ProjectSettings.globalize_path(dev_tool.tool_script)])
  62. )
  63. panel.add_child(command)
  64. panel.name = dev_tool.tool_name
  65. add_control_to_dock(dev_tool.tool_dock, panel)
  66. panel.tree_exited.connect(func():
  67. var json := FileAccess.open(dev_tool.tool_config, FileAccess.WRITE)
  68. json.store_string(JSON.stringify(options, "\t"))
  69. )
  70. tree_exiting.connect(func():
  71. remove_control_from_docks(panel)
  72. panel.queue_free()
  73. )
  74. return panel