diff --git a/ovr-utils/Main.tscn b/ovr-utils/Main.tscn index f46f48f..5490a51 100644 --- a/ovr-utils/Main.tscn +++ b/ovr-utils/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://addons/openvr_overlay/OverlayInstance.tscn" type="PackedScene" id=1] [ext_resource path="res://overlays/FPSOverlay.tscn" type="PackedScene" id=2] @@ -6,10 +6,17 @@ [ext_resource path="res://temp.gd" type="Script" id=4] [ext_resource path="res://overlays/xyz_widget/zx.tscn" type="PackedScene" id=5] [ext_resource path="res://overlays/xyz_widget/yz.tscn" type="PackedScene" id=6] +[ext_resource path="res://overlays/BatteryOverlay.tscn" type="PackedScene" id=7] [node name="Overlays" type="Node"] script = ExtResource( 4 ) +[node name="OverlayInstance Battery" parent="." instance=ExtResource( 1 )] +target = 1 +overlay_scene = ExtResource( 7 ) +offset_pos = Vector3( -0.12, 0, 0.1 ) +offset_rot = Vector3( -135, 90, 0 ) + [node name="OverlayInstance FPS" parent="." instance=ExtResource( 1 )] target = 1 overlay_scene = ExtResource( 2 ) diff --git a/ovr-utils/addons/openvr_overlay/overlay_init.gd b/ovr-utils/addons/openvr_overlay/overlay_init.gd index 7a9110f..7cf5d76 100644 --- a/ovr-utils/addons/openvr_overlay/overlay_init.gd +++ b/ovr-utils/addons/openvr_overlay/overlay_init.gd @@ -1,10 +1,13 @@ extends Node var ovr_interface: ARVRInterface +var ovr_config := preload("res://addons/godot-openvr/OpenVRConfig.gdns").new() +var left_id = 0 +var right_id = 0 func _init() -> void: - var ovr_config = preload("res://addons/godot-openvr/OpenVRConfig.gdns").new() + ovr_config = preload("res://addons/godot-openvr/OpenVRConfig.gdns").new() ovr_config.set_application_type(2) # Set to OVERLAY MODE = 2, NORMAL MODE = 1 ovr_config.set_tracking_universe(1) # Set to SEATED MODE = 0, STANDING MODE = 1, RAW MODE = 2 @@ -15,7 +18,20 @@ func _init() -> void: func _ready() -> void: + ARVRServer.connect("tracker_added", self, "_tracker_changed") + ARVRServer.connect("tracker_removed", self, "_tracker_changed") + update_hand_ids() + +func _tracker_changed(tracker_name: String, type: int, id: int): + update_hand_ids() + +func update_hand_ids(): for i in ARVRServer.get_tracker_count(): var tracker = ARVRServer.get_tracker(i) print(tracker.get_name(), ": hand ", tracker.get_hand()) + var tracking_id = tracker.get_name().split("_")[-1] + if tracker.get_hand() == 1: + left_id = tracking_id + elif tracker.get_hand() == 2: + right_id = tracking_id diff --git a/ovr-utils/addons/openvr_overlay/overlay_instance.gd b/ovr-utils/addons/openvr_overlay/overlay_instance.gd index f7f1498..a8693e6 100644 --- a/ovr-utils/addons/openvr_overlay/overlay_instance.gd +++ b/ovr-utils/addons/openvr_overlay/overlay_instance.gd @@ -56,7 +56,7 @@ func update_offset() -> void: func _tracker_changed(tracker_name: String, type: int, id: int): - print("tracker changed: ", tracker_name) +# print("tracker changed: ", tracker_name) update_tracker_id() update_offset() diff --git a/ovr-utils/overlays/BatteryOverlay.tscn b/ovr-utils/overlays/BatteryOverlay.tscn new file mode 100644 index 0000000..a9c391e --- /dev/null +++ b/ovr-utils/overlays/BatteryOverlay.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://overlays/battery.gd" type="Script" id=1] +[ext_resource path="res://fonts/OpenSans-Regular.ttf" type="DynamicFontData" id=2] + +[sub_resource type="StyleBoxFlat" id=1] +bg_color = Color( 0, 0, 0, 0.705882 ) +expand_margin_left = 8.0 +expand_margin_right = 8.0 +expand_margin_top = 8.0 +expand_margin_bottom = 8.0 + +[sub_resource type="DynamicFont" id=2] +size = 128 +font_data = ExtResource( 2 ) + +[node name="Overlay" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ColorRect" type="PanelContainer" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -673.0 +margin_top = -87.5 +margin_right = 673.0 +margin_bottom = 87.5 +size_flags_horizontal = 0 +custom_styles/panel = SubResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label" type="Label" parent="ColorRect"] +margin_right = 1346.0 +margin_bottom = 175.0 +custom_fonts/font = SubResource( 2 ) +text = "Left: 100% Right: 100%" +align = 1 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/ovr-utils/overlays/battery.gd b/ovr-utils/overlays/battery.gd new file mode 100644 index 0000000..9df26f3 --- /dev/null +++ b/ovr-utils/overlays/battery.gd @@ -0,0 +1,26 @@ +extends Label + +var _delay = 0 + + +func _ready() -> void: + pass + +func _process(delta: float) -> void: + _delay += delta + if _delay > 1: + update_text() + _delay = 0 + +func update_text(): + var l = "NaN" + var r = "NaN" + if OverlayInit.left_id: + l = OverlayInit.ovr_config.get_device_battery_percentage(OverlayInit.left_id)*100 + l = str(int(l)) + if OverlayInit.right_id: + r = OverlayInit.ovr_config.get_device_battery_percentage(OverlayInit.right_id)*100 + r = str(int(r)) + if OverlayInit.ovr_config.is_device_charging(OverlayInit.right_id): + r += "+" + text = "Left: " + l + "% Right: " + r + "%"