2023-11-16 20:23:17 +02:00
|
|
|
extends StaticBody3D
|
|
|
|
class_name Button3D
|
|
|
|
|
|
|
|
@export var toggleable: bool = false
|
|
|
|
@export var disabled: 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):
|
|
|
|
print("set active", value)
|
|
|
|
animation_player.stop()
|
|
|
|
if value == active:
|
|
|
|
return
|
|
|
|
|
|
|
|
active = value
|
|
|
|
|
|
|
|
if active:
|
|
|
|
animation_player.play("down")
|
|
|
|
else:
|
|
|
|
animation_player.play_backwards("down")
|
|
|
|
get:
|
2023-11-18 15:27:42 +02:00
|
|
|
return active
|
2023-11-16 20:23:17 +02:00
|
|
|
|
|
|
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
|
|
|
|
2023-11-18 15:27:42 +02:00
|
|
|
func _ready():
|
|
|
|
if initial_active:
|
|
|
|
active = true
|
|
|
|
|
2023-11-16 20:23:17 +02:00
|
|
|
func _on_click(_event):
|
|
|
|
if disabled:
|
|
|
|
return false
|
|
|
|
|
|
|
|
if !toggleable:
|
|
|
|
return
|
|
|
|
|
|
|
|
active = !active
|
|
|
|
|
|
|
|
return {
|
|
|
|
"active": active
|
|
|
|
}
|
|
|
|
|
|
|
|
func _on_press_down(_event):
|
|
|
|
if disabled:
|
|
|
|
return false
|
|
|
|
|
|
|
|
if toggleable:
|
|
|
|
return
|
|
|
|
|
|
|
|
animation_player.play("down")
|
|
|
|
|
|
|
|
func _on_press_up(_event):
|
|
|
|
if disabled:
|
|
|
|
return false
|
|
|
|
|
|
|
|
if toggleable:
|
|
|
|
return
|
|
|
|
|
|
|
|
animation_player.play_backwards("down")
|