MenuIndicator.gd 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. extends Control
  2. @onready var content : Control = $MenuContent
  3. @onready var items : Control = $MenuContent/HBoxItems
  4. @onready var button : Button = $MenuButton
  5. var progress_speed : float = 0.0
  6. var is_playing : bool = false
  7. var is_opening : bool = false
  8. #
  9. func SetItemsVisible(toggle : bool):
  10. for w in items.get_children():
  11. w.set_visible(toggle)
  12. if w.targetWindow and not toggle:
  13. w.targetWindow.EnableControl(toggle)
  14. #
  15. func _on_button_pressed():
  16. is_playing = true
  17. is_opening = !is_opening
  18. if is_opening and not items.is_visible():
  19. items.set_visible(true)
  20. #
  21. func _ready():
  22. assert(content != null and content.material != null and items != null, "Menu Indicator nodes are not set correctly")
  23. content.material.set_shader_parameter("progress", progress_speed)
  24. items.set_visible(false)
  25. func _process(delta : float):
  26. if is_playing:
  27. if is_opening:
  28. progress_speed += delta / 2.0
  29. if progress_speed >= 1.0:
  30. progress_speed = 1.0
  31. is_playing = false
  32. else:
  33. progress_speed -= delta
  34. if progress_speed <= 0.0:
  35. items.set_visible(false)
  36. progress_speed = 0.0
  37. is_playing = false
  38. if content.material:
  39. content.material.set_shader_parameter("progress", progress_speed)