Improve choice nodes
This commit is contained in:
parent
0ce0bc8986
commit
3b54fe4e06
2 changed files with 33 additions and 20 deletions
|
@ -39,6 +39,7 @@ func add_choice():
|
||||||
|
|
||||||
func set_structure(new_json_structure):
|
func set_structure(new_json_structure):
|
||||||
_json_structure = new_json_structure
|
_json_structure = new_json_structure
|
||||||
|
_clear_choice_nodes()
|
||||||
for i in range(0, _json_structure.size()):
|
for i in range(0, _json_structure.size()):
|
||||||
var node: Choice = _add_choice_node(i)
|
var node: Choice = _add_choice_node(i)
|
||||||
node.set_structure(_json_structure[i])
|
node.set_structure(_json_structure[i])
|
||||||
|
@ -59,8 +60,15 @@ func _add_choice_node(id: int):
|
||||||
|
|
||||||
func _remove_choice_node(index):
|
func _remove_choice_node(index):
|
||||||
# Remove the node
|
# Remove the node
|
||||||
_nodes[index].queue_free()
|
if (index >= 0 and index < _nodes.size()):
|
||||||
_nodes.remove(index)
|
_nodes[index].queue_free()
|
||||||
# Update remaining nodes indexes
|
_nodes.remove(index)
|
||||||
for i in range(0, _nodes.size()):
|
# Update remaining nodes indexes
|
||||||
_nodes[i].set_id(i)
|
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):
|
if (self.get_slot_amount() != slot_number):
|
||||||
self.set_slot_amount(slot_number)
|
self.set_slot_amount(slot_number)
|
||||||
self._update_slots()
|
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()
|
_emit_text()
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,12 +128,9 @@ func set_slot_amount(new_amount : int):
|
||||||
|
|
||||||
|
|
||||||
func set_text(new_text : String):
|
func set_text(new_text : String):
|
||||||
print("New text received:")
|
|
||||||
print(new_text)
|
|
||||||
json_structure = JSON.parse(new_text).get_result()
|
json_structure = JSON.parse(new_text).get_result()
|
||||||
print(JSON.print(json_structure, "\t"))
|
|
||||||
_update_components()
|
_update_components()
|
||||||
self.emit_signal("text_changed", self._nid, new_text)
|
_emit_text()
|
||||||
|
|
||||||
#Private Methods
|
#Private Methods
|
||||||
|
|
||||||
|
@ -144,7 +142,6 @@ func _update_components():
|
||||||
_ChoicesList.set_structure(json_structure.dialog.choices_multiple)
|
_ChoicesList.set_structure(json_structure.dialog.choices_multiple)
|
||||||
|
|
||||||
func _emit_text():
|
func _emit_text():
|
||||||
print(get_text())
|
|
||||||
self.emit_signal("text_changed", self._nid, get_text())
|
self.emit_signal("text_changed", self._nid, get_text())
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,18 +149,28 @@ func _clear_link_labels():
|
||||||
var children = self.get_children()
|
var children = self.get_children()
|
||||||
for child in children:
|
for child in children:
|
||||||
if child is Label:
|
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():
|
func _update_slots():
|
||||||
self.clear_all_slots()
|
self.clear_all_slots()
|
||||||
self._clear_link_labels()
|
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)
|
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()
|
var base_link_label = Label.new()
|
||||||
if (json_structure.dialog.choices_multiple.size() == 0):
|
base_link_label.text = self._get_choice_name(0)
|
||||||
base_link_label.text = "Next"
|
|
||||||
else:
|
|
||||||
base_link_label.text = "Choice #1"
|
|
||||||
base_link_label.align = Label.ALIGN_RIGHT
|
base_link_label.align = Label.ALIGN_RIGHT
|
||||||
self.add_child(base_link_label)
|
self.add_child(base_link_label)
|
||||||
self.move_child(base_link_label, 0)
|
self.move_child(base_link_label, 0)
|
||||||
|
@ -171,9 +178,7 @@ func _update_slots():
|
||||||
for slot in range(1, self._slot_amount):
|
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)
|
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()
|
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
|
output_link_label.align = Label.ALIGN_RIGHT
|
||||||
self.add_child_below_node(last_output_link_label, output_link_label)
|
self.add_child_below_node(last_output_link_label, output_link_label)
|
||||||
last_output_link_label = output_link_label
|
last_output_link_label = output_link_label
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue