Browse Source

Improve choice nodes

Arnaud Vergnet 3 years ago
parent
commit
3b54fe4e06

+ 13
- 5
addons/EXP-System-Dialog/Dialog Editor/Nodes/Line/ChoicesList/ChoicesList.gd View File

@@ -39,6 +39,7 @@ func add_choice():
39 39
 
40 40
 func set_structure(new_json_structure):
41 41
 	_json_structure = new_json_structure
42
+	_clear_choice_nodes()
42 43
 	for i in range(0, _json_structure.size()):
43 44
 		var node: Choice = _add_choice_node(i)
44 45
 		node.set_structure(_json_structure[i])
@@ -59,8 +60,15 @@ func _add_choice_node(id: int):
59 60
 
60 61
 func _remove_choice_node(index):
61 62
 	# Remove the node
62
-	_nodes[index].queue_free()
63
-	_nodes.remove(index)
64
-	# Update remaining nodes indexes
65
-	for i in range(0, _nodes.size()):
66
-		_nodes[i].set_id(i)
63
+	if (index >= 0 and index < _nodes.size()):
64
+		_nodes[index].queue_free()
65
+		_nodes.remove(index)
66
+		# Update remaining nodes indexes
67
+		for i in range(0, _nodes.size()):
68
+			_nodes[i].set_id(i)
69
+
70
+
71
+func _clear_choice_nodes():
72
+	_nodes.clear()
73
+	for node in _VBoxContainer.get_children():
74
+		node.queue_free()

+ 20
- 15
addons/EXP-System-Dialog/Dialog Editor/Nodes/Line/line_node.gd View File

@@ -96,8 +96,9 @@ func _on_ChoicesList_choices_changed(new_json_structure):
96 96
 	if (self.get_slot_amount() != slot_number):
97 97
 		self.set_slot_amount(slot_number)
98 98
 		self._update_slots()
99
-		# TODO fix slots resetting when editing choice data
100
-	self.emit_signal("changed_slots", self)
99
+		self.emit_signal("changed_slots", self)
100
+	else:
101
+		_update_slots_labels()
101 102
 	_emit_text()
102 103
 
103 104
 
@@ -127,12 +128,9 @@ func set_slot_amount(new_amount : int):
127 128
 
128 129
 
129 130
 func set_text(new_text : String):
130
-	print("New text received:")
131
-	print(new_text)
132 131
 	json_structure = JSON.parse(new_text).get_result()
133
-	print(JSON.print(json_structure, "\t"))
134 132
 	_update_components()
135
-	self.emit_signal("text_changed", self._nid, new_text)
133
+	_emit_text()
136 134
 
137 135
 #Private Methods
138 136
 
@@ -144,7 +142,6 @@ func _update_components():
144 142
 	_ChoicesList.set_structure(json_structure.dialog.choices_multiple)
145 143
 
146 144
 func _emit_text():
147
-	print(get_text())
148 145
 	self.emit_signal("text_changed", self._nid, get_text())
149 146
 	
150 147
 
@@ -152,18 +149,28 @@ func _clear_link_labels():
152 149
 	var children = self.get_children()
153 150
 	for child in children:
154 151
 		if child is Label:
155
-			child.free()
152
+			child.queue_free()
153
+
154
+
155
+func _update_slots_labels():
156
+	for slot in range(0, self.get_slot_amount()):
157
+		var output_link_label = self.get_children()[slot]
158
+		if (output_link_label is Label):
159
+			output_link_label.text = self._get_choice_name(slot)
156 160
 
161
+func _get_choice_name(index):
162
+	var choices: Array = json_structure.dialog.choices_multiple;
163
+	if (choices.size() > 0):
164
+		return choices[index].title
165
+	else:
166
+		return "Next"
157 167
 
158 168
 func _update_slots():
159 169
 	self.clear_all_slots()
160 170
 	self._clear_link_labels()
161 171
 	self.set_slot(0, true, 0, Color(1.0, 1.0, 1.0, 1.0), true, 0, Color(1.0, 1.0, 1.0, 1.0), null, null)
162 172
 	var base_link_label = Label.new()
163
-	if (json_structure.dialog.choices_multiple.size() == 0):
164
-		base_link_label.text = "Next"
165
-	else:
166
-		base_link_label.text = "Choice #1"
173
+	base_link_label.text = self._get_choice_name(0)
167 174
 	base_link_label.align = Label.ALIGN_RIGHT
168 175
 	self.add_child(base_link_label)
169 176
 	self.move_child(base_link_label, 0)
@@ -171,9 +178,7 @@ func _update_slots():
171 178
 	for slot in range(1, self._slot_amount):
172 179
 		self.set_slot(slot, false, 0, Color(1.0, 1.0, 1.0, 1.0), true, 0, Color(1.0, 1.0, 1.0, 1.0), null, null)
173 180
 		var output_link_label = Label.new()
174
-		output_link_label.text = "Choice #" + str(slot + 1)
181
+		output_link_label.text = self._get_choice_name(slot)
175 182
 		output_link_label.align = Label.ALIGN_RIGHT
176 183
 		self.add_child_below_node(last_output_link_label, output_link_label)
177 184
 		last_output_link_label = output_link_label
178
-
179
-

Loading…
Cancel
Save