Swipe/Mouse-drag across buttons on a grid

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By charloalberto

I made a grid of buttons (also tried with texturebuttons and texturerects) and I’m trying to detect the buttons the player swipe/mouse over, like tracing lines between icons. I’ve tried combining the on_button_down and on_mouse_over signals, but I can’t really make it work like that. Any suggestions?

Here’s the script I’ve attached to the grid. The buttons have no script of their own, they just emit signals to the grid script.

extends GridContainer

var isClicked = false

func _on_mouse_entered():
	if(isClicked):
		print("click-hovered")
	else:
		print("hovered")

func _on_button_down():
	isClicked = true
	print("clicked")


func _on_button_up():
	isClicked = false
	print("unclicked")

You need to know which button is activated. I myself would attach a script to your ‘special’ buttons which generate their own signals so your GridContainer gets it :wink:

You can also attach your buttons through code in GridContainer passing the button itself

onready var button1:Button = $Button1

func _ready():
  button1.connect('mouse_entered', self, '_on_mouse_entered', [button1])

func _on_mouse_entered(b:Button):
  pass

clemens.tolboom | 2021-07-19 10:40

Knowing which button was activated will be important in the logic, sure, but it doesn’t help me with the current problem of undetected hover while holding mouse button down.

I’ve made the alterations you recommended but to no avail.

extends GridContainer

# declarar texturas possíveis para tiles
var clickedTile
var isClicked = false
var isDragging = false

func _ready():
	for _i in self.get_children():
		_i.connect("gui_input", _i.get_parent(), "_on_gui_input", [_i])
		_i.connect("mouse_entered", _i.get_parent(), "_on_mouse_entered", [_i])

func _on_mouse_entered(tile):
	print(tile.name + " was hovered over")
	if(isClicked):
		print("click-hovered")

func _on_gui_input(event, tile):
	if event is InputEventMouseButton and event.pressed:
		clickedTile = tile
		isClicked = true
		print(tile.name+" was clicked!")
	else :
		if event is InputEventMouseButton and !event.pressed:
			isClicked = false
			print("mouse was let go!")

charloalberto | 2021-07-20 00:03

Maybe this Q&A helps

clemens.tolboom | 2021-07-21 07:30

i’m sorry, but I cant see anything. maybe you wanted post a link but forgot to paste it? lol

charloalberto | 2021-07-21 15:53