pause_menu.gd 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. class_name PauseMenu
  2. extends Control
  3. @export var fade_in_duration := 0.3
  4. @export var fade_out_duration := 0.2
  5. @onready var center_cont := $ColorRect/CenterContainer as CenterContainer
  6. @onready var resume_button := center_cont.get_node(^"VBoxContainer/ResumeButton") as Button
  7. @onready var coins_counter := $ColorRect/CoinsCounter as CoinsCounter
  8. func _ready() -> void:
  9. hide()
  10. func close() -> void:
  11. var tween := create_tween()
  12. get_tree().paused = false
  13. tween.tween_property(
  14. self,
  15. ^"modulate:a",
  16. 0.0,
  17. fade_out_duration
  18. ).set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_OUT)
  19. tween.parallel().tween_property(
  20. center_cont,
  21. ^"anchor_bottom",
  22. 0.5,
  23. fade_out_duration
  24. ).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
  25. tween.tween_callback(hide)
  26. func open() -> void:
  27. show()
  28. resume_button.grab_focus()
  29. modulate.a = 0.0
  30. center_cont.anchor_bottom = 0.5
  31. var tween := create_tween()
  32. tween.tween_property(
  33. self,
  34. ^"modulate:a",
  35. 1.0,
  36. fade_in_duration
  37. ).set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_IN)
  38. tween.parallel().tween_property(
  39. center_cont,
  40. ^"anchor_bottom",
  41. 1.0,
  42. fade_out_duration
  43. ).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
  44. func _on_coin_collected() -> void:
  45. coins_counter.collect_coin()
  46. func _on_resume_button_pressed() -> void:
  47. close()
  48. func _on_singleplayer_button_pressed() -> void:
  49. if visible:
  50. get_tree().paused = false
  51. get_tree().change_scene_to_file("res://game_singleplayer.tscn")
  52. func _on_splitscreen_button_pressed() -> void:
  53. if visible:
  54. get_tree().paused = false
  55. get_tree().change_scene_to_file("res://game_splitscreen.tscn")
  56. func _on_quit_button_pressed() -> void:
  57. if visible:
  58. get_tree().quit()