Improve choice nodes
Esse commit está contido em:
pai
0ce0bc8986
commit
3b54fe4e06
2 arquivos alterados com 33 adições e 20 exclusões
|
@ -39,6 +39,7 @@ func add_choice():
|
|||
|
||||
func set_structure(new_json_structure):
|
||||
_json_structure = new_json_structure
|
||||
_clear_choice_nodes()
|
||||
for i in range(0, _json_structure.size()):
|
||||
var node: Choice = _add_choice_node(i)
|
||||
node.set_structure(_json_structure[i])
|
||||
|
@ -59,8 +60,15 @@ func _add_choice_node(id: int):
|
|||
|
||||
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)
|
||||
if (index >= 0 and index < _nodes.size()):
|
||||
_nodes[index].queue_free()
|
||||
_nodes.remove(index)
|
||||
# Update remaining nodes indexes
|
||||
for i in range(0, _nodes.size()):
|
||||
_nodes[i].set_id(i)
|
||||
|
||||
|
||||
func _clear_choice_nodes():
|
||||
_nodes.clear()
|
||||
for node in _VBoxContainer.get_children():
|
||||
node.queue_free()
|
||||
|
|
|
@ -96,8 +96,9 @@ func _on_ChoicesList_choices_changed(new_json_structure):
|
|||
if (self.get_slot_amount() != slot_number):
|
||||
self.set_slot_amount(slot_number)
|
||||
self._update_slots()
|
||||
# TODO fix slots resetting when editing choice data
|
||||
self.emit_signal("changed_slots", self)
|
||||
self.emit_signal("changed_slots", self)
|
||||
else:
|
||||
_update_slots_labels()
|
||||
_emit_text()
|
||||
|
||||
|
||||
|
@ -127,12 +128,9 @@ func set_slot_amount(new_amount : int):
|
|||
|
||||
|
||||
func set_text(new_text : String):
|
||||
print("New text received:")
|
||||
print(new_text)
|
||||
json_structure = JSON.parse(new_text).get_result()
|
||||
print(JSON.print(json_structure, "\t"))
|
||||
_update_components()
|
||||
self.emit_signal("text_changed", self._nid, new_text)
|
||||
_emit_text()
|
||||
|
||||
#Private Methods
|
||||
|
||||
|
@ -144,7 +142,6 @@ func _update_components():
|
|||
_ChoicesList.set_structure(json_structure.dialog.choices_multiple)
|
||||
|
||||
func _emit_text():
|
||||
print(get_text())
|
||||
self.emit_signal("text_changed", self._nid, get_text())
|
||||
|
||||
|
||||
|
@ -152,18 +149,28 @@ func _clear_link_labels():
|
|||
var children = self.get_children()
|
||||
for child in children:
|
||||
if child is Label:
|
||||
child.free()
|
||||
child.queue_free()
|
||||
|
||||
|
||||
func _update_slots_labels():
|
||||
for slot in range(0, self.get_slot_amount()):
|
||||
var output_link_label = self.get_children()[slot]
|
||||
if (output_link_label is Label):
|
||||
output_link_label.text = self._get_choice_name(slot)
|
||||
|
||||
func _get_choice_name(index):
|
||||
var choices: Array = json_structure.dialog.choices_multiple;
|
||||
if (choices.size() > 0):
|
||||
return choices[index].title
|
||||
else:
|
||||
return "Next"
|
||||
|
||||
func _update_slots():
|
||||
self.clear_all_slots()
|
||||
self._clear_link_labels()
|
||||
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)
|
||||
var base_link_label = Label.new()
|
||||
if (json_structure.dialog.choices_multiple.size() == 0):
|
||||
base_link_label.text = "Next"
|
||||
else:
|
||||
base_link_label.text = "Choice #1"
|
||||
base_link_label.text = self._get_choice_name(0)
|
||||
base_link_label.align = Label.ALIGN_RIGHT
|
||||
self.add_child(base_link_label)
|
||||
self.move_child(base_link_label, 0)
|
||||
|
@ -171,9 +178,7 @@ func _update_slots():
|
|||
for slot in range(1, self._slot_amount):
|
||||
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)
|
||||
var output_link_label = Label.new()
|
||||
output_link_label.text = "Choice #" + str(slot + 1)
|
||||
output_link_label.text = self._get_choice_name(slot)
|
||||
output_link_label.align = Label.ALIGN_RIGHT
|
||||
self.add_child_below_node(last_output_link_label, output_link_label)
|
||||
last_output_link_label = output_link_label
|
||||
|
||||
|
||||
|
|
Carregando…
Referência em uma nova issue