Nifty problems after update to jME3-beta

You can also use the visible to mouse option on the panel. Not sure what the exact method name is though.

@glaucomardano said:
Remove NiftyJmeDisplay from viewport or deactive the "interact" event from your panels. For the second way, first you request the panel element :

[java]
Element panel = screen.findElementById("MyPanelId");
[/java]

Then you can get the "interact" event from the element. I don't remember the exactly name, but you can get it from a getter method in element object.
Also, maybe there's a way to remove the current screen from the NiftyJmeDisplay without removing NiftyJmeDisplay from viewport, but I never tried it before.

I don't know. But it should never work anyway. Jme has itself input system. Nifty has itself too.


I've been allways removing the NiftyJmeDisplay from the viewport in my deactivate method which is clearer than removing/changing the interact of each element or removing a screen which I'll need later. So this should work as is, right? Here is the code, please notice the "guiViewPort.removeProcessor(niftyDisplay);" part ;):

[java]
public void deactivateState()
{
stateManager.detach(this);

if(guiViewPort!=null)
{
guiViewPort.removeProcessor(niftyDisplay);
guiViewPort.setClearFlags(false,false,false);
renderManager.removePostView(guiViewPort);
}

}
[/java]

@ractoc said:
You can also use the visible to mouse option on the panel. Not sure what the exact method name is though.


That's other way, but like changing interacts this has to be done individually for each element because something like screen.getRootElement().setVisibleToMouseEvents(false); doesn't have any effect :S.

Maybe you are doing something wrong with your gui viewports, since you are creating them yourself. I use the gui viewport provided by SimpleApplication. I add my NiftyJmeDisplay to that.

Sorry to bother again, but I changed my code to use the guiViewport of SimpleApplication and, when niftyDisplay is removed from the viewport I’m still getting the same behaviour. As usual I copy here the modified class.



NiftyState1 (using guiViewport from main [SimpleApp]):

[java]

public class NiftyState1 extends AbstractAppState implements ScreenController

{

protected Main main;

protected AppStateManager stateManager;

protected RenderManager renderManager;



private NiftyJmeDisplay niftyDisplay;

private Nifty nifty;

private Screen screen;



@Override

public void initialize(AppStateManager stateManager, Application app)

{

super.initialize(stateManager, app);



main=((Main)app);

niftyDisplay = main.getNiftyDisplay();



renderManager=app.getRenderManager();

this.stateManager=stateManager;



niftyDisplay.getNifty().gotoScreen(“start1”);

main.getGuiViewPort().addProcessor(niftyDisplay);

}



public void deactivateState()

{

stateManager.detach(this);



if(main.getGuiViewPort()!=null)

{

main.getGuiViewPort().removeProcessor(niftyDisplay);

}



}



@Override

public void update(float tpf) {

super.update(tpf);

}



public void bind(Nifty nifty, Screen screen)

{

this.nifty=nifty;

this.screen=screen;

}



public void onStartScreen() {

}



public void onEndScreen() {

}



/**

  • Callback from nifty1 screen

    *
  • Deactivates nifty1 and activates nifty2

    */

    public void nifty1()

    {

    Logger.getLogger("").log(Level.WARNING, "Nifty1 callback - changing to nifty2 screen");

    this.deactivateState();

    NiftyState2 nifty2=(NiftyState2)nifty.getScreen("start2").getScreenController();

    stateManager.attach(nifty2);

    }



    /**
  • Callback from nifty1 screen

    *
  • Deactivates nifty1

    */

    public void nifty1deactivate()

    {

    Logger.getLogger("").log(Level.WARNING, "Nifty1 callback - deactivate");

    this.deactivateState();

    }



    /**
  • Callback from nifty1 screen

    *
  • Deactivates nifty1 and activates other state

    */

    public void nifty1other()

    {

    Logger.getLogger("").log(Level.WARNING, "Nifty1 callback - changing to otherstate screen");

    this.deactivateState();

    stateManager.attach(main.getOtherState());

    }

    }

    [/java]

Maybe you are attaching NiftyJmeDisplay to the gui viewport twice? Because you are calling that in initialize() method of your screen controller-app state at:



[java]

main.getGuiViewPort().addProcessor(niftyDisplay);

[/java]

It’s only called there. Also if I main.getGuiViewPort().getProcessors() after removing it in my deactivate method, I get a list with 0 size. :S

@joliver82 said:
It's only called there. Also if I main.getGuiViewPort().getProcessors() after removing it in my deactivate method, I get a list with 0 size. :S


Lol. It sounds like you don't know what's a "getter" method in java :P. Create a getter method for your NiftyJmeDisplay in your Main application class. Also, make sure you are attaching it only once to the gui viewport.

:? I already have that getter method. The use of main.getGuiViewPort().getProcessors() in the deactivate is just to check if there was only one processor (the niftyDisplay) and that was successfully removed after the call to main.getGuiViewPort().removeProcessor(niftyDisplay). So I assure you that niftyDisplay was only attached once to the gui viewport. Probably I missexplined myself… :stuck_out_tongue:

Hi,

I was just trying to reproduce your issue, and you are really right. I did so



Interact method from my Screen Controller



[java]

public void fuckyeah() {

for (SceneProcessor processor : getApp().getGuiViewPort().getProcessors()) {

if (processor instanceof NiftyJmeDisplay) {

getApp().getGuiViewPort().removeProcessor(processor);

System.out.println("fuckyeah " + processor);

}

}

}

[/java]



My custom control with the interact event



[xml]

<control id=“rhythmTrack” name=“rhythmTrack” height=“20%”>

<interact onClick=“fuckyeah()”/>

</control>

[/xml]



I’ll try to find another solution for this.



EDIT: It does remove the processor, but the nifty events are still there.

-.- -.- -.- -.- -.-.



The solution is more easier than I thought ;P. Just remove the screen from nifty object lol.



[java]

public void fuckyeah() {

System.out.println(";P");

// for (SceneProcessor processor : getApp().getGuiViewPort().getProcessors()) {

// if (processor instanceof NiftyJmeDisplay) {

// getApp().getGuiViewPort().removeProcessor(processor);

// System.out.println("fuckyeah " + processor);

// }

// }

getNifty().removeScreen(“soundEditorScreen”);

}

[/java]



Then just removing the processor does not remove the nifty properly. @ractoc Maybe it’s an issue?

Now I’m using other temporary “solution” instead of getNifty().removeScreen(screenID) I added an empty nifty screen without controller and use getNifty().goToScreen(emptyScreenID) :stuck_out_tongue: although I’d prefer removeProcessor to work properly :wink:

Will you use getNifty().removeScreen(screenID), will you? It works fine.

Hmmm no. Removing the screen is not a solution, because you’ll have to re-add the xml again. Then keep using your temporary solution as you said.

I’ll keep with my goToScreen(empty) workaround. Thanks for all your help and if it’s finally an issue please keep me informed when it’s solved. :wink: