123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- tool
- extends VBoxContainer
-
- class_name ConditionsList
-
- signal conditions_changed(new_json_structure)
-
- var _condition_scene = preload("res://addons/EXP-System-Dialog/Dialog Editor/Nodes/Line/ConditionsList/Condition/Condition.tscn")
-
- onready var _VBoxContainer = self.get_node("VBoxContainer")
-
- var _json_structure = []
- var _nodes = []
-
- #Callback Methods
-
- func _on_condition_changed(index, new_structure):
- _json_structure[index] = new_structure
- _emit_changed_signal()
-
- func _on_condition_removed(index):
- _json_structure.remove(index)
- _remove_choice_node(index)
- _emit_changed_signal()
-
- func _on_ContitionAddButton_pressed():
- add_condition(
- {
- "id": "",
- "value": 0
- },
- _json_structure.size() - 1
- )
-
- #Public Methods
-
- func set_structure(new_json_structure):
- _json_structure = new_json_structure
- for i in range(0, _json_structure.size()):
- add_condition(_json_structure[0], i)
-
-
- func add_condition(structure: Dictionary, id: int):
- _json_structure.append(structure)
- _add_choice_node(structure, id)
- _emit_changed_signal()
-
- #Private Methods
-
- func _emit_changed_signal():
- emit_signal("conditions_changed", _json_structure)
-
- func _add_choice_node(structure: Dictionary, id: int):
- var node: Condition = _condition_scene.instance()
- _VBoxContainer.add_child(node)
- node.set_id(id)
- node.set_structure(structure)
- _nodes.append(node)
- node.connect("condition_changed", self, "_on_condition_changed")
- node.connect("condition_removed", self, "_on_condition_removed")
- return node
-
- func _remove_choice_node(index):
- # Remove the node
- _nodes[index].queue_free()
- _nodes.remove(index)
- # Update remaining nodes indexes
- for i in range(0, _nodes.size()):
- _nodes[i].set_id(i)
|