2023-11-16 20:23:17 +02:00
|
|
|
extends StaticBody3D
|
|
|
|
class_name Button3D
|
|
|
|
|
2023-11-22 02:44:07 +02:00
|
|
|
signal on_button_down()
|
|
|
|
signal on_button_up()
|
|
|
|
|
2023-11-16 20:23:17 +02:00
|
|
|
@export var toggleable: bool = false
|
|
|
|
@export var disabled: bool = false
|
2023-11-23 04:41:13 +02:00
|
|
|
@export var external_state: bool = false
|
2023-11-18 15:27:42 +02:00
|
|
|
@export var initial_active: bool = false
|
2023-11-16 20:23:17 +02:00
|
|
|
var active: bool = false :
|
|
|
|
set(value):
|
|
|
|
animation_player.stop()
|
|
|
|
if value == active:
|
|
|
|
return
|
|
|
|
|
|
|
|
active = value
|
|
|
|
|
|
|
|
if active:
|
|
|
|
animation_player.play("down")
|
|
|
|
else:
|
|
|
|
animation_player.play_backwards("down")
|
|
|
|
|
|
|
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
|
|
|
|
2023-11-18 15:27:42 +02:00
|
|
|
func _ready():
|
|
|
|
if initial_active:
|
|
|
|
active = true
|
|
|
|
|
2023-11-22 02:44:07 +02:00
|
|
|
func _on_press_down(event):
|
2023-11-16 20:23:17 +02:00
|
|
|
if disabled:
|
2023-11-22 02:44:07 +02:00
|
|
|
event.bubbling = false
|
2023-11-16 20:23:17 +02:00
|
|
|
return
|
|
|
|
|
2023-11-23 04:41:13 +02:00
|
|
|
AudioPlayer.play_effect("click")
|
|
|
|
|
|
|
|
if external_state || toggleable:
|
2023-11-16 20:23:17 +02:00
|
|
|
return
|
2023-11-22 02:44:07 +02:00
|
|
|
|
|
|
|
active = true
|
|
|
|
on_button_down.emit()
|
2023-11-16 20:23:17 +02:00
|
|
|
|
2023-11-22 02:44:07 +02:00
|
|
|
|
2023-11-16 20:23:17 +02:00
|
|
|
|
2023-11-22 02:44:07 +02:00
|
|
|
func _on_press_up(event):
|
2023-11-16 20:23:17 +02:00
|
|
|
if disabled:
|
2023-11-22 02:44:07 +02:00
|
|
|
event.bubbling = false
|
2023-11-16 20:23:17 +02:00
|
|
|
return
|
|
|
|
|
2023-11-23 04:41:13 +02:00
|
|
|
if external_state:
|
|
|
|
return
|
|
|
|
|
2023-11-22 02:44:07 +02:00
|
|
|
if toggleable:
|
|
|
|
active = !active
|
2023-11-23 04:41:13 +02:00
|
|
|
|
2023-11-22 02:44:07 +02:00
|
|
|
if active:
|
|
|
|
on_button_down.emit()
|
|
|
|
else:
|
|
|
|
on_button_up.emit()
|
|
|
|
else:
|
|
|
|
active = false
|
|
|
|
on_button_up.emit()
|