Skip to content

Instantly share code, notes, and snippets.

@demoth
Created August 15, 2012 11:23
Show Gist options
  • Save demoth/3359285 to your computer and use it in GitHub Desktop.
Save demoth/3359285 to your computer and use it in GitHub Desktop.
Nifty control trouble
package org.caster.client;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.controls.TextField;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
import org.json.JSONObject;
import java.util.Queue;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by IntelliJ IDEA.
* User: demoth
* Date: 8/13/12
* Time: 3:23 PM
* <p/>
* Draws the model and stores commands from user in 'out'
*/
public class GameEngine extends SimpleApplication {
private Queue<JSONObject> out;
private WorldModel model;
Nifty nifty;
private ScreenController controller;
public GameEngine(Queue<JSONObject> out, WorldModel model) {
this.out = out;
this.model = model;
this.controller = new ScreenController() {
private Nifty nifty;
public void login() {
TextField loginField = this.nifty.getScreen("login").findNiftyControl("login_field", TextField.class);
TextField passwordField = this.nifty.getScreen("login").findNiftyControl("password_field", TextField.class);
System.out.println("login lols");
}
@Override
public void bind(Nifty nifty, Screen screen) {
this.nifty = nifty;
}
@Override
public void onStartScreen() {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onEndScreen() {
//To change body of implemented methods use File | Settings | File Templates.
}
};
}
@Override
public void simpleInitApp() {
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
this.nifty = niftyDisplay.getNifty();
assetManager.registerLocator("/media/f9157386-4243-4142-836c-e97e978bb8ba/media/devel/src/java/client/jCaster/res", FileLocator.class);
nifty.fromXml("gui/gui.xml", "login", controller);
guiViewPort.addProcessor(niftyDisplay);
inputManager.setCursorVisible(true);
flyCam.setEnabled(false);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
<useStyles filename="nifty-default-styles.xml"/>
<useControls filename="nifty-default-controls.xml"/>
<screen id="login">
<layer id="login" childLayout="center">
<panel childLayout="vertical" width="50%">
<panel childLayout="horizontal">
<panel id="labels" childLayout="vertical" width="50%">
<control name="label" text="login"/>
<control name="label" text="password"/>
<control name="label" text="remember"/>
</panel>
<panel id="fields" childLayout="vertical" width="50%">
<control id="login_field" name="textfield" maxLength="20" text=""/>
<control id="password_field" name="textfield" maxLength="20" text="" passwordChar="*"/>
<control id="remember_field" name="checkbox"/>
</panel>
</panel>
<panel childLayout="horizontal">
<control id="login_button" name="button" label="login" visibleToMouse="true">
<interact onClick="login()"/>
</control>
<control id="cancel_button" name="button" label="cancel"/>
</panel>
</panel>
</layer>
</screen>
</nifty>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment