Files
MovementTests/scenes/tuto_trigger/tuto_trigger.gd

70 lines
2.3 KiB
GDScript

extends Area3D
class_name TutoTrigger
@export_group("First input")
@export var first_input_icon: Texture
@export var first_input_icon_keyboard: Texture
@export_group("Second input")
@export var second_input_icon: Texture
@export var second_input_icon_keyboard: Texture
@export_group("Third input")
@export var third_input_icon: Texture
@export var third_input_icon_keyboard: Texture
@export_group("Text")
@export var input_related_text: String
@export var tuto_text: String
@onready var control: Control = $Control
@onready var inputs_container: HBoxContainer = %MultipleInputsContainer
@onready var first_input: TextureRect = %FirstInput
@onready var first_plus_sign: Label = %first_plus_sign
@onready var second_input: TextureRect = %SecondInput
@onready var second_plus_sign: Label = %second_plus_sign
@onready var third_input: TextureRect = %ThirdInput
@onready var complex_input_label: Label = %ComplexInputLabel
@onready var tuto_text_label: Label = %TutoText
var current_input_method = GlobalHelpers.GamepadDetectionEvent.GAMEPAD
func _ready() -> void:
complex_input_label.visible = !input_related_text.is_empty()
complex_input_label.text = input_related_text
tuto_text_label.text = tuto_text
_on_input_mappings_changed()
func _input(event: InputEvent) -> void:
var event_gamepad = GlobalHelpers.is_event_gamepad(event)
if event_gamepad == GlobalHelpers.GamepadDetectionEvent.IRRELEVANT:
return
if current_input_method == event_gamepad:
return
current_input_method = event_gamepad
_on_input_mappings_changed()
func _on_input_mappings_changed():
var is_gamepad = current_input_method == GlobalHelpers.GamepadDetectionEvent.GAMEPAD
first_input.visible = first_input_icon != null
if first_input.visible:
first_input.texture = first_input_icon if is_gamepad else first_input_icon_keyboard
second_input.visible = second_input_icon != null
first_plus_sign.visible = second_input.visible
if second_input.visible:
second_input.texture = second_input_icon if is_gamepad else second_input_icon_keyboard
third_input.visible = third_input_icon != null
second_plus_sign.visible = third_input.visible
if third_input.visible:
third_input.texture = third_input_icon if is_gamepad else third_input_icon_keyboard
func _on_body_entered(body: Node3D) -> void:
control.visible = true
func _on_body_exited(body: Node3D) -> void:
control.visible = false