fix long press and add quick actions
This commit is contained in:
parent
be958486b7
commit
d858dc54e5
|
@ -34,3 +34,6 @@ func set_state(state):
|
|||
else:
|
||||
button.icon = false
|
||||
button.label = name
|
||||
|
||||
func quick_action():
|
||||
HomeApi.set_state(entity_id, "pressed")
|
|
@ -132,3 +132,12 @@ func _on_click(event):
|
|||
|
||||
HomeApi.set_state(entity_id, "on" if !state else "off", attributes)
|
||||
set_state(!state, attributes)
|
||||
|
||||
func quick_action():
|
||||
var attributes = {}
|
||||
|
||||
if !state&&brightness != null:
|
||||
attributes["brightness"] = int(brightness)
|
||||
|
||||
HomeApi.set_state(entity_id, "on" if !state else "off", attributes)
|
||||
set_state(!state, attributes)
|
|
@ -27,7 +27,7 @@ func _ready():
|
|||
icon.value="toggle_" + new_state["state"]
|
||||
)
|
||||
|
||||
func _on_click(event):
|
||||
func _on_click(_event):
|
||||
HomeApi.set_state(entity_id, "off" if sprite.get_frame() == 0 else "on")
|
||||
if sprite.get_frame() == 0:
|
||||
sprite.set_frame(1)
|
||||
|
@ -36,3 +36,10 @@ func _on_click(event):
|
|||
|
||||
func _on_request_completed():
|
||||
pass
|
||||
|
||||
func quick_action():
|
||||
HomeApi.set_state(entity_id, "off" if sprite.get_frame() == 0 else "on")
|
||||
if sprite.get_frame() == 0:
|
||||
sprite.set_frame(1)
|
||||
else:
|
||||
sprite.set_frame(0)
|
|
@ -2,12 +2,16 @@ extends StaticBody3D
|
|||
|
||||
const Entity = preload ("res://content/entities/entity.gd")
|
||||
|
||||
const TOUCH_LONG = 400.0
|
||||
|
||||
@export var entity: Entity
|
||||
|
||||
@onready var collision = $CollisionShape3D
|
||||
@onready var label = $Label3D
|
||||
var active = R.state(false)
|
||||
var disabled = R.state(true)
|
||||
var touched_enter = 0.0
|
||||
var moved_ran = false
|
||||
|
||||
var miniature = House.body.mini_view
|
||||
|
||||
|
@ -34,5 +38,19 @@ func _on_click(_event: EventPointer):
|
|||
else:
|
||||
miniature.entity_select.toggle(entity)
|
||||
|
||||
func _on_move_start(_event: EventPointer):
|
||||
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()
|
||||
|
||||
func _on_touch_leave(_event: EventTouch):
|
||||
if Time.get_ticks_msec() - touched_enter < TOUCH_LONG&&entity.has_method("quick_action"):
|
||||
entity.quick_action()
|
||||
else:
|
||||
miniature.entity_select.toggle(entity)
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://b5buw1sas18n4"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b5buw1sas18n4"]
|
||||
|
||||
[ext_resource type="Script" path="res://content/system/dot/dot.gd" id="1_vdpux"]
|
||||
[ext_resource type="FontVariation" uid="uid://sshfnckriqxn" path="res://assets/icons/icons.tres" id="4_504vw"]
|
||||
|
@ -7,6 +7,10 @@
|
|||
custom_solver_bias = 0.2
|
||||
radius = 0.1
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_y1ne8"]
|
||||
custom_solver_bias = 0.2
|
||||
radius = 0.2
|
||||
|
||||
[node name="Dot" type="StaticBody3D"]
|
||||
script = ExtResource("1_vdpux")
|
||||
|
||||
|
@ -20,3 +24,11 @@ text = "lightbulb"
|
|||
font = ExtResource("4_504vw")
|
||||
font_size = 100
|
||||
outline_size = 18
|
||||
|
||||
[node name="Area3D" type="Area3D" parent="."]
|
||||
collision_layer = 4
|
||||
collision_mask = 0
|
||||
monitoring = false
|
||||
|
||||
[node name="CollisionShape3D2" type="CollisionShape3D" parent="Area3D"]
|
||||
shape = SubResource("SphereShape3D_y1ne8")
|
||||
|
|
Loading…
Reference in New Issue
Block a user