From d2e4c28a868e35f0062896849902fe3dbbfb2918 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 22 May 2021 22:15:09 +0200 Subject: [PATCH] add dropdown to ui demo that changes tracking target --- .../addons/openvr_overlay/move_overlay.gd | 14 ------------ .../addons/openvr_overlay/overlay_instance.gd | 4 ++-- ovr-utils/overlays/UI_demo.tscn | 4 ++-- ovr-utils/overlays/move_overlay.gd | 22 +++++++++++++++++++ 4 files changed, 26 insertions(+), 18 deletions(-) delete mode 100644 ovr-utils/addons/openvr_overlay/move_overlay.gd create mode 100644 ovr-utils/overlays/move_overlay.gd diff --git a/ovr-utils/addons/openvr_overlay/move_overlay.gd b/ovr-utils/addons/openvr_overlay/move_overlay.gd deleted file mode 100644 index 0d519eb..0000000 --- a/ovr-utils/addons/openvr_overlay/move_overlay.gd +++ /dev/null @@ -1,14 +0,0 @@ -extends Control - -var ihandler - -func _ready() -> void: - ihandler = get_viewport().get_node("../OverlayInteraction") - - -func _on_DragButton_button_down() -> void: - ihandler.begin_move() - - -func _on_DragButton_button_up() -> void: - ihandler.finish_move() diff --git a/ovr-utils/addons/openvr_overlay/overlay_instance.gd b/ovr-utils/addons/openvr_overlay/overlay_instance.gd index 0baed78..f811b19 100644 --- a/ovr-utils/addons/openvr_overlay/overlay_instance.gd +++ b/ovr-utils/addons/openvr_overlay/overlay_instance.gd @@ -14,10 +14,10 @@ export var width_meters = 0.4 setget set_width_in_meters # if this is exported, all overlays sync offset when a controller is turned off/on # this seems to be a bug with the godot editor- var offsets:Dictionary = { - "head": {"pos": Vector3(), "rot": Quat()}, + "head": {"pos": Vector3(0,0,-0.4), "rot": Quat()}, "left": {"pos": Vector3(), "rot": Quat()}, "right": {"pos": Vector3(), "rot": Quat()}, - "world": {"pos": Vector3(), "rot": Quat()} + "world": {"pos": Vector3(0,1,0), "rot": Quat()} } # what's actually tracking diff --git a/ovr-utils/overlays/UI_demo.tscn b/ovr-utils/overlays/UI_demo.tscn index fb359a7..1799787 100644 --- a/ovr-utils/overlays/UI_demo.tscn +++ b/ovr-utils/overlays/UI_demo.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=9 format=2] -[ext_resource path="res://addons/openvr_overlay/move_overlay.gd" type="Script" id=1] +[ext_resource path="res://overlays/move_overlay.gd" type="Script" id=1] [ext_resource path="res://fonts/OpenSans-Regular.ttf" type="DynamicFontData" id=2] [ext_resource path="res://fonts/OpenSans-Bold.ttf" type="DynamicFontData" id=3] @@ -47,7 +47,6 @@ margin_right = 111.0 margin_bottom = 41.0 theme = SubResource( 2 ) text = "Item 0" -items = [ "Item 0", null, false, 0, null, "Item 1", null, false, 1, null, "Item 2", null, false, 2, null, "Item 3", null, false, 3, null ] selected = 0 __meta__ = { "_edit_use_anchors_": false @@ -66,5 +65,6 @@ __meta__ = { "_edit_use_anchors_": false } +[connection signal="item_selected" from="OptionButton" to="." method="_on_OptionButton_item_selected"] [connection signal="button_down" from="DragButton" to="." method="_on_DragButton_button_down"] [connection signal="button_up" from="DragButton" to="." method="_on_DragButton_button_up"] diff --git a/ovr-utils/overlays/move_overlay.gd b/ovr-utils/overlays/move_overlay.gd new file mode 100644 index 0000000..e7592c2 --- /dev/null +++ b/ovr-utils/overlays/move_overlay.gd @@ -0,0 +1,22 @@ +extends Control + +var ihandler +var oinst + +func _ready() -> void: + oinst = get_viewport().get_parent() + ihandler = get_viewport().get_node("../OverlayInteraction") + for t in oinst.TARGETS: + $OptionButton.add_item(t) + $OptionButton.selected = oinst.TARGETS.find(oinst.target) + +func _on_DragButton_button_down() -> void: + ihandler.begin_move() + + +func _on_DragButton_button_up() -> void: + ihandler.finish_move() + + +func _on_OptionButton_item_selected(index: int) -> void: + oinst.target = oinst.TARGETS[index]