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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. tool
  2. extends ScrollContainer
  3. var editor_reference
  4. onready var master_tree = get_node('../MasterTree')
  5. var current_section = ''
  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(section):
  21. current_section = section
  22. reset_editor()
  23. nodes['name'].editable = true
  24. nodes['name'].text = get_definition('name', 'Unnamed')
  25. var type = get_definition('type', 0)
  26. nodes['type'].select(type)
  27. if type == 0:
  28. nodes['value'].text = get_definition('value', '')
  29. if type == 1:
  30. nodes['extra_title'].text = get_definition('extra_title', '')
  31. nodes['extra_text'].text = get_definition('extra_text', '')
  32. nodes['extra_extra'].text = get_definition('extra_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. nodes['type'].select(get_definition('type', 0))
  41. func _on_name_changed(text):
  42. var item = master_tree.get_selected()
  43. item.set_text(0, text)
  44. func _on_type_selected(index):
  45. nodes['type'].select(index)
  46. var item = master_tree.get_selected()
  47. item.set_icon(0, get_icon("Variant", "EditorIcons"))
  48. if index == 1:
  49. item.set_icon(0, get_icon("ScriptCreateDialog", "EditorIcons"))
  50. show_sub_editor(index)
  51. func show_sub_editor(type):
  52. nodes['extra_editor'].visible = false
  53. nodes['value_editor'].visible = false
  54. if type == 0:
  55. nodes['value_editor'].visible = true
  56. if type == 1:
  57. nodes['extra_editor'].visible = true
  58. func get_definition(key, default):
  59. if current_section != '':
  60. var config = ConfigFile.new()
  61. config.load(DialogicUtil.get_path('DEFINITIONS_FILE'))
  62. if config.has_section(current_section):
  63. return config.get_value(current_section, key, default)
  64. else:
  65. return default
  66. func new_definition():
  67. var config = ConfigFile.new()
  68. var section = DialogicUtil.generate_random_id()
  69. var err = config.load(DialogicUtil.get_path('DEFINITIONS_FILE'))
  70. if err == OK:
  71. config.set_value(section, 'name', 'New definition')
  72. config.set_value(section, 'type', 0)
  73. config.set_value(section, 'value', '')
  74. config.save(DialogicUtil.get_path('DEFINITIONS_FILE'))
  75. master_tree.add_definition({'section': section,'name': 'New definition', 'type': 0}, true)
  76. else:
  77. print('Error loading definitions')
  78. func save_definition():
  79. if current_section != '':
  80. var config = ConfigFile.new()
  81. var err = config.load(DialogicUtil.get_path('DEFINITIONS_FILE'))
  82. if err == OK:
  83. config.set_value(current_section, 'name', nodes['name'].text)
  84. var type = nodes['type'].selected
  85. config.set_value(current_section, 'type', type)
  86. if type == 0:
  87. config.set_value(current_section, 'value', nodes['value'].text)
  88. if type == 1:
  89. config.set_value(current_section, 'extra_title', nodes['extra_title'].text)
  90. config.set_value(current_section, 'extra_text', nodes['extra_text'].text)
  91. config.set_value(current_section, 'extra_extra', nodes['extra_extra'].text)
  92. config.save(DialogicUtil.get_path('DEFINITIONS_FILE'))