refactor interaction module handling, cleanup

This commit is contained in:
Crispy 2021-10-10 16:49:15 +02:00
parent a284c87792
commit 43d3ce3e16
12 changed files with 99 additions and 37 deletions

View file

@ -8,6 +8,5 @@
script = ExtResource( 4 ) script = ExtResource( 4 )
[node name="MainOverlay" parent="." instance=ExtResource( 2 )] [node name="MainOverlay" parent="." instance=ExtResource( 2 )]
add_cursor = true
[node name="OverlaySettingsSync" parent="MainOverlay" instance=ExtResource( 3 )] [node name="OverlaySettingsSync" parent="MainOverlay" instance=ExtResource( 3 )]

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=5 format=2] [gd_scene load_steps=6 format=2]
[ext_resource path="res://addons/openvr_overlay/overlay_instance.gd" type="Script" id=1] [ext_resource path="res://addons/openvr_overlay/overlay_instance.gd" type="Script" id=1]
[ext_resource path="res://addons/openvr_overlay/OverlayInteraction.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/godot-openvr/OpenVROverlay.gdns" type="Script" id=3] [ext_resource path="res://addons/godot-openvr/OpenVROverlay.gdns" type="Script" id=3]
[sub_resource type="StyleBoxFlat" id=1] [sub_resource type="StyleBoxFlat" id=1]
@ -64,3 +65,5 @@ texture = SubResource( 2 )
expand = true expand = true
stretch_mode = 5 stretch_mode = 5
flip_v = true flip_v = true
[node name="OverlayInteraction" parent="." instance=ExtResource( 2 )]

View file

@ -34,6 +34,8 @@ func _ready() -> void:
get_parent().connect("width_changed", self, "_update_width") get_parent().connect("width_changed", self, "_update_width")
get_parent().connect("offset_changed", self, "_update_offset") get_parent().connect("offset_changed", self, "_update_offset")
get_parent().connect("target_changed", self, "_update_target") get_parent().connect("target_changed", self, "_update_target")
get_parent().connect("path_changed", self, "_update_modules")
get_parent().connect("path_changed", self, "_update_target")
OverlayManager.connect("grab_mode_changed", self, "update_selection") OverlayManager.connect("grab_mode_changed", self, "update_selection")
@ -55,7 +57,11 @@ func _trigger_off():
func _on_OverlayArea_entered(body: Node) -> void: func _on_OverlayArea_entered(body: Node) -> void:
if OverlayInit.DEBUG_TRIGGERS:
print(body.name + " entered trigger")
if body.get_node("../../..") != self or pause_triggers or !get_parent().overlay_visible: if body.get_node("../../..") != self or pause_triggers or !get_parent().overlay_visible:
if OverlayInit.DEBUG_TRIGGERS:
print("ignored")
return return
touch_state = true touch_state = true
active_controller = body.get_parent().name active_controller = body.get_parent().name
@ -64,6 +70,8 @@ func _on_OverlayArea_entered(body: Node) -> void:
func _on_OverlayArea_exited(body: Node) -> void: func _on_OverlayArea_exited(body: Node) -> void:
if OverlayInit.DEBUG_TRIGGERS:
print(body.name + " left trigger")
if body.get_node("../../..") != self or pause_triggers or !get_parent().overlay_visible: if body.get_node("../../..") != self or pause_triggers or !get_parent().overlay_visible:
return return
# TODO revert to other controller if both were touching (edge case) # TODO revert to other controller if both were touching (edge case)
@ -106,6 +114,30 @@ func _update_target():
$VR/right/OverlayActivator/Collision.disabled = !_right_is_activator $VR/right/OverlayActivator/Collision.disabled = !_right_is_activator
func _update_modules():
# this should be handled better, DRY
# grab module
var grab_module_exists: bool = get_node_or_null("OverlayGrab") != null
if get_parent().get_property("has_grab"):
if !grab_module_exists:
var module = preload("res://addons/openvr_overlay/OverlayGrab.tscn")
add_child(module.instance())
elif grab_module_exists:
get_node("OverlayGrab").queue_free()
# cursor module
var cursor_module_exists: bool = get_node_or_null("OverlayCursor") != null
if get_parent().get_property("has_cursor"):
if !cursor_module_exists:
var module = preload("res://addons/openvr_overlay/OverlayCursor.tscn")
add_child(module.instance())
elif cursor_module_exists:
get_node("OverlayCursor").queue_free()
func _on_RightHand_button_pressed(button: int) -> void: func _on_RightHand_button_pressed(button: int) -> void:
if button == JOY_VR_TRIGGER and _right_is_activator: if button == JOY_VR_TRIGGER and _right_is_activator:
_trigger_on("right") _trigger_on("right")

View file

@ -1,5 +1,16 @@
extends Node extends Node
const DEBUG_TRIGGERS = true
const OVERLAY_PROPERTIES_DEFAULT = {
"allow_delete": true,
"allow_hide": true,
# "interaction": true,
"has_cursor": false,
"has_grab": true,
}
var ovr_interface: ARVRInterface var ovr_interface: ARVRInterface
var ovr_config := preload("res://addons/godot-openvr/OpenVRConfig.gdns").new() var ovr_config := preload("res://addons/godot-openvr/OpenVRConfig.gdns").new()

View file

@ -12,9 +12,9 @@ const TARGETS = ["head", "left", "right", "world"]
export (String, "head", "left", "right", "world") var target = "left" setget set_target export (String, "head", "left", "right", "world") var target = "left" setget set_target
export var width_meters := 0.4 setget set_width_in_meters export var width_meters := 0.4 setget set_width_in_meters
export var alpha := 1.0 setget set_alpha export var alpha := 1.0 setget set_alpha
export var add_grabbing := true # add grabbing module #export var add_grabbing := true # add grabbing module
export var add_cursor := false # add cursor module #export var add_cursor := false # add cursor module
var _tracker_id := 0 var _tracker_id := 0
var _offsets:Dictionary = { var _offsets:Dictionary = {
@ -31,7 +31,7 @@ var interaction_handler: Node
var overlay_visible := true setget set_overlay_visible var overlay_visible := true setget set_overlay_visible
var path := "res://special_overlays/MainOverlay.tscn" setget set_path var path := "res://special_overlays/MainOverlay.tscn" setget set_path
var path_invalid := false var path_invalid := false
var OVERLAY_PROPERTIES: Dictionary var OVERLAY_PROPERTIES: Dictionary # defined in overlay root script (optional)
onready var container = $OverlayViewport/Container onready var container = $OverlayViewport/Container
var overlay_scene: Node var overlay_scene: Node
@ -46,24 +46,21 @@ func _ready() -> void:
$VROverlayViewport.size = OverlayInit.ovr_interface.get_render_targetsize() $VROverlayViewport.size = OverlayInit.ovr_interface.get_render_targetsize()
set_notify_transform(true) set_notify_transform(true)
if add_cursor or add_grabbing: # if add_cursor:
interaction_handler = load("res://addons/openvr_overlay/OverlayInteraction.tscn").instance() # add_cursor()
add_child(interaction_handler) # if add_grabbing:
if add_cursor: # add_grab()
add_cursor()
if add_grabbing:
add_grab()
update_tracker_id() update_tracker_id()
call_deferred("update_offset") call_deferred("update_offset")
func add_cursor(): #func add_cursor():
interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayCursor.tscn").instance()) # interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayCursor.tscn").instance())
func add_grab(): #func add_grab():
interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayGrab.tscn").instance()) # interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayGrab.tscn").instance())
func update_tracker_id(): func update_tracker_id():
@ -156,15 +153,15 @@ func set_path(new: String) -> void:
overlay_scene = load("res://special_overlays/UnknownType.tscn").instance() overlay_scene = load("res://special_overlays/UnknownType.tscn").instance()
else: else:
overlay_scene = packed_overlay.instance() overlay_scene = packed_overlay.instance()
if overlay_scene.get("OVERLAY_PROPERTIES") != null:
OVERLAY_PROPERTIES = overlay_scene.OVERLAY_PROPERTIES
emit_signal("path_changed")
if container.get_child_count() > 0: if container.get_child_count() > 0:
container.get_child(0).queue_free() container.get_child(0).queue_free()
container.add_child(overlay_scene) container.add_child(overlay_scene)
if overlay_scene.get("OVERLAY_PROPERTIES") != null:
OVERLAY_PROPERTIES = overlay_scene.OVERLAY_PROPERTIES
emit_signal("path_changed")
func set_alpha(val: float): func set_alpha(val: float):
@ -184,3 +181,10 @@ func reset_offset() -> void:
func _notification(what: int) -> void: func _notification(what: int) -> void:
if what == NOTIFICATION_TRANSFORM_CHANGED: if what == NOTIFICATION_TRANSFORM_CHANGED:
emit_signal("offset_changed") emit_signal("offset_changed")
func get_property(name: String):
if OVERLAY_PROPERTIES.has(name):
return OVERLAY_PROPERTIES[name]
return OverlayInit.OVERLAY_PROPERTIES_DEFAULT[name]

View file

@ -1,8 +1,12 @@
extends Control extends Control
const OVERLAY_PROPERTIES = {
"has_cursor": true,
}
func _ready() -> void: func _ready() -> void:
get_viewport().get_parent().add_cursor() #get_viewport().get_parent().add_cursor()
var homefolder = OS.get_user_data_dir() var homefolder = OS.get_user_data_dir()
homefolder = homefolder.get_base_dir().get_base_dir().get_base_dir() homefolder = homefolder.get_base_dir().get_base_dir().get_base_dir()
$FileDialog.current_dir = homefolder $FileDialog.current_dir = homefolder

View file

@ -1,8 +1,10 @@
extends Control extends Control
const OVERLAY_PROPERTIES = { const OVERLAY_PROPERTIES = {
"no_hide": true, "allow_hide": false,
"no_delete": true, "allow_delete": false,
"has_cursor": true,
"has_grab": true,
} }

View file

@ -1,11 +1,15 @@
extends Label extends Label
const OVERLAY_PROPERTIES = {
}
var _delay = 0 var _delay = 0
func _process(delta: float) -> void: func _process(delta: float) -> void:
_delay += delta _delay += delta
if _delay > 0.5: if _delay > 0.2:
update_time() update_time()
_delay = 0 _delay = 0

View file

@ -1,5 +1,9 @@
extends Control extends Control
const OVERLAY_PROPERTIES = {
"has_cursor": true,
}
var ihandler var ihandler
var oinst var oinst
@ -7,8 +11,8 @@ var oinst
func _ready() -> void: func _ready() -> void:
oinst = get_viewport().get_parent() oinst = get_viewport().get_parent()
ihandler = get_viewport().get_node("../OverlayInteraction/OverlayGrab") ihandler = get_viewport().get_node("../OverlayInteraction/OverlayGrab")
if not oinst.add_cursor: #if not oinst.add_cursor:
oinst.add_cursor() # oinst.add_cursor()
for t in oinst.TARGETS: for t in oinst.TARGETS:
$OptionButton.add_item(t) $OptionButton.add_item(t)
$OptionButton.selected = oinst.TARGETS.find(oinst.target) $OptionButton.selected = oinst.TARGETS.find(oinst.target)

View file

@ -36,8 +36,8 @@ theme = ExtResource( 2 )
window_title = "Open a File or Directory" window_title = "Open a File or Directory"
mode = 3 mode = 3
access = 2 access = 2
current_dir = "/home/crispypin/proj/godot/ovr-utils/ovr-utils" current_dir = "/home/crispypin/proj/godot/ovr-utils/src"
current_path = "/home/crispypin/proj/godot/ovr-utils/ovr-utils/" current_path = "/home/crispypin/proj/godot/ovr-utils/src/"
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }

View file

@ -28,8 +28,8 @@ gdscript/warnings/return_value_discarded=false
[display] [display]
window/size/width=2048 window/size/width=16
window/size/height=2048 window/size/height=16
[editor_plugins] [editor_plugins]

View file

@ -31,10 +31,10 @@ func _update_warning():
func _on_Visibility_toggled(state: bool) -> void: func _on_Visibility_toggled(state: bool) -> void:
if overlay.OVERLAY_PROPERTIES.has("no_hide") and overlay.OVERLAY_PROPERTIES.no_hide: if overlay.get_property("allow_hide"):
overlay.overlay_visible = true
else:
overlay.overlay_visible = state overlay.overlay_visible = state
else:
overlay.overlay_visible = true
func _on_Grab_toggled(state: bool) -> void: func _on_Grab_toggled(state: bool) -> void:
@ -52,9 +52,8 @@ func _overlay_visible_changed(state: bool):
func _on_Remove_pressed() -> void: func _on_Remove_pressed() -> void:
if overlay.OVERLAY_PROPERTIES.has("no_delete") and overlay.OVERLAY_PROPERTIES.no_delete: if overlay.get_property("allow_delete"):
return OverlayManager.remove_overlay(overlay_name)
OverlayManager.remove_overlay(overlay_name)
func _on_Reset_pressed() -> void: func _on_Reset_pressed() -> void: