I created a Nifty ListBox with a custom ListItem control, containing a few text elements as well as an image.
With the help of this Tutorial here this was easy doable, so thanks for that.
<control id=“shopBuyList” name=“listBox” vertical=“off” horizontal=“off” selection=“Single” viewConverterClass=“de.ethasia.terratown.gui.ShopItemConverter”>
<control name=“shopItem” />
However I encountered a few issues when it comes to selecting items in my new ListBox. As the Tutorial notes in the last part, I have to create a style, or at least assign an existing one. I just assumed that the style has to be set on the ListItem control I created, as the Tutorial doesn’t mention anything specifically.
For easy testing, I just used the Nifty standard style for ListBox items.
<controlDefinition name=“shopItem” style=“nifty-listbox-item”>
<panel childLayout=“horizontal” width=“100%” align=“left”>
With that definition, the color changes when hovering above an item just fine, but if I click on an item, <b>only the first item in the ListBox will be selected.</b> (I can use the arrow keys to change the selected item though). In addition to that, the <b>onListBoxSelectionChanged-Event</b> is not called in any of those cases.
I’m certain that this has only to do with my custom Item, because if I remove it from the ListBox and just add strings, everything behaves as expected.