immersive-home/app/content/system/dot/dot.gd

71 lines
1.7 KiB
GDScript3
Raw Normal View History

extends StaticBody3D
const Entity = preload ("res://content/entities/entity.gd")
2024-04-17 22:27:09 +03:00
const TOUCH_LONG = 400.0
@export var entity: Entity
@onready var collision = $CollisionShape3D
2024-05-09 13:40:41 +03:00
@onready var snap_sound = $SnapSound
@onready var label = $Label3D
var active = R.state(false)
var disabled = R.state(true)
2024-04-17 22:27:09 +03:00
var touched_enter = 0.0
var moved_ran = false
2024-04-17 22:34:21 +03:00
var touch_ran = false
var miniature = House.body.mini_view
func _ready():
R.effect(func(_arg):
label.text=entity.icon.value
label.modulate=entity.icon_color.value
)
# Update active
R.effect(func(_arg):
2024-04-17 20:49:45 +03:00
label.outline_modulate=Color(242 / 255.0, 90 / 255.0, 56 / 255.0, 1) if active.value else Color(0, 0, 0, 1)
)
# Update disabled
R.effect(func(_arg):
visible=!disabled.value
collision.disabled=disabled.value
)
func _on_click(_event: EventPointer):
2024-04-18 13:10:20 +03:00
if entity.has_method("quick_action")&&miniature.entity_select.selection_active() == false:
entity.quick_action()
2024-05-09 13:40:41 +03:00
snap_sound.play()
else:
miniature.entity_select.toggle(entity)
2024-04-17 22:27:09 +03:00
func _on_press_move(_event: EventPointer):
if moved_ran: return
miniature.entity_select.toggle(entity)
moved_ran = true
func _on_press_up(_event: EventPointer):
moved_ran = false
func _on_touch_enter(_event: EventTouch):
touched_enter = Time.get_ticks_msec()
2024-04-17 22:34:21 +03:00
touch_ran = false
func _on_touch_move(_event: EventTouch):
if touch_ran||Time.get_ticks_msec() - touched_enter < TOUCH_LONG: return
miniature.entity_select.toggle(entity)
touch_ran = true
2024-04-17 22:27:09 +03:00
func _on_touch_leave(_event: EventTouch):
2024-04-17 22:34:21 +03:00
if touch_ran: return
2024-04-18 13:10:20 +03:00
if entity.has_method("quick_action")&&miniature.entity_select.selection_active() == false:
2024-05-09 13:40:41 +03:00
snap_sound.play()
2024-04-17 22:27:09 +03:00
entity.quick_action()
else:
2024-05-09 19:19:39 +03:00
miniature.entity_select.toggle(entity)