From 5766378651c80e9e1082c5eeabd657ba4b581ce2 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Wed, 2 Jun 2021 12:50:09 +0200 Subject: [PATCH] add overlay menu works --- .../addons/openvr_overlay/overlay_instance.gd | 6 ++-- ovr-utils/overlay_manager.gd | 8 ++++- ovr-utils/overlay_scripts/main_menu.gd | 15 +++++--- ovr-utils/overlays/MainOverlay.tscn | 15 ++++---- ovr-utils/ui/AddMenu.tscn | 28 +++++++++++++++ ovr-utils/ui/AddOverlayButton.tscn | 6 ++++ ovr-utils/{ => ui}/ListOverlayItem.tscn | 36 +++++++++---------- ovr-utils/ui/add_menu.gd | 36 +++++++++++++++++++ ovr-utils/{ => ui}/overlay_list_item.gd | 0 9 files changed, 119 insertions(+), 31 deletions(-) create mode 100644 ovr-utils/ui/AddMenu.tscn create mode 100644 ovr-utils/ui/AddOverlayButton.tscn rename ovr-utils/{ => ui}/ListOverlayItem.tscn (70%) create mode 100644 ovr-utils/ui/add_menu.gd rename ovr-utils/{ => ui}/overlay_list_item.gd (100%) diff --git a/ovr-utils/addons/openvr_overlay/overlay_instance.gd b/ovr-utils/addons/openvr_overlay/overlay_instance.gd index ab6394a..28f7054 100644 --- a/ovr-utils/addons/openvr_overlay/overlay_instance.gd +++ b/ovr-utils/addons/openvr_overlay/overlay_instance.gd @@ -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() diff --git a/ovr-utils/overlay_manager.gd b/ovr-utils/overlay_manager.gd index cc0be57..bb88f7f 100644 --- a/ovr-utils/overlay_manager.gd +++ b/ovr-utils/overlay_manager.gd @@ -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) diff --git a/ovr-utils/overlay_scripts/main_menu.gd b/ovr-utils/overlay_scripts/main_menu.gd index e9fe711..e7c306f 100644 --- a/ovr-utils/overlay_scripts/main_menu.gd +++ b/ovr-utils/overlay_scripts/main_menu.gd @@ -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 + diff --git a/ovr-utils/overlays/MainOverlay.tscn b/ovr-utils/overlays/MainOverlay.tscn index d4b1c4d..158b886 100644 --- a/ovr-utils/overlays/MainOverlay.tscn +++ b/ovr-utils/overlays/MainOverlay.tscn @@ -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"] diff --git a/ovr-utils/ui/AddMenu.tscn b/ovr-utils/ui/AddMenu.tscn new file mode 100644 index 0000000..edd54fb --- /dev/null +++ b/ovr-utils/ui/AddMenu.tscn @@ -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 diff --git a/ovr-utils/ui/AddOverlayButton.tscn b/ovr-utils/ui/AddOverlayButton.tscn new file mode 100644 index 0000000..7e6c13a --- /dev/null +++ b/ovr-utils/ui/AddOverlayButton.tscn @@ -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 diff --git a/ovr-utils/ListOverlayItem.tscn b/ovr-utils/ui/ListOverlayItem.tscn similarity index 70% rename from ovr-utils/ListOverlayItem.tscn rename to ovr-utils/ui/ListOverlayItem.tscn index 161e598..e973975 100644 --- a/ovr-utils/ListOverlayItem.tscn +++ b/ovr-utils/ui/ListOverlayItem.tscn @@ -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"] diff --git a/ovr-utils/ui/add_menu.gd b/ovr-utils/ui/add_menu.gd new file mode 100644 index 0000000..436b037 --- /dev/null +++ b/ovr-utils/ui/add_menu.gd @@ -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 diff --git a/ovr-utils/overlay_list_item.gd b/ovr-utils/ui/overlay_list_item.gd similarity index 100% rename from ovr-utils/overlay_list_item.gd rename to ovr-utils/ui/overlay_list_item.gd