- Refactored VibrationComponent (RumbleComponent) -- Now supports multiple vibrations and adjustable curves. -- Inspired by the RumblePak addon. - Added a new startup scene.
57 lines
1.8 KiB
GDScript
57 lines
1.8 KiB
GDScript
class_name Hud
|
|
extends CanvasLayer
|
|
|
|
const _CROSSHAIR_ANIM_TO_DOT: StringName = &"to_dot"
|
|
const _CROSSHAIR_ANIM_TO_HOLLOW: StringName = &"to_hollow"
|
|
|
|
@export var interaction_ray: InteractionRay: set = set_interaction_ray
|
|
|
|
@onready var interaction_prompt: RichTextLabel = $InteractionPrompt
|
|
@onready var crosshair: AnimatedSprite2D = %Crosshair
|
|
|
|
|
|
func _ready() -> void:
|
|
crosshair.play(_CROSSHAIR_ANIM_TO_DOT, 1.0, true)
|
|
|
|
|
|
func set_interaction_ray(ray: InteractionRay) -> void:
|
|
if is_instance_valid(interaction_ray):
|
|
interaction_ray.focused_gained.disconnect(_on_interaction_ray_focused)
|
|
interaction_ray.focus_lost.disconnect(_on_interaction_ray_focus_lost)
|
|
|
|
interaction_ray = ray
|
|
|
|
if is_instance_valid(interaction_ray):
|
|
interaction_ray.focused_gained.connect(_on_interaction_ray_focused)
|
|
interaction_ray.focus_lost.connect(_on_interaction_ray_focus_lost)
|
|
|
|
|
|
func _on_interaction_ray_focused(area: InteractionArea) -> void:
|
|
if is_instance_valid(area):
|
|
area.hint_prompts_changed.connect(_populate_focused_hints.bind(area))
|
|
_populate_focused_hints(area)
|
|
_play_crosshair_anim(_CROSSHAIR_ANIM_TO_HOLLOW)
|
|
else:
|
|
interaction_prompt.clear()
|
|
_play_crosshair_anim(_CROSSHAIR_ANIM_TO_DOT)
|
|
|
|
|
|
func _on_interaction_ray_focus_lost(area: InteractionArea) -> void:
|
|
interaction_prompt.clear()
|
|
_play_crosshair_anim(_CROSSHAIR_ANIM_TO_DOT)
|
|
|
|
if is_instance_valid(area):
|
|
area.hint_prompts_changed.disconnect(_populate_focused_hints)
|
|
|
|
|
|
func _play_crosshair_anim(anim_name: StringName) -> void:
|
|
if crosshair.animation != anim_name:
|
|
crosshair.play(anim_name)
|
|
|
|
|
|
func _populate_focused_hints(area: InteractionArea) -> void:
|
|
interaction_prompt.clear()
|
|
interaction_prompt.push_paragraph(HORIZONTAL_ALIGNMENT_CENTER)
|
|
interaction_prompt.append_text("\n".join(area.get_interaction_strings()))
|
|
interaction_prompt.pop_all()
|