Hi,
I just found something strange with the control builder. The id I give is not always the one used oO
Sorry : Since I had problem, I tried to force the initialist of the child control inside the main control and it seems that is what was causing the issue.
As long as I don’t try to access to my child control inside my main control during the init method, it semms its working correctly.
So, no need to go further. I will manage with what I have.
But for the curious ones, I havn’t removed the rest of my post
I have a Nifty screen wth something like that :
[java]
[...]
<layer id="popupLayer" childLayout="center" >
<control id="toolbarPopup" name="ae-popup" />
</layer>
[/java]
And inside this control, I have :
[java]
<controlDefinition name="ae-popup" controller="com.didigame.acariaempire.gui.controls.PopupControl">
<panel width="100%" height="100%" visibleToMouse="true" childLayout="center" >
[...]
<control id="#popupText" name="ae-scrollText" width="100%" height="100%" text="Insert here what you want to say" />
[...]
</panel>
</controlDefinition>
[/java]
This second control (ae-scrollText) has for Controller the class CustomTextScrollControl.
Wich has this method :
[java]
public class CustomTextScrollControl implements Controller
{
[...]
@Override
public void init(Properties arg0, Attributes arg1)
{
createListElt();
if( firstText != "" )
setText( firstText );
}
[...]
private void createListElt()
{
int lineHeight = textElt.getRenderer( TextRenderer.class ).getFont().getHeight();
int panelHeight = panelElt.getHeight();
int nbLines = panelHeight / lineHeight;
String id = panelElt.getId() + "#listControl";
ControlBuilder builder = new ControlBuilder( id, "ae-listBox" );
builder.height( "100%" );
builder.width( "100%" );
builder.set( "vertical", "optional" );
builder.set( "horizontal", "optional" );
builder.set( "selection", "Disabled" );
builder.set( "displayItems", String.valueOf( nbLines ) );
builder.build( nifty, screen, listPanel );
listElt = screen.findElementByName( id );
}
[...]
[/java]
This control create a listBox with the correct number of line ( depending of the height of the control )
The control ae-listBox is a classic listBoc, ( same controller ) but with different default panels.
So, in short, I have :
layer
__ custom control : ae-popup
__ |__ custom control : ae-scrollText
__ __ |__ listbox that is dinamicly created during initialisation
The problem resides in those 4 lines :
[java]
String id = panelElt.getId() + "#listControl";
ControlBuilder builder = new ControlBuilder( id, "ae-listBox" );
[...]
builder.build( nifty, screen, listPanel );
listElt = screen.findElementByName( id );
[/java]
On most of the cases it works, but when I use the ae-scrollText inside a ae-popup control, listElt = null;
In this case :
[java]
id = "toolbarPopup#popupText#listControl"
[/java]
But, when I use the debugger, the element is created with id :
[java]
real element id = "toolbarPopup#popupText#popupText#listPanel"
[/java]
I don't understand why xD
Is it something normal ?
PS : the best way to retrieve would be
[java]
listElt = builder.build( nifty, screen, listPanel );
[/java]
But, most of the time I retrieve a null Element :'(