mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-21 23:20:25 +01:00
refactor interaction module handling, cleanup
This commit is contained in:
parent
a284c87792
commit
43d3ce3e16
12 changed files with 99 additions and 37 deletions
|
@ -8,6 +8,5 @@
|
|||
script = ExtResource( 4 )
|
||||
|
||||
[node name="MainOverlay" parent="." instance=ExtResource( 2 )]
|
||||
add_cursor = true
|
||||
|
||||
[node name="OverlaySettingsSync" parent="MainOverlay" instance=ExtResource( 3 )]
|
||||
|
|
|
@ -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/OverlayInteraction.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://addons/godot-openvr/OpenVROverlay.gdns" type="Script" id=3]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=1]
|
||||
|
@ -64,3 +65,5 @@ texture = SubResource( 2 )
|
|||
expand = true
|
||||
stretch_mode = 5
|
||||
flip_v = true
|
||||
|
||||
[node name="OverlayInteraction" parent="." instance=ExtResource( 2 )]
|
||||
|
|
|
@ -34,6 +34,8 @@ func _ready() -> void:
|
|||
get_parent().connect("width_changed", self, "_update_width")
|
||||
get_parent().connect("offset_changed", self, "_update_offset")
|
||||
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")
|
||||
|
||||
|
@ -55,7 +57,11 @@ func _trigger_off():
|
|||
|
||||
|
||||
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 OverlayInit.DEBUG_TRIGGERS:
|
||||
print("ignored")
|
||||
return
|
||||
touch_state = true
|
||||
active_controller = body.get_parent().name
|
||||
|
@ -64,6 +70,8 @@ func _on_OverlayArea_entered(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:
|
||||
return
|
||||
# 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
|
||||
|
||||
|
||||
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:
|
||||
if button == JOY_VR_TRIGGER and _right_is_activator:
|
||||
_trigger_on("right")
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
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_config := preload("res://addons/godot-openvr/OpenVRConfig.gdns").new()
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ export (String, "head", "left", "right", "world") var target = "left" setget se
|
|||
|
||||
export var width_meters := 0.4 setget set_width_in_meters
|
||||
export var alpha := 1.0 setget set_alpha
|
||||
export var add_grabbing := true # add grabbing module
|
||||
export var add_cursor := false # add cursor module
|
||||
#export var add_grabbing := true # add grabbing module
|
||||
#export var add_cursor := false # add cursor module
|
||||
|
||||
var _tracker_id := 0
|
||||
var _offsets:Dictionary = {
|
||||
|
@ -31,7 +31,7 @@ var interaction_handler: Node
|
|||
var overlay_visible := true setget set_overlay_visible
|
||||
var path := "res://special_overlays/MainOverlay.tscn" setget set_path
|
||||
var path_invalid := false
|
||||
var OVERLAY_PROPERTIES: Dictionary
|
||||
var OVERLAY_PROPERTIES: Dictionary # defined in overlay root script (optional)
|
||||
|
||||
onready var container = $OverlayViewport/Container
|
||||
var overlay_scene: Node
|
||||
|
@ -46,24 +46,21 @@ func _ready() -> void:
|
|||
$VROverlayViewport.size = OverlayInit.ovr_interface.get_render_targetsize()
|
||||
set_notify_transform(true)
|
||||
|
||||
if add_cursor or add_grabbing:
|
||||
interaction_handler = load("res://addons/openvr_overlay/OverlayInteraction.tscn").instance()
|
||||
add_child(interaction_handler)
|
||||
if add_cursor:
|
||||
add_cursor()
|
||||
if add_grabbing:
|
||||
add_grab()
|
||||
# if add_cursor:
|
||||
# add_cursor()
|
||||
# if add_grabbing:
|
||||
# add_grab()
|
||||
|
||||
update_tracker_id()
|
||||
call_deferred("update_offset")
|
||||
|
||||
|
||||
func add_cursor():
|
||||
interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayCursor.tscn").instance())
|
||||
#func add_cursor():
|
||||
# interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayCursor.tscn").instance())
|
||||
|
||||
|
||||
func add_grab():
|
||||
interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayGrab.tscn").instance())
|
||||
#func add_grab():
|
||||
# interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayGrab.tscn").instance())
|
||||
|
||||
|
||||
func update_tracker_id():
|
||||
|
@ -156,15 +153,15 @@ func set_path(new: String) -> void:
|
|||
overlay_scene = load("res://special_overlays/UnknownType.tscn").instance()
|
||||
else:
|
||||
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:
|
||||
container.get_child(0).queue_free()
|
||||
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):
|
||||
|
@ -184,3 +181,10 @@ func reset_offset() -> void:
|
|||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_TRANSFORM_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]
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
extends Control
|
||||
|
||||
const OVERLAY_PROPERTIES = {
|
||||
"has_cursor": true,
|
||||
}
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
get_viewport().get_parent().add_cursor()
|
||||
#get_viewport().get_parent().add_cursor()
|
||||
var homefolder = OS.get_user_data_dir()
|
||||
homefolder = homefolder.get_base_dir().get_base_dir().get_base_dir()
|
||||
$FileDialog.current_dir = homefolder
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
extends Control
|
||||
|
||||
const OVERLAY_PROPERTIES = {
|
||||
"no_hide": true,
|
||||
"no_delete": true,
|
||||
"allow_hide": false,
|
||||
"allow_delete": false,
|
||||
"has_cursor": true,
|
||||
"has_grab": true,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
extends Label
|
||||
|
||||
const OVERLAY_PROPERTIES = {
|
||||
|
||||
}
|
||||
|
||||
var _delay = 0
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_delay += delta
|
||||
if _delay > 0.5:
|
||||
if _delay > 0.2:
|
||||
update_time()
|
||||
_delay = 0
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
extends Control
|
||||
|
||||
const OVERLAY_PROPERTIES = {
|
||||
"has_cursor": true,
|
||||
}
|
||||
|
||||
var ihandler
|
||||
var oinst
|
||||
|
||||
|
@ -7,8 +11,8 @@ var oinst
|
|||
func _ready() -> void:
|
||||
oinst = get_viewport().get_parent()
|
||||
ihandler = get_viewport().get_node("../OverlayInteraction/OverlayGrab")
|
||||
if not oinst.add_cursor:
|
||||
oinst.add_cursor()
|
||||
#if not oinst.add_cursor:
|
||||
# oinst.add_cursor()
|
||||
for t in oinst.TARGETS:
|
||||
$OptionButton.add_item(t)
|
||||
$OptionButton.selected = oinst.TARGETS.find(oinst.target)
|
||||
|
|
|
@ -36,8 +36,8 @@ theme = ExtResource( 2 )
|
|||
window_title = "Open a File or Directory"
|
||||
mode = 3
|
||||
access = 2
|
||||
current_dir = "/home/crispypin/proj/godot/ovr-utils/ovr-utils"
|
||||
current_path = "/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/src/"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ gdscript/warnings/return_value_discarded=false
|
|||
|
||||
[display]
|
||||
|
||||
window/size/width=2048
|
||||
window/size/height=2048
|
||||
window/size/width=16
|
||||
window/size/height=16
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
|
|
|
@ -31,10 +31,10 @@ func _update_warning():
|
|||
|
||||
|
||||
func _on_Visibility_toggled(state: bool) -> void:
|
||||
if overlay.OVERLAY_PROPERTIES.has("no_hide") and overlay.OVERLAY_PROPERTIES.no_hide:
|
||||
overlay.overlay_visible = true
|
||||
else:
|
||||
if overlay.get_property("allow_hide"):
|
||||
overlay.overlay_visible = state
|
||||
else:
|
||||
overlay.overlay_visible = true
|
||||
|
||||
|
||||
func _on_Grab_toggled(state: bool) -> void:
|
||||
|
@ -52,8 +52,7 @@ func _overlay_visible_changed(state: bool):
|
|||
|
||||
|
||||
func _on_Remove_pressed() -> void:
|
||||
if overlay.OVERLAY_PROPERTIES.has("no_delete") and overlay.OVERLAY_PROPERTIES.no_delete:
|
||||
return
|
||||
if overlay.get_property("allow_delete"):
|
||||
OverlayManager.remove_overlay(overlay_name)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue