diff --git a/README.md b/README.md index 4f846ba..a1cad4b 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,8 @@ Thus I've decided to use a custom event system that is similar to the one used i | -- | -- | | `entity` | Marks the object as being an entity placed in space | | `ui_focus` | The element can be focused, can be a parent | -| `ui_focus_skip` | The focus will not be reset. Useful for keyboard | +| `ui_focus_skip` | Focus checking on this element will be skipped | +| `ui_focus_stop` | The focus will not be reset. Useful for keyboard | ### Functions diff --git a/content/system/hands/hands.gd b/content/system/hands/hands.gd index 0561f00..bd7873a 100644 --- a/content/system/hands/hands.gd +++ b/content/system/hands/hands.gd @@ -23,10 +23,10 @@ var grabbed_right = false func _ready(): touch = Touch.new({ - Finger.Type.INDEX_RIGHT: $XRHandRight/IndexTip/IndexArea, - Finger.Type.INDEX_LEFT: $XRHandLeft/IndexTip/IndexArea, - Finger.Type.MIDDLE_RIGHT: $XRHandRight/MiddleTip/MiddleArea, - Finger.Type.MIDDLE_LEFT: $XRHandLeft/MiddleTip/MiddleArea + Finger.Type.INDEX_RIGHT: $XRHandRight/IndexTip/TouchArea, + Finger.Type.INDEX_LEFT: $XRHandLeft/IndexTip/TouchArea, + Finger.Type.MIDDLE_RIGHT: $XRHandRight/MiddleTip/TouchArea, + Finger.Type.MIDDLE_LEFT: $XRHandLeft/MiddleTip/TouchArea }) add_child(touch) diff --git a/content/system/hands/hands.tscn b/content/system/hands/hands.tscn index e7653c7..746bd28 100644 --- a/content/system/hands/hands.tscn +++ b/content/system/hands/hands.tscn @@ -28,13 +28,13 @@ external_skeleton = NodePath("../left_hand/Armature_001/Skeleton3D") [node name="Marker3D" type="Marker3D" parent="XRHandLeft/IndexTip"] gizmo_extents = 0.02 -[node name="IndexArea" type="Area3D" parent="XRHandLeft/IndexTip"] +[node name="TouchArea" type="Area3D" parent="XRHandLeft/IndexTip"] transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.01) collision_layer = 2 collision_mask = 2 monitorable = false -[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandLeft/IndexTip/IndexArea"] +[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandLeft/IndexTip/TouchArea"] transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, 1, 0, 0, 0) shape = SubResource("CapsuleShape3D_dopke") @@ -58,13 +58,13 @@ external_skeleton = NodePath("../left_hand/Armature_001/Skeleton3D") [node name="Marker3D" type="Marker3D" parent="XRHandLeft/MiddleTip"] gizmo_extents = 0.02 -[node name="IndexArea" type="Area3D" parent="XRHandLeft/MiddleTip"] +[node name="TouchArea" type="Area3D" parent="XRHandLeft/MiddleTip"] transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.01) collision_layer = 2 collision_mask = 2 monitorable = false -[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandLeft/MiddleTip/IndexArea"] +[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandLeft/MiddleTip/TouchArea"] transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, 1, 0, 0, 0) shape = SubResource("CapsuleShape3D_dopke") @@ -86,13 +86,13 @@ external_skeleton = NodePath("../right_hand/Armature/Skeleton3D") [node name="Marker3D" type="Marker3D" parent="XRHandRight/IndexTip"] gizmo_extents = 0.02 -[node name="IndexArea" type="Area3D" parent="XRHandRight/IndexTip"] +[node name="TouchArea" type="Area3D" parent="XRHandRight/IndexTip"] transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.01) collision_layer = 2 collision_mask = 2 monitorable = false -[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandRight/IndexTip/IndexArea"] +[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandRight/IndexTip/TouchArea"] transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, 1, 0, 0, 0) shape = SubResource("CapsuleShape3D_dopke") @@ -116,13 +116,13 @@ external_skeleton = NodePath("../right_hand/Armature/Skeleton3D") [node name="Marker3D" type="Marker3D" parent="XRHandRight/MiddleTip"] gizmo_extents = 0.02 -[node name="IndexArea" type="Area3D" parent="XRHandRight/MiddleTip"] +[node name="TouchArea" type="Area3D" parent="XRHandRight/MiddleTip"] transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0.01) collision_layer = 2 collision_mask = 2 monitorable = false -[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandRight/MiddleTip/IndexArea"] +[node name="CollisionShape3D" type="CollisionShape3D" parent="XRHandRight/MiddleTip/TouchArea"] transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, 1, 0, 0, 0) shape = SubResource("CapsuleShape3D_dopke") diff --git a/content/system/keyboard/keyboard.tscn b/content/system/keyboard/keyboard.tscn index b6f6c71..2e891f5 100644 --- a/content/system/keyboard/keyboard.tscn +++ b/content/system/keyboard/keyboard.tscn @@ -11,7 +11,7 @@ size = Vector3(0.79, 0.01, 0.26) [sub_resource type="BoxMesh" id="BoxMesh_7rntc"] size = Vector3(0.79, 0.01, 0.26) -[node name="Keyboard" type="StaticBody3D" groups=["ui_focus_skip"]] +[node name="Keyboard" type="StaticBody3D" groups=["ui_focus_stop"]] transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0) script = ExtResource("1_maojw") diff --git a/content/ui/components/button/button.gd b/content/ui/components/button/button.gd index 7670d55..5dbfad1 100644 --- a/content/ui/components/button/button.gd +++ b/content/ui/components/button/button.gd @@ -16,11 +16,10 @@ const IconFont = preload("res://assets/icons/icons.tres") @export var focusable: bool = true: set(value): focusable = value - if !is_node_ready(): await ready - if value: - add_to_group("ui_focus_skip") + if value == false: + add_to_group("ui_focus_stop") else: - remove_from_group("ui_focus_skip") + remove_from_group("ui_focus_stop") @export var font_size: int = 10: set(value): diff --git a/content/ui/components/button/button.tscn b/content/ui/components/button/button.tscn index a26404d..e0836ef 100644 --- a/content/ui/components/button/button.tscn +++ b/content/ui/components/button/button.tscn @@ -73,10 +73,9 @@ size = Vector3(0.0501598, 0.0195937, 0.0501598) [node name="Button" type="Node3D" groups=["ui_focus"]] script = ExtResource("1_74x7g") -focusable = null label = "Example Text" -[node name="Body" type="StaticBody3D" parent="."] +[node name="Body" type="StaticBody3D" parent="." groups=["ui_focus_skip"]] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.01, 0) [node name="MeshInstance3D" type="MeshInstance3D" parent="Body"] diff --git a/content/ui/components/input/input.gd b/content/ui/components/input/input.gd index d324872..b069c0d 100644 --- a/content/ui/components/input/input.gd +++ b/content/ui/components/input/input.gd @@ -115,6 +115,7 @@ func update_caret_position(event): func _on_focus_out(_event): + print("focus out") animation.stop() caret.hide() diff --git a/content/ui/menu/menu.tscn b/content/ui/menu/menu.tscn index 53c22c8..a91b2c6 100644 --- a/content/ui/menu/menu.tscn +++ b/content/ui/menu/menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://c3kdssrmv84kv"] +[gd_scene load_steps=13 format=3 uid="uid://c3kdssrmv84kv"] [ext_resource type="Script" path="res://content/ui/menu/menu.gd" id="1_ng4u3"] [ext_resource type="PackedScene" uid="uid://crrb0l3ekuotj" path="res://content/ui/menu/edit/edit_menu.tscn" id="4_r2raj"] @@ -13,6 +13,9 @@ material = SubResource("StandardMaterial3D_ti5t2") size = Vector3(0.3, 0.01, 0.3) +[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_mgnm0"] +points = PackedVector3Array(-0.15, -0.005, -0.15, -0.15, 0.005, -0.15, 0.15, -0.005, -0.15, -0.15, -0.005, 0.15, -0.15, 0.005, 0.15, 0.15, 0.005, -0.15, 0.15, -0.005, 0.15, 0.15, 0.005, 0.15) + [sub_resource type="Animation" id="Animation_61md4"] length = 0.001 tracks/0/type = "bezier" @@ -153,47 +156,46 @@ _data = { [node name="Menu" type="Node3D"] script = ExtResource("1_ng4u3") -[node name="AnimationContainer" type="Node3D" parent="."] +[node name="AnimationContainer" type="StaticBody3D" parent="."] [node name="Background" type="MeshInstance3D" parent="AnimationContainer"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.21, 0, 0.15) mesh = SubResource("BoxMesh_08du6") skeleton = NodePath("../..") +[node name="CollisionShape3D" type="CollisionShape3D" parent="AnimationContainer"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.21, 0, 0.15) +shape = SubResource("ConvexPolygonShape3D_mgnm0") + [node name="Navigation" type="Node3D" parent="AnimationContainer"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0, 0) [node name="View" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.03) -focusable = true label = "visibility" icon = true toggleable = true [node name="Edit" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.09) -focusable = true label = "widgets" icon = true toggleable = true [node name="Room" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.15) -focusable = true label = "view_in_ar" icon = true toggleable = true [node name="Automate" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.21) -focusable = true label = "schema" icon = true toggleable = true [node name="Settings" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.27) -focusable = true label = "settings" icon = true toggleable = true diff --git a/content/ui/menu/settings/settings_menu.tscn b/content/ui/menu/settings/settings_menu.tscn index 61f53eb..e279d0a 100644 --- a/content/ui/menu/settings/settings_menu.tscn +++ b/content/ui/menu/settings/settings_menu.tscn @@ -32,7 +32,6 @@ outline_size = 0 [node name="Button" parent="Content" instance=ExtResource("1_faxng")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0458097, 0, 0.253575) -focusable = true label = "sports_basketball" icon = true @@ -85,7 +84,6 @@ horizontal_alignment = 0 [node name="Connect" parent="Content" instance=ExtResource("1_faxng")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, 0, 0.12) -focusable = true label = "wifi" icon = true diff --git a/lib/globals/event_system.gd b/lib/globals/event_system.gd index 7681812..3ccabc5 100644 --- a/lib/globals/event_system.gd +++ b/lib/globals/event_system.gd @@ -35,11 +35,14 @@ func emit(type: String, event: Event): func is_focused(node: Node): return _active_node == node -func _handle_focus(event: EventBubble): - var target = event.target +func _handle_focus(target: Variant, event: EventBubble): + print("focus ", target, " ", target.get_groups(), " ", event) - if target != null && target.is_in_group("ui_focus_skip"): - return + if target != null: + if target.is_in_group("ui_focus_skip"): + return false + if target.is_in_group("ui_focus_stop"): + return true var event_focus = EventFocus.new() event_focus.previous_target = _active_node @@ -51,15 +54,19 @@ func _handle_focus(event: EventBubble): if target == null || target.is_in_group("ui_focus") == false: _active_node = null - return + return false _active_node = target + print("focus", _active_node ) + if _active_node != null && _active_node.has_method(FN_PREFIX + "focus_in"): _active_node.call(FN_PREFIX + "focus_in", event_focus) on_focus_in.emit(event_focus) -func _bubble_call(type: String, target: Variant, event: EventBubble): + return true + +func _bubble_call(type: String, target: Variant, event: EventBubble, focused = false): if target == null: return false @@ -73,8 +80,8 @@ func _bubble_call(type: String, target: Variant, event: EventBubble): if event.bubbling == false: return false - if type == "press_down" || type == "touch_enter": - _handle_focus(event) + if (type == "press_down" || type == "touch_enter") && focused == false: + focused = _handle_focus(target, event) for child in target.get_children(): if child is Function && child.has_method(FN_PREFIX + type): @@ -83,7 +90,7 @@ func _bubble_call(type: String, target: Variant, event: EventBubble): var parent = target.get_parent() if parent != null && parent is Node: - _bubble_call(type, parent, event) + _bubble_call(type, parent, event, focused) else: # in case the top has been reached _root_call(type, event)