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 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. tool
  2. extends ScrollContainer
  3. var editor_reference
  4. onready var master_tree = get_node('../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 load_definition(id):
  21. current_definition = DialogicResources.get_default_definition_item(id)
  22. reset_editor()
  23. nodes['name'].editable = true
  24. nodes['name'].text = current_definition['name']
  25. var type = current_definition['type']
  26. nodes['type'].select(type)
  27. if type == 0:
  28. nodes['value'].text = current_definition['value']
  29. if type == 1:
  30. nodes['extra_title'].text = current_definition['title']
  31. nodes['extra_text'].text = current_definition['text']
  32. nodes['extra_extra'].text = current_definition['extra']
  33. show_sub_editor(type)
  34. func reset_editor():
  35. nodes['name'].text = ''
  36. nodes['value'].text = ''
  37. nodes['extra_title'].text = ''
  38. nodes['extra_text'].text = ''
  39. nodes['extra_extra'].text = ''
  40. var type = 0
  41. if current_definition != null:
  42. type = current_definition['type']
  43. nodes['type'].select(type)
  44. func _on_name_changed(text):
  45. var item = master_tree.get_selected()
  46. item.set_text(0, text)
  47. func _on_type_selected(index):
  48. nodes['type'].select(index)
  49. var item = master_tree.get_selected()
  50. item.set_icon(0, get_icon("Variant", "EditorIcons"))
  51. if index == 1:
  52. item.set_icon(0, get_icon("ScriptCreateDialog", "EditorIcons"))
  53. show_sub_editor(index)
  54. func show_sub_editor(type):
  55. nodes['extra_editor'].visible = false
  56. nodes['value_editor'].visible = false
  57. if type == 0:
  58. nodes['value_editor'].visible = true
  59. if type == 1:
  60. nodes['extra_editor'].visible = true
  61. func new_definition():
  62. var id = DialogicUtil.generate_random_id()
  63. DialogicResources.set_default_definition_variable(id, 'New definition', '')
  64. master_tree.add_definition({'id': id, 'name': 'New definition', 'type': 0}, true)
  65. func save_definition():
  66. if current_definition['id'] != '':
  67. var type: int = nodes['type'].selected
  68. if type == 0:
  69. DialogicResources.set_default_definition_variable(current_definition['id'], nodes['name'].text, nodes['value'].text)
  70. if type == 1:
  71. DialogicResources.set_default_definition_glossary(current_definition['id'], nodes['name'].text, nodes['extra_title'].text, nodes['extra_text'].text, nodes['extra_extra'].text)