fix problems and add select interface to light

This commit is contained in:
Nitwel 2024-05-27 18:16:45 +02:00
parent 7cd2fe727e
commit 96c2ab1b20
15 changed files with 61 additions and 86 deletions

View File

@ -122,5 +122,5 @@ func get_options():
}
func set_options(options):
cam_active.value = options["cam_active"]
cam_fps.value = options["cam_fps"]
if options.has("cam_active"): cam_active.value = options["cam_active"]
if options.has("cam_fps"): cam_fps.value = options["cam_fps"]

View File

@ -7,7 +7,7 @@
[ext_resource type="PackedScene" uid="uid://pk5k1q8bx0rj" path="res://content/ui/components/slider/slider.tscn" id="4_t8xp5"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="5_opf0y"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5ufyx"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_oovyb"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("2_wwobq")
@ -22,15 +22,15 @@ shader_parameter/corner_radius = 0.2
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_4xo3t"]
[sub_resource type="QuadMesh" id="QuadMesh_cftc5"]
size = Vector2(0.3, 0.2)
[node name="Settings" type="Node3D"]
script = ExtResource("1_1ixy6")
[node name="Panel" parent="." instance=ExtResource("1_myvk1")]
material_override = SubResource("ShaderMaterial_5ufyx")
mesh = SubResource("QuadMesh_4xo3t")
material_override = SubResource("ShaderMaterial_oovyb")
mesh = SubResource("QuadMesh_cftc5")
skeleton = NodePath("../..")
size = Vector2(0.3, 0.2)

View File

@ -8,10 +8,7 @@ const Entity = preload ("../entity.gd")
@onready var lightbulb = $Lightbulb
@onready var slider: Slider3D = $Slider
@onready var color_wheel = $ColorWheel
@onready var modes = $Modes
@onready var mode_next = $Modes/Next
@onready var mode_before = $Modes/Previous
@onready var mode_label = $Modes/Label
@onready var modes: Select3D = $Modes
@onready var snap_sound = $SnapSound
@onready var settings = $Settings
@onready var movable = $Movable
@ -72,30 +69,17 @@ func _ready():
modes_supported.value = true
if stateInfo["attributes"].has("effect")&&stateInfo["attributes"]["effect"] != null:
mode_label.text = stateInfo["attributes"]["effect"]
modes.selected = stateInfo["attributes"]["effect"]
mode_next.on_button_down.connect(func():
var index=stateInfo["attributes"]["effect_list"].find(stateInfo["attributes"]["effect"])
if index == - 1:
index=0
else:
index=(index + 1) % stateInfo["attributes"]["effect_list"].size()
var options = {}
mode_label.text=stateInfo["attributes"]["effect_list"][index]
for effect in stateInfo["attributes"]["effect_list"]:
options[effect] = effect
HomeApi.set_state(entity_id, "on", {"effect": stateInfo["attributes"]["effect_list"][index]})
)
modes.options = options
mode_before.on_button_down.connect(func():
var index=stateInfo["attributes"]["effect_list"].find(stateInfo["attributes"]["effect"])
if index == - 1:
index=0
else:
index=(index - 1) % stateInfo["attributes"]["effect_list"].size()
mode_label.text=stateInfo["attributes"]["effect_list"][index]
HomeApi.set_state(entity_id, "on", {"effect": stateInfo["attributes"]["effect_list"][index]})
modes.on_select.connect(func(option):
HomeApi.set_state(entity_id, "on", {"effect": option})
)
if stateInfo.has("attributes")&&stateInfo["attributes"].has("supported_color_modes")&&stateInfo["attributes"]["supported_color_modes"].has("rgb"):
@ -174,6 +158,6 @@ func get_options():
}
func set_options(options):
show_color_wheel.value = options["color_wheel"]
show_brightness.value = options["brightness"]
show_modes.value = options["modes"]
if options.has("color_wheel"): show_color_wheel.value = options["color_wheel"]
if options.has("brightness"): show_brightness.value = options["brightness"]
if options.has("modes"): show_modes.value = options["modes"]

View File

@ -5,8 +5,8 @@
[ext_resource type="Material" uid="uid://vce66e7sbc3n" path="res://content/entities/light/light_on.tres" id="5_50gph"]
[ext_resource type="PackedScene" uid="uid://chrjqr4l7atrc" path="res://content/ui/components/color_wheel/color_wheel.tscn" id="5_qj75k"]
[ext_resource type="PackedScene" uid="uid://pk5k1q8bx0rj" path="res://content/ui/components/slider/slider.tscn" id="6_mhjlm"]
[ext_resource type="PackedScene" uid="uid://wgnowarejk5y" path="res://content/ui/components/select/select.tscn" id="7_wbegr"]
[ext_resource type="AudioStream" uid="uid://du7ur0lu28cvn" path="res://assets/sound/finger-snap.mp3" id="8_3togy"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="8_nhcff"]
[ext_resource type="Script" path="res://content/functions/camera_follower.gd" id="9_a7u7m"]
[ext_resource type="PackedScene" uid="uid://de34yde00ngkv" path="res://content/entities/light/settings.tscn" id="10_su84f"]
@ -55,25 +55,9 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.15, 0, 0)
color = Color(0, 0.616667, 1, 1)
size = Vector3(0.15, 0.2, 0.01)
[node name="Modes" type="Node3D" parent="."]
[node name="Modes" parent="." instance=ExtResource("7_wbegr")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.11, 0)
[node name="Next" parent="Modes" instance=ExtResource("8_nhcff")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.04, 0, 0)
label = "navigate_next"
icon = true
[node name="Previous" parent="Modes" instance=ExtResource("8_nhcff")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.1, 0, 0)
label = "navigate_before"
icon = true
[node name="Label" type="Label3D" parent="Modes"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.01, 0, 0)
pixel_size = 0.001
text = "Default"
horizontal_alignment = 0
[node name="SnapSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("8_3togy")
volume_db = -20.0

View File

@ -59,7 +59,7 @@ func request_history():
match duration.value:
Duration.ONE_HOUR:
date = now - 60 * 60
date = now - 2 * 60 * 60
Duration.ONE_DAY:
date = now - 24 * 60 * 60
Duration.ONE_WEEK:
@ -68,6 +68,8 @@ func request_history():
date = now - 30 * 24 * 60 * 60
Duration.ONE_YEAR:
date = now - 365 * 24 * 60 * 60
_:
date = now - 24 * 60 * 60
var start = Time.get_datetime_string_from_unix_time(date) + ".000Z"
@ -92,5 +94,5 @@ func get_options():
"duration": duration.value
}
func set_options(options):
duration.value = options["duration"]
func set_options(options: Dictionary):
if options.has("duration"): duration.value = options["duration"]

View File

@ -7,7 +7,7 @@
[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="5_ecnnd"]
[ext_resource type="PackedScene" uid="uid://wgnowarejk5y" path="res://content/ui/components/select/select.tscn" id="6_egqee"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mfny2"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_boysj"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("3_vjmg5")
@ -22,15 +22,15 @@ shader_parameter/corner_radius = 0.2
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_fngct"]
[sub_resource type="QuadMesh" id="QuadMesh_e21ey"]
size = Vector2(0.3, 0.2)
[node name="Settings" type="Node3D"]
script = ExtResource("1_xxfkt")
[node name="Panel" parent="." instance=ExtResource("2_4g761")]
material_override = SubResource("ShaderMaterial_mfny2")
mesh = SubResource("QuadMesh_fngct")
material_override = SubResource("ShaderMaterial_boysj")
mesh = SubResource("QuadMesh_e21ey")
skeleton = NodePath("../..")
size = Vector2(0.3, 0.2)

View File

@ -15,7 +15,7 @@ const FontTools = preload ("res://lib/utils/font_tools.gd")
if !is_inside_tree(): return
label.text = text
var text_width = FontTools.get_font_size(label).x
var text_width = FontTools.get_label_size(label).x
var offset = (text_width - base_width) / 0.2

View File

@ -5,7 +5,7 @@
[ext_resource type="Script" path="res://content/ui/components/panel/panel.gd" id="3_skm86"]
[ext_resource type="AudioStream" uid="uid://c1yu80uj3fsn7" path="res://assets/sound/click.wav" id="4_51sb0"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_n8raw"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_w8rdk"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("2_db5by")
@ -20,7 +20,7 @@ shader_parameter/corner_radius = 0.2
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_g3nfn"]
[sub_resource type="QuadMesh" id="QuadMesh_6niqb"]
size = Vector2(0.04, 0.04)
[sub_resource type="BoxShape3D" id="BoxShape3D_xwopm"]
@ -43,8 +43,8 @@ collision_mask = 0
[node name="Panel3D" type="MeshInstance3D" parent="Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.005)
material_override = SubResource("ShaderMaterial_n8raw")
mesh = SubResource("QuadMesh_g3nfn")
material_override = SubResource("ShaderMaterial_w8rdk")
mesh = SubResource("QuadMesh_6niqb")
skeleton = NodePath("../..")
script = ExtResource("3_skm86")
size = Vector2(0.04, 0.04)

View File

@ -81,7 +81,7 @@ func _calculate_text_gaps():
for i in range(text.length()):
var chars = text.substr(0, i + 1) # Can't use single chars because of kerning.
var size = FontTools.get_font_size(label, chars)
var size = FontTools.get_label_size(label, chars)
offsets.append(size.x)

View File

@ -28,5 +28,5 @@ func _ready():
func _update_text():
label.font_size = font_size
label.text = text
var text_size = FontTools.get_font_size(label)
var text_size = FontTools.get_label_size(label)
size = Vector3(text_size.x, text_size.y, 0.1)

View File

@ -1,7 +1,7 @@
@tool
extends Node3D
const FontTools = preload ("res://lib/utils/font_tools.gd")
const LabelFont = preload ("res://assets/fonts/Raleway-Medium.ttf")
@onready var label = $Body/Label3D
@onready var collision = $Body/CollisionShape3D
@ -24,7 +24,7 @@ func _ready():
_update()
func get_size() -> Vector2:
return FontTools.get_font_size(label)
return LabelFont.get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, 10000, 18) * 0.001
func _update():
var size = get_size()

View File

@ -19,7 +19,13 @@ signal on_select(value: String)
@onready var options_panel = $Options/Panel
@onready var options_collision = $Options/CollisionShape3D
@export var options: Dictionary = {}
@export var options: Dictionary = {}:
set(value):
options = value
if is_node_ready() == false: return
_update_options()
@export var selected: Variant = null:
set(value):
if selected != value:
@ -47,6 +53,7 @@ var _options_list = []
func _ready():
_update()
_update_options()
_update_options_visible()
func _on_focus_out(_event: EventFocus):
open = false
@ -68,7 +75,7 @@ func _on_touch_leave(event: EventTouch):
open = false
func _update():
if selected == null:
if selected == null||options == null||options.has(selected) == false:
label.text = "Select..."
else:
label.text = options[selected]

View File

@ -5,7 +5,7 @@
[ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="3_8yxox"]
[ext_resource type="FontVariation" uid="uid://sshfnckriqxn" path="res://assets/icons/icons.tres" id="4_61i7u"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wfc33"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_o58sw"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("3_8yxox")
@ -20,15 +20,14 @@ shader_parameter/corner_radius = 0.2
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_sal60"]
resource_local_to_scene = true
[sub_resource type="QuadMesh" id="QuadMesh_xblx4"]
size = Vector2(0.2, 0.04)
[sub_resource type="BoxShape3D" id="BoxShape3D_uwnbp"]
resource_local_to_scene = true
size = Vector3(0.16, 0.03, 0.01)
size = Vector3(0.2, 0.04, 0.01)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_qowt5"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_fnoxg"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("3_8yxox")
@ -43,17 +42,16 @@ shader_parameter/corner_radius = 0.2
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_3gij7"]
resource_local_to_scene = true
[sub_resource type="QuadMesh" id="QuadMesh_6v0t1"]
size = Vector2(0.02, 0.01)
[sub_resource type="BoxShape3D" id="BoxShape3D_cv4hj"]
resource_local_to_scene = true
size = Vector3(0.114, 0.17, 0.01)
size = Vector3(0.02, 0.01, 0.01)
[sub_resource type="BoxShape3D" id="BoxShape3D_n5ty8"]
resource_local_to_scene = true
size = Vector3(0.16, 0.03, 0.01)
size = Vector3(0.2, 0.04, 0.01)
[node name="Select" type="Node3D" groups=["ui_focus"]]
script = ExtResource("1_0yka7")
@ -65,8 +63,8 @@ collision_mask = 0
[node name="Panel" parent="Body" instance=ExtResource("2_5mspw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.01)
material_override = SubResource("ShaderMaterial_wfc33")
mesh = SubResource("QuadMesh_sal60")
material_override = SubResource("ShaderMaterial_o58sw")
mesh = SubResource("QuadMesh_xblx4")
skeleton = NodePath("../..")
size = Vector2(0.2, 0.04)
@ -103,8 +101,8 @@ collision_mask = 0
[node name="Panel" parent="Options" instance=ExtResource("2_5mspw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01, -0.005, 0)
material_override = SubResource("ShaderMaterial_qowt5")
mesh = SubResource("QuadMesh_3gij7")
material_override = SubResource("ShaderMaterial_fnoxg")
mesh = SubResource("QuadMesh_6v0t1")
skeleton = NodePath("../..")
size = Vector2(0.02, 0.01)

View File

@ -37,5 +37,5 @@ func get_history(entity_id: String, start: String, interval: String="5minute", e
"unit": meta_response.payload.result[0]["display_unit_of_measurement"],
"has_mean": meta_response.payload.result[0]["has_mean"],
"unit_class": meta_response.payload.result[0]["unit_class"],
"data": data_response.payload.result[entity_id]
"data": data_response.payload.result[entity_id] if data_response.payload.result.has(entity_id) else []
}

View File

@ -1,5 +1,5 @@
## Returns the size of a Label3D in standard units
static func get_font_size(label: Label3D, chars=null) -> Vector2:
static func get_label_size(label: Label3D, chars=null) -> Vector2:
var font = label.font
if font == null: