Issue 211 - NiftyGui does not consume input events

Hi.

I’m just wondering if there is an eta for this problem, as it’s probably my biggest gripe at the moment, and seriously impacts the user experience.

(To clarify: When clicking a nifty gui element, the player also clicks on the ground behind it, sometimes leading to unexpected results)



Is there a work around i can implement, or can i help out in any way?

Because the other 210 issues still needs to be taken care of there is no ETA for Nifty 1.3 available yet… I’m still confident for an “early” 2011 release tho.



A workaround is currently difficult. What might work, is to manually ask Nifty if the mouse currently hovers any element at all. Nifty has this information inside. I could make this information public available but that would require that a) you’re using an (probably) instable 1.3 nightly build and b) that you can make use of this information to workaround the issue.



Should I add it? Would that help?

I’m already using 1.3, so that would probably work.

You’re saying i would call nifty.isMouseInsideElement() or something similar from my input manager? Sounds like it would be a fairly simple solution that would work for me.



I think it would help me a lot, actually.



Thanks.

I’ve just commited the following change to 1.3 SVN:



[java]@public

two additional methods added to the Screen to check for mouse hovering any elements:



/**

  • Checks if the mouse currently hovers any element that is able to handle mouse events.

    *
  • @return true if the mouse hovers an element that is visibleToMouse and
  •     false if the mouse would hit the background and not any element at all<br />
    

*/

public boolean isMouseOverElement() {

return mouseOverHandler.hitsElement();

}



/**

  • This returns an informational String containing all elements that Nifty is aware of that
  • could handle mouse events with the ones currently hovering the mouse sorted from top to
  • bottom.
  • @return String for debug output purpose

    */

    public String getMouseOverInfoString() {

    return mouseOverHandler.getInfoString();

    }[/java]



    which should help.



    There is another problem however :slight_smile:



    I’ve commited another change this afternoon:



    [java]@public

    #3126996: Seperate Input-Processing from Rendering Nifty

    Attention: You’ll need to call update() AND render() now. Just calling

    render() is not enough. InputSystem processing is now called in update()

    and separated from rendering.[/java]



    which means Momoko_Fan can now change the JME3 Nifty Renderer to better handle input events that Nifty already handled. This way he should be able to detect all of the events that Nifty processed and he might stop forwarding these events to your application.



    The problem is, that this requires another call to Nifty. Instead of nifty.render() you’ll need a nifty.update() call before. This should all be handled inside the JME3 Nifty Renderer Adapter and you usually don’t need to care about this. But as the time of this writing the JME3 Renderer has probably not been updated to the latest 1.3 Nifty. So, I’m pretty sure the current 1.3 SVN Head is not compatible with JME3 at the moment.



    I think this will change soon but at the moment this is the situation.
1 Like

Sweet. I’ll see how/if it works tomorrow, otherwise i’ll wait until jme gets updated.

With the separation of update/render, I was able to add this feature to my build and it seems to work okay.



For some reason I had to download a library called “eventbus” since it seems the Nifty class uses the “EventServiceExistsException” class from it …



I still have a few minor issues which I am working on resolving atm

Thanks Momoko_Fan and sorry that I’ve forgot to mention the new eventbus library! It’s required for 1.3 and it will be used for all Notifications of things like text of a textfield is changed, listbox selection changed and so on. It’s using a simple publish/subscribe mechanism that decouples event sources (like the new 1.3 Nifty standard controls) from the event receivers like your Nifty application.



I’ve created a special Nifty Annotation for this that makes listening to the events pretty easy too. Here is an example to listen to text on a textfield changed:



[java]@NiftyEventSubscriber(id=“textFieldId”)

public void onTextFieldChanged(final String id, final TextFieldChangedEvent event) {

System.out.println(“textField [” + id + “] changed. New text [” + event.getText() + “]”);

}[/java]



I’ll blog about this soon and the Nifty wiki will be updated accordingly. Stay tuned :slight_smile:

Hey!

Just checking in to see if there’s been any progress on this.

I’ve tried implementing it myself, but after getting rid of the exceptions, i was greeted by a white screen. So i must be missing something.

Thanks

No progress, we agreed to wait for Nifty 1.3 official release before fixing it.

Hi guys,
I am also having the same problem. Mouse events are propogating below the nifty gui hud in game. I am using the latest stable version. Do I require nightly build for this?
Thanks.

did you set the visibleToMouse flag to true for those elements?

Yes, the lowest element is an
and it has the tag. which indicates that it is visible to Mouse.
Also I have defined an onMouseOver event for it., and I am returning false from that method implementation.
Still, the mouseevent goes below the nifty gui and into the game.

Note: the earlier post is not displaying the tags… Putting it again with quotes

Yes, the lowest element is an “image”
and it has the tag “interact”. which indicates that it is visible to Mouse.
Also I have defined an onMouseOver event for it., and I am returning false from that method implementation.
Still, the mouseevent goes below the nifty gui and into the game.

All I can say is I use nifty all the time and never have this problem. Make sure your visibleToMouse element is the size and position you think it is - give it a green background or something.

Hi, Now I tried with an simple screen, still mouse event is propogating to the game below.
Code used is as below:

<!-- +++++++++++++++++++++++++++++++++++++++ -->
<!-- start screen -->
<!-- +++++++++++++++++++++++++++++++++++++++ -->

Removing tags, reply not supporting tags :frowning:

#screen id=“start” controller=“com.tigdum.tilism.client.controls.TilismScreenController”#
#layer childLayout=“vertical”#
#panel height=“40%”/#
#panel height=“20%” width=“100%” backgroundColor="#ffff" childLayout=“absolute” visibleToMouse=“true”/#
#panel height=“40%”/#
#/layer#
#/screen#

Looks ok. So you click on the white bar and the click goes through to the scene below?

Just to be clear. You are running jME RC2 and have updated to the latest stable? If so, make a simple testcase with code and xml and we can have a look at it

Yes, its going below the white. Also I am having an AnalogListener for Jme, which listens to the mouse Axis. That Listener is getting these events. and also click event, which is an ActionListener.

Yea, I am using JME3 RC Stable updated version, The screen code is same as above, Will put the Game MouseListener code as I reach Home, Thanks