No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefinitionEditor.gd 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. tool
  2. extends ScrollContainer
  3. var editor_reference
  4. onready var master_tree = get_node('../MasterTreeContainer/MasterTree')
  5. var current_definition = null
  6. onready var nodes = {
  7. 'name' : $VBoxContainer/HBoxContainer/VBoxContainer/Name,
  8. 'type': $VBoxContainer/HBoxContainer/VBoxContainer/TypeMenuButton,
  9. 'extra_editor': $VBoxContainer/HBoxContainer/ExtraInfo,
  10. 'value_editor': $VBoxContainer/HBoxContainer/Value,
  11. 'value': $VBoxContainer/HBoxContainer/Value/ValueInput,
  12. 'extra_title': $VBoxContainer/HBoxContainer/ExtraInfo/Title,
  13. 'extra_text': $VBoxContainer/HBoxContainer/ExtraInfo/Text,
  14. 'extra_extra': $VBoxContainer/HBoxContainer/ExtraInfo/Extra,
  15. }
  16. func _ready():
  17. reset_editor()
  18. nodes['name'].connect('text_changed', self, '_on_name_changed')
  19. nodes['type'].connect('item_selected', self, '_on_type_selected')
  20. func is_selected(id: String):
  21. return current_definition != null and current_definition['id'] == id
  22. func load_definition(id):
  23. current_definition = DialogicResources.get_default_definition_item(id)
  24. reset_editor()
  25. nodes['name'].editable = true
  26. nodes['name'].text = current_definition['name']
  27. var type = current_definition['type']
  28. nodes['type'].select(type)
  29. if type == 0:
  30. nodes['value'].text = current_definition['value']
  31. if type == 1:
  32. nodes['extra_title'].text = current_definition['title']
  33. nodes['extra_text'].text = current_definition['text']
  34. nodes['extra_extra'].text = current_definition['extra']
  35. show_sub_editor(type)
  36. func reset_editor():
  37. nodes['name'].text = ''
  38. nodes['value'].text = ''
  39. nodes['extra_title'].text = ''
  40. nodes['extra_text'].text = ''
  41. nodes['extra_extra'].text = ''
  42. var type = 0
  43. if current_definition != null:
  44. type = current_definition['type']
  45. nodes['type'].select(type)
  46. func _on_name_changed(text):
  47. var item = master_tree.get_selected()
  48. item.set_text(0, text)
  49. if current_definition != null:
  50. save_definition()
  51. master_tree.build_definitions(current_definition['id'])
  52. func _on_type_selected(index):
  53. nodes['type'].select(index)
  54. var item = master_tree.get_selected()
  55. item.set_icon(0, get_icon("Variant", "EditorIcons"))
  56. if index == 1:
  57. item.set_icon(0, get_icon("ScriptCreateDialog", "EditorIcons"))
  58. show_sub_editor(index)
  59. func show_sub_editor(type):
  60. nodes['extra_editor'].visible = false
  61. nodes['value_editor'].visible = false
  62. if type == 0:
  63. nodes['value_editor'].visible = true
  64. if type == 1:
  65. nodes['extra_editor'].visible = true
  66. func new_definition():
  67. var id = DialogicUtil.generate_random_id()
  68. DialogicResources.set_default_definition_variable(id, 'New definition', '')
  69. master_tree.build_definitions(id)
  70. func save_definition():
  71. if current_definition != null and current_definition['id'] != '':
  72. var type: int = nodes['type'].selected
  73. if type == 0:
  74. DialogicResources.set_default_definition_variable(current_definition['id'], nodes['name'].text, nodes['value'].text)
  75. if type == 1:
  76. DialogicResources.set_default_definition_glossary(current_definition['id'], nodes['name'].text, nodes['extra_title'].text, nodes['extra_text'].text, nodes['extra_extra'].text)