From d858dc54e5090dd2e8bea8836bb4cce3ccd239be Mon Sep 17 00:00:00 2001 From: Nitwel Date: Wed, 17 Apr 2024 21:27:09 +0200 Subject: [PATCH] fix long press and add quick actions --- app/content/entities/button/button.gd | 3 +++ app/content/entities/light/light.gd | 9 +++++++++ app/content/entities/switch/switch.gd | 11 +++++++++-- app/content/system/dot/dot.gd | 22 ++++++++++++++++++++-- app/content/system/dot/dot.tscn | 14 +++++++++++++- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/app/content/entities/button/button.gd b/app/content/entities/button/button.gd index 09b6f93..0533788 100644 --- a/app/content/entities/button/button.gd +++ b/app/content/entities/button/button.gd @@ -34,3 +34,6 @@ func set_state(state): else: button.icon = false button.label = name + +func quick_action(): + HomeApi.set_state(entity_id, "pressed") \ No newline at end of file diff --git a/app/content/entities/light/light.gd b/app/content/entities/light/light.gd index e61366f..b867392 100644 --- a/app/content/entities/light/light.gd +++ b/app/content/entities/light/light.gd @@ -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) \ No newline at end of file diff --git a/app/content/entities/switch/switch.gd b/app/content/entities/switch/switch.gd index 4cb1b19..1a0c5d7 100644 --- a/app/content/entities/switch/switch.gd +++ b/app/content/entities/switch/switch.gd @@ -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) @@ -35,4 +35,11 @@ func _on_click(event): sprite.set_frame(0) func _on_request_completed(): - pass \ No newline at end of file + 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) \ No newline at end of file diff --git a/app/content/system/dot/dot.gd b/app/content/system/dot/dot.gd index 0650f44..89e175b 100644 --- a/app/content/system/dot/dot.gd +++ b/app/content/system/dot/dot.gd @@ -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): - miniature.entity_select.toggle(entity) \ No newline at end of file +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) \ No newline at end of file diff --git a/app/content/system/dot/dot.tscn b/app/content/system/dot/dot.tscn index 4e1901b..5d307ed 100644 --- a/app/content/system/dot/dot.tscn +++ b/app/content/system/dot/dot.tscn @@ -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")