From 6385d7c165adc5e30e140abed43495801c44598d Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Mon, 31 May 2021 18:57:36 +0200 Subject: [PATCH] overlay visibility is saved and loaded --- ovr-utils/ListOverlayItem.tscn | 6 ++++++ .../addons/openvr_overlay/overlay_instance.gd | 19 +++++++++++++------ .../settings-manager/settings_definition.gd | 6 ++++++ ovr-utils/overlay_list_item.gd | 13 +++++++++---- ovr-utils/overlays/MainOverlay.tscn | 3 +++ 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/ovr-utils/ListOverlayItem.tscn b/ovr-utils/ListOverlayItem.tscn index 7124106..161e598 100644 --- a/ovr-utils/ListOverlayItem.tscn +++ b/ovr-utils/ListOverlayItem.tscn @@ -39,6 +39,7 @@ alignment = 2 margin_left = 952.0 margin_right = 1128.0 margin_bottom = 191.0 +focus_mode = 0 toggle_mode = true icon = ExtResource( 5 ) @@ -46,12 +47,14 @@ icon = ExtResource( 5 ) margin_left = 1132.0 margin_right = 1308.0 margin_bottom = 191.0 +focus_mode = 0 icon = ExtResource( 6 ) [node name="Target" type="OptionButton" parent="HBoxContainer"] margin_left = 1312.0 margin_right = 1492.0 margin_bottom = 191.0 +focus_mode = 0 text = "Left" icon = ExtResource( 8 ) clip_text = true @@ -62,6 +65,7 @@ selected = 1 margin_left = 1496.0 margin_right = 1672.0 margin_bottom = 191.0 +focus_mode = 0 toggle_mode = true icon = ExtResource( 7 ) @@ -69,6 +73,7 @@ icon = ExtResource( 7 ) margin_left = 1676.0 margin_right = 1852.0 margin_bottom = 191.0 +focus_mode = 0 toggle_mode = true icon = ExtResource( 4 ) @@ -76,6 +81,7 @@ icon = ExtResource( 4 ) margin_left = 1856.0 margin_right = 2032.0 margin_bottom = 191.0 +focus_mode = 0 toggle_mode = true pressed = true icon = ExtResource( 2 ) diff --git a/ovr-utils/addons/openvr_overlay/overlay_instance.gd b/ovr-utils/addons/openvr_overlay/overlay_instance.gd index 1b73fff..ab6394a 100644 --- a/ovr-utils/addons/openvr_overlay/overlay_instance.gd +++ b/ovr-utils/addons/openvr_overlay/overlay_instance.gd @@ -3,6 +3,7 @@ extends Spatial signal width_changed signal offset_changed signal target_changed +signal overlay_visibility_changed const TARGETS = ["head", "left", "right", "world"] export (String, "head", "left", "right", "world") var target = "left" setget set_target @@ -66,17 +67,20 @@ func add_grab(): func load_settings(): if Settings.s.overlays.has(name): - if Settings.s.overlays[name].has("fallback"): - fallback = Settings.s.overlays[name].fallback - set_target(Settings.s.overlays[name].target) + var loaded = Settings.s.overlays[name] + if loaded.has("fallback"): + fallback = loaded.fallback + set_target(loaded.target) - set_width_in_meters(Settings.s.overlays[name].width) + set_width_in_meters(loaded.width) - for t_key in Settings.s.overlays[name].offsets: - var t_offset = Settings.s.overlays[name].offsets[t_key] + for t_key in loaded.offsets: + var t_offset = loaded.offsets[t_key] _offsets[t_key].pos = t_offset.pos _offsets[t_key].rot = t_offset.rot update_offset() + if loaded.has("visible"): + set_overlay_visible(loaded.visible) else: #TEMP defaults (remove when dragging any overlay is possible) set_offset(current_target, translation, transform.basis.get_rotation_quat()) @@ -143,6 +147,9 @@ func update_current_target(): func set_overlay_visible(state: bool): overlay_visible = state $OverlayViewport.overlay_visible = state + Settings.s.overlays[name].visible = state + emit_signal("overlay_visibility_changed", state) + save_settings() func _tracker_changed(tracker_name: String, type: int, id: int): diff --git a/ovr-utils/addons/settings-manager/settings_definition.gd b/ovr-utils/addons/settings-manager/settings_definition.gd index 34c593f..159dc86 100644 --- a/ovr-utils/addons/settings-manager/settings_definition.gd +++ b/ovr-utils/addons/settings-manager/settings_definition.gd @@ -20,6 +20,11 @@ const DEF = { "type": "string", "default": "UI_demo" }, + "visible": { + "name": "Overlay Visible", + "type": "bool", + "default": true + }, "width": { "name": "Width (m)", "type": "number", @@ -61,6 +66,7 @@ const DEF = { "default": { "MainOverlay": { "type": "MainOverlay", + "visible": true, "width": 0.4, "target": "left", "fallback": ["left", "right", "head"], diff --git a/ovr-utils/overlay_list_item.gd b/ovr-utils/overlay_list_item.gd index e910cd1..76165ee 100644 --- a/ovr-utils/overlay_list_item.gd +++ b/ovr-utils/overlay_list_item.gd @@ -7,14 +7,11 @@ func _ready() -> void: overlay = get_node("/root/Main/OverlayManager").get_node(overlay_name) $Label.text = overlay_name $HBoxContainer/Target.selected = overlay.TARGETS.find(overlay.target) + overlay.connect("overlay_visibility_changed", self, "_overlay_visibility_changed") func _on_Visibility_toggled(state: bool) -> void: overlay.overlay_visible = state - if state: - $HBoxContainer/Visibility.icon = preload("res://icons/visible.svg") - else: - $HBoxContainer/Visibility.icon = preload("res://icons/hidden.svg") func _on_Target_item_selected(index: int) -> void: @@ -27,3 +24,11 @@ func _on_Reset_pressed() -> void: func _on_Grab_toggled(state: bool) -> void: overlay.get_node("OverlayInteraction").grab_mode = state + + +func _overlay_visibility_changed(state: bool): + $HBoxContainer/Visibility.pressed = state + if state: + $HBoxContainer/Visibility.icon = preload("res://icons/visible.svg") + else: + $HBoxContainer/Visibility.icon = preload("res://icons/hidden.svg") diff --git a/ovr-utils/overlays/MainOverlay.tscn b/ovr-utils/overlays/MainOverlay.tscn index e6588fc..d4b1c4d 100644 --- a/ovr-utils/overlays/MainOverlay.tscn +++ b/ovr-utils/overlays/MainOverlay.tscn @@ -47,6 +47,7 @@ __meta__ = { [node name="GrabMode" type="Button" parent="VSplitContainer/MainBar"] margin_right = 176.0 margin_bottom = 191.0 +focus_mode = 0 toggle_mode = true icon = ExtResource( 5 ) @@ -54,6 +55,7 @@ icon = ExtResource( 5 ) margin_left = 180.0 margin_right = 356.0 margin_bottom = 191.0 +focus_mode = 0 toggle_mode = true icon = ExtResource( 6 ) @@ -61,6 +63,7 @@ icon = ExtResource( 6 ) margin_left = 360.0 margin_right = 536.0 margin_bottom = 191.0 +focus_mode = 0 icon = ExtResource( 4 ) [connection signal="toggled" from="VSplitContainer/MainBar/GrabMode" to="." method="_on_GrabMode_toggled"]