Nifty Window not accepting input after clicking into the scene

It is indeed ugly but if it works it can be a temporary workaround.

I will test it this evening but I hope that more elegant solution to this bug will be found.

Yes you are right, the solution in ‘update’ sounds ugly and no elegant, but meanwhile nobody else make a solution… it is fine.

well… I tried this solution in the “NiftyGuiDemo”, and I added only 2 lines in the simpleInitApp:



[java]inputManager.addMapping(“FLYCAM_RotateDrag”, new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));

inputManager.addMapping(“FLYCAM_RotateDrag”, new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));[/java]



and the last one in update:

[java]inputManager.deleteTrigger(“FLYCAM_RotateDrag”, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));[/java]



and finally, I remember that somebody generated a ticket for this bug, but it was more than one year ago, so far no one has solved

Are you talking about this issue report?

http://code.google.com/p/jmonkeyengine/issues/detail?id=500

no, it was another one. let me find it and I will post it

ok I found it.

http://sourceforge.net/tracker/?func=detail&aid=3407350&group_id=223898&atid=1059825



I guess this is the same. but this one says 2011-09-10. and your link May-2012. mmmm rare

@davidbt: Why is the issue on the nifty tracker if the issue only happens in jME3? This is something that needs to be fixed on the jME3 side, not Nifty side.

actually, I did not create this ticket, or I did not ask to be created this for someone.

I was just looking for a solution to the problem and found that.

please @Momoko_Fan if you have some time and can check my topic that I started http://hub.jmonkeyengine.org/groups/gui/forum/topic/nifty-gui-listbox-with-a-controlbuilder-textfield-problem/





thank you in advance

@davidbt said:
I was just looking for a solution to the problem and found that.

I noticed that one of the fixes mentioned included changing the drag button. Does this indicate the issue happens with the disappearance of the cursor when the mouse is dragged (to rotate the camera)? If so, then this issue does not have to do with jME3, but with the camera configuration. jME3 by default does not pass mouse events to nifty if the cursor isn't visible.

@davidbt said:
please @Momoko_Fan if you have some time and can check my topic that I started http://hub.jmonkeyengine.org/groups/gui/forum/topic/nifty-gui-listbox-with-a-controlbuilder-textfield-problem/

I am afraid I lack experience with nifty gui to help you with your problem.

@Momoko_Fan Is there a mouse event queue for SimpleApplication? Just throwing this into the wind, I think this might be solved by giving niftygui the chance to “bubble-up” its control events first in precedence, this may solve this issue!? :?

Ok, besides the solution presented, I messed around a little and found this a tad useful when you declare a left mouse button event:

[java]

ActionListener actionListener = new ActionListener()

{

public void onAction(String name, boolean keypressed, float tpf)

{

if (name.equals("whatever"))

{

niftyDisplay.getNifty().gotoScreen("PlayerScreen");

niftyDisplay.getNifty().resetMouseInputEvents();

}

}

}

[/java]

Its a little sluggish but it does the job. I nested this inside the niftygui build. Let me know if anyone wants the full implementation.

Does anyone have news on this issue?

@peacemaker said:
Does anyone have news on this issue?

The issue is still in the tracker. If someone posts a patch, we can apply it and fix the issue.

is there any solution for this issue?

Please check my answer that I did 2 months ago.

I did a temportal solution for this problem

ok, thx . btw why not just add

[java]inputManager.deleteTrigger("FLYCAM_RotateDrag", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); [/java]

in simpleinitApp?



what these code function in your solution ?

[java]

inputManager.addMapping(“FLYCAM_RotateDrag”, new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));

inputManager.addMapping(“FLYCAM_RotateDrag”, new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));

[/java]

I’d like to collaborate to solve this problem that I have been suffering some days as well.



As mentioned above, the problem comes from the invisibility of the mouse in the dragging, that is set in ChaseCamera class. This problem is indeed not related with niftygui at all.



In InputSystemJme.java we find



[java]public void onMouseButtonEvent(MouseButtonEvent evt) {

if (inputManager.isCursorVisible() && evt.getButtonIndex() >= 0 && evt.getButtonIndex() <= 2) {

inputQueue.add(evt);

}

}

[/java]



That code usually generates two events, clicked and released, for every click.



But when you drag in ChaseCamera, you first click, then you makes the mouse invisible, you release the button, and, just at this moment, the release button has the mouse invisibilized yet, so in this code, there is not queued event with the release button.



So, internally, button is still pressed. Why is niftygui not working if I can click and release over a button?



Unless you are playing over a tablet, for clicking over a button, you have to arrive there with the mouse. The last event that is processed just before you click the button, is arriving at that possition with the mouse AND REMEMBER, YOU ARE STILL PUSHING THE BUTTON (internally, of course).



When you click over the button, this code is in the chain of calls (from MouseInputEventProcessor.java)



[java]public boolean canProcess(final NiftyMouseInputEvent mouseEvent) {

hadAnyEvents = true;



int mouseX = mouseEvent.getMouseX();

int mouseY = mouseEvent.getMouseY();

int mouseWheel = mouseEvent.getMouseWheel();

boolean button0Down = mouseEvent.isButton0Down();

boolean button1Down = mouseEvent.isButton1Down();

boolean button2Down = mouseEvent.isButton2Down();



if (mouseX != lastMouseX ||

mouseY != lastMouseY ||

mouseWheel != 0 ||

button0Down != lastButtonDown0 ||

button1Down != lastButtonDown1 ||

button2Down != lastButtonDown2) {

return true;

}



return false;

}[/java]



As the last event processed was exactly similar to the clicking you just made with the mouse (same x, y, wheel, and button), the processing is skipped.



GUESSING MODE ON

Then the event reaches the next listener, the chasecam, processes the mouse, hides the pointer, and you can play with that a while, as long as you have the mouse clicked

GUESSING MODE OFF



Once again, you release the button, the mouse is yet invisible, no release event populated, and start again.



Solution?



I can’t say yet, I’ve been working with this framework for only a month, and this is the first night I try to solve this problem. I am amazed I got this far!



The easiest way, if you cannot or you don’t want to download and modify jMonkeyEngine, is to change the behavior of ChaseCamera by extending it.



Create a class like this in your project, and use it instead ChaseCamera:



[java]

package com.navid.trafalgar.camera;



import com.jme3.input.InputManager;

import com.jme3.renderer.Camera;

import com.jme3.scene.Node;



/**

*

  • @author anavarro

    */

    public class ChaseCamera extends com.jme3.input.ChaseCamera{



    public ChaseCamera(Camera camera, Node target){

    super(camera, target);

    }



    public ChaseCamera(Camera camera, Node target, InputManager inputManager) {

    super(camera, target, inputManager);

    }



    @Override

    public void onAction(String name, boolean keyPressed, float tpf) {

    if (dragToRotate) {

    if (name.equals(ChaseCamToggleRotate) && enabled) {

    if (keyPressed) {

    canRotate = true;

    } else {

    canRotate = false;

    }

    }

    }



    }



    }

    [/java]



    Please notice that “inputManager.setCursorVisible(false); and (true)” are removed from the original version. The mouse will always be visible in dragging operations with ChaseCamera. That’s the easiest solution if you don’t want or don’t know how to mess inside the engine. It’s my case, I don’t dare to modify anything, only God knows the consequences of every little act in there :stuck_out_tongue:



    I’m glad if anybody finds this information useful, and remember, my project needs help :slight_smile:



    Alberto
2 Likes

Wow! Thanks for finding this!



I could add a “hideCursorOnRotate” flag on the ChaseCam…

It’s already bloated anyway…

I committed a patch

you can now use chaseCam.setHideCursorOnRotate(false) to avoid the issue.

1 Like

If you make it optional, people will continue having the same problem, maybe the optional one should be making the mouse invisible, and letting the mouse visible by default, avoiding the bug, but yet a workaround.



Anyway, the fixing for me is more related with the “released” event of dragging, it is filtered because the mouse is invisible and it shouldn’t.



Thanks for your prompty response!

1 Like

well, I can see this is fixed when you want to use a ‘chasecam’. but if I’m using a ‘flycam’? I didn’t find the ‘setHideCursosOnRotate’, please #nehon try to fix it too.

Thank you.