Nifty GUI - Fallen at second hurdle!

Hi guys,



So I ran through the tutorial and all is good. I had to use a font from a previous project, but no problems with displaying a box on screen.



But when I try to do anything else, it doesn’t work! I’ve tried using the panel “style”… No good. And also the window-3. Nothing seems to work. I’ve attached the XML and code. I know it’s using the XML file. The text does appear, but nothing surrounds it :frowning:



Hope you can help!



XML:

[xml]

<?xml version=“1.0” encoding=“UTF-8”?>

<nifty xmlns=“http://nifty-gui.sourceforge.net/nifty.xsd

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance

xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty.xsd”>

<screen id=“start” controller=“com.lonedev.sandbox.jme.Test1”>

<layer id=“layer” childLayout=“absolute”>

<control id=“window-3” name=“window” title=“Please Drag Me Too!” width=“500px” height=“400px” x=“400px”>

<text text=“I’m Freddy Window!” font=“battlefield16.fnt” color="#eeef" valign=“center” width=“100%” /> -->

</control>

<!–

<panel style=“nifty-panel-red” height=“25%” width=“25%” align=“center” valign=“center” childLayout=“center” visibleToMouse=“true”>

<text font=“battlefield16.fnt” text=“Hello World!” align=“center” valign=“center” />

<interact onClick=“sayHello(hi)”/>

</panel>

–>

</layer>

</screen>

</nifty>

[/xml]



Java:

[java]

package com.lonedev.sandbox.jme;



import com.jme3.app.SimpleApplication;

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.screen.ScreenController;

import java.util.logging.Level;

import java.util.logging.Logger;



/**

*

  • @author Richard

    */

    public class Test1 extends SimpleApplication implements ScreenController {

    private Nifty nifty;

    private Logger logger = Logger.getLogger(Test1.class.getName());



    public static void main(String[] args){

    Test1 app = new Test1();

    app.setPauseOnLostFocus(false);

    app.start();

    }



    @Override

    public void simpleInitApp() {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    Geometry geom = new Geometry("Box", b);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));

    geom.setMaterial(mat);

    rootNode.attachChild(geom);



    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);

    nifty = niftyDisplay.getNifty();



    nifty.fromXml("HelloWorld.xml", "start", this);



    // attach the nifty display to the gui view port as a processor

    guiViewPort.addProcessor(niftyDisplay);



    // disable the fly cam

    // flyCam.setEnabled(false);

    flyCam.setDragToRotate(true);

    }



    @Override

    public void bind(Nifty nifty, Screen screen) {

    logger.log(Level.INFO, "bind( " + screen.getScreenId() + ")");

    }



    @Override

    public void onStartScreen() {

    logger.log(Level.INFO, "onStartScreen");

    }



    @Override

    public void onEndScreen() {

    logger.log(Level.INFO, "onEndScreen");

    }



    public void quit(){

    nifty.gotoScreen("end");

    }



    public void sayHello(String myarg) {

    logger.log(Level.INFO, "Nifty says "+myarg);

    }

    }

    [/java]

Add this at the top of your xml, right below the open tag:

[xml]

<useStyles filename="nifty-default-styles.xml" />

<useControls filename="nifty-default-controls.xml" />

[/xml]



It gives you the nifty styles and the nifty default controls. Both need their own Jar as well, but those should be availlable with JME3.

You the man !!