Hi, I want to use multiple XML files and now I have a controller problem.
I load the files with the code:
[java] nifty = niftyDisplay.getNifty();
nifty.addXml("Interface/textfield.xml");
nifty.addXml("Interface/textfield2.xml");
nifty.gotoScreen("start1");[/java]
And in the XML File the controller is set with
[xml]<screen id="start1" controller="mygame.Test">[/xml]
But this code only works when the controller is the main application which extends SimpleApplication.
So class Test extends SimpleApplication implements ScreenController works and
Test implements ScreenController does not work.
Edit:
I fixed the problem:
[java] nifty = niftyDisplay.getNifty();
nifty.registerScreenController(new Test());
nifty.addXml("Interface/textfield.xml");
nifty.addXml("Interface/textfield2.xml");
nifty.gotoScreen("start1");[/java]
It is important to register the controller before loading the xml files.
Hm, I have another question related to this topic.
I need the other XML file to add some elements and panels to the gui.
[xml]<controlDefinition name=“abilityPanel” controller=“mygame.AbilityPanel”>
pannels…etc
<image id=“ability0” filename=“bla.png” height=“100%” width=“100%”>
<interact onClick=“test()” />
</image>
</controlDefinition>[/xml]
With the code:
[java]
CustomControlCreator createMultiplayerPanel = new CustomControlCreator(“myAbilityPanel”, “abilityPanel”);
createMultiplayerPanel.create(nifty, screen, screen.findElementByName(“box-ability”));[/java]
This works but the controller is not added to the panel and the “test()” method of the image only calls the test method of the Screencontroller.
This works but the controller is not added to the panel
Why are you doing that dinamically? Does doing that via xml work? Make sure the parent panel's childLayout param is set.
the “test()” method of the image only calls the test method of the Screencontroller.
And what would you expect instead of?
Why are you doing that dinamically?
Because I want seperated files for some areas of the GUI. (for example to swap panels)
Does doing that via xml work?
When I add the code with the controlDefinition nothing happens but when I remove the controlDefinition the panel is displayed.
Make sure the parent panel’s childLayout param is set.
Is set.
And what would you expect instead of?
I want a special controler for this area of the screen (AbilityPanel) and not work with the global screencontroler.
Argh, the controller did not have an empty constructor. D:
@ogerlord said:
Argh, the controller did not have an empty constructor. D:
No. It does. Just look at the moment when you instance your controller
[java]
nifty.registerScreenController(new Test());
[/java]
Just create an empty construtor for that and put thing that. You can use the bind() method too. I use this one. If your controller extends AbstractAppState, you can initialize some parameters on initialize() method too. Nifty elements' initializations should be into the bind() method, and app objects' initializations should be into the initialize() method.