Created a game login form using the Nifty GUI. The interface reacts to the movement and clicking of the mouse, but ignores the input in the text fields. Whether the program is looking for a click handler, instead of typing, or I don’t know what. What could be the case and how to fix it?
Interface/screen.xml:
<?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="start" controller="mygame.LoginScreen">
<layer id="background" childLayout="center">
<image filename="Interface/start-background.jpg"></image>
</layer>
<layer id="foreground" childLayout="center">
<panel id="panel" height="25%" width="75%" align="center" childLayout="horizontal">
<panel id="panel_left" height="100%" width="25%" align="left" childLayout="vertical">
<text text="E-mail:" font="Interface/Fonts/Default.fnt"/>
<text text="Password:" font="Interface/Fonts/Default.fnt"/>
</panel>
<panel id="panel_center" height="100%" width="50%" align="center" childLayout="vertical">
<control name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
<control name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>
</panel>
<panel id="panel_right" height="100%" width="25%" align="right" childLayout="vertical">
</panel>
</panel>
</layer>
</screen>
<screen id="hud" controller="de.lessvoid.nifty.screen.DefaultScreenController">
</screen>
</nifty>
src/mygame/Main.java:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.renderer.RenderManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
public String driver = "org.apache.derby.jdbc.EmbeddedDriver";
public Nifty nifty = null;
@Override
public void simpleInitApp() {
NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
nifty = niftyDisplay.getNifty();
nifty.fromXml("Interface/screen.xml", "start");
guiViewPort.addProcessor(niftyDisplay);
inputManager.beginInput();
flyCam.setDragToRotate(true);
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
nifty.update();
inputManager.update(tpf);
}
}
src/mygame/LoginScreen.java:
package mygame;
import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
public class LoginScreen extends BaseAppState implements ScreenController {
@Override
protected void initialize(Application app) {
}
@Override
protected void cleanup(Application app) {
}
@Override
protected void onEnable() {
}
@Override
protected void onDisable() {
}
@Override
public void update(float tpf) {
}
@Override
public void bind(Nifty nifty, Screen screen) {
}
@Override
public void onStartScreen() {
}
@Override
public void onEndScreen() {
}
}
The error was in XML. Interactive interface elements without an id remain static. Need not so:
<control name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
<control name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>
Well right:
<control id="mail" name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
<control id="password" name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>
Then the fields are activated.