Skip to content

Commit

Permalink
fix: touch and scroll, and click and move with a new custom touch button
Browse files Browse the repository at this point in the history
  • Loading branch information
kuruk-mm committed Jan 30, 2024
1 parent a1f7a7c commit 956d55f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
8 changes: 7 additions & 1 deletion godot/.godot/global_script_class_cache.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ list=Array[Dictionary]([{
"language": &"GDScript",
"path": "res://src/config/config_data.gd"
}, {
"base": &"Button",
"class": &"CustomTouchButton",
"icon": "",
"language": &"GDScript",
"path": "res://src/ui/components/custom_touch_button/custom_touch_button.gd"
}, {
"base": &"MeshInstance3D",
"class": &"DclMeshRenderer",
"icon": "",
Expand Down Expand Up @@ -149,7 +155,7 @@ list=Array[Dictionary]([{
"language": &"GDScript",
"path": "res://src/ui/components/wearable_button/wearable_filter_button.gd"
}, {
"base": &"Button",
"base": &"CustomTouchButton",
"class": &"WearableItem",
"icon": "",
"language": &"GDScript",
Expand Down
2 changes: 2 additions & 0 deletions godot/src/ui/components/backpack/backpack.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,13 @@ filter_category = 17
custom_minimum_size = Vector2(580, 320)
layout_mode = 2
size_flags_vertical = 3
mouse_filter = 0

[node name="MarginContainer" type="MarginContainer" parent="HBoxContainer/MarginContainer/ColorRect_Sidebar/MarginContainer/VBoxContainer/VBoxContainer_WearableSelector/ScrollContainer_Items"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2

[node name="GridContainer_WearablesList" type="GridContainer" parent="HBoxContainer/MarginContainer/ColorRect_Sidebar/MarginContainer/VBoxContainer/VBoxContainer_WearableSelector/ScrollContainer_Items/MarginContainer"]
unique_name_in_owner = true
Expand Down
41 changes: 41 additions & 0 deletions godot/src/ui/components/custom_touch_button/custom_touch_button.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class_name CustomTouchButton
extends Button

var is_pressing = false


func _init():
button_mask = 0
mouse_filter = Control.MOUSE_FILTER_PASS
gui_input.connect(self._on_gui_input)


func _set_group_pressed_button(_pressed: bool):
if is_instance_valid(button_group) and is_instance_valid(button_group.get_pressed_button()):
button_group.get_pressed_button().set_pressed(_pressed)


func _on_gui_input(event):
if event is InputEventScreenTouch:
if event.pressed:
is_pressing = true
elif is_pressing and not event.pressed:
is_pressing = false
var inside = get_global_rect().has_point(get_global_mouse_position())
if not inside:
return

if is_instance_valid(button_group):
if button_group.allow_unpress:
if button_group.get_pressed_button() == self:
if button_pressed:
set_pressed(false)
else:
_set_group_pressed_button(false)
button_pressed = not button_pressed
else:
if button_group.get_pressed_button() != self:
_set_group_pressed_button(false)
button_pressed = not button_pressed
else:
button_pressed = not button_pressed
2 changes: 1 addition & 1 deletion godot/src/ui/components/wearable_item/wearable_item.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name WearableItem
extends Button
extends CustomTouchButton

signal equip(wearable_id: String)
signal unequip(wearable_id: String)
Expand Down
14 changes: 12 additions & 2 deletions godot/src/ui/components/wearable_item/wearable_item.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ offset_bottom = 160.0
size_flags_horizontal = 0
size_flags_vertical = 0
focus_mode = 0
mouse_filter = 1
toggle_mode = true
button_mask = 0
flat = true
script = ExtResource("1_vccc4")

Expand All @@ -56,7 +58,7 @@ offset_right = 80.0
offset_bottom = 80.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 1
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_24axm")

[node name="MarginContainer" type="MarginContainer" parent="."]
Expand All @@ -66,27 +68,30 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
theme_override_constants/margin_left = 5
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5

[node name="PanelContainer_White" type="PanelContainer" parent="MarginContainer"]
layout_mode = 2
mouse_filter = 1
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_6655i")

[node name="TextureRect_Background" type="TextureRect" parent="MarginContainer/PanelContainer_White"]
unique_name_in_owner = true
layout_mode = 2
size_flags_stretch_ratio = 0.0
mouse_filter = 2
texture = ExtResource("2_bnu38")
expand_mode = 3
stretch_mode = 5

[node name="TextureRect_Preview" type="TextureRect" parent="MarginContainer/PanelContainer_White"]
unique_name_in_owner = true
layout_mode = 2
mouse_filter = 2
expand_mode = 3
stretch_mode = 5

Expand All @@ -105,6 +110,7 @@ offset_top = -20.0
grow_horizontal = 0
grow_vertical = 0
size_flags_horizontal = 0
mouse_filter = 2
texture = ExtResource("4_cqflp")
expand_mode = 1
stretch_mode = 4
Expand All @@ -115,6 +121,7 @@ layout_mode = 1
offset_right = 36.0
offset_bottom = 36.0
size_flags_horizontal = 0
mouse_filter = 2
texture = ExtResource("5_dtfap")
expand_mode = 1
stretch_mode = 4
Expand All @@ -125,6 +132,7 @@ layout_mode = 1
offset_right = 28.0
offset_bottom = 28.0
size_flags_horizontal = 0
mouse_filter = 2
texture = ExtResource("6_ckipv")
expand_mode = 1
stretch_mode = 4
Expand All @@ -141,6 +149,7 @@ anchor_bottom = 0.07
offset_right = 12.0
offset_bottom = 12.0
size_flags_horizontal = 0
mouse_filter = 2
texture = ExtResource("7_h4p8s")
expand_mode = 1
stretch_mode = 4
Expand All @@ -159,5 +168,6 @@ offset_right = 64.0
offset_bottom = 64.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2

[connection signal="toggled" from="." to="." method="_on_toggled"]

0 comments on commit 956d55f

Please sign in to comment.