12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- @tool
- extends EditorPlugin
- func _enter_tree() -> void:
- var helper := preload('tblext.gd')
- var base_dir: String = helper.resource_path.get_base_dir()
- var tools_dir := base_dir.path_join('editor/tools')
- var dir := DirAccess.open(tools_dir)
- for file in dir.get_files():
- if file.get_extension() == 'tres':
- make_panel(load(tools_dir.path_join(file)))
- func make_panel(dev_tool:DevTool) -> VBoxContainer:
- var panel := VBoxContainer.new()
- var options := JSON.parse_string(FileAccess.get_file_as_string(dev_tool.tool_config))
- for option in options:
- if option.value is String:
- var comment := Label.new()
- var line_edit := LineEdit.new()
- comment.text = option.comment
- line_edit.text = option.value
- panel.add_child(comment)
- panel.add_child(line_edit)
- panel.tree_exiting.connect(func():
- option.value = line_edit.text
- )
- elif option.value is int:
- var comment := Label.new()
- var range := SpinBox.new()
- comment.text = option.comment
- range.value = option.value
- range.step = 1
- range.min_value = -65535
- range.max_value = 65535
- panel.add_child(comment)
- panel.add_child(range)
- panel.tree_exiting.connect(func():
- option.value = int(range.value)
- )
- elif option.value is float:
- var comment := Label.new()
- var range := SpinBox.new()
- comment.text = option.comment
- range.value = option.value
- panel.add_child(comment)
- panel.add_child(range)
- panel.tree_exiting.connect(func():
- option.value = range.value
- )
- elif option.value is bool:
- var check_box := CheckBox.new()
- check_box.text = option.comment
- check_box.button_pressed = option.value
- panel.add_child(check_box)
- panel.tree_exiting.connect(func():
- option.value = check_box.button_pressed
- )
- else:
- print("unsupported option value({0}): {1}".format([option.name, typeof(option.value)]))
- var command := Button.new()
- command.text = dev_tool.tool_command_name
- command.button_up.connect(func():
- OS.execute('ruby', [ProjectSettings.globalize_path(dev_tool.tool_script)])
- )
- panel.add_child(command)
- panel.name = dev_tool.tool_name
- add_control_to_dock(dev_tool.tool_dock, panel)
- panel.tree_exited.connect(func():
- var json := FileAccess.open(dev_tool.tool_config, FileAccess.WRITE)
- json.store_string(JSON.stringify(options, "\t"))
- )
- tree_exiting.connect(func():
- remove_control_from_docks(panel)
- panel.queue_free()
- )
- return panel
|