Game Development Community

MouseMovement in a GUI (Drag and Drop)

by Colin Richardson · in Torque Game Builder · 08/09/2009 (12:43 pm) · 0 replies

Hello,

Been a few days since my last post. I must say i'm getting on quite well with our game and even though we set the pole quite high i feel we're able to get there.

However every now and then something gets in my way, and this it todays.

I'm working on an inventory system for our RPG style game. I have the Inventory GUI frame done, and now i'm designing the workings.

The Inventory will have a background and part of that will be the slots for each pack carried. For each slot i plan to have an image of the type of slot (say Hands) and then overlay that with the item in that location.

Now comes to the tricky part.

I want to be able to drag and item from anyone slot and drop it into another slot.

I've been doing some research on this and i found this great resource from Matthew Langley
www.garagegames.com/community/resources/view/7540

Using it (i've updated it to work inside my game) it allows me to take any item that i tick as selectable and drop it anywhere and then using the sceneWindow2d::onMouseDown i can run checks to see if i want it there.

That's perfect, however i want this to work inside my Inventory GUI yet i can't seem to find a way to do this.

So i researched that issue and i've since seen that IF i make all my graphical items/slots button's i then do get the feedback so i perhaps could code it like that and make sure nothing out.

However i tried that and it didn't work, for example

I called my button guiInventoryButton and ticked the 'useMouseEvents' chech box (it's a GuiBitmapButtonControl).
function guiInventoryButton::onMouseDown( %this, %mod, %worldPos, %mouseClicks )  
{  
     echo("Mouse Down");  
    //lets store the mouses position  
    //%this.mousePos = %worldPos;  
    //%this.objectFollowCheck();  
}

Yet this doesn't get called (and i know it's been compiled fine as i stuck a bug inside it to check).

Another bit of research told me i could modify the source and add the mouse behaviour to all the controls, however i'd rather not tinker with the source code unless i really have to.

So open to suggestions here, if there's a method to get Matthew Langleys code working inside my large GUI all good, if not how to get my code to read the button events in the example i've given above.

Many thanks in advance and apology on a long post.
Colin