The book says:
"We began by creating a new class called LoadingScreenController that extends the Controller class. We
define two Strings: loadingText and loadingScreen. And create setters for these as well. Next we override the onStartScreen() method and add the following three lines of code:
screen.findElementByName("centralPanel").getRenderer(ImageRenderer.class).setImage(nifty.createImage(loadingScreen, true));
screen.findElementByName("loadingPanel").setVisible(true);
The book says:
"First we need to add the screen to Nifty. If we have the NiftyAppState method from the previous recipe, we should add the following line just after the nifty.fromXml
call:
nifty.addXml("Interface/Screens/loadingScreen.xml");
"We can also add a convenience
class to access nifty.gotoScreen()
The book says:
"Before calling gotoScreen("loadingScreen")
from our main class, we can add the following lines to set loadingText
and loadingImage
…Now where do I put this code at??? I’m Confused from what the book is telling me…
((LoadingScreenController)niftyState.getNifty().getScreen("loadingScreen").getScreenController()).setLoadingText("Loading Test Scene");((LoadingScreenController)niftyState.getNifty().getScreen("loadingScreen").getScreenController()).setLoadingImage("Interface/loadingScreen.png");
Now here is my code for LoadingScreenController class:
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;
import java.io.IOException;
import de.lessvoid.nifty.elements.render.ImageRenderer;
import de.lessvoid.nifty.controls.Label;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.Nifty;
public class LoadingScreenController extends Controller { //error LoadingScreenController not abstract
public void onStartScreen(Screen screen, Nifty nifty, String loadingText, String loadingScreen) {
screen.findNiftyControl("caption", Label.class).setText(loadingText);
screen.findElementByName("centralPanel").getRenderer(ImageRenderer.class)
.setImage(nifty.createImage(loadingScreen, true));
screen.findElementByName("loadingPanel").setVisible(true);
}
}
Controller class…
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.controls.Console;
import de.lessvoid.nifty.screen.ScreenController;
abstract public class Controller extends SimpleApplication implements ScreenController {
protected NiftyJmeDisplay niftDisplay;
protected Screen screen;
Nifty nifty;
Console console;
boolean optionsMenuVisible = false;
public static void main(String[] args){
}
@Override
public void bind(Nifty nifty, Screen screen) {
System.out.println("bind( " + screen.getScreenId() + ")");
nifty.getCurrentScreen().findElementById("");
nifty.getScreen("main").findNiftyControl("console", Console.class);
}
public void outputToConsole(String input){
console.output(input);
}
public void toggleConsole(){
console.getElement().hide();
//page 339
}
public void onConsoleCommand(final String id){
//page 339
}
public void toggleOptionsMenu(){
nifty.gotoScreen("options");
optionsMenuVisible=true;
}
@Override
public void onStartScreen() {
System.out.println("onStartScreen");
}
@Override
public void onEndScreen() {
System.out.println("onEndScreen");
}
public void quit(Controller app){
app.stop();
}
}
And lastly my NiftyAppState class…
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.asset.AssetManager;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import de.lessvoid.nifty.screen.ScreenController;
import de.lessvoid.nifty.Nifty;
import com.jme3.renderer.ViewPort;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.controls.Parameters;
import com.jme3.input.InputManager;
import com.jme3.audio.AudioRenderer;
public class NiftyAppState extends AbstractAppState implements ActionListener {
private Nifty nifty;
private NiftyJmeDisplay niftDisplay;
private InputManager inputManager;
private AssetManager assetManager;
private ViewPort guiViewPort;
private AudioRenderer audioRenderer;
public static void main(String[]args){
}
public void simpleInitApp() {
niftDisplay = new NiftyJmeDisplay(assetManager,
inputManager,
audioRenderer,
guiViewPort);
nifty = niftDisplay.getNifty();
nifty.loadStyleFile("nifty-default-styles.xml");
nifty.loadControlFile("nifty-default-controls.xml");
nifty.fromXml("Interface/optionsmenu.xml","start");
nifty.addXml("Interface/loadingScreen.xml");
guiViewPort.addProcessor(niftDisplay);
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
app.getAssetManager(), app.getInputManager(), app.getAudioRenderer(),
app.getRenderManager().getPostView("Gui Default"));
app.getRenderManager().getPostView("Gui Default")
.addProcessor(niftyDisplay);
app.getInputManager().deleteMapping(SimpleApplication.INPUT_MAPPING_EXIT);
app.getInputManager().addMapping("TOGGLE_OPTIONS", new KeyTrigger
(KeyInput.KEY_ESCAPE));
app.getInputManager().addListener(this, "TOGGLE_OPTIONS");
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
}
public void onAction(String name, boolean isPressed, float tpf){
if(name.equals("TOGGLE_OPTIONS") && isPressed){
((Controller)nifty.getCurrentScreen().getScreenController())
.toggleOptionsMenu();
}
}
}
Help me put this in order