I want to create an inventory on top of a nifty gui window, but for it to work, I need to be able to respond to mouse input. Unfortunately, nifty gui captures the mouse input when the mouse is on top of the window, so any input there won’t get to the code controlling the inventory. I tried setting visibleToMouse to false in the xml file defining the window for the window itself, the panel it’s in, and the component under the inventory, but this had no effect.
Does anyone know how to solve this?
Many thanks in advance.
If it’s not visible to mouse then it won’t block the mouse clicks…
Can you be a bit more explicit about exactly what:
- You are trying to do
- How you did it
- What actually happens.
I am trying to code an inventory: For that, I attach some pictures representing items to the guiNode.
I use nifty GUI for the rest of the HUD, including the background of the inventory.
For responding to mouse input, I use the inputManager to check for clicks, and nifty.getNiftyMouse() to check the location of the mouse. For now, I only respond to mouse input by a System.out.println showing the location of the mouse, and wether it was pressed or released.
This works fine when the mouse isn’t on top of anything of nifty gui, but when the mouse is on top of a nifty gui component, it doesn’t respond to clicks, even tough the inventory background has visibleToMouse set to false in the xml file.
You can get the mouse position directly from jme rather than going through nifty - although I don’t know why that wouldn’t work.
Have you confirmed that every part of the nifty panel has neither visible to mouse (at every level of the hierarchy) nor interactive stuff (including mouse over effects) ?
Except for 2 buttons, the nifty window and all it’s parents and children have visibleToMouse set to false. I have tried to comment out the buttons, but it didn’t change anything (except for making the buttons dissapear offcourse).
As a test, remove the gui entirely, and then add it back one element at a time until you reproduce the problem. See what is special about that element.
I’ve never seen the symptoms you are seeing (but I use mouse picking in scene as per the mouse picking tutorial) rather than picking against the gui node.
It seems to be the window that makes the mouse not work. I have put it in the xml file like this:
[java]<control name=“window” id=“inventory” title=“Inventory” width=“150px” height=“300px” align=“right” valign=“bottom” closeable=“false” visibleToMouse=“false”>
Even though visibleToMoust is set to false, the window is still draggable.
EDIT: It is a bit unrelated, but does anyone know how to change the location of nifty gui windown trough a controller class?
I found out that mouse events can get trough to the app if I temporarly disable the window. I can always do that when the mouse is in a location where the app and not nifty gui should recieve the input.
But to do this correctly, I need to be able to get and set the location of nifty gui windows on the screen. Does anyone know how this can be done? I googled for it, but I really can’t find it.
Honestly I can’t help on that as I’ve never used the windows in Nifty. There may be something in the settings of the control? It could be as simple as setting the x and y position of the control.