[Solved] Nifty change the effect for an element

Hey,

Is it possible to change an effect of an element? I have a xml file with my hud and i want to change the onclick effect via java ScreenController.

http://sourceforge.net/projects/nifty-gui/files/nifty-gui/nifty-gui-the-manual-v1.0.pdf/download

i read this manual and found this:

[java]nifty.getCurrentScreen().findElementByName(element).hide()[/java]

and this is the thing i need because i want to show and hide a layer with just one button so i set the interaction to

[xml]<interact onClick=“show(layer)” />[/xml]

the java method:

[java]public void show(String layer){

Element niftyElement = nifty.getCurrentScreen().findElementByName(layer);

if(niftyElement.isVisible()) niftyElement.hide();

else niftyElement.show();

}[/java]

but it doesn’t work what is wrong?

Could you show the entire xml file?

[xml]<screen id="hud" controller="GUI.NiftyController">

<layer childLayout="vertical" name="bottom">

<panel id="space" childLayout="vertical" height="${CALL.getSpaceHeight()}" width="100%" />

<panel id="bottom" childLayout="horizontal" height="35px" width="100%" backgroundImage="Interface/Ingame/bottom_bg.png">

<panel id="space" childLayout="vertical" height="100%" width="${CALL.getSpaceWidth(1)}" />

<panel id="build_panel" childLayout="vertical" height="100%" width="60px" valign="center">

<control type="label" id="economy" text="Build" font="Font/font-24.fnt" height="100%" color="#fff" />

</panel>

<panel id="space" childLayout="vertical" height="100%" width="${CALL.getSpaceWidth(2)}" />

<panel id="economy_panel" childLayout="vertical" height="100%" width="100px" valign="center">

<control type="label" id="economy" text="Economy" font="Font/font-24.fnt" height="100%" color="#fff" visibleToMouse="true">

<effect>

<onHover name="textColor" color="#fff000ff" />

</effect>

<interact onClick="show(economy_layer)" />

</control>

</panel>

</panel>

</layer>

<layer childLayout="vertical" name="economy_layer">

<effect>

<onStartScreen name="hide" targetElement="frame" />

</effect>

<panel id="space" childLayout="vertical" height="${CALL.getSpaceHeight2()}" width="100%" />

<panel id="frames" childLayout="horizontal" height="500px" width="100%" >

<panel id="space" childLayout="vertical" height="500px" width="${CALL.getSpaceWidth(3)}" />

<panel id="frame" childLayout="vertical" height="500px" width="500px" align="right" backgroundImage="Interface/Ingame/bottom_frame.png">

<panel id="titles" childLayout="horizontal" height="30px" width="500px">

<control id="facility_label" type="label" text="Facility" font="Font/font-24.fnt" width="170px"/>

<control id="energy_label" type="label" text="Energy" font="Font/font-24.fnt" width="110px" />

<control id="airium_label" type="label" text="Airium" font="Font/font-24.fnt" width="110px" />

<control id="food_label" type="label" text="Food" font="Font/font-24.fnt" width="110px" />

</panel>

<panel id="statics" childLayout="horizontal" height="470" width="500px">

<panel id="facilities" childLayout="vertical" height="100%" width="170px">

<control id="factory" type="label" text="+ Factory" font="Font/font-24.fnt" height="30px" align="left" />

</panel>

<panel id="energies" childLayout="vertical" height="100%" width="110px" backgroundImage="Interface/Ingame/statistik_trennung.png">



</panel>

<panel id="airiums" childLayout="vertical" height="100%" width="110px" backgroundImage="Interface/Ingame/statistik_trennung.png">



</panel>

<panel id="foods" childLayout="vertical" height="100%" width="110px" backgroundImage="Interface/Ingame/statistik_trennung.png">



</panel>

</panel>

</panel>

</panel>

</layer>

</screen>[/xml]

It should work. Btw instead of getCurrentScreen() use getScreen(id).

I chanced it to getScreen(id) so the method is now:

[java]public void show(String element, String ScreenID){

Element niftyElement = nifty.getScreen(ScreenID).findElementByName(element);

if(niftyElement.isVisible()) niftyElement.hide();

else niftyElement.show();

}[/java]

and the xml:

[xml]<interact onClick=“show(economy_layer, hud)” />[/xml]

Still it doesn’t work…

If i debug it niftyElement.isVisible() is always true…

it now works… :slight_smile:

i wrote:

[xml]<layer childLayout=“vertical” name=“economy_layer” visible=“false”>[/xml]

and it should be

[xml]<layer childLayout=“vertical” id=“economy_layer” visible=“false”>[/xml]

and now it works

the problem is that nifty doesn’t show NullPointerExceptions

1 Like