Hi,
In niftygui I’m creating text from java code using a style that defines some effects. If I set onclick interaction, the onclick effect doesn’t run.
This is the snippet:
style:
<style id="menu-item">
<attributes align="center" valign="center" textHAlign="center" color="#fd0f" width="100%" font="Interface/fonts/barbatrick-30-3-8-0.fnt"
focusable="true" visibleToMouse="true"
controller="de.lessvoid.nifty.controls.MenuItemControl"
inputMapping="de.lessvoid.nifty.input.mapping.MenuInputMapping"
/>
<effect>
<onHover name="focus" />
<onFocus name="textColor" color="#ff0f" />
<onFocus name="textSize" startSize="1.0" endSize="1.25" length="150" />
<onLostFocus name="textSize" startSize="1.25" endSize="1.0" length="150" />
<onClick name="playSound" sound="menuSelect" />
</effect>
</style>
Java code:
TextCreator lblCreator=new TextCreator("");
lblCreator.setStyle("menu-item");
for(Data data : dataArray)
{
lblCreator.setId(data.getId());
lblCreator.setText(data.getName());
lblCreator.setInteractOnClick("doSomethingWithData(" + data.getId() + ")");
lblCreator.create(niftyDisplay.getNifty(), niftyDisplay.getNifty().getCurrentScreen(), parent);
}
If I just remove the setInteractOnClick line, the sound is played, but obviously the desired action is not done.
I’ve tried also to add the effect from code like lblCreator.addEffectsOnClick(new ControlEffectAttributes() setName setAttribute…with the same result, if setting the interaction the onclick effect doesn’t work
But if I define the text in xml like
<text id="id1" text="Label1" style="menu-item" height="25%">
<interact onClick="doSomethingWithData(test)" />
</text>
it works as expected, but the data is dynamic, so I need to create the text in code
Thanks for any help