Hi!
I got this inGame menu that I want to interact with.
But the method back() does not get executed. I wasn’t suprised but I need to solve it.
Heres my xml:
[xml]<?xml version=“1.0” encoding=“UTF-8”?>
<nifty>
<screen id=“start” controller=“jme3test.niftygui.TestNiftyGui”>
<layer id=“layer” backgroundColor="#00000011" childLayout=“center”>
<panel id=“panel4” height=“50%” width=“25%” align=“left” valign=“top” childLayout=“vertical”>
<panel id=“2Buttons” height=“50%” width=“100%” align=“left” valign=“top” childLayout=“vertical”>
<panel id=“panel” height=“50%” width=“100%” align=“left” valign=“top” childLayout=“center”>
<effect>
<onStartScreen name=“move” timeType=“exp” factor=“3.5” direction=“left” mode=“in” length=“300” inherit=“true” />
<onEndScreen name=“move” timeType=“exp” factor=“3.5” direction=“left” mode=“out” length=“300” inherit=“true” />
</effect>
<panel childLayout=“center” width=“100%” height=“50%” backgroundColor="#a2a2a2" valign=“center” visibleToMouse=“true”>
<text id=“text” font=“aurulent-sans-16.fnt” color="#000f" text=“Soldier Class” align=“center” valign=“center” childLayout=“center” />
<control id=“backButton2” name=“button” label=“Soldier” align=“left”>
<interact onClick=“back()” />
</control>
</panel>
</panel>
<panel id=“panel2” height=“50%” width=“100%” align=“left” valign=“bottom” childLayout=“center”>
<effect>
<onStartScreen name=“move” timeType=“exp” factor=“3.5” direction=“left” mode=“in” length=“300” inherit=“true” startDelay=“100” />
<onEndScreen name=“move” timeType=“exp” factor=“3.5” direction=“left” mode=“out” length=“300” inherit=“true” startDelay=“100” />
</effect>
<panel childLayout=“center” width=“100%” height=“50%” backgroundColor="#a2a2a2" valign=“center” visibleToMouse=“true”>
<text id=“text” font=“aurulent-sans-16.fnt” color="#000f" text=“Medic Class” align=“center” valign=“center” childLayout=“center” />
<control id=“backButton” name=“button” label=“Medic” align=“left”>
<interact onClick=“back()” />
</control>
</panel>
</panel>
</panel>
<panel id=“2moreButtons” height=“50%” width=“100%” align=“left” valign=“top” childLayout=“vertical”>
<panel id=“panel” height=“50%” width=“100%” align=“left” valign=“top” childLayout=“center”>
<effect>
<onStartScreen name=“move” timeType=“exp” factor=“3.5” direction=“left” mode=“in” length=“300” inherit=“true” startDelay=“200” />
<onEndScreen name=“move” timeType=“exp” factor=“3.5” direction=“left” mode=“out” length=“300” inherit=“true” startDelay=“200” />
</effect>
<panel childLayout=“center” width=“100%” height=“50%” backgroundColor="#a2a2a2" valign=“center” visibleToMouse=“true”>
<text id=“text” font=“aurulent-sans-16.fnt” color="#000f" text=“Sniper Class” align=“center” valign=“center” childLayout=“center” />
<control id=“backButton2” name=“button” label=“Sniper” align=“left”>
<interact onClick=“back()” />
</control>
</panel>
</panel>
<panel id=“panel2” height=“50%” width=“100%” align=“left” valign=“bottom” childLayout=“center” visibleToMouse=“true”>
<effect>
<onStartScreen name=“move” timeType=“exp” factor=“3.5” direction=“left” mode=“in” length=“300” inherit=“true” startDelay=“300” />
<onEndScreen name=“move” timeType=“exp” factor=“3.5” direction=“left” mode=“out” length=“300” inherit=“true” startDelay=“300” />
</effect>
<panel childLayout=“center” width=“100%” height=“50%” backgroundColor="#a2a2a2" valign=“center”>
<text id=“text” font=“aurulent-sans-16.fnt” color="#000f" text=“Heavyload Class” align=“center” valign=“center” childLayout=“center” />
</panel>
<control id=“backButton” name=“button” label=“Heavyload” align=“left”>
<interact onClick=“back()” />
</control>
</panel>
</panel>
</panel>
</layer>
</screen>
<screen id=“end”></screen>
</nifty>[/xml]
Sorry for the indent thats messed up with spaces instead of tabs, but a stupid xml beautifier did it too me and the Idiotic notepad can’t redo 2 steps -.- (Huge facepalm).
So I set up my class by doing:
[java]public void setupMenu() {
niftyDisplay = new NiftyJmeDisplay(app.getAsset(),app.getInput(), app.getAudio(), app.getGuiViewPort());
nifty = niftyDisplay.getNifty();
nifty.fromXml(“Menus/InGame.xml”, “start”, this);
nifty.setDebugOptionPanelColors(true);
}[/java]
After the superclass initiation is done.
This class implements ScreenController and to get up the ingame gui
I call showMenu():
[java]public void showMenu(){
System.out.println(“Show menu!”);
nifty.getScreen(“start”).startScreen();
app.getGuiViewPort().addProcessor(niftyDisplay);
app.getInput().setCursorVisible(true);
}[/java]
app could be replaced with “this”.
My method back() is here:
[java]public void back(){
System.out.println(“Clicked”);
}[/java]
So why isn’t my method “back()” running?
not an expert in nifty but your controller class point to jme3test.niftygui.TestNiftyGui, I doubt you added your back() method there, did you?
If that’s the case I guess you should set your own controller method there.
I don’t know anything about nifty xD, but in component events in html files, when you call javascript functions you have to add “;” at final, e.g.
[xml]<interact onClick=“back();” />[/xml]
Yes thats the weard part.
The class that implements ScreenController is the class with the back() and showMenu() and setupMenu() methods.
@glaucomardano: no you dont need same with “javascript:back()” dont need
i dont know nifty but propably you need to set control class (it must know wich one back() it want to execute) - in xml file
nehon said:
your controller class point to jme3test.niftygui.TestNiftyGui
Heeelllllooo!!! Solution just went past you :roll:
Ahh thanks!
But still not working
I set it to main.ClientGame because in eclipse its in src.main.ClientGame (but src isn’t the vailed path in moste cases)
Could it be that another panel is covering over that area thus disabling the buttons?
I found out that the problem is I can not have a panel with text AND interact. I have to choose either to have text or to interact.
Thats just stupid.
Heres a simple example to show it:
[xml]<?xml version="1.0" encoding="UTF-8"?>
<nifty>
<screen id="start" controller="main.ClientGame">
<layer id="layer" backgroundColor="#00000011" childLayout="center">
<panel id="panel4" height="50%" width="100%" align="left" valign="bottom" childLayout="vertical">
<panel childLayout="center" width="100%" height="50%" backgroundColor="#a2a2a2" valign="center" visibleToMouse="true">
<text id="text" font="aurulent-sans-16.fnt" color="#000f" text="Heavyload Class" align="center" valign="center" childLayout="center"/>
<control id="backButton" name="button" label="Heavyload" align="left" visibleToMouse="true">
<interact onClick="back()" />
</control>
<effect>
<onStartScreen name="move" timeType="exp" factor="3.5" direction="left" mode="in" length="300" inherit="true" startDelay="300" />
<onEndScreen name="move" timeType="exp" factor="3.5" direction="left" mode="out" length="300" inherit="true" startDelay="300" />
</effect>
</panel>
</panel>
</layer>
</screen>
<screen id="end"></screen>
</nifty>[/xml]
If you place the control BEFORE the text part then the click will work, but no text will appear.
If you place the control AFTER the text will appear but nothing will react to clicks. Not even outside the text.
Is this a bug?
Solution to this problem is to make the textlabel appear as a text inside a panel.
By setting its backgroundcolor and size it will look like a panel.
Otherwise it wont work.