PDA

View Full Version : onDrop function and dragdata



joshuha
June 19th, 2007, 14:42
I have created my own custom genericcontrol that I want to drop a die on to do some special processing. However, any time I drag and drop a die onto the control it tells me dragdata is nil after the die hits the control when I release the click. Am I doing something wrong or is a die not triggering a dragdata object?



function onDrop(button,x,y,dragdata)
if dragdata.type == "dice" then
print(dragdata.getDieList()[1].type);
end
end


I do have the droptype defined in the control as well:


<droptypes>
<type>dice</type>
</droptypes>

Dachannien
June 19th, 2007, 17:42
There's an error in the documentation. The onDrop event function only provides three parameters: x, y, and dragdata.

joshuha
June 19th, 2007, 18:09
Ahh thanks! Will try that out.

joshuha
June 20th, 2007, 04:20
Alright that worked, thanks.

Next quest but related is how do I go from a custom dragdata and pass that to the onDrag function to use that dragdata?



function onDrag(button,x,y,dragdata)
dragdata = dragdata.createBaseData("dice");
die = {};
die.type = source.getValue();
dragdata.setIcon(die.type .. "icon");
dragdata.setDieList(die);
dragdata.setDescription(getName());
print("FIRING");
return true;
end


The above when my control is click and I drag the mouse around does a constant firing but no icon or dragdata becomes apparent. I am guessing this is because onDrop is returning it what dragdata is getting from the control which is nothing. Can I on the onInit funciton create the dragdata or is there some sort of setDragData function I am missing?

TarynWinterblade
June 20th, 2007, 07:25
Alright that worked, thanks.

Next quest but related is how do I go from a custom dragdata and pass that to the onDrag function to use that dragdata?



function onDrag(button,x,y,dragdata)
dragdata = dragdata.createBaseData("dice");
die = {};
die.type = source.getValue();
dragdata.setIcon(die.type .. "icon");
dragdata.setDieList(die);
dragdata.setDescription(getName());
print("FIRING");
return true;
end


The above when my control is click and I drag the mouse around does a constant firing but no icon or dragdata becomes apparent. I am guessing this is because onDrop is returning it what dragdata is getting from the control which is nothing. Can I on the onInit funciton create the dragdata or is there some sort of setDragData function I am missing?

Wow... the refdoc is horribly confusing on this point...



To support specialized operations in cases where a default function is applicable, a base dragdata inherited object can be created. An example of such a case could be a token control that attaches extra information to a token, but it is still desired that the drag can be used as a framework supported "token" drag if the custom type is not supported by the target element. To implement this, the custom data should first be set, and the createBaseData function used to create the base object. The returned reference to the base object can then be used to set up data matching a built in type. Base objects can be chained.


... which would lead me to think that createBaseData would be last... however, that's obviously not the case, since createBaseData returns a dragdata object instead of being passed one.

What I think you may need to do, though, is:



function onDrag(button,x,y,dragdata)
dragdata = dragdata.createBaseData("dice");
die = {};
die.type = source.getValue();
dragdata.setIcon(die.type .. "icon");

dragdata.setType("MyType");
dragdata.setSlot(1);
dragdata.setDieList(die);
dragdata.setDescription(getName());
print("FIRING");
return true;
end


The icon isn't necessary, iirc, as the program will always render any dice it has attached to the drag data. Also, you probably need the slot set beforehand (dunno... the whole slot system is... strange, imo).

Anyways, I hope that helps... (I'd be more long winded and try and test it, but I've gotta be up and getting ready for work in 6 hours... :cry: )

joshuha
June 22nd, 2007, 18:32
Doesn't work either. I think it would work using a control that normally spits out a dragdata and then you could modify it. However, I am using a genericcontrol (for the icons) and I think I need a way to tell the system to use custom dragdata (like a setDragTemplate or something).

Any comments on this devs?

(the work around I think I can do on this is to use the diecontrol and overlay a bitmapwidget icon on it and then modify that dragdata but I am not sure if that is going to work for what I want to do.)

TarynWinterblade
June 23rd, 2007, 06:46
Doesn't work either. I think it would work using a control that normally spits out a dragdata and then you could modify it. However, I am using a genericcontrol (for the icons) and I think I need a way to tell the system to use custom dragdata (like a setDragTemplate or something).

That shouldn't be the case. If you look at charsheet_combat.xml, the control that you can drag the attack dice from is a linkednumber.

Can't... really think more right now... *sigh* Sorry.

joshuha
June 23rd, 2007, 14:24
Yeah but a numberfield supports dragdata by default so its modifying it. I might need to convert my genericcontrol over to something like that.

phantomwhale
January 30th, 2011, 03:08
There's an error in the documentation. The onDrop event function only provides three parameters: x, y, and dragdata.

How I got caught out by this after writing dozens of these handlers, I'll never know... but THIS ERROR is still in the documentation !

Worth adjusting before it get's to it's fourth year anniversary ?!?