game.gd 769 B

123456789101112131415161718192021222324
  1. class_name Game extends Node
  2. @onready var _pause_menu := $InterfaceLayer/PauseMenu as PauseMenu
  3. func _unhandled_input(event: InputEvent) -> void:
  4. if event.is_action_pressed(&"toggle_fullscreen"):
  5. var mode := DisplayServer.window_get_mode()
  6. if mode == DisplayServer.WINDOW_MODE_FULLSCREEN or \
  7. mode == DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
  8. DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
  9. else:
  10. DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
  11. get_tree().root.set_input_as_handled()
  12. elif event.is_action_pressed(&"toggle_pause"):
  13. var tree := get_tree()
  14. tree.paused = not tree.paused
  15. if tree.paused:
  16. _pause_menu.open()
  17. else:
  18. _pause_menu.close()
  19. get_tree().root.set_input_as_handled()