Drag and Drop – confused! (bump)

Hi,

First off, thanks for making this GUI toolkit. I’m new JME and to game development, although a long time Java programmer. Nifty, although great, was starting to drive me crazy, and this seems to be the solution :slight_smile:

I’m a bit confused as to how drag and drop works though. I have a DragElement, and it can happily be dragged, and spring back works, but I can’t seem to make it drop anywhere.

The wiki mentions “dragEl.addDropElement(Element element);”, but I can’t find any mention of this method anywhere. I’m sort of glad of this, it looks hard to maintain if that method does what it appears to do.

When “onDragEnd(MouseButtonEvent mbe, Element el)” gets called, “el” is null no matter where the element is dropped. Digging through the source, it appears this should be the target element.

Any ideas?

@rockfire said: Hi,

First off, thanks for making this GUI toolkit. I’m new JME and to game development, although a long time Java programmer. Nifty, although great, was starting to drive me crazy, and this seems to be the solution :slight_smile:

I’m a bit confused as to how drag and drop works though. I have a DragElement, and it can happily be dragged, and spring back works, but I can’t seem to make it drop anywhere.

The wiki mentions “dragEl.addDropElement(Element element);”, but I can’t find any mention of this method anywhere. I’m sort of glad of this, it looks hard to maintain if that method does what it appears to do.

When “onDragEnd(MouseButtonEvent mbe, Element el)” gets called, “el” is null no matter where the element is dropped. Digging through the source, it appears this should be the target element.

Any ideas?

Sorry fr the delay on response. Had a very busy week. The drag/drop functionality is probably the least developed of all, unfortunately and I am fairly sure that this was changed at someones request who was using it fairly extensively. Let me do a bit of looking through my notes here and give a definitive answer on how this works now. It won’t be long!

Hehe four hours is not a long time, please do not worry :slight_smile: Ok, I figured it was something like that. I know this is still only beta and I am expecting some rough edges. I look forward to your definitive answer!

RR

1 Like

This is becoming more important to me now., and as much as I hate doing this… bump

Any news?

I am interested in this as well, an update would be nice. TonegodGUI was making some excellent progress then it flat-lined.

I am not sure what I was doing wrong orginally, but after going back to basics I have this working now. I think the key is using setIsDragDropDropElement() on the element you wish to allow drops. The below examples works for me, except the spring back doesn’t seem to work properly (it just disappears completely on rejected drop).

[java]

import com.jme3.app.SimpleApplication;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector4f;
import com.jme3.renderer.RenderManager;
import tonegod.gui.controls.extras.DragElement;
import tonegod.gui.controls.windows.Window;
import tonegod.gui.core.Element;
import tonegod.gui.core.Screen;

public class TestDnd extends SimpleApplication {

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

@Override
public void simpleInitApp() {
    flyCam.setDragToRotate(true);

    // Tonegodgui bits
    Screen screen = new Screen(this);
    Window window = new Window(screen, new Vector2f(100, 100));
    window.getDragBar().setText("Drag Test");
    window.setIsMovable(true);
    window.setIsResizable(false);
    
    // A place to drop (we will accept drop here). I think a dropable can be
    // anything that extends Element as has setIsDragDropDropElement(true)
    Element dropOk = new Element(screen, "DropOk", new Vector2f(150, 60), new Vector2f(180, 20), Vector4f.ZERO, null);
    dropOk.setText("Drop OK here!");        
    dropOk.setIsDragDropDropElement(true);
    
    // And now another drop element. This one we reject dynamically at end of drag,
    // but still need to make droppable
    Element dropNotOk = new Element(screen, "DropNotOk", new Vector2f(150, 120), new Vector2f(180, 20), Vector4f.ZERO, null);
    dropNotOk.setText("Don't drop here!");
    dropNotOk.setIsDragDropDropElement(true);

    // Draggable thing
    DragElement draggable = new DragElement(screen, new Vector2f(40, 90), new Vector2f(120, 20), Vector4f.ZERO, null) {
        @Override
        public void onDragStart(MouseButtonEvent evt) {
            System.out.println("Drag started");
        }

        @Override
        public boolean onDragEnd(MouseButtonEvent evt, Element dropElement) {
            if(dropElement == null) {
                System.out.println("Don't drop nowhere!");
                return false;
            }
            else if(dropElement.getUID().equals("DropNotOk")) {
                dropElement.setText("I said DONT!");
                return false;
            }
            else {
                setText("");       
                dropElement.setText("Thanks for dropping!");                    
                return true;
            }
        }
    };
    draggable.setUseSpringBack(true);
    draggable.setText("Drag me!");
    
    // Add and show
    window.addChild(draggable);
    window.addChild(dropOk);
    window.addChild(dropNotOk);
    screen.addElement(window);
    guiNode.addControl(screen);

}

@Override
public void simpleUpdate(float tpf) {
}

@Override
public void simpleRender(RenderManager rm) {
}

}
[/java]

https://code.google.com/p/tonegodgui/issues/detail?id=44
there is a file atached whit fixed DragElement springback

Thanks, that’s great, worked perfectly :slight_smile: