update settings menu and auto reconnect

This commit is contained in:
Nitwel 2024-05-06 11:41:23 +02:00
parent a86b560773
commit dc32cac1e2
11 changed files with 279 additions and 210 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2b7e5cb00328c9b9d8076a826c368d012628edadf108d078167620945c4742b0
size 32849426
oid sha256:4ceab794a82c7596f1610c929fc5b14a6b2b835c66ffed7d8db1c8804731c23c
size 38613813

View File

@ -10,6 +10,7 @@ const environment_passthrough_material = preload ("res://assets/environment_pass
@onready var house = $House
@onready var menu = $Menu
@onready var keyboard = $Keyboard
@onready var xr: XRToolsStartXR = $StartXR
var voice_assistant = null
func _ready():
@ -67,6 +68,11 @@ func _ready():
remove_child(keyboard)
)
xr.xr_started.connect(func():
if HomeApi.has_connected() == false:
HomeApi.start()
)
func create_voice_assistant():
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded

View File

@ -0,0 +1,35 @@
extends Node3D
@onready var status_label = $LabelStatus
@onready var input_url = $InputURL
@onready var input_token = $InputToken
@onready var button_connect = $Connect
func _ready():
var settings_store = Store.settings.state
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
input_url.text = settings_store.url
input_token.text = settings_store.token
button_connect.on_button_down.connect(func():
var url=input_url.text
var token=input_token.text
HomeApi.start_adapter("hass_ws", url, token)
settings_store.url=url
settings_store.token=token
Store.settings.save_local()
)
HomeApi.on_connect.connect(func():
status_label.text="Status: Connected"
)
HomeApi.on_disconnect.connect(func():
status_label.text="Status: Disconnected"
)

View File

@ -0,0 +1,64 @@
[gd_scene load_steps=4 format=3 uid="uid://cdto8shis71nu"]
[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="1_01lhk"]
[ext_resource type="Script" path="res://content/ui/menu/settings/menus/api_menu.gd" id="1_uatcf"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="2_kmvrs"]
[node name="ApiMenu" type="Node3D"]
script = ExtResource("1_uatcf")
[node name="LabelURL" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.08, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Url:
"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="InputURL" parent="." instance=ExtResource("1_01lhk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.19, -0.08, 0)
text = "ws://192.168.0.1:8123"
size = Vector3(0.2, 0.03, 0.01)
[node name="LabelToken" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.12, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Token:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="InputToken" parent="." instance=ExtResource("1_01lhk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.19, -0.12, 0)
text = "..."
size = Vector3(0.2, 0.03, 0.01)
[node name="LabelConnect" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.17, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Connect:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="Connect" parent="." instance=ExtResource("2_kmvrs")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.13, -0.17, 0)
label = "login"
icon = true
[node name="LabelStatus" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.22, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Status: Disconnected"
font_size = 18
outline_size = 0
horizontal_alignment = 0

View File

@ -0,0 +1,39 @@
extends Node3D
@onready var voice_assist = $Content/VoiceAssist
func _ready():
var settings_store = Store.settings.state
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
var button_label = R.computed(func(_arg):
return "mic_off" if settings_store.voice_assistant == false else "mic"
)
voice_assist.on_button_down.connect(func():
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
OS.request_permissions()
voice_assist.label="mic"
settings_store.voice_assistant=true
Store.settings.save_local()
)
voice_assist.on_button_up.connect(func():
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
voice_assist.label="mic_off"
settings_store.voice_assistant=false
Store.settings.save_local()
)
R.bind(voice_assist, "label", button_label)
R.bind(voice_assist, "active", settings_store, "voice_assistant")

View File

@ -0,0 +1,23 @@
[gd_scene load_steps=3 format=3 uid="uid://4hai6lp64m2o"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_52ufi"]
[ext_resource type="Script" path="res://content/ui/menu/settings/menus/features_menu.gd" id="1_imqs2"]
[node name="FeaturesMenu" type="Node3D"]
script = ExtResource("1_imqs2")
[node name="VoiceAssist" parent="." instance=ExtResource("1_52ufi")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.19, -0.08, 0)
label = "mic_off"
icon = true
toggleable = true
[node name="LabelVoiceAssist" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.08, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Voice Assistant: "
font_size = 18
outline_size = 0
horizontal_alignment = 0

View File

@ -0,0 +1,16 @@
extends Node3D
@onready var save = $Save
@onready var clear_save = $ClearSave
func _ready():
save.on_button_down.connect(func():
House.body.save_all_entities()
Store.house.save_local()
)
clear_save.on_button_down.connect(func():
Store.house.clear()
House.body.update_house()
)

View File

@ -0,0 +1,50 @@
[gd_scene load_steps=3 format=3 uid="uid://cxom4iapa02bb"]
[ext_resource type="Script" path="res://content/ui/menu/settings/menus/save_menu.gd" id="1_7j7hb"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_y2t0y"]
[node name="SaveMenu" type="Node3D"]
script = ExtResource("1_7j7hb")
[node name="SaveLabel" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.08, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Manual Save:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="Save" parent="." instance=ExtResource("1_y2t0y")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.18, -0.08, 0)
label = "save"
icon = true
[node name="clearSaveLabel" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.13, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Clear Save:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="ClearSave" parent="." instance=ExtResource("1_y2t0y")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.18, -0.14, 0)
label = "close"
icon = true
[node name="clearSaveWarning" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, -0.15, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
modulate = Color(1, 0, 0, 1)
text = "Caution! This will delete all your rooms and placed devices."
font_size = 8
outline_size = 0
horizontal_alignment = 0
autowrap_mode = 3
width = 150.0

View File

@ -1,104 +1,14 @@
extends Node3D
const credits_scene = preload ("./credits.tscn")
@onready var connection_status = $Content/ConnectionStatus
@onready var input_url = $Content/InputURL
@onready var input_token = $Content/InputToken
@onready var button_connect = $Content/Connect
@onready var credits = $Content/Credits/Clickable
@onready var save = $Content/Save
@onready var clear_save = $Content/ClearSave
@onready var background = $Background
@onready var voice_assist = $Content/VoiceAssist
@onready var version_label = $Content/LabelVersion
func _ready():
_load_game_version()
var settings_store = Store.settings.state
background.visible = false
credits.on_click.connect(func(_event):
var credits_instance=credits_scene.instantiate()
get_tree().root.add_child(credits_instance)
var label=$Content/Credits/Label
credits_instance.global_position=+ label.to_global(label.position + Vector3(0.1, 0, -0.15))
)
if Store.settings.is_loaded():
input_url.text = settings_store.url
input_token.text = settings_store.token
else:
Store.settings.on_loaded.connect(func():
input_url.text=settings_store.url
input_token.text=settings_store.token
)
button_connect.on_button_down.connect(func():
var url=input_url.text
var token=input_token.text
HomeApi.start_adapter("hass_ws", url, token)
settings_store.url=url
settings_store.token=token
Store.settings.save_local()
)
save.on_button_down.connect(func():
House.body.save_all_entities()
Store.house.save_local()
)
clear_save.on_button_down.connect(func():
Store.house.clear()
House.body.update_house()
)
voice_assist.on_button_down.connect(func():
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
OS.request_permissions()
voice_assist.label="mic"
settings_store.voice_assistant=true
Store.settings.save_local()
)
voice_assist.on_button_up.connect(func():
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
voice_assist.label="mic_off"
settings_store.voice_assistant=false
Store.settings.save_local()
)
HomeApi.on_connect.connect(func():
connection_status.text="Connected"
)
HomeApi.on_disconnect.connect(func():
connection_status.text="Disconnected"
)
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
var button_label = R.computed(func(_arg):
return "mic_off" if settings_store.voice_assistant == false else "mic"
)
R.bind(voice_assist, "label", button_label)
R.bind(voice_assist, "active", settings_store, "voice_assistant")
func _load_game_version():
var presets = ConfigFile.new()
presets.load("res://export_presets.cfg")

View File

@ -1,11 +1,15 @@
[gd_scene load_steps=10 format=3 uid="uid://c6r4higceibif"]
[gd_scene load_steps=14 format=3 uid="uid://c6r4higceibif"]
[ext_resource type="Script" path="res://content/ui/menu/settings/settings_menu.gd" id="1_0lte6"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_faxng"]
[ext_resource type="Script" path="res://content/functions/clickable.gd" id="3_qmg6q"]
[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="4_q3x6k"]
[ext_resource type="FontVariation" uid="uid://sshfnckriqxn" path="res://assets/icons/icons.tres" id="5_eiwd4"]
[ext_resource type="Shader" path="res://content/ui/components/panel/glass.gdshader" id="6_mubnp"]
[ext_resource type="Script" path="res://content/ui/components/tabs/tabs.gd" id="7_oydon"]
[ext_resource type="Script" path="res://content/ui/components/tabs/tabs_content.gd" id="8_ctbdo"]
[ext_resource type="PackedScene" uid="uid://cdto8shis71nu" path="res://content/ui/menu/settings/menus/api_menu.tscn" id="8_jicvf"]
[ext_resource type="PackedScene" uid="uid://4hai6lp64m2o" path="res://content/ui/menu/settings/menus/features_menu.tscn" id="9_k7004"]
[ext_resource type="PackedScene" uid="uid://cxom4iapa02bb" path="res://content/ui/menu/settings/menus/save_menu.tscn" id="10_5aa3y"]
[sub_resource type="BoxShape3D" id="BoxShape3D_3qdps"]
size = Vector3(0.07, 0.02, 0.01)
@ -31,62 +35,6 @@ size = Vector2(0.42, 0.32)
script = ExtResource("1_0lte6")
[node name="Content" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.007, 0)
[node name="ConnectionStatus" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.251, -0.151, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Disconnected"
font_size = 8
outline_size = 0
[node name="LabelURL" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01, -0.03, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "url:
"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="InputURL" parent="Content" instance=ExtResource("4_q3x6k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.18, -0.03, 0)
text = "ws://192.168.0.1:8123"
size = Vector3(0.2, 0.03, 0.01)
[node name="LabelToken" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01, -0.07, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "token:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="InputToken" parent="Content" instance=ExtResource("4_q3x6k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.18, -0.07, 0)
text = "..."
size = Vector3(0.2, 0.03, 0.01)
[node name="LabelConnect" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.14, -0.12, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Connect"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="Connect" parent="Content" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, -0.12, 0)
label = "login"
icon = true
[node name="Credits" type="StaticBody3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.37, -0.300229, 0)
@ -120,66 +68,6 @@ outline_size = 0
[node name="Clickable" type="Node" parent="Content/Credits"]
script = ExtResource("3_qmg6q")
[node name="SaveLabel" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01, -0.21, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Manual Save:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="Save" parent="Content" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.17, -0.21, 0)
label = "save"
icon = true
[node name="clearSaveLabel" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01, -0.26, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Clear Save:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="ClearSave" parent="Content" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.17, -0.27, 0)
label = "close"
icon = true
[node name="clearSaveWarning" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01, -0.28, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
modulate = Color(1, 0, 0, 1)
text = "Caution! This will delete all your rooms and placed devices."
font_size = 8
outline_size = 0
horizontal_alignment = 0
autowrap_mode = 3
width = 150.0
[node name="VoiceAssist" parent="Content" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1, -0.12, 0)
label = "mic_off"
icon = true
toggleable = true
[node name="LabelVoiceAssist" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01, -0.12, 0)
pixel_size = 0.001
render_priority = 15
outline_render_priority = 14
text = "Voice-
Assist:"
font_size = 18
outline_size = 0
horizontal_alignment = 0
[node name="LabelVersion" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.41, -0.31, 0)
pixel_size = 0.001
@ -195,3 +83,38 @@ transform = Transform3D(1, 0, 0, 0, 1, 1.06581e-14, 0, -1.06581e-14, 1, 0.21, -0
material_override = SubResource("ShaderMaterial_3iv64")
mesh = SubResource("QuadMesh_d0l0p")
skeleton = NodePath("../..")
[node name="Tabs" type="Node3D" parent="." node_paths=PackedStringArray("initial_selected")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01, -0.03, 0)
script = ExtResource("7_oydon")
initial_selected = NodePath("Api")
gap = 0.01
[node name="Api" parent="Tabs" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, 0, 0)
font_size = 18
label = "Api"
[node name="Features" parent="Tabs" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.095, 0, 0)
font_size = 18
label = "Features"
size = Vector3(0.09, 0.04, 0.01)
[node name="Save" parent="Tabs" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.18, 0, 0)
font_size = 18
label = "Other"
size = Vector3(0.06, 0.04, 0.01)
[node name="TabsContent3D" type="Node3D" parent="." node_paths=PackedStringArray("tabs")]
script = ExtResource("8_ctbdo")
tabs = NodePath("../Tabs")
[node name="ApiMenu" parent="TabsContent3D" instance=ExtResource("8_jicvf")]
[node name="FeaturesMenu" parent="TabsContent3D" instance=ExtResource("9_k7004")]
visible = false
[node name="SaveMenu" parent="TabsContent3D" instance=ExtResource("10_5aa3y")]
visible = false

View File

@ -32,7 +32,10 @@ var api: Node
func _ready():
print("HomeApi ready")
start()
## Starts the adapter with the settings from the settings file
func start():
var success = Store.settings.load_local()
if success: