[SOLVED] "interact" works, but NiftyEventSubscriber doesn't :(

Hi.

[EDIT] The forum is eating my XML! :frowning: Is there an explanation somewhere of how to paste XML in here? using the code tag does not seem to help… Trying with square brackets, this time …

I’ve started on Nifty GUI. I had some significant difficulties to get started, but now I think I got the idea. Atm, I’m just trying to have multiple transparent screen with buttons and labels, and move between them by clicking the buttons.

In the start screen, I have this:

[control align="center" childLayout="center" id="playAlone" label="PLAY ALONE" name="button" width="120px" textVAlign="center"]
   [interact onClick="singlePlayer()"/]
[/control]

This does call the singlePlayer() method on the StartControler properly, which does this:

    public void singlePlayer() {
        System.out.println("singlePlayer()");
        nifty.gotoScreen("singlePlayer");
    }

The singlePlayer screen has it’s own controller. It seems to be created properly, as I can get it from Nifty, and set a reference to the app in it.

In the singlePlayer screen config, I have:

[panel childLayout="horizontal" height="9%" id="titleRow" style="nifty-panel-simple" width="*"]
    [control childLayout="center" id="closeButton" label="X" name="button" textVAlign="center" valign="center"/]
[/panel]

And in the singlePlayer controller I have:

    @NiftyEventSubscriber(id = "closeButton")
    public void onCloseButtonClicked(final String id, final ButtonClickedEvent event) {
System.out.println(getClass().getSimpleName()+".onCloseButtonClicked()");
        nifty.gotoScreen("start");
    }

But this method does not get called. Why could that be?

If I comment out the event handler, and add an interact in the XML, pointing to this method instead:

    public void onCloseButton() {
System.out.println("**************************************************"onCloseButton()");
        nifty.gotoScreen("start");
    }

Then the output comes, so I can see that my single player controller is connected to the screen. But then the nifty.gotoScreen(“start”); doesn’t have any effect, although the nifty.gotoScreen(“singlePlayer”); in the start screen works. Maybe the two issues are related?

Use [xml] tags to post xml :slight_smile:

OK. Will try again. A “post preview” would have saved me all the editing …

[xml]
test
[/xml]

test

@monster said: OK. Will try again. A "post preview" would have saved me all the editing ... [xml] test [/xml]
http://bbpress.org/support

OK. All my attempts to make the XML visible have failed. Neither does it work with:

SQUARE-BRACKET-OPEN xml SQUARE-BRACKET-CLOSE

nor does it work with:

LESS-THEN xml GREATER-THEN

And I totally fail to see how the link you gave me should help, since it says nothing about XML on that page. Presumably you were trying to tell me which software you use for the forum, rather then send me to an explanation of how to embed XML. I’m too tired. I think I’ll just give up for today and go to bed. Maybe it will miraculously work tomorrow :-?

:?
[xml] [/xml]

what browser?

And I was suggesting to tell the developers of the forum about what you see can be improved in their software.

1 Like

I’ve had trouble getting XML tags to work [xml][/xml].

Yeah, they don’t work for me…everything inside the angle brackets gets eaten.
(Win 7, Chrome)

@Monster - the forums and website here were recently upgraded and the web guys are still working on getting some of the kinks out of the system. It still needs some stuff to be done but it has already improved immeasurably from where it was when they first flipped the switch.

i just tried the Nifty button event and it worked fine. Perhaps try make a simple testcase, and you may be able to spot something on your end

Edit: test [xml]apples [/xml]

I use Firefox. I can see @normen’s XML, but not mine. And if @zarch and @wezrule tried too, then I don’t see their XML either.

Maybe @normen could post us a snapshot of what the editor window contains for his test? (PLEASE!)

I’ll try to write a testcase, as @wezrule suggested. Maybe the problem will become obvious then.

Yeah, I tried xml for mine and I assume wezrule did too :slight_smile:

Hm, I guess then its because I can do this too :smiley:

@destroflyer? ideas?

OK. Progress. :slight_smile: If I swap my “start” screen, and my “singlePlayer” , such that my singlePlayer screen controller is created explicit by me, and associated with the screen.xml, instead of created implicitly by Nifty, then it gets the event. I thought for a single XML screen file, I should only have one call like:

nifty.fromXml("Interface/screen.xml", "start", new StartController(this));

But if I try this:

nifty.fromXml("Interface/screen.xml", "start", new StartController(this));
nifty.fromXml("Interface/screen.xml", "singlePlayer", new SinglePlayerController(this));

Then it works too. :-o I would have expected it to crash in flames. So it seems the @NiftyEventSubscriber(id=“…") only work on Controllers set explicitly, instead of created using reflection by Nifty itself. Is it OK to call nifty.fromXml(“xxx”) with the same XML file multiple times? :-?

Just use addXml? These basics are well documented though: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:nifty_gui

Sorry, I missed that one part. :roll: