-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: touch and scroll, and click and move with a new custom touch button
- Loading branch information
Showing
5 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
godot/src/ui/components/custom_touch_button/custom_touch_button.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters