Slick2d/Nifty-gui input

Posted by eerongal on Game Development See other posts from Game Development or by eerongal
Published on 2012-12-08T18:24:03Z Indexed on 2012/12/08 23:38 UTC
Read the original article Hit count: 456

Filed under:
|
|

I'm trying to get input from slick2d into nifty gui. Ive searched online, and I've seen a few examples, but I can't seem to get it working right.

i've tried the example on here but I can't seem to get everything working. I'm not entirely sure what I'm doing wrong.

I've also looked at examples using the JMonkeyEngine to help point me in the right direction, but still having issues with input. I can get everything else working like i need.

Here's the code for my element controller:

package gui;

import java.util.Properties;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.controls.Controller;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.input.NiftyInputEvent;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.xml.xpp3.Attributes;

public class BaseElementController implements Controller {

private Element element;

public void bind(Nifty arg0, Screen arg1, Element arg2, Properties arg3,
        Attributes arg4) {
    this.element = element;

}

public void init(Properties arg0, Attributes arg1) {
    // TODO Auto-generated method stub

}

public boolean inputEvent(NiftyInputEvent arg0) {
    // TODO Auto-generated method stub
    return false;
}

public void onFocus(boolean arg0) {
    // TODO Auto-generated method stub

}

public void onStartScreen() {
    // TODO Auto-generated method stub

}

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

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

}

Here's my XML file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<nifty>
  <useStyles filename="nifty-default-styles.xml"/>
  <useControls filename="nifty-default-controls.xml"/>
  <screen id="screen2" controller="gui.BaseScreenController">
    <layer backgroundColor="#fff0" childLayout="absolute" id="layer4" controller="gui.BaseElementController">
  <panel childLayout="center" height="30%" id="panel1" style="nifty-panel-simple" width="50%" x="282" y="334" controller="gui.BaseElementController">
    <control id="checkbox1" name="checkbox"/>
    <control childLayout="center" id="button2" label="button2" name="button" x="381" y="224" visibleToMouse="true" controller="gui.BaseElementController">
        <interact onClick="bam()"/>
    </control>
  </panel>
  <text text="${CALL.getPlayerName()}" style="nifty-label" width="100%" height="100%"  x="0" y="10" />
</layer>
  </screen>
</nifty>

Here's how I'm trying to bind the controller:

public void init(GameContainer gc) throws SlickException {
    Input input = gc.getInput();
    inputSystem = new PlainSlickInputSystem();
    inputSystem.setInput(input);


    gui = new Gui();

    gui.init(gc, inputSystem, "gui/tset.xml", "screen2");

    input.removeListener(this);
    input.removeListener(inputSystem);
    input.addListener(inputSystem);
}

Essentially, all that happens right now is the screen loads up and displays, and it grabs the variable correctly in the label, but none of the input seems to be getting forwarded to Nifty from slick. I assume there's something I'm missing, but I can't seem to figure out what that is.

In so far as what I have tried, I attempted to define a custom input listener to pick up events and assign that to my game in order to pick up input, which did not work, so i dropped that implementation, at current i'm trying to take the default inputs and bind then with a PlainSlickInputSystem and assigning that to the input (as shown in the first example link).

On code execution, all the code is hit, and i've put several system.out.println's to get ouput of what is happening (the code above has been cleaned for presentation), and i even see the elements getting bound to the controller, yet it doesn't pick up controller events. As far as EXACTLY what's wrong, that I don't know, because I've followed all implementations i can find of this, and none of them seem to do anything it's like the input is just getting thrown out.

None of the objects from niftyGui appear to be recognizing any input. Here is the binding from my objects at run time:

******INITIALIZED SCREEN: de.lessvoid.nifty.screen.Screen@4a1ab1c1
******INITIALIZED ELEMENT: button2 (de.lessvoid.nifty.elements.Element@1e8c1be9)
******INITIALIZED ELEMENT: focusable => true, width => 100px {nifty-button#panel}, backgroundImage => button/button.png {nifty-button#panel}, label => button2, paddingLeft => 7px {nifty-button#panel}, imageMode => sprite-resize:100,23,0,2,96,2,2,2,96,2,19,2,96,2,2 {nifty-button#panel}, paddingRight => 7px {nifty-button#panel}, id => button2, visibleToMouse => true, height => 23px {nifty-button#panel}, style => nifty-button, name => button, inputMapping => de.lessvoid.nifty.input.mapping.MenuInputMapping, childLayout => center, controller => gui.BaseElementController, y => 224, x => 381
******INITIALIZED SCREEN: de.lessvoid.nifty.screen.Screen@4a1ab1c1
******INITIALIZED ELEMENT: panel1 (de.lessvoid.nifty.elements.Element@373ec894)
******INITIALIZED ELEMENT: id => panel1, height => 30%, style => nifty-panel-simple, width => 50%, backgroundImage => panel/nifty-panel-simple.png {nifty-panel-simple}, controller => gui.BaseElementController, childLayout => center, padding => 5px {nifty-panel-simple}, imageMode => resize:9,2,9,9,9,2,9,2,9,2,9,9 {nifty-panel-simple}, y => 334, x => 282
******INITIALIZED SCREEN: de.lessvoid.nifty.screen.Screen@4a1ab1c1
******INITIALIZED ELEMENT: layer4 (de.lessvoid.nifty.elements.Element@6427d489)
******INITIALIZED ELEMENT: id => layer4, backgroundColor => #fff0, controller => gui.BaseElementController, childLayout => absolute

the button2 object is getting bound to my BaseElementController, but i can't seem to get it into the defined "onClick" call.

© Game Development or respective owner

Related posts about java

Related posts about slick2d