123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- tool
- extends VBoxContainer
-
- class_name ChoicesList
-
- signal choices_changed(new_json_structure)
-
- var _choice_scene = preload("res://addons/EXP-System-Dialog/Dialog Editor/Nodes/Line/ChoicesList/Choice/Choice.tscn")
-
- onready var _VBoxContainer: VBoxContainer = self.get_node("VBoxContainer")
-
- var _json_structure: Array = []
- var _nodes: Array = []
-
- #Callback Methods
-
- func _on_choice_changed(index, new_structure):
- _json_structure[index] = new_structure
- _emit_changed_signal()
-
- func _on_choice_removed(index):
- _json_structure.remove(index)
- _remove_choice_node(index)
- _emit_changed_signal()
-
- func _on_ChoiceAddButton_pressed():
- add_choice()
-
-
- #Public Methods
-
- func add_choice():
- _json_structure.append({
- "title": "",
- "conditions": []
- })
- _add_choice_node(_json_structure.size() - 1)
- _emit_changed_signal()
-
- func set_structure(new_json_structure):
- _json_structure = new_json_structure
- for i in range(0, _json_structure.size()):
- var node: Choice = _add_choice_node(i)
- node.set_structure(_json_structure[i])
-
- #Private Methods
-
- func _emit_changed_signal():
- emit_signal("choices_changed", _json_structure)
-
- func _add_choice_node(id: int):
- var node: Choice = _choice_scene.instance()
- _VBoxContainer.add_child(node)
- node.set_id(id)
- _nodes.append(node)
- node.connect("choice_changed", self, "_on_choice_changed")
- node.connect("choice_removed", self, "_on_choice_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)
|