node_logic.gd 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. extends GraphNode
  2. @export var min_gap: float = 0.5 # editable value in inspector for the minimum gap between min and max
  3. signal open_help
  4. func _ready() -> void:
  5. var sliders := _get_all_hsliders(self) #finds all sliders
  6. #links sliders to this script
  7. for slider in sliders:
  8. slider.value_changed.connect(_on_slider_value_changed.bind(slider))
  9. #add button to title bar
  10. var titlebar = self.get_titlebar_hbox()
  11. var btn = Button.new()
  12. btn.text = "?"
  13. btn.tooltip_text = "Open help for " + self.title
  14. btn.connect("pressed", Callable(self, "_open_help")) #pass key (process name) when button is pressed
  15. titlebar.add_child(btn)
  16. func _get_all_hsliders(node: Node) -> Array:
  17. #moves through all children recusively to find nested sliders
  18. var result: Array = []
  19. for child in node.get_children():
  20. if child is HSlider:
  21. result.append(child)
  22. elif child.has_method("get_children"):
  23. result += _get_all_hsliders(child)
  24. return result
  25. func _on_slider_value_changed(value: float, changed_slider: HSlider) -> void:
  26. #checks if the slider moved has min or max meta data
  27. var is_min = changed_slider.get_meta("min")
  28. var is_max = changed_slider.get_meta("max")
  29. var is_outputduration = changed_slider.get_meta("outputduration")
  30. #if not exits function
  31. if not is_min and not is_max:
  32. return
  33. var sliders := _get_all_hsliders(self)
  34. for other_slider in sliders:
  35. if other_slider == changed_slider:
  36. continue
  37. if is_min and other_slider.get_meta("max"):
  38. var max_value: float = other_slider.value
  39. if changed_slider.value > max_value - min_gap:
  40. changed_slider.value = max_value - min_gap
  41. elif is_max and other_slider.get_meta("min"):
  42. var min_value: float = other_slider.value
  43. if changed_slider.value < min_value + min_gap:
  44. changed_slider.value = min_value + min_gap
  45. #set output duration meta if this is the output duration slider
  46. if is_outputduration:
  47. set_meta("outputduration", value)
  48. func _open_help():
  49. open_help.emit(self.get_meta("command"), self.title)