Nifty - Cannot have an onclick on listbox

Hello,

I spent hours trying to have this f… listbox do a simple item click

can someone look a this code ?


    <controlDefinition name="marketItemListItem" >
      <interact onClick="listBoxItemClicked()" />
      <effect>
        <onCustom customKey="select" name="colorBar" post="false" color="#F00F" neverStopRendering="true" timeType="infinite" />
        <onCustom customKey="select" name="textColor" post="false" color="#0F0F" neverStopRendering="true" timeType="infinite" />
      </effect>  
      <panel id="#marketItemListItem" childLayout="horizontal" width="*" height="66px" backgroundColor="#0000" >
          <control name="marketItem" itemType="$itemType" amount="$amount" buyer="$buyer" credits="$credits" imageFileName="$imageFileName" />
      </panel>
    </controlDefinition>     

    <screen id="Hud" controller="mygame.appstates.HudAppState" >
...   
         <layer id="marketLayer" childLayout="center" backgroundColor="#0000">
            <panel id="marketPanel" width="500" height="400" childLayout="vertical">
                <control id="marketList" name="mylistbox" style="my-listbox" width="500" height="400" vertical="on" horizontal="off" displayItems="4" selection="Single" forceSelection="true" viewConverterClass="mygame.gui.converters.MarketItemListConverter" >
                   <control name="marketItemListItem" /> 
                </control>
            </panel>
        </layer>
   ...


   @NiftyEventSubscriber(id="marketList")
    public void onListBoxSelectionChanged(final String id, final ListBoxSelectionChangedEvent<MarketItemListItem> event) 
    { 
        List<MarketItemListItem> selection = event.getSelection();
//        only comes here at statup
    }

    public void listBoxItemClicked()
    {
        // never gets here
    }

Rather than adding the interact tag in the controlDefinition, try adding it to the control tag.

<control name="marketItemListItem"> 
    <interact onClick="listBoxItemClicked()" />
</control>

well it does not work and it does not make any sens, what if you got ten lists

Of course it makes sense, you might use the same controlDefinition list in different screens with different controllers which might not have the same methods.

But you’re saying it still doesn’t work? I tried this on a GUI I have with a list defined in a control and that way works for me. Can you see any errors in the console?

no, nnothing
just like if listbox was not getting any event
I tried visibleToMouse, but still the same
just hate nifty so bad, averytime I try to implement a new stuff, it takes me a whole week to figure out why it’s not working

the code I pasted is inspired by the official nifty example
nifty has nothing logic to it

Right and listBoxItemClicked() is defined in HudAppState I take it?

yep, the appstate is a screencontroller

I have a listbox in my project and here’s how I did the item control:

<?xml version="1.0" encoding="UTF-8"?>
<nifty-controls>
  <controlDefinition name="listbox-unit-item-control" style="listbox-unit-item" controller="de.lessvoid.nifty.controls.listbox.ListBoxItemController">
      <panel style="#root" childLayout="horizontal">
          <text id="#name" style="#name" text="" >
              <interact onClick="listBoxItemClicked()" />
          </text>
          <panel id="#infoAreaPanel" style="#infoAreaPanel" childLayout="absolute">
            <panel id="#infoAreaBackground" style="#infoAreaBackground" childLayout="horizontal" />
            <panel id="#armorBar" style="#armorBar" childLayout="horizontal" />
            <text id="#infoText" style="#infoText" text="" />
          </panel>
      </panel>
  </controlDefinition>
</nifty-controls>

Ultimately I plan on replacing this particular listbox with a different list control I made based on the ScrollPanel control, but for now I’m still using that.

As far as hating Nifty, I suppose you could write your own UI API or use one of the other available GUIs for jME. I find that Nifty has a bit of a learning curve, but, in my personal experience, things get much easier once you get used to it.

making as simple listbox sould’nt be so criptic, and the doc sometimes is not really furnished

even if my entry point is not called becos of a misplaced tag , the whole listbox should still behave on its own and show the selection effect

still not working, the listbox, as I click on it does not even change it’s state

if at least I could add the latest version of nifty to JME3 so I would have the last updates and be able to debug what’s wrong
[damned I finaly got it to work , visible to mouse= false for my child component
alos backgroundcolor=#0000 was messing up the color bar collor … wtf ?? anyways thanks everyone

but interract “had to” be in the control definition

    <controlDefinition name="marketItemListItem" controller="de.lessvoid.nifty.controls.listbox.ListBoxItemController">
        <interact onClick="listBoxItemClicked()" />
        <effect>
        <onCustom customKey="select" name="colorBar" post="false" color="#000F" neverStopRendering="true" timeType="infinite" />
        <onCustom customKey="select" name="textColor" post="false" color="#0FFF" neverStopRendering="true" timeType="infinite" />
      </effect>  
      <panel id="#marketItemListItem" childLayout="horizontal" width="*" height="66px" >
           <control name="marketItem" itemType="$itemType" amount="$amount" buyer="$buyer" credits="$credits" imageFileName="$imageFileName" />
      </panel>
    </controlDefinition>