plugin: grab and cursor modules are loaded at runtime instead of being manual

This commit is contained in:
Crispy 2021-05-27 10:50:23 +02:00
parent 7634b952be
commit 97a3fb5e80
4 changed files with 24 additions and 18 deletions

View file

@ -1,14 +1,11 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://addons/openvr_overlay/OverlayInstance.tscn" type="PackedScene" id=1]
[ext_resource path="res://overlays/FPSOverlay.tscn" type="PackedScene" id=2]
[ext_resource path="res://overlays/TimeOverlay.tscn" type="PackedScene" id=3]
[ext_resource path="res://overlays/xyz_widget/XYZ Widget.tscn" type="PackedScene" id=4]
[ext_resource path="res://overlays/UI_demo.tscn" type="PackedScene" id=5]
[ext_resource path="res://addons/openvr_overlay/OverlayGrab.tscn" type="PackedScene" id=6]
[ext_resource path="res://overlays/BatteryOverlay.tscn" type="PackedScene" id=7]
[ext_resource path="res://addons/openvr_overlay/OverlayInteraction.tscn" type="PackedScene" id=8]
[ext_resource path="res://addons/openvr_overlay/OverlayCursor.tscn" type="PackedScene" id=9]
[node name="Overlays" type="Node"]
@ -24,12 +21,7 @@ width_meters = 0.1
[node name="OverlayInstance UI demo" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.25 )
overlay_scene = ExtResource( 5 )
[node name="OverlayInteraction" parent="OverlayInstance UI demo" instance=ExtResource( 8 )]
[node name="OverlayCursor" parent="OverlayInstance UI demo/OverlayInteraction" instance=ExtResource( 9 )]
[node name="OverlayGrab" parent="OverlayInstance UI demo/OverlayInteraction" instance=ExtResource( 6 )]
add_cursor = true
[node name="XYZ Widget" parent="." instance=ExtResource( 4 )]

View file

@ -10,6 +10,8 @@ export (String, "head", "left", "right", "world") var target = "left" setget se
export var overlay_scene =\
preload("res://addons/openvr_overlay/MissingOverlay.tscn") setget set_overlay_scene
export var width_meters = 0.4 setget set_width_in_meters
export var add_grabbing := true # add grabbing module
export var add_cursor := false # add cursor module
# if this is exported, all overlays sync offset when a controller is turned off/on
# this seems to be a bug with the godot editor-
@ -35,16 +37,25 @@ func _ready() -> void:
ARVRServer.connect("tracker_added", self, "_tracker_changed")
ARVRServer.connect("tracker_removed", self, "_tracker_changed")
$OverlayViewport.overlay_width_in_meters = width_meters
# $OverlayViewport.overlay_width_in_meters = width_meters
$OverlayViewport.size = OverlayInit.ovr_interface.get_render_targetsize()
# emit_signal("target_changed")
set_notify_transform(true)
# call_deferred("load_settings") # TODO call directly (when overlays are loaded at runtime, after settings have loaded
load_settings()
if add_cursor or add_grabbing:
var interaction_handler = load("res://addons/openvr_overlay/OverlayInteraction.tscn").instance()
add_child(interaction_handler)
if add_cursor:
interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayCursor.tscn").instance())
if add_grabbing:
interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayGrab.tscn").instance())
if overlay_scene:
container.add_child(overlay_scene.instance())
update_tracker_id()
emit_signal("target_changed")
set_notify_transform(true)
call_deferred("load_settings")
func load_settings():
@ -133,7 +144,7 @@ func set_target(new: String):
target = new
call_deferred("update_offset")
update_current_target()
save_settings()
# save_settings()
func _set_current_target(new: String): # overrides target

View file

@ -49,6 +49,9 @@ func save_settings():
file.close()
emit_signal("settings_saved")
if DEBUG_SETTINGS:
print("Settings saved to file")
func _save_sub_setting(val, def):
if has_flag(def, "no_save"):
@ -92,7 +95,7 @@ func load_settings() -> void:
emit_signal("settings_loaded")
if DEBUG_SETTINGS:
print("Loaded settings from file")
print(s)
# print(s)
func _load_sub_setting(val, def):

View file

@ -18,8 +18,8 @@ config/icon="res://icon.png"
[autoload]
OverlayInit="*res://addons/openvr_overlay/overlay_init.gd"
Settings="*res://addons/settings-manager/Settings.tscn"
OverlayInit="*res://addons/openvr_overlay/overlay_init.gd"
[editor_plugins]