Draggable Controls not receiving focus (or registering event) when clicked

Hi all.

This is an issue I’ve now been wrestling with an obscene amount of time.

I have an inventory system with slots for items on a base bar. Items are draggables that are created and placed on the droppable slots. If the GUI has been clicked (say to open the inventory), any item clicked will move as expected.

However, if the main screen (a non setVisibleToMouse area) has been clicked before a draggable is clicked, the draggable will NOT move on the first click. So, you click on the main (jME) screen, go to move an item, and it will not respond. In fact, it won’t respond to any mouse event (it appears).

I have tried to: reset focus onto the draggable using hover events; reset the mouse; make focus on the draggable element exclusive (nifty.getCurrentScreen().getFocusHandler().requestExclusiveMouseFocus(d.getElement())); manipulate the MouseInputEventQueue. I’ve tried every combination of control formation I can think of. Nothing appears to work.

I’ve found this exact issue asked before, but it was never answered: Slick Forums • View topic - Nifty-GUI: Creating and attaching Drag'n'Drop objects

Any help here would be hugely appreciated.

You may need a response from @void256 from this, it’s certainly not something I’ve used :frowning:

I’ve been in contact with @carbonnz and he provided example code to reproduce the issue. I think we’ve fixed this now. I’m about to commit the change to svn and will update this issue here with the link to the commit.

Here is the provided example code which helped me to reproduce the issue for reference:

[java]import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.builder.LayerBuilder;
import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.builder.ScreenBuilder;
import de.lessvoid.nifty.controls.dragndrop.builder.DraggableBuilder;
import de.lessvoid.nifty.screen.DefaultScreenController;

public class HelloSimple extends SimpleApplication {

public static void main(String[] args){
HelloSimple app = new HelloSimple();
app.start();
}

@Override
public void simpleInitApp() {

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
assetManager, inputManager, audioRenderer, guiViewPort);
Nifty nifty = niftyDisplay.getNifty();
guiViewPort.addProcessor(niftyDisplay);
flyCam.setDragToRotate(true);
nifty.loadStyleFile(”nifty-default-styles.xml”);
nifty.loadControlFile(”nifty-default-controls.xml”);

nifty.addScreen(”Screen_ID”, new ScreenBuilder(”Hello Nifty Screen”){{
controller(new DefaultScreenController());

layer(new LayerBuilder(”Layer_ID”) {{
childLayoutHorizontal();
width(”100%”);
panel(new PanelBuilder(”Panel_ID”) {{
childLayoutHorizontal();
padding(”10”);
valignCenter();
height(”25%”);
width(”25%”);
control(new DraggableBuilder(”test123”){{
backgroundColor(”#ffff”);
}});
}});
panel(new PanelBuilder(”Panel_ID”) {{
width(”50%”);
childLayoutHorizontal();
}});
panel(new PanelBuilder(”Panel_ID2”) {{
childLayoutHorizontal();
padding(”10”);
valignCenter();
height(”25%”);
width(”25%”);
control(new DraggableBuilder(”test1234”){{
backgroundColor(”#ffff”);
}});
}});

}});
}}.build(nifty));
nifty.gotoScreen(”Screen_ID”);

Box b = new Box(1, 1, 1); // create cube shape
Geometry geom = new Geometry(”Box”, b); // create cube geometry from the shape
Material mat = new Material(assetManager,
”Common/MatDefs/Misc/Unshaded.j3md”); // create a simple material
mat.setColor(”Color”, ColorRGBA.Blue); // set color of material to blue
geom.setMaterial(mat); // set the cube’s material
rootNode.attachChild(geom); // make the cube appear in the scene
}
}[/java]

This should fix the problem now: http://code.google.com/p/jmonkeyengine/source/detail?r=10821