Hi!
I’m learning to use Nifty to make a good GUI for my game.
I have a little command line area that you can show by pressing the TAB button. So, it’s all OK (the area is displayed correctly) but the problem is: how can I send the text in the cmd line textfield to the game?
The Nifty XML is:
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.lessvoid.com/nifty-gui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd">
<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<screen id="cmd" controller="mygame.appstates.main.MenuAppState">
<layer id="layer" backgroundColor="#0000" childLayout="center">
<panel id="panel" height="3%" width="100%" align="center" valign="bottom" backgroundColor="#fff1" childLayout="center" visibleToMouse="true">
<control name="textfield" text="Enter Command">
</control>
</panel>
</layer>
</screen>
</nifty>
Nifty initialization:
private NiftyJmeDisplay niftyDisplay;
protected void prepareNifty(){
niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, app.getAudioRenderer(), guiViewPort);
nifty = niftyDisplay.getNifty();
nifty.fromXml("Interface/NiftyGUI/cmd.xml", "cmd", this);
}
Nifty attach (in the update()
method):
if(niftyDisplay != null){
if(consoleOpened){
guiViewPort.addProcessor(niftyDisplay);
} else {
guiViewPort.removeProcessor(niftyDisplay);
}
}
I also followed the jme Nifty guide (https://jmonkeyengine.github.io/wiki/jme3/advanced/nifty_gui.html)
And also: TextField · nifty-gui/nifty-gui Wiki · GitHub
But it didn’t help me.
Thank you!