[Nifty] Capturing click --Work around

Hello,



I’ve got a little problem :

I have my GUIs in the frontground and a 3D scene behind.



I’ve mapped my Left click button inside the 3D scene :

[java]

inputManager.addMapping(“LClick”, new MouseButtonTrigger(0)); // Left-button click

[/java]



But I don’t want it to be triggered when I click on an element of one of my gui buttons. Is there a simple way to do that ?

Like :

[java]

|control id=“btnStartBattle” type=“button” … |

|interact onClick=“startBattle()” captureMouseClick=“true” /|

|/control|

[/java]



Or do I need to create a field guiCliked :

[java]

public void startBattle()

{

guiClicked = true;

[…]

}



[…]

public void onAction( String mappedAction, boolean isClicking, float tpf )

{

if( guiCliked )

{

guiCliked = false;

return;

}

guiCliked = false;

[…]

}

[/java]

I think this is not yet supported by the JME3 Nifty InputSystem implementation but Nifty 1.2 notifies the InputSystem implementation if a certain Nifty MouseInputEvent has been processed by Nifty (e.g. it has “hit” a Nifty input element) or if this event could be passed through to the underlying game engine or whatever is “below” a GUI layer.



The Nifty InputSystemJme currently does not use this information as far as I understand it while looking at the code.



Actually this was integrated into Nifty 1.2 because of a special feature request by Kirill :slight_smile: I think there have been some problems to really get this working with the way Nifty currently handles this. Do you want to explain the details a bit more @Momoko_Fan? :slight_smile: I can’t remember it right now to be honest :slight_smile:

Ok, thanks !



I will try to see how it works with Momoko fan :slight_smile:

This is a known issue.



Unfortunately fixing it would be rather hard because I would need to render nifty on input, pass it the inputs, check which ones are used, and then buffer all the draw calls that result from that. You can see that if I buffer up all the draw calls, any changes made to nifty after the input will not be seen until the next frame.



I have two options, either modify the nifty source code so it doesn’t render when I give it the input, or draw nifty twice for each frame, first I give it the input and then ignore all draw calls, and then draw it a second time after user update has passed.



As you can see neither of those options are preferable.

It would be best if the input handling part of nifty can be separated from the drawing/rendering part (and in such way that its possible to make changes to nifty in between).

Ok :slight_smile:



For what I’ve understood there is nothing I can do on my side.

I will stay with this solution for the moment then :



[java]

public abstract class AbstractSheetController implements ScreenController, GameEventListener {

[…]

protected final void interceptClick()

{

SheetManager.guiClick();

}

}





public class SheetManager extends GenericManager {



private static boolean guiClicked = false;



public static void guiClick()

{

guiClicked = true;

}



public static boolean wasGuiClicked()

{

boolean result = guiClicked;

guiClicked = false;

return result;

}

[…]

}



public class GameApplication extends SimpleApplication {

[…]

@Override

public void onAction( String mappedAction, boolean isClicking, float tpf )

{

if( SheetManager.wasGuiClicked() )

return;

[…]

}

}

[/java]

Momoko_Fan said:either modify the nifty source code so it doesn't render when I give it the input...


Filed as a feature request here: https://sourceforge.net/tracker/?func=detail&aid=3126996&group_id=223898&atid=1059825

Shouldn't be that hard to separate this really. Not sure if this will make the jump into 1.3 but I will definetly consider it!