Skip to content

Commit 966f5af

Browse files
committed
ParameterInput: Use DragDropArea
Instead of using ParameterInput's own input events, add a DragDropArea for each input component. This allows us to use _gui_input events so events are correctly filtered based on z order and visibility.
1 parent c5c4873 commit 966f5af

File tree

2 files changed

+41
-31
lines changed

2 files changed

+41
-31
lines changed

addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ signal modified
2020
var default_value: Variant
2121

2222
var _drag_start: Vector2 = Vector2.INF
23-
var _is_dragging: bool = false
2423

2524
@onready var _panel := %Panel
2625
@onready var snap_point := %SnapPoint
@@ -156,6 +155,10 @@ func _ready():
156155
set_raw_input(default_value)
157156

158157

158+
func _on_drag_drop_area_drag_started():
159+
drag_started.emit()
160+
161+
159162
func get_snapped_block() -> Block:
160163
return snap_point.get_snapped_block()
161164

@@ -289,32 +292,3 @@ func _on_option_input_item_selected(index):
289292

290293
func _on_snap_point_snapped_block_changed(block):
291294
_update_visible_input()
292-
293-
294-
func _input(event: InputEvent) -> void:
295-
if snap_point.has_snapped_block():
296-
return
297-
298-
if event is InputEventMouseButton:
299-
var button_event: InputEventMouseButton = event as InputEventMouseButton
300-
301-
if button_event.button_index != MOUSE_BUTTON_LEFT:
302-
return
303-
304-
if button_event.double_click:
305-
# Double click event (with the mouse released) has both pressed=true
306-
# and double_click=true, so ignore it as a special case.
307-
pass
308-
elif button_event.pressed and get_global_rect().has_point(button_event.global_position):
309-
# Keep track of where the mouse click originated, but allow this
310-
# event to propagate to other nodes.
311-
_drag_start = event.global_position
312-
else:
313-
_drag_start = Vector2.INF
314-
elif _drag_start != Vector2.INF and event is InputEventMouseMotion:
315-
var motion_event: InputEventMouseMotion = event as InputEventMouseMotion
316-
317-
if not get_global_rect().has_point(event.global_position) and _drag_start.distance_to(event.global_position) > Constants.MINIMUM_DRAG_THRESHOLD:
318-
get_viewport().set_input_as_handled()
319-
drag_started.emit()
320-
_drag_start = Vector2.INF

addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
[gd_scene load_steps=10 format=3 uid="uid://cjvxs6euc6xbm"]
1+
[gd_scene load_steps=11 format=3 uid="uid://cjvxs6euc6xbm"]
22

33
[ext_resource type="Script" path="res://addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd" id="1_rgmxn"]
4+
[ext_resource type="PackedScene" uid="uid://c1l0mpkvmvwfd" path="res://addons/block_code/ui/blocks/utilities/drag_drop_area/drag_drop_area.tscn" id="2_05gck"]
45
[ext_resource type="PackedScene" uid="uid://b1oge52xhjqnu" path="res://addons/block_code/ui/blocks/utilities/snap_point/snap_point.tscn" id="2_6esp3"]
56

67
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tn6h4"]
@@ -71,6 +72,10 @@ theme_override_styles/normal = SubResource("StyleBoxEmpty_6oowp")
7172
placeholder_text = "Parameter"
7273
expand_to_text_length = true
7374

75+
[node name="DragDropArea" parent="InputSwitcher/TextInput/LineEdit" instance=ExtResource("2_05gck")]
76+
layout_mode = 1
77+
drag_outside = true
78+
7479
[node name="ColorInput" type="ColorPickerButton" parent="InputSwitcher"]
7580
unique_name_in_owner = true
7681
visible = false
@@ -80,6 +85,10 @@ layout_mode = 2
8085
mouse_default_cursor_shape = 2
8186
theme_override_styles/normal = SubResource("StyleBoxEmpty_5hq7f")
8287

88+
[node name="DragDropArea" parent="InputSwitcher/ColorInput" instance=ExtResource("2_05gck")]
89+
layout_mode = 1
90+
drag_outside = true
91+
8392
[node name="OptionInput" type="OptionButton" parent="InputSwitcher"]
8493
unique_name_in_owner = true
8594
visible = false
@@ -90,6 +99,10 @@ theme_override_styles/normal = SubResource("StyleBoxEmpty_fjquj")
9099
action_mode = 1
91100
fit_to_longest_item = false
92101

102+
[node name="DragDropArea" parent="InputSwitcher/OptionInput" instance=ExtResource("2_05gck")]
103+
layout_mode = 1
104+
drag_outside = true
105+
93106
[node name="Vector2Input" type="MarginContainer" parent="InputSwitcher"]
94107
unique_name_in_owner = true
95108
visible = false
@@ -121,6 +134,10 @@ placeholder_text = "x"
121134
alignment = 1
122135
expand_to_text_length = true
123136

137+
[node name="DragDropArea" parent="InputSwitcher/Vector2Input/HBoxContainer/XLineEdit" instance=ExtResource("2_05gck")]
138+
layout_mode = 1
139+
drag_outside = true
140+
124141
[node name="Control3" type="Control" parent="InputSwitcher/Vector2Input/HBoxContainer"]
125142
layout_mode = 2
126143
size_flags_horizontal = 3
@@ -135,6 +152,10 @@ layout_mode = 2
135152
size_flags_horizontal = 4
136153
color = Color(0.804743, 0.804743, 0.804743, 1)
137154

155+
[node name="DragDropArea" parent="InputSwitcher/Vector2Input/HBoxContainer/CenterContainer/ColorRect" instance=ExtResource("2_05gck")]
156+
layout_mode = 1
157+
drag_outside = true
158+
138159
[node name="Control4" type="Control" parent="InputSwitcher/Vector2Input/HBoxContainer"]
139160
layout_mode = 2
140161
size_flags_horizontal = 3
@@ -154,6 +175,10 @@ placeholder_text = "y"
154175
alignment = 1
155176
expand_to_text_length = true
156177

178+
[node name="DragDropArea" parent="InputSwitcher/Vector2Input/HBoxContainer/YLineEdit" instance=ExtResource("2_05gck")]
179+
layout_mode = 1
180+
drag_outside = true
181+
157182
[node name="Control2" type="Control" parent="InputSwitcher/Vector2Input/HBoxContainer"]
158183
layout_mode = 2
159184
size_flags_horizontal = 3
@@ -179,6 +204,10 @@ popup/item_0/text = "false"
179204
popup/item_1/text = "true"
180205
popup/item_1/id = 1
181206

207+
[node name="DragDropArea" parent="InputSwitcher/BoolInput/BoolInputOption" instance=ExtResource("2_05gck")]
208+
layout_mode = 1
209+
drag_outside = true
210+
182211
[node name="SnapPoint" parent="." instance=ExtResource("2_6esp3")]
183212
unique_name_in_owner = true
184213
layout_mode = 2
@@ -187,11 +216,18 @@ variant_type = 4
187216

188217
[connection signal="focus_exited" from="InputSwitcher/TextInput/LineEdit" to="." method="_on_line_edit_focus_exited"]
189218
[connection signal="text_submitted" from="InputSwitcher/TextInput/LineEdit" to="." method="_on_line_edit_text_submitted"]
219+
[connection signal="drag_started" from="InputSwitcher/TextInput/LineEdit/DragDropArea" to="." method="_on_drag_drop_area_drag_started"]
190220
[connection signal="color_changed" from="InputSwitcher/ColorInput" to="." method="_on_color_input_color_changed"]
221+
[connection signal="drag_started" from="InputSwitcher/ColorInput/DragDropArea" to="." method="_on_drag_drop_area_drag_started"]
191222
[connection signal="item_selected" from="InputSwitcher/OptionInput" to="." method="_on_option_input_item_selected"]
223+
[connection signal="drag_started" from="InputSwitcher/OptionInput/DragDropArea" to="." method="_on_drag_drop_area_drag_started"]
192224
[connection signal="focus_exited" from="InputSwitcher/Vector2Input/HBoxContainer/XLineEdit" to="." method="_on_x_line_edit_focus_exited"]
193225
[connection signal="text_submitted" from="InputSwitcher/Vector2Input/HBoxContainer/XLineEdit" to="." method="_on_x_line_edit_text_submitted"]
226+
[connection signal="drag_started" from="InputSwitcher/Vector2Input/HBoxContainer/XLineEdit/DragDropArea" to="." method="_on_drag_drop_area_drag_started"]
227+
[connection signal="drag_started" from="InputSwitcher/Vector2Input/HBoxContainer/CenterContainer/ColorRect/DragDropArea" to="." method="_on_drag_drop_area_drag_started"]
194228
[connection signal="focus_exited" from="InputSwitcher/Vector2Input/HBoxContainer/YLineEdit" to="." method="_on_y_line_edit_focus_exited"]
195229
[connection signal="text_submitted" from="InputSwitcher/Vector2Input/HBoxContainer/YLineEdit" to="." method="_on_y_line_edit_text_submitted"]
230+
[connection signal="drag_started" from="InputSwitcher/Vector2Input/HBoxContainer/YLineEdit/DragDropArea" to="." method="_on_drag_drop_area_drag_started"]
196231
[connection signal="item_selected" from="InputSwitcher/BoolInput/BoolInputOption" to="." method="_on_option_input_item_selected"]
232+
[connection signal="drag_started" from="InputSwitcher/BoolInput/BoolInputOption/DragDropArea" to="." method="_on_drag_drop_area_drag_started"]
197233
[connection signal="snapped_block_changed" from="SnapPoint" to="." method="_on_snap_point_snapped_block_changed"]

0 commit comments

Comments
 (0)