add select interface, options for line_chart
This commit is contained in:
parent
8fa356d5b5
commit
7cd2fe727e
|
@ -113,4 +113,14 @@ func load_image(url: String):
|
||||||
var texture = ImageTexture.create_from_image(image)
|
var texture = ImageTexture.create_from_image(image)
|
||||||
view.texture = texture
|
view.texture = texture
|
||||||
view.pixel_size = pixel_size
|
view.pixel_size = pixel_size
|
||||||
mesh.visible = false
|
mesh.visible = false
|
||||||
|
|
||||||
|
func get_options():
|
||||||
|
return {
|
||||||
|
"cam_active": cam_active.value,
|
||||||
|
"cam_fps": cam_fps.value,
|
||||||
|
}
|
||||||
|
|
||||||
|
func set_options(options):
|
||||||
|
cam_active.value = options["cam_active"]
|
||||||
|
cam_fps.value = options["cam_fps"]
|
|
@ -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://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"]
|
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="5_opf0y"]
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_jtvwv"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5ufyx"]
|
||||||
resource_local_to_scene = true
|
resource_local_to_scene = true
|
||||||
render_priority = 10
|
render_priority = 10
|
||||||
shader = ExtResource("2_wwobq")
|
shader = ExtResource("2_wwobq")
|
||||||
|
@ -22,15 +22,15 @@ shader_parameter/corner_radius = 0.2
|
||||||
shader_parameter/roughness = 0.3
|
shader_parameter/roughness = 0.3
|
||||||
shader_parameter/grain_amount = 0.02
|
shader_parameter/grain_amount = 0.02
|
||||||
|
|
||||||
[sub_resource type="QuadMesh" id="QuadMesh_myer6"]
|
[sub_resource type="QuadMesh" id="QuadMesh_4xo3t"]
|
||||||
size = Vector2(0.3, 0.2)
|
size = Vector2(0.3, 0.2)
|
||||||
|
|
||||||
[node name="Settings" type="Node3D"]
|
[node name="Settings" type="Node3D"]
|
||||||
script = ExtResource("1_1ixy6")
|
script = ExtResource("1_1ixy6")
|
||||||
|
|
||||||
[node name="Panel" parent="." instance=ExtResource("1_myvk1")]
|
[node name="Panel" parent="." instance=ExtResource("1_myvk1")]
|
||||||
material_override = SubResource("ShaderMaterial_jtvwv")
|
material_override = SubResource("ShaderMaterial_5ufyx")
|
||||||
mesh = SubResource("QuadMesh_myer6")
|
mesh = SubResource("QuadMesh_4xo3t")
|
||||||
skeleton = NodePath("../..")
|
skeleton = NodePath("../..")
|
||||||
size = Vector2(0.3, 0.2)
|
size = Vector2(0.3, 0.2)
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,35 @@ const Entity = preload ("../entity.gd")
|
||||||
@onready var line_chart = $LineChart
|
@onready var line_chart = $LineChart
|
||||||
@onready var timer = $Timer
|
@onready var timer = $Timer
|
||||||
@onready var label = $Label3D
|
@onready var label = $Label3D
|
||||||
|
@onready var settings = $Settings
|
||||||
|
|
||||||
|
enum Duration {
|
||||||
|
ONE_HOUR,
|
||||||
|
ONE_DAY,
|
||||||
|
ONE_WEEK,
|
||||||
|
ONE_MONTH,
|
||||||
|
ONE_YEAR
|
||||||
|
}
|
||||||
|
|
||||||
|
var duration = R.state(Duration.ONE_DAY)
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
super()
|
super()
|
||||||
|
|
||||||
icon.value = "finance"
|
icon.value = "finance"
|
||||||
|
|
||||||
label.text = entity_id
|
label.text = entity_id
|
||||||
|
|
||||||
|
remove_child(settings)
|
||||||
|
|
||||||
|
R.effect(func(_arg):
|
||||||
|
if show_settings.value:
|
||||||
|
add_child(settings)
|
||||||
|
elif settings.is_inside_tree():
|
||||||
|
remove_child(settings)
|
||||||
|
camera_follower.reset()
|
||||||
|
App.house.save_all_entities()
|
||||||
|
)
|
||||||
|
|
||||||
if HomeApi.has_connected() == false:
|
if HomeApi.has_connected() == false:
|
||||||
await HomeApi.on_connect
|
await HomeApi.on_connect
|
||||||
|
|
||||||
|
@ -22,6 +43,11 @@ func _ready():
|
||||||
|
|
||||||
request_history()
|
request_history()
|
||||||
|
|
||||||
|
R.effect(func(_arg):
|
||||||
|
duration.value
|
||||||
|
request_history()
|
||||||
|
)
|
||||||
|
|
||||||
timer.timeout.connect(request_history)
|
timer.timeout.connect(request_history)
|
||||||
|
|
||||||
func request_history():
|
func request_history():
|
||||||
|
@ -29,12 +55,23 @@ func request_history():
|
||||||
|
|
||||||
var now = Time.get_unix_time_from_datetime_dict(Time.get_datetime_dict_from_system())
|
var now = Time.get_unix_time_from_datetime_dict(Time.get_datetime_dict_from_system())
|
||||||
|
|
||||||
# 2 days ago
|
var date
|
||||||
var two_days_ago = now - 2 * 24 * 60 * 60
|
|
||||||
|
|
||||||
var start = Time.get_datetime_string_from_unix_time(two_days_ago) + ".000Z"
|
match duration.value:
|
||||||
|
Duration.ONE_HOUR:
|
||||||
|
date = now - 60 * 60
|
||||||
|
Duration.ONE_DAY:
|
||||||
|
date = now - 24 * 60 * 60
|
||||||
|
Duration.ONE_WEEK:
|
||||||
|
date = now - 7 * 24 * 60 * 60
|
||||||
|
Duration.ONE_MONTH:
|
||||||
|
date = now - 30 * 24 * 60 * 60
|
||||||
|
Duration.ONE_YEAR:
|
||||||
|
date = now - 365 * 24 * 60 * 60
|
||||||
|
|
||||||
var result = await HomeApi.get_history(entity_id, start)
|
var start = Time.get_datetime_string_from_unix_time(date) + ".000Z"
|
||||||
|
|
||||||
|
var result = await HomeApi.get_history(entity_id, start, "hour")
|
||||||
|
|
||||||
if result == null:
|
if result == null:
|
||||||
return
|
return
|
||||||
|
@ -49,3 +86,11 @@ func request_history():
|
||||||
|
|
||||||
func get_interface():
|
func get_interface():
|
||||||
return "line_chart"
|
return "line_chart"
|
||||||
|
|
||||||
|
func get_options():
|
||||||
|
return {
|
||||||
|
"duration": duration.value
|
||||||
|
}
|
||||||
|
|
||||||
|
func set_options(options):
|
||||||
|
duration.value = options["duration"]
|
|
@ -1,8 +1,10 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://cltcs0gokeald"]
|
[gd_scene load_steps=7 format=3 uid="uid://cltcs0gokeald"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://content/entities/line_chart/line_chart.gd" id="1_5dxim"]
|
[ext_resource type="Script" path="res://content/entities/line_chart/line_chart.gd" id="1_5dxim"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cwvykoymlrrel" path="res://content/ui/components/line_chart/line_chart.tscn" id="2_k4shm"]
|
[ext_resource type="PackedScene" uid="uid://cwvykoymlrrel" path="res://content/ui/components/line_chart/line_chart.tscn" id="2_k4shm"]
|
||||||
[ext_resource type="Script" path="res://content/functions/movable.gd" id="3_lidml"]
|
[ext_resource type="Script" path="res://content/functions/movable.gd" id="3_lidml"]
|
||||||
|
[ext_resource type="Script" path="res://content/functions/camera_follower.gd" id="4_ovcs6"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://q5p1701gdfiq" path="res://content/entities/line_chart/settings.tscn" id="5_w7tql"]
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_rmm5v"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_rmm5v"]
|
||||||
size = Vector3(0.5, 0.3, 0.001)
|
size = Vector3(0.5, 0.3, 0.001)
|
||||||
|
@ -22,6 +24,10 @@ shape = SubResource("BoxShape3D_rmm5v")
|
||||||
script = ExtResource("3_lidml")
|
script = ExtResource("3_lidml")
|
||||||
resizable = true
|
resizable = true
|
||||||
|
|
||||||
|
[node name="CameraFollower" type="Node" parent="." node_paths=PackedStringArray("focus_point")]
|
||||||
|
script = ExtResource("4_ovcs6")
|
||||||
|
focus_point = NodePath("../Settings")
|
||||||
|
|
||||||
[node name="Timer" type="Timer" parent="."]
|
[node name="Timer" type="Timer" parent="."]
|
||||||
wait_time = 60.0
|
wait_time = 60.0
|
||||||
autostart = true
|
autostart = true
|
||||||
|
@ -32,3 +38,6 @@ pixel_size = 0.001
|
||||||
text = "sensor.tada"
|
text = "sensor.tada"
|
||||||
font_size = 18
|
font_size = 18
|
||||||
outline_size = 4
|
outline_size = 4
|
||||||
|
|
||||||
|
[node name="Settings" parent="." instance=ExtResource("5_w7tql")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.67, 0.15, 0)
|
||||||
|
|
20
app/content/entities/line_chart/settings.gd
Normal file
20
app/content/entities/line_chart/settings.gd
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
const LineChart = preload ("./line_chart.gd")
|
||||||
|
|
||||||
|
@onready var close_button: Button3D = $Close
|
||||||
|
@onready var id_input: Input3D = $IDInput
|
||||||
|
@onready var duration_select: Select3D = $DurationSelect
|
||||||
|
|
||||||
|
var line_chart: LineChart
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
line_chart = get_parent()
|
||||||
|
|
||||||
|
close_button.on_button_up.connect(func():
|
||||||
|
line_chart.show_settings.value=false
|
||||||
|
)
|
||||||
|
|
||||||
|
id_input.text = line_chart.entity_id
|
||||||
|
|
||||||
|
R.bind(duration_select, "selected", line_chart.duration, duration_select.on_select)
|
85
app/content/entities/line_chart/settings.tscn
Normal file
85
app/content/entities/line_chart/settings.tscn
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
[gd_scene load_steps=9 format=3 uid="uid://q5p1701gdfiq"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://content/entities/line_chart/settings.gd" id="1_xxfkt"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dnam3fe36gg62" path="res://content/ui/components/panel/panel.tscn" id="2_4g761"]
|
||||||
|
[ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="3_vjmg5"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="4_oroek"]
|
||||||
|
[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"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
render_priority = 10
|
||||||
|
shader = ExtResource("3_vjmg5")
|
||||||
|
shader_parameter/color = Color(1, 1, 1, 0.3)
|
||||||
|
shader_parameter/border_color = Color(1, 1, 1, 1)
|
||||||
|
shader_parameter/edge_color = Color(0, 0, 0, 1)
|
||||||
|
shader_parameter/size = Vector2(7.5, 5)
|
||||||
|
shader_parameter/border_size = 0.01
|
||||||
|
shader_parameter/border_fade_in = 0.05
|
||||||
|
shader_parameter/border_fade_out = 0.0
|
||||||
|
shader_parameter/corner_radius = 0.2
|
||||||
|
shader_parameter/roughness = 0.3
|
||||||
|
shader_parameter/grain_amount = 0.02
|
||||||
|
|
||||||
|
[sub_resource type="QuadMesh" id="QuadMesh_fngct"]
|
||||||
|
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")
|
||||||
|
skeleton = NodePath("../..")
|
||||||
|
size = Vector2(0.3, 0.2)
|
||||||
|
|
||||||
|
[node name="Name" type="Label3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.14, 0.07, 0)
|
||||||
|
pixel_size = 0.001
|
||||||
|
render_priority = 15
|
||||||
|
outline_render_priority = 14
|
||||||
|
text = "Chart Settings"
|
||||||
|
font_size = 24
|
||||||
|
outline_size = 0
|
||||||
|
horizontal_alignment = 0
|
||||||
|
|
||||||
|
[node name="Close" parent="." instance=ExtResource("4_oroek")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.07, 0)
|
||||||
|
label = "close"
|
||||||
|
icon = true
|
||||||
|
|
||||||
|
[node name="IDLabel" type="Label3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.14, 0.03, 0)
|
||||||
|
pixel_size = 0.001
|
||||||
|
render_priority = 15
|
||||||
|
outline_render_priority = 14
|
||||||
|
text = "ID:"
|
||||||
|
font_size = 18
|
||||||
|
outline_size = 0
|
||||||
|
horizontal_alignment = 0
|
||||||
|
|
||||||
|
[node name="IDInput" parent="." instance=ExtResource("5_ecnnd")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0.03, 0)
|
||||||
|
disabled = true
|
||||||
|
|
||||||
|
[node name="VideoLabel" type="Label3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.14, -0.01, 0)
|
||||||
|
pixel_size = 0.001
|
||||||
|
render_priority = 15
|
||||||
|
outline_render_priority = 14
|
||||||
|
text = "Duration:"
|
||||||
|
font_size = 18
|
||||||
|
outline_size = 0
|
||||||
|
horizontal_alignment = 0
|
||||||
|
|
||||||
|
[node name="DurationSelect" parent="." instance=ExtResource("6_egqee")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, -0.01, 0)
|
||||||
|
options = {
|
||||||
|
0: "Last Hour",
|
||||||
|
1: "Last Day",
|
||||||
|
2: "Last Week",
|
||||||
|
3: "Last Month",
|
||||||
|
4: "Last Year"
|
||||||
|
}
|
||||||
|
size = Vector3(0.16, 0.03, 0.01)
|
|
@ -5,7 +5,7 @@
|
||||||
[ext_resource type="Script" path="res://content/ui/components/panel/panel.gd" id="3_skm86"]
|
[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"]
|
[ext_resource type="AudioStream" uid="uid://c1yu80uj3fsn7" path="res://assets/sound/click.wav" id="4_51sb0"]
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_syops"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_n8raw"]
|
||||||
resource_local_to_scene = true
|
resource_local_to_scene = true
|
||||||
render_priority = 10
|
render_priority = 10
|
||||||
shader = ExtResource("2_db5by")
|
shader = ExtResource("2_db5by")
|
||||||
|
@ -20,7 +20,7 @@ shader_parameter/corner_radius = 0.2
|
||||||
shader_parameter/roughness = 0.3
|
shader_parameter/roughness = 0.3
|
||||||
shader_parameter/grain_amount = 0.02
|
shader_parameter/grain_amount = 0.02
|
||||||
|
|
||||||
[sub_resource type="QuadMesh" id="QuadMesh_btecp"]
|
[sub_resource type="QuadMesh" id="QuadMesh_g3nfn"]
|
||||||
size = Vector2(0.04, 0.04)
|
size = Vector2(0.04, 0.04)
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_xwopm"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_xwopm"]
|
||||||
|
@ -43,8 +43,8 @@ collision_mask = 0
|
||||||
|
|
||||||
[node name="Panel3D" type="MeshInstance3D" parent="Body"]
|
[node name="Panel3D" type="MeshInstance3D" parent="Body"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.005)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.005)
|
||||||
material_override = SubResource("ShaderMaterial_syops")
|
material_override = SubResource("ShaderMaterial_n8raw")
|
||||||
mesh = SubResource("QuadMesh_btecp")
|
mesh = SubResource("QuadMesh_g3nfn")
|
||||||
skeleton = NodePath("../..")
|
skeleton = NodePath("../..")
|
||||||
script = ExtResource("3_skm86")
|
script = ExtResource("3_skm86")
|
||||||
size = Vector2(0.04, 0.04)
|
size = Vector2(0.04, 0.04)
|
||||||
|
|
34
app/content/ui/components/select/option.gd
Normal file
34
app/content/ui/components/select/option.gd
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
@tool
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
const FontTools = preload ("res://lib/utils/font_tools.gd")
|
||||||
|
|
||||||
|
@onready var label = $Body/Label3D
|
||||||
|
@onready var collision = $Body/CollisionShape3D
|
||||||
|
@onready var area_collision = $Area3D/CollisionShape3D
|
||||||
|
|
||||||
|
var text = "test"
|
||||||
|
var value = ""
|
||||||
|
var disabled = false:
|
||||||
|
set(value):
|
||||||
|
disabled = value
|
||||||
|
|
||||||
|
if is_node_ready() == false: return
|
||||||
|
|
||||||
|
collision.disabled = value
|
||||||
|
area_collision.disabled = value
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
label.text = text
|
||||||
|
|
||||||
|
_update()
|
||||||
|
|
||||||
|
func get_size() -> Vector2:
|
||||||
|
return FontTools.get_font_size(label)
|
||||||
|
|
||||||
|
func _update():
|
||||||
|
var size = get_size()
|
||||||
|
collision.shape.size = Vector3(size.x, size.y, 0.004)
|
||||||
|
area_collision.shape.size = Vector3(size.x, size.y, 0.01)
|
||||||
|
collision.position = Vector3(size.x / 2, -size.y / 2, 0.002)
|
||||||
|
area_collision.position = Vector3(size.x / 2, -size.y / 2, 0.005)
|
37
app/content/ui/components/select/option.tscn
Normal file
37
app/content/ui/components/select/option.tscn
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
[gd_scene load_steps=5 format=3 uid="uid://c7yxuroa2pfyu"]
|
||||||
|
|
||||||
|
[ext_resource type="FontFile" uid="uid://cs508knjj1lnw" path="res://assets/fonts/Raleway-Medium.ttf" id="1_2dk7o"]
|
||||||
|
[ext_resource type="Script" path="res://content/ui/components/select/option.gd" id="1_cdx1b"]
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_v323n"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
size = Vector3(0.032, 0.022, 0.004)
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_6yqdi"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
size = Vector3(0.032, 0.022, 0.01)
|
||||||
|
|
||||||
|
[node name="Option" type="Node3D"]
|
||||||
|
script = ExtResource("1_cdx1b")
|
||||||
|
|
||||||
|
[node name="Body" type="StaticBody3D" parent="."]
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Body"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.016, -0.011, 0.002)
|
||||||
|
shape = SubResource("BoxShape3D_v323n")
|
||||||
|
|
||||||
|
[node name="Label3D" type="Label3D" parent="Body"]
|
||||||
|
pixel_size = 0.001
|
||||||
|
render_priority = 40
|
||||||
|
text = "test"
|
||||||
|
font = ExtResource("1_2dk7o")
|
||||||
|
font_size = 18
|
||||||
|
outline_size = 0
|
||||||
|
horizontal_alignment = 0
|
||||||
|
vertical_alignment = 0
|
||||||
|
|
||||||
|
[node name="Area3D" type="Area3D" parent="."]
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.016, -0.011, 0.005)
|
||||||
|
shape = SubResource("BoxShape3D_6yqdi")
|
131
app/content/ui/components/select/select.gd
Normal file
131
app/content/ui/components/select/select.gd
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
@tool
|
||||||
|
extends Container3D
|
||||||
|
class_name Select3D
|
||||||
|
|
||||||
|
const FontTools = preload ("res://lib/utils/font_tools.gd")
|
||||||
|
const SelectFont = preload ("res://assets/fonts/Raleway-Medium.ttf")
|
||||||
|
const OptionScene = preload ("./option.tscn")
|
||||||
|
const Option = preload ("./option.gd")
|
||||||
|
|
||||||
|
signal on_select(value: String)
|
||||||
|
|
||||||
|
@onready var body = $Body
|
||||||
|
@onready var panel = $Body/Panel
|
||||||
|
@onready var label = $Body/Label
|
||||||
|
@onready var icon = $Body/Icon
|
||||||
|
@onready var collision = $Body/CollisionShape3D
|
||||||
|
@onready var area_collision = $Area3D/CollisionShape3D
|
||||||
|
@onready var options_body = $Options
|
||||||
|
@onready var options_panel = $Options/Panel
|
||||||
|
@onready var options_collision = $Options/CollisionShape3D
|
||||||
|
|
||||||
|
@export var options: Dictionary = {}
|
||||||
|
@export var selected: Variant = null:
|
||||||
|
set(value):
|
||||||
|
if selected != value:
|
||||||
|
on_select.emit(value)
|
||||||
|
|
||||||
|
selected = value
|
||||||
|
|
||||||
|
if is_node_ready() == false: return
|
||||||
|
|
||||||
|
_update()
|
||||||
|
|
||||||
|
@export var mandatory: bool = true
|
||||||
|
|
||||||
|
@export var open: bool = false:
|
||||||
|
set(value):
|
||||||
|
if open == value: return
|
||||||
|
|
||||||
|
open = value
|
||||||
|
|
||||||
|
if is_node_ready() == false: return
|
||||||
|
|
||||||
|
_update_options_visible()
|
||||||
|
var _options_list = []
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
_update()
|
||||||
|
_update_options()
|
||||||
|
|
||||||
|
func _on_focus_out(_event: EventFocus):
|
||||||
|
open = false
|
||||||
|
|
||||||
|
func _on_press_up(event: EventPointer):
|
||||||
|
if event.target == body:
|
||||||
|
open = !open
|
||||||
|
|
||||||
|
if event.target.get_parent() is Option:
|
||||||
|
selected = event.target.get_parent().value
|
||||||
|
open = false
|
||||||
|
|
||||||
|
func _on_touch_leave(event: EventTouch):
|
||||||
|
if event.target == body:
|
||||||
|
open = !open
|
||||||
|
|
||||||
|
if event.target.get_parent() is Option:
|
||||||
|
selected = event.target.get_parent().value
|
||||||
|
open = false
|
||||||
|
|
||||||
|
func _update():
|
||||||
|
if selected == null:
|
||||||
|
label.text = "Select..."
|
||||||
|
else:
|
||||||
|
label.text = options[selected]
|
||||||
|
|
||||||
|
label.position = Vector3( - size.x / 2 + 0.01, 0, 0.01)
|
||||||
|
icon.position = Vector3(size.x / 2, 0, 0.01)
|
||||||
|
|
||||||
|
panel.size = Vector2(size.x, size.y)
|
||||||
|
collision.shape.size = Vector3(size.x, size.y, 0.01)
|
||||||
|
collision.position = Vector3(0, 0, 0.005)
|
||||||
|
area_collision.shape.size = Vector3(size.x, size.y, 0.01)
|
||||||
|
area_collision.position = Vector3(0, 0, 0.015)
|
||||||
|
|
||||||
|
func _update_options_visible():
|
||||||
|
options_body.visible = open
|
||||||
|
options_collision.disabled = !open
|
||||||
|
|
||||||
|
icon.text = "arrow_drop_up" if open else "arrow_drop_down"
|
||||||
|
|
||||||
|
for option in _options_list:
|
||||||
|
option.disabled = !open
|
||||||
|
|
||||||
|
func _update_options():
|
||||||
|
for option in _options_list:
|
||||||
|
options_body.remove_child(option)
|
||||||
|
option.queue_free()
|
||||||
|
|
||||||
|
_options_list.clear()
|
||||||
|
|
||||||
|
var total_size = Vector2(0, 0)
|
||||||
|
|
||||||
|
var display_options = options
|
||||||
|
|
||||||
|
if mandatory == false:
|
||||||
|
display_options[null] = "Deselect"
|
||||||
|
|
||||||
|
var keys = display_options.keys()
|
||||||
|
keys.sort()
|
||||||
|
|
||||||
|
for i in range(keys.size()):
|
||||||
|
var key = keys[i]
|
||||||
|
var option = OptionScene.instantiate()
|
||||||
|
option.value = key
|
||||||
|
option.text = display_options[key]
|
||||||
|
|
||||||
|
options_body.add_child(option)
|
||||||
|
_options_list.append(option)
|
||||||
|
|
||||||
|
var size = option.get_size()
|
||||||
|
size.y += 0.01
|
||||||
|
total_size = Vector2(max(total_size.x, size.x), total_size.y + size.y)
|
||||||
|
|
||||||
|
option.position = Vector3(0.01, -i * size.y - 0.01, 0)
|
||||||
|
|
||||||
|
total_size += Vector2(0.02, 0.01)
|
||||||
|
options_panel.size = total_size
|
||||||
|
options_panel.position = Vector3(total_size.x / 2, -total_size.y / 2, 0)
|
||||||
|
options_body.position = Vector3( - size.x / 2, -size.y / 2, 0.02)
|
||||||
|
options_collision.shape.size = Vector3(total_size.x, total_size.y, 0.01)
|
||||||
|
options_collision.position = Vector3(total_size.x / 2, -total_size.y / 2, -0.005)
|
122
app/content/ui/components/select/select.tscn
Normal file
122
app/content/ui/components/select/select.tscn
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
[gd_scene load_steps=12 format=3 uid="uid://wgnowarejk5y"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://content/ui/components/select/select.gd" id="1_0yka7"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dnam3fe36gg62" path="res://content/ui/components/panel/panel.tscn" id="2_5mspw"]
|
||||||
|
[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"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
render_priority = 10
|
||||||
|
shader = ExtResource("3_8yxox")
|
||||||
|
shader_parameter/color = Color(1, 1, 1, 0.3)
|
||||||
|
shader_parameter/border_color = Color(1, 1, 1, 1)
|
||||||
|
shader_parameter/edge_color = Color(0, 0, 0, 1)
|
||||||
|
shader_parameter/size = Vector2(5, 1)
|
||||||
|
shader_parameter/border_size = 0.01
|
||||||
|
shader_parameter/border_fade_in = 0.05
|
||||||
|
shader_parameter/border_fade_out = 0.0
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_qowt5"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
render_priority = 10
|
||||||
|
shader = ExtResource("3_8yxox")
|
||||||
|
shader_parameter/color = Color(1, 1, 1, 0.3)
|
||||||
|
shader_parameter/border_color = Color(1, 1, 1, 1)
|
||||||
|
shader_parameter/edge_color = Color(0, 0, 0, 1)
|
||||||
|
shader_parameter/size = Vector2(0.5, 0.25)
|
||||||
|
shader_parameter/border_size = 0.01
|
||||||
|
shader_parameter/border_fade_in = 0.05
|
||||||
|
shader_parameter/border_fade_out = 0.0
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_n5ty8"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
size = Vector3(0.16, 0.03, 0.01)
|
||||||
|
|
||||||
|
[node name="Select" type="Node3D" groups=["ui_focus"]]
|
||||||
|
script = ExtResource("1_0yka7")
|
||||||
|
size = Vector3(0.2, 0.04, 0.01)
|
||||||
|
|
||||||
|
[node name="Body" type="StaticBody3D" parent="." groups=["ui_focus_skip"]]
|
||||||
|
collision_layer = 6
|
||||||
|
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")
|
||||||
|
skeleton = NodePath("../..")
|
||||||
|
size = Vector2(0.2, 0.04)
|
||||||
|
|
||||||
|
[node name="Label" type="Label3D" parent="Body"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.09, 0, 0.01)
|
||||||
|
pixel_size = 0.001
|
||||||
|
double_sided = false
|
||||||
|
render_priority = 30
|
||||||
|
text = "Select..."
|
||||||
|
font_size = 18
|
||||||
|
outline_size = 0
|
||||||
|
horizontal_alignment = 0
|
||||||
|
|
||||||
|
[node name="Icon" type="Label3D" parent="Body"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1, 0, 0.01)
|
||||||
|
pixel_size = 0.001
|
||||||
|
double_sided = false
|
||||||
|
render_priority = 30
|
||||||
|
text = "arrow_drop_down"
|
||||||
|
font = ExtResource("4_61i7u")
|
||||||
|
font_size = 30
|
||||||
|
outline_size = 0
|
||||||
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Body"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.005)
|
||||||
|
shape = SubResource("BoxShape3D_uwnbp")
|
||||||
|
|
||||||
|
[node name="Options" type="StaticBody3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.1, -0.02, 0.02)
|
||||||
|
visible = false
|
||||||
|
collision_layer = 6
|
||||||
|
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")
|
||||||
|
skeleton = NodePath("../..")
|
||||||
|
size = Vector2(0.02, 0.01)
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Options"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01, -0.005, -0.005)
|
||||||
|
shape = SubResource("BoxShape3D_cv4hj")
|
||||||
|
disabled = true
|
||||||
|
|
||||||
|
[node name="Area3D" type="Area3D" parent="." groups=["ui_focus_skip"]]
|
||||||
|
collision_layer = 4
|
||||||
|
collision_mask = 0
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.015)
|
||||||
|
shape = SubResource("BoxShape3D_n5ty8")
|
|
@ -106,6 +106,9 @@ func _handle_focus(target: Variant, event: EventBubble):
|
||||||
if target.is_in_group("ui_focus_stop"):
|
if target.is_in_group("ui_focus_stop"):
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
if target == _active_node:
|
||||||
|
return true
|
||||||
|
|
||||||
if is_instance_valid(_active_node) == false:
|
if is_instance_valid(_active_node) == false:
|
||||||
_active_node = null
|
_active_node = null
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ func get_voice_assistant() -> VoiceAssistant:
|
||||||
|
|
||||||
return api.get_voice_assistant()
|
return api.get_voice_assistant()
|
||||||
|
|
||||||
func get_history(entity_id, start, end=null):
|
func get_history(entity_id, start, interval, end=null):
|
||||||
assert(has_connected(), "Not connected")
|
assert(has_connected(), "Not connected")
|
||||||
|
|
||||||
if api.has_method("get_history") == false:
|
if api.has_method("get_history") == false:
|
||||||
|
@ -155,4 +155,4 @@ func get_history(entity_id, start, end=null):
|
||||||
if groups.is_group(entity_id):
|
if groups.is_group(entity_id):
|
||||||
return null
|
return null
|
||||||
|
|
||||||
return await api.get_history(entity_id, start, end)
|
return await api.get_history(entity_id, start, interval, end)
|
||||||
|
|
|
@ -6,7 +6,7 @@ var integration_exists: bool = false
|
||||||
func _init(hass: HASS_API):
|
func _init(hass: HASS_API):
|
||||||
self.api = hass
|
self.api = hass
|
||||||
|
|
||||||
func get_history(entity_id: String, start: String, end=null):
|
func get_history(entity_id: String, start: String, interval: String="5minute", end=null):
|
||||||
var meta_response = await api.connection.send_request_packet({
|
var meta_response = await api.connection.send_request_packet({
|
||||||
"type": "recorder/get_statistics_metadata",
|
"type": "recorder/get_statistics_metadata",
|
||||||
"statistic_ids": [
|
"statistic_ids": [
|
||||||
|
@ -23,7 +23,7 @@ func get_history(entity_id: String, start: String, end=null):
|
||||||
"statistic_ids": [
|
"statistic_ids": [
|
||||||
entity_id
|
entity_id
|
||||||
],
|
],
|
||||||
"period": "5minute",
|
"period": interval,
|
||||||
"types": [
|
"types": [
|
||||||
"state",
|
"state",
|
||||||
"mean"
|
"mean"
|
||||||
|
|
|
@ -164,5 +164,5 @@ func update_room(room: String):
|
||||||
func get_voice_assistant():
|
func get_voice_assistant():
|
||||||
return assist_handler
|
return assist_handler
|
||||||
|
|
||||||
func get_history(entity_id, start, end=null):
|
func get_history(entity_id, start, interval, end=null):
|
||||||
return await history_handler.get_history(entity_id, start, end)
|
return await history_handler.get_history(entity_id, start, interval, end)
|
|
@ -29,6 +29,10 @@ EventSystem="*res://lib/globals/event_system.gd"
|
||||||
Request="*res://lib/globals/request.gd"
|
Request="*res://lib/globals/request.gd"
|
||||||
TouchManager="*res://lib/utils/touch/touch.gd"
|
TouchManager="*res://lib/utils/touch/touch.gd"
|
||||||
|
|
||||||
|
[debug_draw_3d]
|
||||||
|
|
||||||
|
settings/3d/volumetric_defaults/thickness=0.001
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/vsync/vsync_mode=0
|
window/vsync/vsync_mode=0
|
||||||
|
@ -49,6 +53,12 @@ folder_colors={
|
||||||
|
|
||||||
import/fbx/enabled=false
|
import/fbx/enabled=false
|
||||||
|
|
||||||
|
[global_group]
|
||||||
|
|
||||||
|
ui_focus="Makes the node foucsable"
|
||||||
|
ui_focus_skip="Skip the focus check on this node"
|
||||||
|
ui_focus_stop="Stops checking for focus entirely"
|
||||||
|
|
||||||
[gui]
|
[gui]
|
||||||
|
|
||||||
theme/custom_font="res://assets/fonts/Montserrat-Medium.ttf"
|
theme/custom_font="res://assets/fonts/Montserrat-Medium.ttf"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user