TitleScreenOptions.gd 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. class_name TitleScreenOptions
  2. extends VBoxContainer
  3. @export var active := false
  4. @export var can_exit := true
  5. var selected_index := 0
  6. @export var options: Array[Label] = []
  7. @onready var title_screen_parent := owner
  8. signal option_1_selected
  9. signal option_2_selected
  10. signal option_3_selected
  11. signal closed
  12. func _process(_delta: float) -> void:
  13. if active:
  14. handle_inputs()
  15. func open() -> void:
  16. Global.world_num = clamp(Global.world_num, 1, 8) # have this, cause i cba to make a fix for backing out of world 9 keeping you at world 9
  17. title_screen_parent.active_options = self
  18. show()
  19. await get_tree().physics_frame
  20. active = true
  21. func close() -> void:
  22. active = false
  23. hide()
  24. func handle_inputs() -> void:
  25. if Input.is_action_just_pressed("ui_down"):
  26. selected_index += 1
  27. if Settings.file.audio.extra_sfx == 1:
  28. AudioManager.play_global_sfx("menu_move")
  29. if Input.is_action_just_pressed("ui_up"):
  30. selected_index -= 1
  31. if Settings.file.audio.extra_sfx == 1:
  32. AudioManager.play_global_sfx("menu_move")
  33. var amount := []
  34. for i in options:
  35. if i.visible:
  36. amount.append(i)
  37. selected_index = clamp(selected_index, 0, amount.size() - 1)
  38. if Input.is_action_just_pressed("ui_accept"):
  39. option_selected()
  40. elif can_exit and Input.is_action_just_pressed("ui_back"):
  41. close()
  42. closed.emit()
  43. func option_selected() -> void:
  44. active = false
  45. emit_signal("option_" + str(selected_index + 1) + "_selected")