Having a Nifty ScreenController call methods on the rest of the program

Hello, I have been learning Nifty GUI over the past few weeks. I have been pleased with it for the most part, but there is one issue that is problematic. When inside a ScreenContoller, it is difficult to get back to the main classes of your program. You are given a Nifty object during bind which is great if you want to call or edit a menu, but you cannot do much with the rest of the program (like manipulate JMonkey objects).



The only way I have found to solve this (let me know if I am missing something) is to get an instance of another class statically. This is painful, especially when using a framework like Spring or Guice. I personally am using Google Guice, and my entire application is all set up nicely with Guice taking care of all the injections and setting up stuff all automatically, except for the Nifty stuff which I have to write custom static code to get access to my regular services just for Nifty.



Again please let me know if there is another way. If there is not it would be nice if there was. Many larger applications rely on a framwork such as Guice or Spring, and it would be nice if Nifty fit better in.



Other than that, as I said I have been liking Nifty very much ^_^. Its good work.



~David

Hi!, I’ve the same problem!, for example i try to make username and password authentication but I can’t call back the method who contact the server!


  • tgiachi

You can give Nifty ScreenController classes that you’ve instantiated on your own. You can initialize the class any way you need. You are not forced to let Nifty create the class.



I’ve blogged about it a while ago: http://nifty-gui.lessvoid.com/archives/20 and I’ve just added it to the Nifty Wiki which you can find here: http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Nifty_Howto



I think this can prevent the static stuff needed when you let Nifty create the ScreenController.

Link fixed. Thanks :slight_smile:



PS: Sorry for the odd colors in code blocks of old blog posts. I haven’t been able to fix the colors for older blog entries yet (well, you can blame erlend for introducing me to the otherwise awesome wordpress blog theme which unfortunatly made the code block colors go nuts :wink:

Wow yah, completely missed that blog post. Thanks for now adding that to the wiki. I saw several similar question on the forum and hopefully those and future developers can now figure it out.



But yes that is EXACTLY what I need as now I can have Guice take care of everything. I was really hoping I was overlooking something ^_^.



Keep up the good work on nifty void.



~David



PS: your blog link is broken.

void256 said:
Sorry for the odd colors in code blocks of old blog posts. I haven't been able to fix the colors for older blog entries yet (well, you can blame erlend for introducing me to the otherwise awesome wordpress blog theme which unfortunatly made the code block colors go nuts ;)
Eherm, my bad. By the way though, it'd be a good idea to drop a "Update!" link to the wiki in the beginning of that blogpost, as blogs tend to appear more often in searches as opposed to wiki pages thanks to WordPress' SEO.