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.

ConditionsList.gd 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. tool
  2. extends VBoxContainer
  3. class_name ConditionsList
  4. signal conditions_changed(new_json_structure)
  5. var _condition_scene = preload("res://addons/EXP-System-Dialog/Dialog Editor/Nodes/Line/ConditionsList/Condition/Condition.tscn")
  6. onready var _VBoxContainer = self.get_node("VBoxContainer")
  7. var _json_structure = []
  8. var _nodes = []
  9. #Callback Methods
  10. func _on_condition_changed(index, new_structure):
  11. _json_structure[index] = new_structure
  12. _emit_changed_signal()
  13. func _on_condition_removed(index):
  14. _json_structure.remove(index)
  15. _remove_choice_node(index)
  16. _emit_changed_signal()
  17. func _on_ContitionAddButton_pressed():
  18. add_condition(
  19. {
  20. "id": "",
  21. "value": 0
  22. },
  23. _json_structure.size() - 1
  24. )
  25. #Public Methods
  26. func set_structure(new_json_structure):
  27. _json_structure = new_json_structure
  28. for i in range(0, _json_structure.size()):
  29. add_condition(_json_structure[0], i)
  30. func add_condition(structure: Dictionary, id: int):
  31. _json_structure.append(structure)
  32. _add_choice_node(structure, id)
  33. _emit_changed_signal()
  34. #Private Methods
  35. func _emit_changed_signal():
  36. emit_signal("conditions_changed", _json_structure)
  37. func _add_choice_node(structure: Dictionary, id: int):
  38. var node: Condition = _condition_scene.instance()
  39. _VBoxContainer.add_child(node)
  40. node.set_id(id)
  41. node.set_structure(structure)
  42. _nodes.append(node)
  43. node.connect("condition_changed", self, "_on_condition_changed")
  44. node.connect("condition_removed", self, "_on_condition_removed")
  45. return node
  46. func _remove_choice_node(index):
  47. # Remove the node
  48. _nodes[index].queue_free()
  49. _nodes.remove(index)
  50. # Update remaining nodes indexes
  51. for i in range(0, _nodes.size()):
  52. _nodes[i].set_id(i)