Thanks for all your answers.
I will choose this solution :
1) Do you want the text to remain the same size regardless of how far away the battle is going on, and use niftygui effects on it? Use the niftygui text placed at a getScreenCoordinates() location
For doing this, I created this control :
[java]
<controlDefinition name="battleNotif" controller="com.didigame.acariaempire.gui.controls.BattleNotifControl">
<panel width="100%" height="100%" childLayout="absolute" >
<text id="#notif" font="textDialog.fnt" textHAlign="center" textVAlign="bottom" wrap="true" >
<effect>
<onCustom customKey="damage" name="move" mode="in" direction="top" length="1000" inherit="true"/>
<onCustom customKey="damage" name="fade" start="#ff" end="#00" length="1000" />
<onCustom customKey="shout" name="fade" start="#ff" end="#00" length="1000" />
</effect>
</text>
</panel>
</controlDefinition>
[/java]
When I want to add a notif I do something like this :
[java]
private void buildShoutNotif( SceneCharacter sceneChar, String text )
{
BattleNotifControl control = buildNotif();
control.createShoutNotif( sceneChar, text );
}
private synchronized BattleNotifControl buildNotif() {
String id = "battleInfo-battleNotif_" + increment;
increment++;
ControlBuilder builder = new ControlBuilder( id, "battleNotif" );
builder.build( nifty, screen, notifPanel );
Element notif = screen.findElementByName( id );
notifPanel.layoutElements();
return notif.getControl( BattleNotifControl.class );
}
[/java]
This should create the control and give it the correct parameters.
But I have a problem, the effects do not starts
Here is my JAVA class for this control :
[java]
public class BattleNotifControl implements Controller
{
private Element mainElement;
private Element notifElt;
private String text;
private String customKey;
private Color color;
private boolean characterLinked;
private boolean init;
private int x, y, w, h;
public BattleNotifControl() {
text = "???";
customKey = "";
color = Color.WHITE;
characterLinked = false;
init = false;
x = 0;
y = 0;
w = 0;
h = 0;
}
public void bind ( final Nifty nifty,
final Screen screenParam,
final Element element,
final Properties parameter,
final Attributes controlDefinitionAttributes )
{
this.mainElement = element;
mainElement.setFocusable( false );
// Element
this.notifElt = mainElement.findElementByName("#notif");
}
public void createShoutNotif( SceneCharacter sceneChar, String text )
{
this.color = Color.WHITE;
this.customKey = "shout";
createNotif( sceneChar, text );
}
private void createNotif(SceneCharacter sceneChar, String text)
{
// Element position
x = 80;
y = 200;
w = 400;
h = 80;
this.text = text;
this.characterLinked = true;
if( init )
reloadEffect();
}
private void reloadEffect() {
//TODO
notifElt.setConstraintX( new SizeValue( x + "px" ) );
notifElt.setConstraintY( new SizeValue( y +"px" ) );
notifElt.setConstraintWidth( new SizeValue( w + "px" ) );
notifElt.setConstraintHeight( new SizeValue( h + "px" ) );
// Content
TextRenderer notif = notifElt.getRenderer( TextRenderer.class );
notif.setColor( this.color );
notif.setText( text );
//Effect -- TODO
notifElt.startEffect( EffectEventId.onCustom, null, customKey );
}
@Override
public void init(Properties arg0, Attributes arg1) {
init = true;
if( characterLinked )
reloadEffect();
}
[/java]
At first, I thought it was because I tried to start the effect before the initialization method ( So I created the boolean characterLinked and init )
But I seems that's not the problem...
Is there something I don't know about the launch of customEffects ?