node_logic.gd 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.has_meta("min")
  28. var is_max := changed_slider.has_meta("max")
  29. #if not exits function
  30. if not is_min and not is_max:
  31. return
  32. var sliders := _get_all_hsliders(self)
  33. for other_slider in sliders:
  34. if other_slider == changed_slider:
  35. continue
  36. if is_min and other_slider.has_meta("max"):
  37. var max_value: float = other_slider.value
  38. if changed_slider.value > max_value - min_gap:
  39. changed_slider.value = max_value - min_gap
  40. elif is_max and other_slider.has_meta("min"):
  41. var min_value: float = other_slider.value
  42. if changed_slider.value < min_value + min_gap:
  43. changed_slider.value = min_value + min_gap
  44. func _open_help():
  45. open_help.emit(self.get_meta("command"), self.title)