Hello everyone,

I making a little menu box where i have got a texture with each type of vehicles i have selected. This little menu is simply a filter tool.
Actually, when i press one of these textures, the corresponding vehicle's type still selected, the others are unselected.

But if i want more than one type and i want to exclude one type i don't want, i need to use the right mouse. I see i can activate left and mouse button in "button mask", and the tips box says i need to use "button mask left" and "button mask right" but i don't understand how i must use them.

I have just one signal "pressed" so i suppose i must do something in it with these things...

  • Toxe replied to this.
  • TwistedMind Use _gui_input() event. It will catch all events. In the event handler test if the received event is a button event and query the event object to get the exact button, like you'd normally do in a regular _input() callback

    func _on_texture_button_gui_input(event): 
    	if event is InputEventMouseButton and event.is_pressed():
    		match event.button_index:
    			MOUSE_BUTTON_LEFT:
    				print("left")
    			MOUSE_BUTTON_RIGHT:
    				print("right")

    TwistedMind Post the relevant code. Is there some kind of InputEvent or InputEventMouse that gets passed to your signal handler?

    Hello Toxe,

    Here what you ask.

    Is there some kind of InputEvent or InputEventMouse that gets passed to your signal handler ?

    Yes, but not in this code: i make a special script where all inputs are, they called an external function from another script. The left mouse doesn't interfere when i select one vehicle's type from the list, the right mouse interfere because it unselects all vehicles and hide popup, i will need to make a condition for this but i need to be sure it catch the impulsion in the filter first.

    So, about the script: the buttons are dynamically added and dynamically connected. When the mouse is over on one of these buttons, i must do something after a clic. Actually only left mouse is active but i want the right mouse too.

    If you need more informations, please ask.

    Do understand correctly you want to distinguish between a right and a left click on a button?

    I have a similar feature in my current project. Maybe you can adapt the code to your needs:

    extends Button
    class_name MultiButton
    
    
    # Adds support for right mouse button clicks
    
    
    signal button_pressed(right)
    
    
    var _right = false
    
    
    func _ready():
        button_mask = BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT
    
    
    func _pressed():
        if _right:
            grab_focus()
        emit_signal("button_pressed", _right)
    
    func _gui_input(event):
        if event is InputEventMouseButton and event.pressed:
            _right = event.button_index==BUTTON_RIGHT

    Edit: Removed a few irrelevant lines.

    Here what i understand: in the properties of the texture button's node, i see in "button mask" 3 mouse key. If none of them are "on", the button will not emit any signal. By default, only left mouse is "on", so when i clic on a button, the signal is emitted.

    So if i activate right button, i should expect an impulsion in the signal "pressed". This is the case, but i haven't got nothing to distinguish them.

    The help popup says i must use BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT. But what does it mean ? Do i need to catch the input event ?

    In my input script, here my setup. Does it means there are interferences them ?

    func _input(event):
    	if event.is_action_pressed("leftClic"):
    
            elif event.is_action_released("leftClic"):
           
            elif event.is_action_pressed("rightClic"):
    
            elif event.is_action_pressed("screenshotGame"):
    
            elif event.is_action_pressed("activeIA"):
    • xyz replied to this.

      TwistedMind Use _gui_input() event. It will catch all events. In the event handler test if the received event is a button event and query the event object to get the exact button, like you'd normally do in a regular _input() callback

      func _on_texture_button_gui_input(event): 
      	if event is InputEventMouseButton and event.is_pressed():
      		match event.button_index:
      			MOUSE_BUTTON_LEFT:
      				print("left")
      			MOUSE_BUTTON_RIGHT:
      				print("right")