69 lines
1.9 KiB
GDScript
69 lines
1.9 KiB
GDScript
class_name InteractionArea
|
|
extends Area3D
|
|
|
|
signal focused
|
|
signal unfocused
|
|
signal hint_prompts_changed
|
|
|
|
@export var interaction_types: Array[InteractionType] = []: set = set_interaction_types
|
|
@export var focus_highlight_node: Node3D
|
|
|
|
var is_focused: bool = false
|
|
|
|
|
|
func _ready() -> void:
|
|
set_interaction_types(interaction_types)
|
|
|
|
if is_instance_valid(focus_highlight_node):
|
|
focus_highlight_node.hide()
|
|
|
|
|
|
func set_interaction_types(types: Array[InteractionType]) -> void:
|
|
for type: InteractionType in interaction_types:
|
|
if type.hint_prompt_changed.is_connected(hint_prompts_changed.emit):
|
|
type.hint_prompt_changed.disconnect(hint_prompts_changed.emit)
|
|
if type.enabled_changed.is_connected(_on_interaction_type_enabled_changed):
|
|
type.enabled_changed.disconnect(_on_interaction_type_enabled_changed)
|
|
|
|
interaction_types = types
|
|
|
|
for type: InteractionType in interaction_types:
|
|
if not type.hint_prompt_changed.is_connected(hint_prompts_changed.emit):
|
|
type.hint_prompt_changed.connect(hint_prompts_changed.emit)
|
|
if not type.enabled_changed.is_connected(_on_interaction_type_enabled_changed):
|
|
type.enabled_changed.connect(_on_interaction_type_enabled_changed)
|
|
|
|
|
|
func set_area_focused(value: bool) -> void:
|
|
is_focused = value
|
|
(focused if is_focused else unfocused).emit()
|
|
|
|
if is_instance_valid(focus_highlight_node):
|
|
focus_highlight_node.visible = value
|
|
|
|
for type: InteractionType in interaction_types:
|
|
type.set_focused(is_focused)
|
|
|
|
|
|
func get_interaction_strings() -> PackedStringArray:
|
|
var strings: PackedStringArray = []
|
|
|
|
for interaction_type: InteractionType in interaction_types:
|
|
if interaction_type.enabled:
|
|
var hint: String = interaction_type.get_correct_hover_hint()
|
|
strings.append(hint)
|
|
|
|
return strings
|
|
|
|
|
|
func _interaction_started(_interaction_ray: InteractionRay) -> void:
|
|
pass
|
|
|
|
|
|
func _interaction_ended(_interaction_ray: InteractionRay) -> void:
|
|
pass
|
|
|
|
|
|
func _on_interaction_type_enabled_changed() -> void:
|
|
set_area_focused(is_focused)
|