Slide.gd 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. @export var always_visible: bool = false
  7. var center_offset: Vector2
  8. func _ready():
  9. center_offset = _compute_center_offset()
  10. remove_focus()
  11. func remove_focus() -> void:
  12. set_process_unhandled_key_input(false)
  13. func focus() -> void:
  14. set_visible(true)
  15. set_process_unhandled_key_input(true)
  16. func get_center():
  17. return get_position() + center_offset
  18. func gently_hide() -> void:
  19. if always_visible:
  20. return
  21. set_visible(false)
  22. func _unhandled_key_input(event: InputEvent):
  23. if event.is_action("ui_accept") and event.is_pressed():
  24. finished.emit()
  25. get_viewport().set_input_as_handled()
  26. func _compute_center_offset() -> Vector2:
  27. var w: float = ProjectSettings.get("display/window/size/viewport_width")
  28. var h: float = ProjectSettings.get("display/window/size/viewport_height")
  29. return Vector2(w * scale.x / 2, h * scale.y / 2)