mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-22 15:40:25 +01:00
add click with trigger on UI elements in overlays
This commit is contained in:
parent
7c255586db
commit
900fc0809c
5 changed files with 73 additions and 4 deletions
|
@ -1,9 +1,10 @@
|
|||
[gd_scene load_steps=8 format=2]
|
||||
[gd_scene load_steps=9 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]
|
||||
[ext_resource path="res://overlays/TimeOverlay.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://temp.gd" type="Script" id=4]
|
||||
[ext_resource path="res://overlays/UI_demo.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://overlays/BatteryOverlay.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://addons/openvr_overlay/OverlayInteraction.tscn" type="PackedScene" id=8]
|
||||
|
||||
|
@ -41,3 +42,11 @@ width_meters = 0.1
|
|||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource( 1 )
|
||||
|
||||
[node name="OverlayInstance" parent="." instance=ExtResource( 1 )]
|
||||
target = 1
|
||||
overlay_scene = ExtResource( 5 )
|
||||
offset_pos = Vector3( 0, 0, -0.2 )
|
||||
offset_rot = Vector3( 0, 90, 0 )
|
||||
|
||||
[node name="OverlayInteraction" parent="OverlayInstance" instance=ExtResource( 8 )]
|
||||
|
|
|
@ -5,13 +5,17 @@
|
|||
[node name="Cursor" type="Control"]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
margin_left = -70.0
|
||||
margin_top = -70.0
|
||||
margin_right = 70.0
|
||||
margin_bottom = 70.0
|
||||
mouse_filter = 2
|
||||
texture = ExtResource( 1 )
|
||||
expand = true
|
||||
__meta__ = {
|
||||
|
|
|
@ -20,8 +20,8 @@ var _cursor_node = preload("res://addons/openvr_overlay/interaction/Cursor.tscn"
|
|||
var _right_is_activator = false
|
||||
var _left_is_activator = false
|
||||
|
||||
|
||||
onready var panel = get_node("../OverlayViewport/PanelContainer")
|
||||
onready var viewport: Viewport = get_node("../OverlayViewport")
|
||||
onready var panel: PanelContainer = get_node("../OverlayViewport/PanelContainer")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
@ -66,10 +66,19 @@ func _update_cursor():
|
|||
_cursor_node.rect_position = get_canvas_pos()
|
||||
|
||||
|
||||
func _send_click_event(state: bool):
|
||||
var click_event = InputEventMouseButton.new()
|
||||
click_event.position = get_canvas_pos()
|
||||
click_event.pressed = state
|
||||
click_event.button_index = 1
|
||||
viewport.input(click_event)
|
||||
|
||||
|
||||
func _trigger_on(controller):
|
||||
if _touch_state:
|
||||
_active_controller = controller
|
||||
_trigger_state = true
|
||||
_send_click_event(true)
|
||||
_update_selection()
|
||||
emit_signal("trigger_on")
|
||||
|
||||
|
@ -77,6 +86,7 @@ func _trigger_on(controller):
|
|||
func _trigger_off():
|
||||
_trigger_state = false
|
||||
_update_selection()
|
||||
_send_click_event(false)
|
||||
emit_signal("trigger_off")
|
||||
|
||||
|
||||
|
@ -100,6 +110,7 @@ func _on_OverlayArea_exited(body: Node) -> void:
|
|||
|
||||
|
||||
func _update_selection():
|
||||
return
|
||||
if _trigger_state:
|
||||
panel.theme = active_theme
|
||||
elif _touch_state:
|
||||
|
|
|
@ -101,7 +101,7 @@ func _set_width_meters(width: float):
|
|||
func _set_overlay_scene(scene: PackedScene):
|
||||
overlay_scene = scene
|
||||
if not container:
|
||||
print("container does not exist yet [overlay_instance.set_overlay_scene]")
|
||||
# print("container does not exist yet [overlay_instance.set_overlay_scene]")
|
||||
return
|
||||
if container.get_child_count() > 0:
|
||||
container.get_child(0).queue_free()
|
||||
|
|
45
ovr-utils/overlays/UI_demo.tscn
Normal file
45
ovr-utils/overlays/UI_demo.tscn
Normal file
|
@ -0,0 +1,45 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://fonts/OpenSans-Bold.ttf" type="DynamicFontData" id=1]
|
||||
[ext_resource path="res://addons/openvr_overlay/styles/active.stylebox" type="StyleBox" id=3]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 100
|
||||
font_data = ExtResource( 1 )
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="OptionButton" type="OptionButton" parent="."]
|
||||
anchor_left = 0.144
|
||||
anchor_top = 0.483
|
||||
anchor_right = 0.856
|
||||
anchor_bottom = 0.517
|
||||
margin_left = -0.456009
|
||||
margin_top = -17.8
|
||||
margin_right = 0.455933
|
||||
margin_bottom = 16.8
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
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
|
||||
}
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
margin_left = 158.089
|
||||
margin_top = 45.4084
|
||||
margin_right = 473.089
|
||||
margin_bottom = 223.408
|
||||
custom_styles/pressed = ExtResource( 3 )
|
||||
toggle_mode = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
Loading…
Reference in a new issue