PDA

View Full Version : draginfo's getTokenData



Ken L
May 31st, 2018, 06:41
Draginfo's getTokenData allows for multiple returns. This is used in ctentry's tokenfield's onDragEnd to receive both the prototype and the token reference which it uses to replace its own.

local prototype, dropref = draginfo.getTokenData();

setTokenData however only allows setting the string prototype.
https://www.fantasygrounds.com/refdoc/dragdata.xcp#setTokenData

How can I set a token reference in the draginfo's token data? The use case here is an onDrop method where I'm handling a 'token' type draginfo. IE: dragging a token from the CT to an image control.

pindercarl
May 31st, 2018, 14:26
The token that appears on the image control is a token instance. The token control that appears on the combat tracker only includes the token prototype. That prototype is used to create the token instance on the image control. The data that you are looking for does not exist until after a token instance is added to the image control after the onDrop is handled.

Ken L
May 31st, 2018, 15:03
I'm attempting to replicate the default behavior of onDrop such that I can return true on it and prevent the default onDrop from processing. That means I need to perform the exact function of the default onDrop along with my additional logic. However, without the ability to set the token reference/instance, the onDragEnd call that's invoked by the tokenfield of the ctentry, will not find the token reference it needs to finish its process.

From the ruleset reference, it denotes that onDragEnd is invoked on the process that caused the onDrop, (which in this case, is the tokenfield within the ctentry, with the same draginfo reference) and that the draginfo should be modified to transfer information pertinent to that process. The bit of information here is setting the valid token instance that I create with the imagecontrol's addToken.

I could side-step this and manually get the ct window, and the entry, but I'd rather use the built in event chain of onDrop -> onDragEnd.

I believe there may be more, but I'll have to check when I get back later tonight.

pindercarl
May 31st, 2018, 15:21
Unless I've missed something, there is no API call that can directly set the token instance of the drag data.

Ken L
May 31st, 2018, 15:56
So I assume the native onDrop for an imagecontrol can do more than the API allows? It's black box then and I'll have to manually set the reference it seems.

pindercarl
May 31st, 2018, 16:05
Windows and controls have there own event handlers. Executing the LUA is only part of that. Dragging to select text in a formatted text control, for example, is not executed through LUA. It is a native function.

Ken L
May 31st, 2018, 21:41
I figured as much, just expected the get and set methods to be symmetrical, which they aren't. I think I'll have to do this the long way.