No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

line_node.gd 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. tool
  2. extends GraphNode
  3. signal changed_offset(nid, vec2)
  4. signal changed_size(this)
  5. signal changed_slots(this)
  6. signal erased(this)
  7. signal pressed_editor(this)
  8. signal pressed_load(this)
  9. signal pressed_save(this)
  10. signal text_changed(nid, new_text)
  11. onready var _Link_SpinBox = self.get_node("MarginContainer/VBoxContainer/HBoxContainer/Link_SpinBox")
  12. onready var _Text_Editor = self.get_node("MarginContainer/VBoxContainer/HBoxContainer2/VBoxContainer/TextEdit")
  13. var _nid : int = 0
  14. var _slot_amount : int = 1
  15. var json_structure = {
  16. "speaker": {
  17. "id": 0,
  18. "emotion": "happy"
  19. },
  20. "scene": {
  21. "id": 0
  22. },
  23. "dialog": {
  24. "message": "",
  25. "choices_free": {
  26. "placeholder": "",
  27. "global_var_name": "",
  28. },
  29. "choices_multiple": [
  30. {
  31. "title": "",
  32. "arc": 0,
  33. "infobox": {
  34. "title": "",
  35. "text": "",
  36. "conditions": [
  37. {
  38. "id": "education",
  39. "value": 0
  40. }
  41. ],
  42. },
  43. "conditions": [
  44. {
  45. "id": "open_mindeness",
  46. "value": 0
  47. }
  48. ]
  49. }
  50. ]
  51. }
  52. }
  53. #Virtual Methods
  54. func _ready():
  55. self._update_slots()
  56. #Callback Methods
  57. func _on_Editor_BTN_pressed():
  58. self.emit_signal("pressed_editor", self)
  59. func _on_Line_close_request():
  60. self.emit_signal("erased", self)
  61. func _on_Line_offset_changed():
  62. self.emit_signal("changed_offset", self._nid, self.offset)
  63. func _on_Line_resize_request(new_minsize):
  64. self.rect_size = new_minsize
  65. self.emit_signal("changed_size", self)
  66. func _on_Link_SpinBox_value_changed(value):
  67. self._slot_amount = int(self._Link_SpinBox.value)
  68. self._update_slots()
  69. self.emit_signal("changed_slots", self)
  70. func _on_Load_BTN_pressed():
  71. self.emit_signal("pressed_load", self)
  72. func _on_Save_BTN_pressed():
  73. self.emit_signal("pressed_save", self)
  74. func _on_TextEdit_text_changed():
  75. json_structure.dialog.message = self._Text_Editor.text
  76. emit_text()
  77. #Public Methods
  78. func get_nid() -> int:
  79. return self._nid
  80. func get_slot_amount() -> int:
  81. return self._slot_amount
  82. func get_text() -> String:
  83. return self._Text_Editor.text
  84. func set_nid(new_nid):
  85. self._nid = new_nid
  86. var new_name = "NID " + str(new_nid)
  87. self.title = new_name
  88. self.name = new_name
  89. func set_slot_amount(new_amount : int):
  90. self._slot_amount = new_amount
  91. func set_text(new_text : String):
  92. self._Text_Editor.text = new_text
  93. self.emit_signal("text_changed", self._nid, new_text)
  94. #Private Methods
  95. func emit_text():
  96. self.emit_signal("text_changed", self._nid, JSON.print(json_structure))
  97. func _clear_link_labels():
  98. var children = self.get_children()
  99. for child in children:
  100. if child is Label:
  101. child.free()
  102. func _update_slots():
  103. self.clear_all_slots()
  104. self._clear_link_labels()
  105. 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)
  106. var base_link_label = Label.new()
  107. base_link_label.text = "0"
  108. base_link_label.align = Label.ALIGN_RIGHT
  109. self.add_child(base_link_label)
  110. self.move_child(base_link_label, 0)
  111. var last_output_link_label = base_link_label
  112. for slot in range(1, self._slot_amount):
  113. 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)
  114. var output_link_label = Label.new()
  115. output_link_label.text = str(slot)
  116. output_link_label.align = Label.ALIGN_RIGHT
  117. self.add_child_below_node(last_output_link_label, output_link_label)
  118. last_output_link_label = output_link_label