mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-22 07:30:25 +01:00
change to using paths to refer to overlay types for better future expansion
This commit is contained in:
parent
b15c00f5f0
commit
01c11ffd32
7 changed files with 56 additions and 42 deletions
|
@ -11,8 +11,8 @@ signal offset_changed
|
||||||
const TARGETS = ["head", "left", "right", "world"]
|
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 overlay_scene: PackedScene = \
|
export var overlay_scene: PackedScene# = \
|
||||||
preload("res://addons/openvr_overlay/MissingOverlay.tscn") setget set_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 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
|
||||||
|
@ -31,7 +31,8 @@ var current_target: String = "world" setget _set_current_target
|
||||||
var fallback = ["left", "right", "head"] # TODO setget that updates tracking (not important)
|
var fallback = ["left", "right", "head"] # TODO setget that updates tracking (not important)
|
||||||
var interaction_handler: Node
|
var interaction_handler: Node
|
||||||
var overlay_visible := true setget set_overlay_visible
|
var overlay_visible := true setget set_overlay_visible
|
||||||
var type := "main"
|
#var type := "main"
|
||||||
|
var path := "res://special_overlays/MainOverlay.tscn" setget set_path
|
||||||
|
|
||||||
onready var container = $OverlayViewport/Container
|
onready var container = $OverlayViewport/Container
|
||||||
|
|
||||||
|
@ -60,7 +61,6 @@ func _ready() -> void:
|
||||||
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())
|
||||||
|
|
||||||
|
@ -149,8 +149,9 @@ func set_width_in_meters(width: float) -> void:
|
||||||
emit_signal("width_changed")
|
emit_signal("width_changed")
|
||||||
|
|
||||||
|
|
||||||
func set_overlay_scene(scene: PackedScene) -> void:
|
func set_path(new: String) -> void:
|
||||||
overlay_scene = scene
|
path = new
|
||||||
|
overlay_scene = load(path)
|
||||||
if not container:
|
if not container:
|
||||||
return
|
return
|
||||||
if container.get_child_count() > 0:
|
if container.get_child_count() > 0:
|
||||||
|
|
|
@ -20,29 +20,34 @@ func _load_overlays():
|
||||||
return
|
return
|
||||||
loaded = true
|
loaded = true
|
||||||
print("Loading in overlays")
|
print("Loading in overlays")
|
||||||
for key in Settings.s.overlays:
|
for name in Settings.s.overlays:
|
||||||
if not key == "MainOverlay":
|
if not name == "MainOverlay":
|
||||||
add_overlay(Settings.s.overlays[key].type, key)
|
add_overlay(name)
|
||||||
|
|
||||||
|
|
||||||
func add_overlay(type, name):
|
func add_overlay(name):
|
||||||
print("Adding overlay '", name, "' of type '", type, "'")
|
print("Adding overlay '", name, "'")
|
||||||
var scene = load("res://overlays/" + type + ".tscn")
|
# var scene = load("res://overlays/" + type + ".tscn")
|
||||||
|
# if not scene:
|
||||||
if not scene:
|
# print("Unknown overlay type: '", type, "'")
|
||||||
print("Unknown overlay type: '", type, "'")
|
# scene = load("res://special_overlays/UnknownType.tscn")
|
||||||
scene = load("res://special_overlays/UnknownType.tscn")
|
|
||||||
|
|
||||||
var instance = preload("res://addons/openvr_overlay/OverlayInstance.tscn").instance()
|
var instance = preload("res://addons/openvr_overlay/OverlayInstance.tscn").instance()
|
||||||
|
|
||||||
instance.name = name
|
instance.name = name
|
||||||
instance.overlay_scene = scene
|
# instance.overlay_scene = scene
|
||||||
instance.type = type
|
# instance.type = type
|
||||||
instance.add_child(preload("res://OverlaySettingsSync.tscn").instance())
|
instance.add_child(preload("res://OverlaySettingsSync.tscn").instance())
|
||||||
add_child(instance)
|
add_child(instance)
|
||||||
emit_signal("added_overlay", name)
|
emit_signal("added_overlay", name)
|
||||||
|
|
||||||
|
|
||||||
|
func create_overlay(path, name):
|
||||||
|
Settings.s.overlays[name] = {}
|
||||||
|
Settings.s.overlays[name].path = path
|
||||||
|
add_overlay(name)
|
||||||
|
|
||||||
|
|
||||||
func remove_overlay(name):
|
func remove_overlay(name):
|
||||||
print("Removing overlay '", name, "'")
|
print("Removing overlay '", name, "'")
|
||||||
var to_remove = get_node(name)
|
var to_remove = get_node(name)
|
||||||
|
|
|
@ -2,4 +2,4 @@ extends Control
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
$Label.text += get_viewport().get_parent().type
|
$Label.text += get_viewport().get_parent().path
|
||||||
|
|
|
@ -26,7 +26,7 @@ func save_all() -> void:
|
||||||
return
|
return
|
||||||
if not Settings.s.overlays.has(p.name):
|
if not Settings.s.overlays.has(p.name):
|
||||||
Settings.s.overlays[p.name] = {}
|
Settings.s.overlays[p.name] = {}
|
||||||
_save_prop("type", p.type)
|
_save_prop("path", p.path)
|
||||||
_save_prop("visible", p.overlay_visible)
|
_save_prop("visible", p.overlay_visible)
|
||||||
_save_prop("width", p.width_meters)
|
_save_prop("width", p.width_meters)
|
||||||
_save_prop("alpha", p.alpha)
|
_save_prop("alpha", p.alpha)
|
||||||
|
@ -44,6 +44,8 @@ func load_all() -> void:
|
||||||
if Settings.s.overlays.has(p.name):
|
if Settings.s.overlays.has(p.name):
|
||||||
var new = Settings.s.overlays[p.name]
|
var new = Settings.s.overlays[p.name]
|
||||||
|
|
||||||
|
if new.has("path"):
|
||||||
|
p.path = new.path
|
||||||
if new.has("visible"):
|
if new.has("visible"):
|
||||||
p.overlay_visible = new.visible
|
p.overlay_visible = new.visible
|
||||||
if new.has("width"):
|
if new.has("width"):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
const PATH = "user://overlay_data.json"
|
const PATH = "user://overlay_data_DEV.json"
|
||||||
const DEF = {
|
const DEF = {
|
||||||
"grab_mode": {
|
"grab_mode": {
|
||||||
"name": "Grab mode",
|
"name": "Grab mode",
|
||||||
|
@ -16,10 +16,10 @@ const DEF = {
|
||||||
"definition": {
|
"definition": {
|
||||||
"type": "dict",
|
"type": "dict",
|
||||||
"definition": {
|
"definition": {
|
||||||
"type": {
|
"path": {
|
||||||
"name": "Overlay type",
|
"name": "Overlay scene path",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "UI_demo"
|
"default": "res://special_overlays/UnknownType.tscn"
|
||||||
},
|
},
|
||||||
"visible": {
|
"visible": {
|
||||||
"name": "Overlay Visible",
|
"name": "Overlay Visible",
|
||||||
|
@ -71,7 +71,7 @@ const DEF = {
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"MainOverlay": {
|
"MainOverlay": {
|
||||||
"type": "MainOverlay",
|
"path": "res://special_overlays/MainOverlay.tscn",
|
||||||
"visible": true,
|
"visible": true,
|
||||||
"width": 0.4,
|
"width": 0.4,
|
||||||
"alpha": 1.0,
|
"alpha": 1.0,
|
||||||
|
|
|
@ -2,28 +2,28 @@ extends Control
|
||||||
|
|
||||||
signal add_menu_closed
|
signal add_menu_closed
|
||||||
|
|
||||||
var types: Array
|
var paths: Array
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
visible = false
|
visible = false
|
||||||
types = get_overlay_types()
|
paths = get_overlay_paths()
|
||||||
for t in types:
|
for p in paths:
|
||||||
var btn = preload("res://ui/AddOverlayButton.tscn").instance()
|
var btn = preload("res://ui/AddOverlayButton.tscn").instance()
|
||||||
btn.text = t
|
btn.text = path_to_name(p)
|
||||||
btn.connect("pressed", self, "add_overlay", [t])
|
btn.connect("pressed", self, "add_overlay", [p])
|
||||||
$MarginContainer/VBoxContainer.add_child(btn)
|
$MarginContainer/VBoxContainer.add_child(btn)
|
||||||
|
|
||||||
|
|
||||||
func add_overlay(type):
|
func add_overlay(path):
|
||||||
OverlayManager.add_overlay(type, type + " " + str(randi()%1000))
|
OverlayManager.create_overlay(path, path_to_name(path) + " " + str(randi()%1000))
|
||||||
visible = false
|
visible = false
|
||||||
emit_signal("add_menu_closed")
|
emit_signal("add_menu_closed")
|
||||||
|
|
||||||
|
|
||||||
func get_overlay_types(path := "res://overlays/"):
|
func get_overlay_paths(root := "res://overlays/"):
|
||||||
var found = []
|
var found = []
|
||||||
var dir = Directory.new()
|
var dir = Directory.new()
|
||||||
if dir.open(path) == OK:
|
if dir.open(root) == OK:
|
||||||
dir.list_dir_begin(true)
|
dir.list_dir_begin(true)
|
||||||
var file_name = dir.get_next()
|
var file_name = dir.get_next()
|
||||||
while file_name != "":
|
while file_name != "":
|
||||||
|
@ -31,8 +31,11 @@ func get_overlay_types(path := "res://overlays/"):
|
||||||
# TODO make recursive, must include folder as prefix for type
|
# TODO make recursive, must include folder as prefix for type
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
found.append(file_name.split(".")[0])
|
found.append(root + file_name)
|
||||||
file_name = dir.get_next()
|
file_name = dir.get_next()
|
||||||
else:
|
else:
|
||||||
print("An error occurred when trying to access the path ", path)
|
print("An error occurred when trying to access ", root)
|
||||||
return found
|
return found
|
||||||
|
|
||||||
|
func path_to_name(path: String) -> String:
|
||||||
|
return path.split("/")[-1].split(".")[0]
|
||||||
|
|
|
@ -16,13 +16,15 @@ func _ready() -> void:
|
||||||
$MoreOptions/Container/List/Target.selected = overlay.TARGETS.find(overlay.target)
|
$MoreOptions/Container/List/Target.selected = overlay.TARGETS.find(overlay.target)
|
||||||
overlay.connect("overlay_visible_changed", self, "_overlay_visible_changed")
|
overlay.connect("overlay_visible_changed", self, "_overlay_visible_changed")
|
||||||
|
|
||||||
$BasicOptions/List/Warning.visible = overlay.overlay_scene == preload("res://special_overlays/UnknownType.tscn")
|
#TODO use signal to activate warning
|
||||||
$BasicOptions/List/Warning/WarningInfo/Label.text = overlay.type + "\nnot found"
|
# $BasicOptions/List/Warning.visible = overlay.overlay_scene == preload("res://special_overlays/UnknownType.tscn")
|
||||||
|
$BasicOptions/List/Warning/WarningInfo/Label.text = overlay.path + "\nnot found"
|
||||||
|
|
||||||
|
|
||||||
func _on_Visibility_toggled(state: bool) -> void:
|
func _on_Visibility_toggled(state: bool) -> void:
|
||||||
if overlay.type and overlay.type != "main":
|
# TODO check always visible flag
|
||||||
overlay.overlay_visible = state
|
# if overlay.type and overlay.type != "main":
|
||||||
|
overlay.overlay_visible = state
|
||||||
|
|
||||||
|
|
||||||
func _on_Grab_toggled(state: bool) -> void:
|
func _on_Grab_toggled(state: bool) -> void:
|
||||||
|
@ -38,8 +40,9 @@ func _overlay_visible_changed(state: bool):
|
||||||
|
|
||||||
|
|
||||||
func _on_Remove_pressed() -> void:
|
func _on_Remove_pressed() -> void:
|
||||||
if overlay.type and overlay.type != "main":
|
# TODO check stay flag
|
||||||
OverlayManager.remove_overlay(overlay_name)
|
# if overlay.type and overlay.type != "main":
|
||||||
|
OverlayManager.remove_overlay(overlay_name)
|
||||||
|
|
||||||
|
|
||||||
func _on_Reset_pressed() -> void:
|
func _on_Reset_pressed() -> void:
|
||||||
|
|
Loading…
Reference in a new issue