NiftyEventSubscriber pattern event not firing

I’m having the Nifty Event Bus fail to fire the event, or having it correctly wired to my annotated method.



I have 2 different series of Droppable Controls (1 handling my inventory, and 1 handling my equipped items), my droppabledroppedevent fires for only 1 (the inventory).



Here is my code below:



[java]

// never fires

@NiftyEventSubscriber(pattern = “equip-.")

public void onEquipmentChanged(final String id, final DroppableDroppedEvent event) {



}



// works fine

@NiftyEventSubscriber(pattern = "inventorySlot
.”)

public void onInventoryItemChanged(final String id, final DroppableDroppedEvent event) {



}

[/java]





So, these are in the same class (a controller,screen controller, and DroppableDropFilter). The overriden accept method (for the filter part) works as intended and fires off for both series of droppable controls and returns the correct bool (which is true).



I’ve checked and checked, and rechecked that the equipment series of droppables all have ids that start with “equip-” per my pattern above. Is it possible that Nifty only allows one of these annotated methods per control type?



Any and all help or suggestions is very much appreciated!





/A

Is it possible that Nifty only allows one of these annotated methods per control type?


Maybe :P. Btw I think using one method for both controls is the most correct when talking about patterns. Because when you are going to use "pattern" it means the method will be used for several controls, it makes sense. Maybe it works with "@NiftyEventSubscriber(id="myControlId")" instead. If it doesn't, then use the same suffix for your controls per type and do "@NiftyEventSubscriber(pattern=".*mySuffix").".

Apparently, if I got a little more fancy with the RegEx it worked… not exactly sure this makes sense to me, but I got it via.



java[/java]



The thought being that there would be something before it…but after it fires I inspected the event source and it has no character before the ‘equip-’ in the id…



So, not sure–it’s fixed–but I wish I knew why.

1 Like

…because . is not the same thing as . and simply pattern="(equip-).*" would have worked I guess.

Thank you for this pattern discussion, I was looking for something like this to pick up events from 2 text fields at the same time. +1’ed you @alucard :smiley:

An immensely useful utility for sorting out regexes:
http://www.weitz.de/regex-coach/

1 Like

@void256 sorry for bothering. But i have some issues with event.getSource() . If i drop my item first time i get the Source=null.

My code:
[java]
@NiftyEventSubscriber(pattern = “InventorySlot.*”)
public void onInventoryItemChanged(final String id, final DroppableDroppedEvent event) {
event.getSource();
}
[/java]

So if i drag the item first tine - i get event.getSource()=NULL .
The same issue is in the DroppableDropFilter.

Here is the code:
[java]
public class PRItemDropFilter implements DroppableDropFilter {

public boolean accept(Droppable drpbl, Draggable drgbl, Droppable drpbl1) {

}}
[/java]
Where drpbl=NULL will be in the same case when i drag my item first time.

Tested on NIfty 1.3.3/1.3.4.
Is it a bug?

@mifth said: @void256 sorry for bothering.

Tested on NIfty 1.3.3/1.3.4.
Is it a bug?

Ahh! It seems you fixed it in 1.4. Now it’s possible to set Droppable befor creation of the Draggable. https://github.com/void256/nifty-gui/blob/1.4/nifty-controls/src/main/java/de/lessvoid/nifty/controls/dragndrop/DraggableControl.java#L384
Sorry for bothering again.