jMonkeyEngine 忽略 Nifty GUI 形式的键盘输入

jMonkeyEngine ignores keyboard input in Nifty GUI form

使用 Nifty GUI 创建了一个游戏登录表单。界面对鼠标的移动和点击做出反应,但忽略文本字段中的输入。程序是否正在寻找点击处理程序,而不是键入,或者我不知道是什么。可能是什么情况以及如何解决?

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() {

    }
}

错误在 XML。没有 id 的交互式界面元素保持静态。大可不必:

<control name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
<control name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>

好吧:

<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"/>

然后字段被激活。