#Popup Controls not getting Input events

34 messages · Page 1 of 1 (latest)

lethal chasm
#

I have a ColorRect with a script like bellow and a child Container node for a menu. My idea would be to hold the right button to show the menu, then you could click on the menu buttons with the left mouse button and release the right mouse button to hide the menu. Alternatively, releasing the mouse button presses a button, and hides the menu at the same time. But this isn't working. The menu is not receiving any events.

If I do a thing where I press the right mouse button to show the menu, then have to press it again to hide, the menu is functional, though.

func _gui_input(event: InputEvent) -> void:
    if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT:
        if event.is_pressed():
            $menu.position = event.position - menu.center
            $menu.show()
        else:
            $menu.hide()
bleak bobcat
lethal chasm
#

@bleak bobcat
Button held down -> Menu shows -> menu doesn't receive inputs from the other buttons.
Script changed...
Button Clicked -> Menu shows ->menu receives inputs.

bleak bobcat
#

Did you change the mouse mode of all the menu nodes to pass? Otherwise you needing the input to go to both the ColorRect and the menu buttons shouldn't work.

lethal chasm
#

@bleak bobcat

func _gui_input(event: InputEvent) -> void:
    if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT:
        if event.is_pressed():
            $menu.position = event.position - menu.center
            $menu.visible = not $menu.visible
#

The menu has the mouse filter to "stop"

bleak bobcat
lethal chasm
#

No. Pay attention.

bleak bobcat
#

I am

lethal chasm
#

One hides the menu when it's event.is_released()

bleak bobcat
#

i don't see that function in any of the two code blocks

lethal chasm
#

Because if event.is_pressed()... else: implies is_released()

#

It's the same thing

bleak bobcat
#

Ah you mean that. Fair enough.

#

So the new one closes it when you right click a second time?

lethal chasm
#

Yes

#

and while showing, the menu is functional

bleak bobcat
#

And when you rightclick even on the menu it closes again?

lethal chasm
#

Good question, let me check...

#

It shouldn't, right?

bleak bobcat
#

yeah it shouldn't

#

Because with mouse mode stop, only the top most control node will recieve the event.

#

With pass it will be passed on to parent control nodes (don't ask me why only parents, my only guess is performance reasons)

lethal chasm
#

Alright, in functional menu method, the right mouse button doesn't hide it, as we'd expect

bleak bobcat
#

then try changing the mouse modes to pass.

lethal chasm
#

Same problem, but now I can use the right mouse to close in the second method.

#

There might be something about how Godot handles inputs here that I'm not aware

bleak bobcat
lethal chasm
#

In the first method, the menu still doesn't work.

bleak bobcat
#

my guess is that it has something to do with the mouse focus system that dictates what control node you are currently clicking on, so sliding off a button won't immediately register a control below it as clicked. That one probably doesn't differentiate between the mouse buttons.

#

I am kinda wondering why you are using a color rect for the right click. Do you want to limit the area where the right click does that?

lethal chasm
#

Because it's actually a custom UI element based on ColorRect, but I don't think that has anything to do with the problem.