Slide.gd 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. class_name Slide
  2. extends Node2D
  3. # Display slide content
  4. signal finished
  5. @export var always_visible: bool = false
  6. var action_finish := "ui_accept"
  7. var center_offset: Vector2
  8. func _ready() -> void:
  9. center_offset = _compute_center_offset()
  10. disable()
  11. func disable() -> void:
  12. set_process_unhandled_key_input(false)
  13. func enable() -> void:
  14. set_visible(true)
  15. set_process_unhandled_key_input(true)
  16. func get_center() -> Vector2:
  17. return get_position() + center_offset
  18. func gently_hide() -> void:
  19. if always_visible:
  20. return
  21. set_visible(false)
  22. func set_action_finish(action_name: String) -> void:
  23. action_finish = action_name
  24. func _unhandled_key_input(event: InputEvent) -> void:
  25. if event.is_action(action_finish) and event.is_pressed():
  26. finished.emit()
  27. get_viewport().set_input_as_handled()
  28. func _compute_center_offset() -> Vector2:
  29. var w: float = ProjectSettings.get("display/window/size/viewport_width")
  30. var h: float = ProjectSettings.get("display/window/size/viewport_height")
  31. return Vector2(w * scale.x / 2, h * scale.y / 2)