Nifty GUI: Reusability and modularity

Hi

I’m trying to create a custom button with custom background images (normal, hovered, focused). I want to be able to “instantiate” a button of this kind and give it a different set of background images, but I can’t figure out how to do that without copying the whole style xml file and just changing the image file paths. Can you parameterize values in style-definitions? Or can you maybe define styles/controls solely with Java (this would be so much better…)?

This whole area seems quite clunky with nifty.

For buttons I didn’t use the controls at all, I just use normal panels and set the images/styles/etc on them appropriately.

I also have a java method to construct one of those using builders and just use that method whenever I need a button.

i.e. [java]PanelBuilder buildButton(String name, etc)[/java]

For example:

[java]
<style id=“buttonBase”>
<attributes paddingLeft=“5px” paddingRight=“5px” margin=“6px” imageMode=“resize:10,6,10,10,10,6,10,6,10,6,10,10” childLayout=“horizontal”/>
<effect>
<onHover name=“colorBar” color="#ccc8"/>
<onCustom name=“colorPulsate” customKey=“pulsate” startColor="#f88f" endColor="#fddf"
pulsateType=“sin” period=“2000” cycle=“true” neverStopRendering=“true”/>
</effect>
</style>

<style id=“buttonGrey” base=“buttonBase”>
<attributes backgroundImage=“Interface/buttonGrey.png” visibleToMouse=“true”/>
<effect>
<onClick name=“changeImage” active=“Interface/buttonGreyDown.png”
inactive=“Interface/buttonGrey.png”
imageMode=“resize:10,6,10,10,10,6,10,6,10,6,10,10” length=“250” />
</effect>
</style>

<style id=“buttonGreen” base=“buttonBase”>
<attributes backgroundImage=“Interface/buttonGreen.png” visibleToMouse=“true”/>
<effect>
<onClick name=“changeImage” active=“Interface/buttonGreenDown.png”
inactive=“Interface/buttonGreen.png”
imageMode=“resize:10,6,10,10,10,6,10,6,10,6,10,10” length=“250” />
</effect>
</style>
[/java]

Then to use it:

[java] <panel id=“chat” style=“buttonGrey” height=“32px”>
<interact onClick=“chatClicked()” />
<text style=“buttonText” text="${t9n.player.chat}"/>
</panel>
[/java]