I’m having some trouble implementing an inventory system. When I click and drag on an item, the item disappears. When I release the item, it reverts back to where it was. After multiple click-and-drags, the item disappears completely.
I’ve tried to do some digging and I think there’s something wacky going on with the popup layers during the drag. I think the item is going to the popup layer correctly via dragStart(), but then the drag() and dragStop() don’t seem to be firing. Worse, the item doesn’t seem to go back to its slot when done. So the next click and drag is actually dragging the window behind the item.
I’ve created a simplified project that is exhibiting this behavior. Any ideas or suggestions would be appreciated. Thank you in advance!
Main.java:
[java]import com.jme3.app.SimpleApplication;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.renderer.RenderManager;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
/**
- test
-
@author me
*/
public class Main extends SimpleApplication
{
private NiftyJmeDisplay m_display = null;
private MyScreenController m_myScreenController = null;
public static void main(String[] args)
{
Main app = new Main();
java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING);
app.start();
}
@Override
public void simpleInitApp()
{
// fix camera so that mouse can be used to move items rather than point the camera
flyCam.setDragToRotate(true);
// Create GUI
m_display = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
guiViewPort.addProcessor(m_display);
Nifty nifty = m_display.getNifty();
nifty.fromXml("/Interface/inventoryScreen.xml", "inventory");
Screen screen = nifty.getScreen("inventory");
m_myScreenController = (MyScreenController)screen.getScreenController();
m_myScreenController.bind(nifty, screen);
}
@Override
public void simpleUpdate(float tpf)
{
}
@Override
public void simpleRender(RenderManager rm)
{
}
}[/java]
MyScreenController.java
[java]import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.builder.ImageBuilder;
import de.lessvoid.nifty.controls.dragndrop.builder.DraggableBuilder;
import de.lessvoid.nifty.controls.dragndrop.builder.DroppableBuilder;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
import de.lessvoid.nifty.tools.SizeValue;
/**
*
-
@author me
*/
public class MyScreenController implements ScreenController
{
private Screen m_screen;
private Nifty m_nifty;
public void bind(Nifty nifty, Screen screen)
{
m_screen = screen;
m_nifty = nifty;
}
public void onStartScreen()
{
Element window = m_screen.findElementByName(“inventoryWindow_1”);
Element e1 = new DroppableBuilder(“inventoryWindow_1#slot_1”)
{
{
childLayoutCenter();
width(“64px”);
height(“64px”);
style(“nifty-panel”);
}
}.build(m_nifty, m_screen, window);
e1.setConstraintX(SizeValue.px(0));
e1.setConstraintY(SizeValue.px(0));
Element e2 = new DroppableBuilder("inventoryWindow_2#slot_2")
{
{
childLayoutCenter();
width("64px");
height("64px");
style("nifty-panel");
}
}.build(m_nifty, m_screen, window);
e2.setConstraintX(SizeValue.px(75));
e2.setConstraintY(SizeValue.px(0));
Element i1 = new DraggableBuilder("item")
{
{
childLayoutCenter();
revert(true);
image(new ImageBuilder()
{
{
filename("Icons/Potato.png");
}
});
}
}.build(m_nifty, m_screen, e1);
}
public void onEndScreen()
{
}
}[/java]
inventoryScreen.xml:
[xml]<nifty xmlns=“http://nifty-gui.sourceforge.net/nifty-1.3.xsd” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd”>
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<!-- start screen -->
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<useControls filename=“nifty-default-controls.xml”/>
<useStyles filename=“nifty-default-styles.xml”/>
<controlDefinition name=“InventoryWindow”>
<control name=“draggable” width=“300px” height=“74px” style=“nifty-panel” childLayout=“absolute” revert=“false” drop=“false” visible=“true”/>
</controlDefinition>
<screen id=“inventory” controller=“mygame.MyScreenController”>
<layer id=“inventoryLayer” childLayout=“absolute”>
<control id=“inventoryWindow_1” name=“InventoryWindow”/>
</layer>
</screen>
</nifty>
[/xml]