PDA

View Full Version : dragdata question



drahkar
January 5th, 2011, 10:58
Is there a way to create a dragdata instance without having to have the object created in a onDrag or onDrop event function?

Zeus
January 5th, 2011, 11:51
Use the CreateBaseData(type) (https://www.fantasygrounds.com/refdoc/dragdata.xcp#createBaseData) method.

neilgfoster
January 17th, 2011, 16:59
Hi Drahkar,

Did you try this, and does it work? My impression was that you need dragdata in order to call CreateBaseData (as its a method of dragdata)

I too have the need to be able to create a new dragdata without starting a drag/drop operation. Basically, I want to create a dice pool by the user right-clicking on a special desktop panel. So far, I haven't been able to find a way.

drahkar
January 17th, 2011, 17:03
Unfortunately I haven't been able to find a way to create the object. I've worked around it by using onClick events. Not the best solution, but its a usable one. Basically i rebuilt my code to create all the data initially during the onDoubleclick event and then stuff all of that into the dragdata that is created by the onDoubleClick event.

I still would really like to be able to create the dragdata object on my own. Perhaps that could be worked into a future version of the FG2 engine.

Zeus
January 17th, 2011, 17:18
I am not sure I am following the problem correctly as createBaseData() takes a type (string, number etc. etc.) and returns a dragdata object? I usually call it from within an onDrag() method you create for the object your dragging.

e.g.


function onDrag(button, x, y, draginfo)
local mybasedata = draginfo.createBaseData() -- or pass it the type of object you want created.

-- then manipulate as per normal e.g.
mybasedata.setStringData("Hello");

...

end

drahkar
January 17th, 2011, 23:53
We were attempting a situation were our code would create the dragdata object without being within functions like the onDrag event where it creates and passes the draginfo to the contained code. Thats what we were commenting on.

Oberoten
January 18th, 2011, 00:02
I think the solution is a windowlist with

<acceptdrop class="classname" fields="fieldname1, fieldname2" />

- Obe

neilgfoster
January 18th, 2011, 16:13
Drahkar is right, I am trying to start a drag/drop operation in script - without the user actually dragging or dropping anything!

The functionality that I'm trying to re-create is similar to a right click on one of the dice. When you right-click on a dice you are presented with a menu allowing you to select the number of dice you want. You select the number and bam! your mouse pointer now shows that you are holding the right number of dice.

This must start a drag operation and set-up the correct dragdata - but without the user actually dragging anything. I have a custom control to which I would like to add a similar behaviour - right click, select an option, and a dice-pool is automatically created.

Problem is that I can find no way to start a drag/drop operation in script.

Zeus
January 18th, 2011, 16:35
I see. I'm not sure about that then. I'll have to give it a think. Is your control a diefield or a generic control?

Setting up two controls close together to appear as one e.g a diefield and a generic control may yield a similar capability. i.e click the generic control to set the number of die and then update the diefield in script with the appropriate number of die. Downside of course is the user then has to initiate the drag.

Alternatively, do you really need the drag/drop capability? What about right click to select number of die and left double-click to roll? That's how I implement table and partysheet rolls in the same named extensions for 4E.

neilgfoster
January 18th, 2011, 16:40
The drag/drop functionality is not essential - just a 'nice to have' in order to make its use consistent with other controls.

Thanks for the idea regarding right-click then double-click. Ill have a look into this to see how well it could work.

drahkar
January 18th, 2011, 16:53
I worked around it by creating a bunch of global controls that compiled the information seperately and then are referenced when I double click the pool to roll it. Not as pretty as dragging the dice, but it works.

neilgfoster
September 17th, 2011, 10:40
Bump.

Im just wondering if, with the release of 2.8, if there is anyway to achieve the results as posted at the start of the thread - i.e. to start a drag operation from code, rather than from the user actually dragging and dropping.

I would like to be able for a user to right click on a custom desktop panel, select an option, and the code to start a new drag operation - just like when you right click on a dice, select the number, and suddendly you have X number of dice under the mouse pointer.

MoonWizard - if your reading this, do you know if is possible and if not, could it be included for a future release? It would be very nice to have.

Thanks.

Moon Wizard
September 24th, 2011, 22:26
No, there is no mechanism for doing that.

It actually gets a bit complicated in the code, since the drag operation has to make assumptions about the state that may not be true in the scenario you describe. (i.e. either mouse button clicked down and up to select menu option, so no mouse button down currently.)

Your best bet currently is to make separate draggable control objects for each type of drag.

Regards,
JPG