So I’m playing around with drag and drop with Nifty and I have the drag working. I don’t have a drop set up yet as I’m just trying to get the dragging working at the moment.
For the purposes of my game the default drag and drop behavior of moving the draggable to another spot wont work. I’m working on a tower defense kind of game and when the player goes to drag a turret from the inventory into the game, I still need a copy of it to stay in the starting point. So I am trying to use the DraggableDragStartedEvent to determine when the drag starts and make a copy of the dropable to place in the UI so the player can still add more of that turret if they want to. Or is there another way of changing the default behavior so when the player drags they see the item under the mouse/finger but still leaves a copy at the starting point so it can be repeated from the same location?
Here is what I have and it doesn’t seem to be working:
The Nifty book for 1.3.2 (I just now realize JME uses 1.4.2 so this may no longer work and the docs on the github are not as in depth as this book) says to add a methid to your screen controller with the annotation @NiftyEventSubscriber(id=“elementId”) and it must have a String for the first parameter to pass in the id and the second must have an event of the type you want to listen to and its just supposed to work. But its not. I see “bind” in the log and I see “start screen” in the log but when I drag the draggable nothing gets logged. The dragging is working so I know it should be calling this event.
controller(new ScreenController() {
@Override
public void bind(Nifty nifty, Screen screen) {
System.out.println("bind");
}
@Override
public void onStartScreen() {
System.out.println("start screen");
}
@Override
public void onEndScreen() {
System.out.println("end screen");
}
@NiftyEventSubscriber(id="layout")
public void onClick(String id, DraggableDragStartedEvent event) {
System.out.println("drag started");
}
});
And my draggable:
control(new DraggableBuilder("chest") {{
id("layout");
childLayoutCenter();
width("101px");
height("171px");
panel(new PanelBuilder() {{
childLayoutCenter();
text(new TextBuilder(){{
text("My Cool Game");
font("Interface/Fonts/Default.fnt");
alignCenter();
valignCenter();
color(Color.WHITE);
height("5%");
width("15%");
}});
}});
}});
control(new DroppableBuilder("chest")
and@NiftyEventSubscriber(id="chest")
so I also tried changingcontrol(new DraggableBuilder("chest")
tocontrol(new DraggableBuilder("layout")
and it still doesn't work. \$\endgroup\$DraggableDragStartedEvent
might be broken. So I switched to useNiftyMousePrimaryClickedEvent
and I now get an exceptionIllegalAccessException: Class de.lessvoid.nifty.NiftyEventAnnotationProcessor$Subscriber can not access a member of class mygame.Main$1 with modifiers "public"
. Any ideas on why? \$\endgroup\$