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.

ChoicesList.gd 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. tool
  2. extends VBoxContainer
  3. class_name ChoicesList
  4. signal choices_changed(new_json_structure)
  5. var _choice_scene = preload("res://addons/EXP-System-Dialog/Dialog Editor/Nodes/Line/ChoicesList/Choice/Choice.tscn")
  6. onready var _VBoxContainer: VBoxContainer = self.get_node("VBoxContainer")
  7. var _json_structure: Array = []
  8. var _nodes: Array = []
  9. #Callback Methods
  10. func _on_choice_changed(index, new_structure):
  11. _json_structure[index] = new_structure
  12. _emit_changed_signal()
  13. func _on_choice_removed(index):
  14. _json_structure.remove(index)
  15. _remove_choice_node(index)
  16. _emit_changed_signal()
  17. func _on_ChoiceAddButton_pressed():
  18. add_choice()
  19. #Public Methods
  20. func add_choice():
  21. _json_structure.append({
  22. "title": "",
  23. "conditions": []
  24. })
  25. _add_choice_node(_json_structure.size() - 1)
  26. _emit_changed_signal()
  27. func set_structure(new_json_structure):
  28. _json_structure = new_json_structure
  29. for i in range(0, _json_structure.size()):
  30. var node: Choice = _add_choice_node(i)
  31. node.set_structure(_json_structure[i])
  32. #Private Methods
  33. func _emit_changed_signal():
  34. emit_signal("choices_changed", _json_structure)
  35. func _add_choice_node(id: int):
  36. var node: Choice = _choice_scene.instance()
  37. _VBoxContainer.add_child(node)
  38. node.set_id(id)
  39. _nodes.append(node)
  40. node.connect("choice_changed", self, "_on_choice_changed")
  41. node.connect("choice_removed", self, "_on_choice_removed")
  42. return node
  43. func _remove_choice_node(index):
  44. # Remove the node
  45. _nodes[index].queue_free()
  46. _nodes.remove(index)
  47. # Update remaining nodes indexes
  48. for i in range(0, _nodes.size()):
  49. _nodes[i].set_id(i)