Ignoring mouse while function executes

Hi!

I have this card game in which I pick the card I want to play based on the mouse_enter / mouse_exit commands.

When I release the player card on top of an enemy, the player attacks and the enemy retaliates. This works beautifully.

The trouble is, the attack / retaliation functions take a couple of seconds to process, because of the health bar update and so on. During that time, if the player moves the mouse over another one of the player’s cards, the effects get mixed up.

So, basically:

I would like my mouse to stop processing mouse_enter/mouse_exit from the moment I perform the attack until the moment the attack is finished. I can also do with the mouse being completely inactive, whether hidden or not. This would work for me too (in fact, it would be my preferred solution).

I have tried commands such as filter_mouse and mouse_mode_hidden, but these either interrupt the game or keep processing mouse_enter/mouse_exit functions even while the mouse is hidden.

Any tips?

Thanks!

Hi, it sounds like there’s a lot of ways you could accomplish this, what I would do is like this:

first add a static var to the class that actually has mouse_enter/exit response functions:
static var _ignore_mouse:bool = false;

then when you initiate a process during which mouse should be ignored, set _ignore_mouse to true. When that process has finished, set _ignore_mouse = false. And inside the mouse_enter/exit response functions, add (edit: +at the beginning of the function+):

if (_ignore_mouse):
    return

I think that would work for you.

Works like a charm! There had to be simple way to do this… :slight_smile:

Thanks!

Edit. Sometimes it looks like the click/drag I make while the mouse is theoretically ignored is somehow stored and processed immediately the animations take place. Any ideas on this? Maybe and unhandled event function?

hmm. maybe the input event isn’t being marked internally as ‘handled’, so it’s sticking around waiting for something to handle the event. So if that’s the case, maybe putting the ‘if (_ignore_mouse)’ part (and it’s return) actually inside of the parts of the input handler that would normally do enter/exit stuff. So it did handle the event, but it chose to ignore it, that time.

Viewport also has this method, set_input_as_handled(), which you could call like get_viewport().set_input_as_handled() from within the input method you’re using for enter/exit tree response (within that if(_ignore_mouse) block). So you could try that too, or read up a bit on how input events are propogated (it’s not exactly obvious tbh, worth a read).