1

Good morning! I'm trying Nifty Gui with Slick2d. Everything works correct besides input polling by Nifty Gui. It doen't react at all! Here is part of my code:

Xml:

<nifty xmlns="http://nifty-gui.lessvoid.com/nifty-gui">
    <screen id="GamePlay" controller="GamePlayScreenController">
        <layer childLayout="vertical">
            <panel id="roomListPanel" width="100%" height="32px" 
            childLayout="absolute-inside" padding="5px">

                <control id="appendButton" name="button" label="Pause">
            <interact onClick="test()" />       
        </control>
            </panel>
        </layer>
    </screen>
</nifty>

Java:

class GamePlayScreenController implements ScreenController {
    public void bind(Nifty nifty, Screen screen) {
        System.out.println("Bind");
    }

    public void onEndScreen() {
        System.out.println("End");
    }

    public void onStartScreen() {
        System.out.println("Start");
    }

    public void test() {
        System.out.println("Test");
    }
}

... 

// In my state class:

this.nifty = new Nifty(new LwjglRenderDevice(), new NullSoundDevice(),       new LwjglInputSystem(), new TimeProvider());

this.nifty.loadStyleFile("nifty-default-styles.xml");
this.nifty.loadControlFile("nifty-default-controls.xml");
this.nifty.registerScreenController(new GamePlayScreenController());
this.nifty.fromXml("data/test.xml", "GamePlay");
this.nifty.gotoScreen("GamePlay");

...

this.nifty.update();

... 

SlickCallable.enterSafeBlock();
this.nifty.render(false);
SlickCallable.leaveSafeBlock();

I have no ideas, why it doesn't. Please, help! Thanks!

2 Answers2

0

Did you call the startup() method at all on then LwjglInputSystem? We have example code available here on how that is meant to be called. This is necessary to init the LwjglInputSystem properly.

However, why don't you use the ready made Slick2d integration classes we offer here: Slick2d Nifty-GUI classes? They might be better suited to easily integrate Nifty GUI with Slick2d instead of relying on LWJGL directly.

void256
  • 1,286
  • 10
  • 11
  • Thanks, but your solution didn't work. Yep, i have tryed Nifty + Slick 2d states, but they didn't help me. Thanks for you answer! –  Sep 26 '16 at 10:59
0

This should work for you:

    protected void initGameAndGUI(GameContainer arg0, StateBasedGame arg1) {

    LwjglInputSystem inputSystem = new LwjglInputSystem();

    try {
        inputSystem.startup();
    } catch (Exception e) {
        e.printStackTrace();
    }           
    PlainSlickInputSystem psis = new PlainSlickInputSystem();
    GameClient.app.getInput().addListener(psis);    

    prepareNifty(nifty, arg1);
    nifty = new Nifty(new LwjglRenderDevice(), new NullSoundDevice(),psis, new AccurateTimeProvider());
    NullSoundDevice(),psis, new AccurateTimeProvider());    
    initNifty(arg0, arg1, psis);    
    nifty.fromXml("...");

}

and ofcourse

nifty.update();

in your update method.

I was using Slick2d Nifty integration.

LOLWTFasdasd asdad
  • 2,625
  • 5
  • 26
  • 39