pause_menu.gd 1.7 KB

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