12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- class_name Slide
- extends Node2D
- # Display slide content
- signal finished
- @export var always_visible: bool = false
- var action_finish := "ui_accept"
- var center_offset: Vector2
- func _ready() -> void:
- center_offset = _compute_center_offset()
- disable()
- func disable() -> void:
- set_process_unhandled_key_input(false)
- func enable() -> void:
- set_visible(true)
- set_process_unhandled_key_input(true)
- func get_center() -> Vector2:
- return get_position() + center_offset
- func gently_hide() -> void:
- if always_visible:
- return
- set_visible(false)
- func set_action_finish(action_name: String) -> void:
- action_finish = action_name
- func _unhandled_key_input(event: InputEvent) -> void:
- if event.is_action(action_finish) and event.is_pressed():
- finished.emit()
- get_viewport().set_input_as_handled()
- func _compute_center_offset() -> Vector2:
- var w: float = ProjectSettings.get("display/window/size/viewport_width")
- var h: float = ProjectSettings.get("display/window/size/viewport_height")
- return Vector2(w * scale.x / 2, h * scale.y / 2)
|