[Nifty] A begginer needs help --Solved

Hi!

I’m new to this forum and I just discovered the JMonkey Engine and Nifty.



I’m triying to port my project which originally used

  • Java3D for 3D scene
  • Swing for GUI

    to a solution with
  • JMonkeyEngine for 3D scene
  • Nifty for GUI



    With JMonkeyEngine tutorials, I think I will be able to manage the 3D scene part ( at least I hope 0



    But for Nifty… I’ve retrieved the HelloWorld.xml and tried to do the tutorial.



    … After a couple of tries, It nearly worked but …



    There is an issue with :

    [xml]

    <text font="verdana-24-shadow.fnt" text="Hello World!" align="center" valign="center" />

    [/xml]



    When running my program, a warning occurs :

    WARNING: Cannot locate resource: verdana-24-shadow.fnt

    And after that

java.lang.NullPointerException
at com.jme3.niftygui.RenderFontJme.(RenderFontJme.java:56)


When I reading the wiki, I haven't seen how to store / locate fonts.
I tried the code :
[java]
assetManager.registerLocator( "data/polices/", FileLocator.class );
[/java]
But it doesn't seem to work.

Can anyone help me ?

Thanks in advance

PS : I'm trying to use it on a Windows 7 Operating System

For the fonts you can use:



aurulent-sans-17.fnt



That should work.

1 Like

Hello madjack,

thanks for the tip!

I tried with ‘aurulent-sans-17.fnt’ and it works.





I’m interested in understanding how it works.

I tried to add a background image for a layer and I have the same type of message

[xml]



[/xml]


WARNING: Cannot locate resource: endlessblue1280.jpg (Flipped)


Has it something to do with the AssetManager registered locaions or is this something totally different ?

If you’re using jME3, all those files have to be inside assets, in their proper directories. If not, or you’re using a resource locator, I can’t help as I don’t know much about it. Although I think the wiki might have some useful info. Also, don’t forget to check the jME3tests.



Cheers.

Yeah, in a default jMP project nifty should find anything thats either in the assets folder or in the classpath via an imported jar library (e.g. a nifty style).

Thanks!



Now I can manage small GUI in Nifty.

But I have another problem. ( Still with the AssetManager I think )



It’s for the lines :

[xml]

useControls filename=“nifty-default-controls.xml”

[/xml]



I tried to replace it by :

[xml]

useControls filename=“ae-controls.xml”

[/xml]



And I put my ae-controls.xml ( and the other related files ) in my directory assets/Templates/Controls :



assets

== Templates

==== Controls

====== ae-controls.xnl

====== ae-buttons.xml

[…]



I’ve put the path in my assetManager :

[java]assetManager.registerLocator( “assets/Templates/Controls/”, FileLocator.class );[/java]



But when launching my program :


INFO: loading new nifty controls xml file [ae-controls.xml] with schemaId [nifty-controls.nxs]
java.lang.RuntimeException: Resource not found: ae-controls.xml


So, do we need to add the path to another manager ?

In the registerLocator path, shouldn’t “assets” be written with a uppercase A : “Assets”?

I think it depends of the JME version



Mine has no uppercase. I have done like it was said in this tutorial

didialchichi said:
[xml]
useControls filename="nifty-default-controls.xml"
[/xml]

I tried to replace it by :
[xml]
useControls filename="ae-controls.xml"
[/xml]


What is it you're trying to do with the above? I'm asking because it doesn't make sense to me. The useControls line is for an XML file that will contain the internal rendering routines for Nifty controls. Unless you've remade the whole Nifty controls definition (akin to make a new nifty styles definition), I don't think that's the thing you want to use. But I've been wrong before.

If you have made a new control definition, like a text box or a progress bar, that's not the way to use that. In that case, use simply have to make that "definition" inside the current GUI XML file containing the menu items. A bit like so:

[java] <controlDefinition name="progressbar" controller="GUI.ProgBarControl">
<image filename="Textures/progressbar-outer.png" imageMode="resize:15,2,15,15,15,2,15,2,15,2,15,15" childLayout="absolute">
<image id="progress" x="0" y="0" filename="Textures/progressbar-inner.png" width="32px" height="100%" imageMode="resize:15,2,15,15,15,2,15,2,15,2,15,15" />
<text id="progressText" font="aurulent-sans-17.fnt" text="" textHAlign="center" textVAlign="center" width="100%" height="100%" x="0" y="0" color="#f00f" />
</image>
</controlDefinition>[/java]

The above should be OUTSIDE the &st;screen> tag. Then inside the screen, actually where you want it displayed, you will put something like:

[java]<control id="progBarControl" name="progressbar" align="center" valign="center" width="400px" height="32px" />[/java]

Nifty, at loading time, will replace the <controlDefinition> content where the line above is.

As I said, I might be wrong.

Hello,



I don’t plan to rewrite the whole nifty controls. :slight_smile:



In fact, what I want to do is :


  • Changing the default appearance of a button

    For what have seen, the default appearance of a control is descibed inside the control xml file

controlDefinition style="nifty-button" name="button" controller="de.les...


- Create custom button with different appearance and / or behavior ( this one we will se later )

control id="btn5" type="mytoolbarButton"


- Testing what I will be able to do with the new toy I have in my hands :)


After explaining it, it seems that most of my 'problems' can be solved with only changing

useStyles filename="nifty-default-styles.xml"


I will try to do that. For new behaviors, I will wait a bit and use your solution.
There is an example in the wiki explaining how it works. I will try later.

Thanks!

Edit : I have the same problem with the styles xml file :(

INFO: loading new nifty style xml file [ae-styles.xml] with schemaId [nifty-styles.nxs]


Edit 2 : I've 'solved' the problem.
Instead of
[xml]
useStyles filename="ae-styles.xml"
[/xml]
I use
[xml]
useStyles filename="assets/Templates/Styles/ae-styles.xml"
[/xml]
And the same thing inside this file :
[xml]
useStyles filename="ae-button.xml"
[/xml]
I replaced by
[xml]
useStyles filename="assets/Templates/Styles/ae-button.xml"
[/xml]

It will be enough for me - but I think it may be a small bug.