Keypad Fail… HELP!

Hey guys,

I can’t seem to figure out why i don’t see my button along with my text field on the same panel. I want to create a keypad but it’s not working. Also I want to set a custom style just for these types of GUI’s in my game, how would I do so? I want my keypad to look something like Deus Ex Human Revolution’s.



Here is my keypad Code

[java] public void addGUI(Nifty nifty, final Player P)

{

String current = nifty.getCurrentScreen().getScreenId();

// <screen>

nifty.addScreen(“KEY”, new ScreenBuilder(“KEY”) {

{

controller(new KeyPadController(P, “1234”)); // Screen properties

// <layer>

layer(new LayerBuilder(“KeyPad”) {

{



childLayoutCenter(); // layer properties, add more…

// <panel>

panel(new PanelBuilder(“KeyPad”) {

{

style(“nifty-panel”);

childLayoutCenter();

// panel properties, add more…

height(“50%”);

width(“30%”);

x(“250px”); // this doesn’t seem to do anything

control(new TextFieldBuilder(“KEYENTRY”){

{

valignTop();

alignCenter();

passwordChar(’#’);

}

});



control(new ButtonBuilder(“ONE”, “1”){

{

valignTop();

alignLeft();

width(“50%”);

height(“50%”);



visible(true);

visibleToMouse(true);

}

});

//… add more GUI elements here



}

});

// </panel>



//Hint panel

panel(new PanelBuilder(“Hint”){

{

style(“nifty-panel-red”);

childLayoutCenter();

alignRight();

valignCenter();

width(“10%”);

height(“10%”);

}

});

}

});

// </layer>

}

}.build(nifty));

// </screen>

nifty.gotoScreen(“KEY”);

}[/java]

Thanks

Bump^

childLayoutCenter probably isn’t helping :slight_smile:

Thanks! That fixed it. Now I would like to know how do I change the style for Nifty from the java code? I have a custom style that I want to use. But I can’t seem to find a place where I can [java]nifty.setStyle(“Interface/Styles/Keypad.xml”);[/java]. Where am I supposed to set the Style?

The Nifty object provides a registerStyle(StyleType) method - maybe that’s what you’re searchin for?

Your nifty code does just what I do expect it should do. Maybe your childLayout-problem is a version problem.



Anyway I would recommend to load your custom style via ‘nifty.load(‘directionToYourXML’)’ as that is the normal way to load a custom style.

Nifty 1.3.2 is out. Have a look at page 101.

Manual.