Archive for Uncategorized

Localization support and some more cool stuff!

// June 19th, 2010 // 2 Comments » // Uncategorized

A feature request made Nifty user lynorics create a patch that solved the issue and it directly point to solve the localization feature request too :)

Every attribute of every Nifty element can now contain a special markup “${…}” that gets replaced with something else when the xml is loaded.

Example:

<text text="your home directory: ${ENV.HOME}" />

The “${ENV.HOME}” will be replaced with your $HOME environment variable! :D

You have the following options now to use this new feature:

  • ${id.key} lookup resource bundle with “id” and request “key” from it. This is explained in more detail below.
  • ${ENV.key} lookup “key” in the environment variables (System.getEnv()) and replace ${ENV.key} with the value received.
  • ${PROP.key} lookup “key” in the new Nifty.setGlobalProperties(Properties) properties or if the properties are not set this will use System.getProperties() to lookup “key”
  • ${CALL.method()} call method() at the current ScreenController and it is replaced with the value that method() returns. method() should return a String in this case.

If for some reason the replacement does not work out then nothing is replaced and you’ll get the original ${…} String back.

Localization Details

Currently Nifty Localization is using standard Property file based Resourcebundles. This simply means you can create a property file containing keys that are referenced from the xml files.

Example:

dialog.properties:
hello = Hello World in Default Language

dialog_de.properties:
hello = Hallo Welt in Deutsch

dialog_en.properties:
hello = hello world in english

Once you have created these files you need to register the resourceBundle “dialog” with Nifty so that Nifty knows that it exists. You can do that with the new “resourceBundle” tag:

<resourceBundle id="dialog" filename="src/main/resources/dialog" />
 

Now that Nifty knows about your resourceBundle you can access it with the method mentioned above:

<text text="${dialog.hello}" />
 

Now Nifty will use the current set default locale to access the ResourceBundle with the id “dialog” and looks up the value for “hello”. If you don’t like that Nifty uses the default Locale you can set the Locale that Nifty should use with the “nifty.setLocale(Locale)” method.

Nifty stuff and Kudos goes out to lynorics! :D

void

If you liked the black nifty style, you will love this!

// May 28th, 2010 // 3 Comments » // Uncategorized

The old Nifty default style nifty-style-black was pretty nifty but the new style simply rocks \o/

Nifty GUI New Grey Style from void on Vimeo.

… and being very creative with style names we call this one “nifty-style-grey” :D 8)

You can already svn checkout the project from svn here: https://nifty-gui.svn.sourceforge.net/svnroot/nifty-gui/nifty-style-grey/trunk or browse the source online here http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty-style-grey/trunk/.

Together with the “nifty-default-controls” project – which provides the Standard Controls – you can already start to use the shiny new awesome grey design!

A released version will be available together with the upcoming Nifty 1.2 Release.

But remember, Nifty is not at all about the controls only. You can build whatever GUI you like! This new style is meant as another demonstration how shiny and nifty you can make GUIs look with Nifty GUI. But when you are happy with the look of the new style you are of course free to use it or modify it or just stare at it, like I do ;)

Have fun,
void :)

XML-Validation and Text Rendering with In-Text change of the Textcolor

// May 18th, 2010 // 1 Comment » // Uncategorized, sightings

XML-Validation

The actual parsing of Nifty-XML files is still using a XPP3 based parser and does not require a XML-Schema Definition. The nifty.xsd was only added to validate Nifty XML-Files … as well as for special support of the jMonkeyEngine3 SDK but that will be explained somewhere else :)

XML-Validation is now build into Nifty but is still an optional step you can use to ensure your Nifty XML is well formed and valid. To perform the actual validation two new methods have been added to the Nifty class:

public void validateXml(final String filename) throws Exception
public void validateXml(final InputStream stream) throws Exception

Both methods will simply return or will throw an Exception when any errors have been detected.

To successfully validate the nifty xml file, your xml file should start with the two following lines:

<?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 http://nifty-gui.sourceforge.net/nifty.xsd">

This way the XML-File is using the correct Nifty Namespace. If you would omit these declarations your XML-File can still be parsed but it will probably not validate against the XSD.

The namespace that has been definied for nifty is actually the URL where you can download the xsd too: http://nifty-gui.sourceforge.net/nifty.xsd

In-Text changes of Textcolor

Up until now Nifty uses the “binary” character value 0×01 directly in the text to indicate that the next three bytes in the text will contain red, green and blue values that represent the color of the text that follows after the color definition.

So you could write a red word, example:

<text text="a word in &#01;&#255;&#0;&#0;red"/>

This works but is unfortunatly not a valid XML file when trying to validate it with an XML-Schema Definition :) The problem is, that a valid XML attribute value must not contain values below binary 0×20 (with only a couple of exceptions, like the tab character 0×09). 0×01 is not allowed and will always create a validation error! So the current solution is to use a new format that doesn’t use 0×01 as a indicator anymore. Instead Nifty will now watch for the special String “\#” to mark the beginning of a color definition and “#” as the end. So instead of the xml example given above you can now write:

<text text="a word in \#F00#red"/>

Which is more readable too!

There is a short Version supported “\#F00#” as well as a long version “\#FF0000#”. Both are not case sensitive so you could write “\#fa9#” too. But remember the trailing # :)

Have fun,
void

In case you haved missed it …

// April 7th, 2010 // 1 Comment » // Uncategorized

… some very interessting developments are on the way:

http://jmonkeyengine.com/blog/blog/2010/04/06/jmonkeyengine-3-0-gets-a-very-nifty-gui/

http://www.jmonkeyengine.com/forum/index.php?topic=11246.msg98829#msg98829

:)

And besides that, the current Nifty SVN has all dependencies to LWJGL and Slick2D removed! :D Nifty is now completly independent of the actual rendering system!

There is a lwjgl-slick2d renderer already available here:
http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty-lwjgl-slick-renderer/trunk/

There is a work in progress JME2 renderer available here:
http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty-jme-renderer/trunk/

And the friendly people over at http://www.jmonkeyengine.com/ are already working on a JME3 nifty renderer too! :)

If you want to create your own Nifty renderer for some other rendering system, well, you can do that now too!

Take a look at the http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty/trunk/src/main/java/de/lessvoid/nifty/spi/ ServiceProviderInterface for Nifty rendering. What about a Java2D implementation? :D

void

Nifty 1.1 released

// March 22nd, 2010 // 7 Comments » // Uncategorized

Nifty 1.1 – Download it
Nifty 1.1 – View Changelog
Nifty 1.1 – Enjoy the Demo

And there is a special new tutorial/demo available too:
Nifty 1.1 – New Tutorial/Demo

nifty tutorial screenshot

nifty tutorial screenshot

have fun :)

New effect “gradient” Available

// December 6th, 2009 // No Comments » // Uncategorized

There is a new Effect available in SVN now. The “gradient” Effect allows you to draw vertical or horizontal gradients. You can use different colors and a percentage or pixel value for the position where the specific color should be.

Example:

<onActive name="gradient" direction="vertical">
  <value offset="0%" color="#f00f" />
  <value offset="20%" color="#0f0f" />
  <value offset="60%" color="#00ff" />
  <value offset="70%" color="#ff0f" />
  <value offset="100%" color="#ffff" />
</onActive>

Result:

Awesome! :D

You can use different Alpha Values for the colors too to make a gradient overlay elements or you could change the blendMode to multiply before applying the gradient with the “blendMode” effect :)

Have Fun!
void :)

Nifty Snapshots are now available

// December 6th, 2009 // No Comments » // Uncategorized

To get access to the latest and greates Nifty, Snapshots (= Development Versions) are now available at the Nifty Maven Repository I’ve set up at sourceforge.net.

You can get the latest Snapshot here: http://nifty-gui.sourceforge.net/nifty-maven-repo/lessvoid/nifty/1.1-SNAPSHOT/

In case you’re using Maven you’ve probably already using this in your pom.xml:

<repositories>
  <repository>
    <id>nifty-maven-repo.sourceforge.net</id>
    <url>http://nifty-gui.sourceforge.net/nifty-maven-repo</url>
  </repository>
</repositories>

You only need to change your nifty dependency to snapshot and you’re always using the latest Nifty Build:

<dependency>
  <groupId>lessvoid</groupId>
  <artifactId>nifty</artifactId>
  <version>1.1-SNAPSHOT</version>
</dependency>

Good Luck and Have Fun!
void

Switching images with nifty effects in game

// November 1st, 2009 // 1 Comment » // Uncategorized

Someone over at the nifty forums asked how to switch images from java. You can find the thread and my answer here.

Well. So far so good but switching images can be a lot more exciting with nifty effects :)

So let’s start with adding a new effect and attach it to the image with the onCustom effect:

<image id="inventar" filename="icon1.png">
  <effect>
    <onCustom name="imageSize" startSize="1.7" endSize="1.0" length="150" />
  </effect>
</image>

This adds an “imageSize” effect that starts with a imagesize of 1.7 times the original size and resizes the image back to the original size over the time of 150 ms. The “onCustom” effect means, that we can trigger this effect from java.

So when it comes time to change the image to the rocket launcher, the plasma gun or the BFG9000 :D we can use the following java code to trigger the effect and change the image:

getElement("inventar").getRenderer(ImageRenderer.class).setImage(iconRocketLauncher)
getElement("inventar").startEffect(EffectEventId.onCustom);

The first line changes the image and the second line triggers the onCustom effect.

I’ve updated the slick overlay example with a little nifty image switching in the right upper border of the screen. You can change the different images with pressing the keys “a”, “b” and “c”.

You can find it here:

http://nifty-gui.sourceforge.net/webstart/nifty-slick-overlay-demo.jnlp

and you can find the updated example in svn or you can browse it online here:

http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty-examples/trunk/src/main/java/de/lessvoid/nifty/examples/slick/niftyoverlay/ (Java classes)

http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty-examples/trunk/src/main/resources/slick/niftyoverlay/overlay.xml?revision=534&view=markup (Nifty XML for the Screen – overlay.xml)

Nifty! :D

Effect Reference with little animated gifs … soon

// October 17th, 2009 // No Comments » // Uncategorized

Ok, I was not able to add a effect reference each day but there was some progress, which is good.

Today I added “imageSize” and I’ve started to add little code snippets and animated gifs to the reference page too. So that the explanation makes more sense and you’ll get some code to start with.

I’ll continue to add effects documentation over the coming weeks :)

And here is the first with gif and code:

http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Effects#imageSize

Have fun,
void

To document one nifty effect each day project started =)

// October 3rd, 2009 // No Comments » // Uncategorized

I started to document the different nifty effects in the nifty wiki:

http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Effects

I’ll try to continue with documenting at least one effect each day :)