No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PauseMenu.gd 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. extends Control
  2. onready var panel := $MarginContainer/Panel
  3. onready var background := $Background
  4. onready var tween := $Tween
  5. var animation_speed = 0.4
  6. func load_main_menu():
  7. Transit.change_scene("res://scenes/MainMenu.tscn", 0.5)
  8. func pause():
  9. if not get_tree().paused:
  10. get_tree().paused = true
  11. show()
  12. tween.stop_all()
  13. tween.interpolate_property(background, "modulate", null, Color(1, 1, 1, 1), 2*animation_speed/3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
  14. tween.interpolate_property(panel, "modulate", null, Color(1, 1, 1, 1), animation_speed, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
  15. tween.start()
  16. func unpause():
  17. if get_tree().paused:
  18. get_tree().paused = false
  19. tween.stop_all()
  20. tween.interpolate_property(background, "modulate", null, Color(1, 1, 1, 0), animation_speed/2, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
  21. tween.interpolate_property(panel, "modulate", null, Color(1, 1, 1, 0), animation_speed/2, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
  22. tween.start()
  23. func _ready():
  24. panel.modulate = Color(1, 1, 1, 0)
  25. background.modulate = Color(1, 1, 1, 0)
  26. connect("gui_input", self, '_on_gui_input')
  27. tween.connect("tween_all_completed", self, "_on_Tween_tween_all_completed")
  28. func _input(event: InputEvent):
  29. if event.is_action_pressed("ui_cancel") and visible:
  30. unpause()
  31. get_tree().set_input_as_handled()
  32. elif event.is_action_pressed("ui_cancel") and not visible:
  33. pause()
  34. get_tree().set_input_as_handled()
  35. func _on_BackgroundButton_pressed():
  36. unpause()
  37. func _on_ContinueButton_pressed():
  38. unpause()
  39. func _on_MenuButton_pressed():
  40. unpause()
  41. load_main_menu()
  42. func _on_Tween_tween_all_completed():
  43. if panel.modulate == Color(1, 1, 1, 0):
  44. hide()