Slide.gd 964 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. @icon("res://common/graphics/icons/godot_icon_slide.svg")
  2. class_name Slide
  3. extends Node2D
  4. # Display slide content
  5. signal finished
  6. var center_offset: Vector2
  7. func _ready():
  8. center_offset = _compute_center_offset()
  9. set_visible(false)
  10. remove_focus()
  11. func remove_focus() -> void:
  12. set_process_unhandled_input(false)
  13. func focus() -> void:
  14. set_visible(true)
  15. set_process_unhandled_input(true)
  16. func get_center():
  17. return get_position() + center_offset
  18. func _unhandled_key_input(event: InputEvent):
  19. if not is_processing_unhandled_input():
  20. return # seems to be hacky, see if it's an engine bug
  21. if event.is_action("ui_accept") and event.is_pressed():
  22. finished.emit()
  23. get_viewport().set_input_as_handled()
  24. func _compute_center_offset() -> Vector2:
  25. var w: float = ProjectSettings.get("display/window/size/viewport_width")
  26. var h: float = ProjectSettings.get("display/window/size/viewport_height")
  27. return Vector2(w * scale.x / 2, h * scale.y / 2)