Lately Cabo-Trafalgar projects are on fire, I want to make the damn release and take some months of resting, but in the meanwhile I bring my last present to the JME3 community.
Something I didn’t like from the beginning was replacing XML with Java Builders when I needed a dynamic number of elements in the screen. It was annoying for me to learn how to do exactly the same in a different way, including aspect/style of elements. Also, you need to build inside-out all elements you need.
As part of my web-oriented background, and given I had already nifty-flow in place, I dared to fix the problem myself by using Freemarker templates. Here you have an example, it’s really nifty:
<?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">
<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<screen id="${screenUniqueId}" controller="com.navid.trafalgar.mod.common.SelectKeyboardControlsScreenController">
<layer id="background" childLayout="center">
</layer>
<layer id="foreground" childLayout="vertical" style="nifty-panel-no-shadow">
<panel id="panel_top" height="15%" width="75%" align="center" childLayout="center">
<text text="Select the keys..." font="Interface/Fonts/Default.fnt" width="100%" height="100%" />
</panel>
<panel id="panel_mid" height="70%" width="75%" align="center" childLayout="horizontal" style="nifty-panel-red">
<panel id="panel_mid_left" width="100%" align="center" childLayout="horizontal">
<#list partitionedKeyboardCommands as partition>
<panel id="partition_${partition?counter}" width="50%" align="center" childLayout="vertical">
<#list partition as keyboardCommands>
<panel id="keyboardCommands_${keyboardCommands}" align="center" childLayout="horizontal">
<control id="${keyboardCommands}" name="listBox" displayItems="4" forceSelection="true" horizontal="off" width="30%" align="left" />
<text text="${keyboardCommands}" font="Interface/Fonts/Default.fnt" align="right" />
</panel>
<text text="" font="Interface/Fonts/Default.fnt" align="right" />
</#list>
</panel>
</#list>
</panel>
</panel>
<panel id="panel_bottom" height="15%" width="75%" align="center" childLayout="horizontal">
<panel id="panel_bottom_right" height="50%" width="25%" valign="center" childLayout="center">
<control name="button" label="Back" id="QuitButton" align="center" valign="center"
visibleToMouse="true" >
<interact onClick="back()"/>
</control>
</panel>
<panel id="panel_bottom_right3" height="50%" width="25%" valign="center" childLayout="center">
<control name="button" label="Select ship" id="PlayButton" align="center" valign="center"
visibleToMouse="true" >
<interact onClick="next()"/>
</control>
</panel>
</panel>
</layer>
</screen>
</nifty>
Full example and explanations here: Freemarker in nifty-gui