add overlay menu works

This commit is contained in:
Crispy 2021-06-02 12:50:09 +02:00
parent 6385d7c165
commit 5766378651
9 changed files with 119 additions and 31 deletions

View file

@ -28,6 +28,7 @@ var current_target: String = "world" setget _set_current_target# most of the tim
var fallback = ["left", "right", "head"] # TODO setget that updates tracking (not important)
var interaction_handler: Node
var overlay_visible := true setget set_overlay_visible
var type: String
var _tracker_id: int = 0
@ -60,11 +61,11 @@ func _ready() -> void:
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 load_settings():
if Settings.s.overlays.has(name):
var loaded = Settings.s.overlays[name]
@ -94,6 +95,7 @@ func save_settings():
Settings.s.overlays[name].target = target
Settings.s.overlays[name].width = width_meters
Settings.s.overlays[name].fallback = fallback
Settings.s.overlays[name].type = type
if not Settings.s.overlays[name].has("offsets"):
Settings.s.overlays[name]["offsets"] = {}
@ -200,7 +202,7 @@ func set_overlay_scene(scene: PackedScene):
func reset_offset():
_offsets[current_target].rot = Quat()
_offsets[current_target].pos = Vector3()
if current_target == "world":
if current_target == "head":
_offsets[current_target].pos.z = -0.5
update_offset()
save_settings()

View file

@ -1,5 +1,7 @@
extends Node
signal added_overlay
signal removed_overlay
var loaded := false
@ -23,6 +25,9 @@ func _load_overlays():
func add_overlay(type, name):
if type == "":
print("no type specified for overlay ", name)
return
var scene = load("res://overlays/" + type + ".tscn")
if scene == null:
print("Unknown overlay type: ", type, ". Skipping overlay \"", name, "\"")
@ -30,5 +35,6 @@ func add_overlay(type, name):
var instance = preload("res://addons/openvr_overlay/OverlayInstance.tscn").instance()
instance.name = name
instance.overlay_scene = scene
instance.type = type
add_child(instance)
emit_signal("added_overlay", name)

View file

@ -2,13 +2,19 @@ extends Control
func _ready() -> void:
get_node("/root/Main/OverlayManager").connect("added_overlay", self, "_add_overlay_to_list")
for o in Settings.s.overlays:
var new = preload("res://ListOverlayItem.tscn").instance()
new.overlay_name = o
$VSplitContainer/Control/Overlays.add_child(new)
_add_overlay_to_list(o)
$VSplitContainer/Control/Overlays.visible = false
func _add_overlay_to_list(name):
var new = preload("res://ui/ListOverlayItem.tscn").instance()
new.overlay_name = name
$VSplitContainer/Control/Overlays.add_child(new)
func _on_GrabMode_toggled(state: bool) -> void:
Settings.s.grab_mode = state
Settings.emit_signal("settings_changed")
@ -19,4 +25,5 @@ func _on_ShowOverlays_toggled(state: bool) -> void:
func _on_AddOverlay_pressed() -> void:
pass # Replace with function body.
$VSplitContainer/Control/AddMenu.visible = true

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://overlay_scripts/main_menu.gd" type="Script" id=1]
[ext_resource path="res://styles/menu.theme" type="Theme" id=2]
[ext_resource path="res://ui/AddMenu.tscn" type="PackedScene" id=3]
[ext_resource path="res://icons/add.svg" type="Texture" id=4]
[ext_resource path="res://icons/move.svg" type="Texture" id=5]
[ext_resource path="res://icons/list.svg" type="Texture" id=6]
@ -36,6 +37,8 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="AddMenu" parent="VSplitContainer/Control" instance=ExtResource( 3 )]
[node name="MainBar" type="HBoxContainer" parent="VSplitContainer"]
margin_top = 1857.0
margin_right = 2048.0
@ -44,20 +47,20 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="GrabMode" type="Button" parent="VSplitContainer/MainBar"]
[node name="ShowOverlays" type="Button" parent="VSplitContainer/MainBar"]
margin_right = 176.0
margin_bottom = 191.0
focus_mode = 0
toggle_mode = true
icon = ExtResource( 5 )
icon = ExtResource( 6 )
[node name="ShowOverlays" type="Button" parent="VSplitContainer/MainBar"]
[node name="GrabMode" type="Button" parent="VSplitContainer/MainBar"]
margin_left = 180.0
margin_right = 356.0
margin_bottom = 191.0
focus_mode = 0
toggle_mode = true
icon = ExtResource( 6 )
icon = ExtResource( 5 )
[node name="AddOverlay" type="Button" parent="VSplitContainer/MainBar"]
margin_left = 360.0
@ -66,6 +69,6 @@ margin_bottom = 191.0
focus_mode = 0
icon = ExtResource( 4 )
[connection signal="toggled" from="VSplitContainer/MainBar/GrabMode" to="." method="_on_GrabMode_toggled"]
[connection signal="toggled" from="VSplitContainer/MainBar/ShowOverlays" to="." method="_on_ShowOverlays_toggled"]
[connection signal="toggled" from="VSplitContainer/MainBar/GrabMode" to="." method="_on_GrabMode_toggled"]
[connection signal="pressed" from="VSplitContainer/MainBar/AddOverlay" to="." method="_on_AddOverlay_pressed"]

28
ovr-utils/ui/AddMenu.tscn Normal file
View file

@ -0,0 +1,28 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://ui/add_menu.gd" type="Script" id=1]
[node name="AddMenu" type="PanelContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="MarginContainer" type="MarginContainer" parent="."]
margin_left = 7.0
margin_top = 7.0
margin_right = 2041.0
margin_bottom = 2041.0
custom_constants/margin_right = 32
custom_constants/margin_top = 32
custom_constants/margin_left = 32
custom_constants/margin_bottom = 32
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
margin_left = 32.0
margin_top = 32.0
margin_right = 2002.0
margin_bottom = 2002.0
alignment = 2

View file

@ -0,0 +1,6 @@
[gd_scene format=2]
[node name="Button" type="Button"]
margin_top = 1950.0
margin_right = 1970.0
margin_bottom = 1970.0

View file

@ -1,22 +1,22 @@
[gd_scene load_steps=10 format=2]
[ext_resource path="res://styles/menu.theme" type="Theme" id=1]
[ext_resource path="res://icons/visible.svg" type="Texture" id=2]
[ext_resource path="res://overlay_list_item.gd" type="Script" id=3]
[ext_resource path="res://icons/move.svg" type="Texture" id=4]
[ext_resource path="res://icons/remove.svg" type="Texture" id=5]
[ext_resource path="res://icons/reset.svg" type="Texture" id=6]
[ext_resource path="res://icons/size.svg" type="Texture" id=7]
[ext_resource path="res://icons/hand_r.svg" type="Texture" id=8]
[ext_resource path="res://icons/person.svg" type="Texture" id=9]
[ext_resource path="res://ui/overlay_list_item.gd" type="Script" id=1]
[ext_resource path="res://icons/remove.svg" type="Texture" id=2]
[ext_resource path="res://icons/move.svg" type="Texture" id=3]
[ext_resource path="res://icons/size.svg" type="Texture" id=4]
[ext_resource path="res://icons/reset.svg" type="Texture" id=5]
[ext_resource path="res://icons/hand_r.svg" type="Texture" id=6]
[ext_resource path="res://icons/person.svg" type="Texture" id=7]
[ext_resource path="res://icons/visible.svg" type="Texture" id=8]
[ext_resource path="res://styles/menu.theme" type="Theme" id=9]
[node name="ListOverlayItem" type="PanelContainer"]
margin_top = 1727.0
margin_right = 2048.0
margin_bottom = 1920.0
rect_min_size = Vector2( 100, 128 )
theme = ExtResource( 1 )
script = ExtResource( 3 )
theme = ExtResource( 9 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
@ -41,14 +41,14 @@ margin_right = 1128.0
margin_bottom = 191.0
focus_mode = 0
toggle_mode = true
icon = ExtResource( 5 )
icon = ExtResource( 2 )
[node name="Reset" type="Button" parent="HBoxContainer"]
margin_left = 1132.0
margin_right = 1308.0
margin_bottom = 191.0
focus_mode = 0
icon = ExtResource( 6 )
icon = ExtResource( 5 )
[node name="Target" type="OptionButton" parent="HBoxContainer"]
margin_left = 1312.0
@ -56,9 +56,9 @@ margin_right = 1492.0
margin_bottom = 191.0
focus_mode = 0
text = "Left"
icon = ExtResource( 8 )
icon = ExtResource( 6 )
clip_text = true
items = [ "Head", ExtResource( 9 ), false, 0, null, "Left", ExtResource( 8 ), false, 1, null, "Right", ExtResource( 8 ), false, 2, null, "World", ExtResource( 4 ), false, 3, null ]
items = [ "Head", ExtResource( 7 ), false, 0, null, "Left", ExtResource( 6 ), false, 1, null, "Right", ExtResource( 6 ), false, 2, null, "World", ExtResource( 3 ), false, 3, null ]
selected = 1
[node name="Size" type="Button" parent="HBoxContainer"]
@ -67,7 +67,7 @@ margin_right = 1672.0
margin_bottom = 191.0
focus_mode = 0
toggle_mode = true
icon = ExtResource( 7 )
icon = ExtResource( 4 )
[node name="Grab" type="Button" parent="HBoxContainer"]
margin_left = 1676.0
@ -75,7 +75,7 @@ margin_right = 1852.0
margin_bottom = 191.0
focus_mode = 0
toggle_mode = true
icon = ExtResource( 4 )
icon = ExtResource( 3 )
[node name="Visibility" type="Button" parent="HBoxContainer"]
margin_left = 1856.0
@ -84,7 +84,7 @@ margin_bottom = 191.0
focus_mode = 0
toggle_mode = true
pressed = true
icon = ExtResource( 2 )
icon = ExtResource( 8 )
[connection signal="pressed" from="HBoxContainer/Reset" to="." method="_on_Reset_pressed"]
[connection signal="item_selected" from="HBoxContainer/Target" to="." method="_on_Target_item_selected"]

36
ovr-utils/ui/add_menu.gd Normal file
View file

@ -0,0 +1,36 @@
extends Control
var types: Array
func _ready() -> void:
visible = false
types = get_overlay_types()
for t in types:
var btn = preload("res://ui/AddOverlayButton.tscn").instance()
btn.text = t
btn.connect("pressed", self, "add_overlay", [t])
$MarginContainer/VBoxContainer.add_child(btn)
func add_overlay(type):
get_node("/root/Main/OverlayManager").add_overlay(type, type + str(randi()%100))
visible = false
func get_overlay_types(path := "res://overlays/"):
var found = []
var dir = Directory.new()
if dir.open(path) == OK:
dir.list_dir_begin(true)
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir():
# TODO make recursive, must include folder as prefix for type
pass
else:
found.append(file_name.split(".")[0])
file_name = dir.get_next()
else:
print("An error occurred when trying to access the path ", path)
return found