PDA

View Full Version : Mastering windowreferencecontrol



Tarostar
November 10th, 2008, 11:34
After changing the combattracker to save data in the database the <windowreferencecontrol name="link"> no longer works to open up NPCs or PCs. It opens the correct window but only with the data from the combattracker and modifying the data updates the combattracker but not the original character/NPC sheet.

After adding some print commands I see the problem is the record being opened is from the current window rather than the sheet I stored in the windowreferencecontrol. So for example combattracker.list.id_00001 rather than charsheet.id-00003. I have a few ideas, but since I'm unable to test them until tonight I'll list them here to sort out my own thinking and hopefully get some insightful help.

1. Remove the default <class>npc</class> as it may somehow be overriding the record (and besides I don't see any point in having it there?).

2. Change it to windowreferencefield so that it will be stored. However this shouldn't make a difference as long as I don't close the window, so I doubt this will sort the problem.

3. Abandon the windowreferencecontrol and write my own custom buttoncontrol instead that uses a script to handle storing the databasenode when set and retriveing it in onInit. Less elegant, but should work...

Comments?

Tenian
November 10th, 2008, 13:30
Just to be clear:

1) You are taking a personality/character and dropping it onto the combat tracker. This creates an entry in the combat tracker's window list.

2) The combat tracker's window list entry contains a windowreference. Clicking on this reference refers back to the window list entry and not to the source object (character sheet/personality)

If this is the case, it should just be a matter of changing the function that adds them to the combat tracker. Typically this is an onDrop event that probably breaks off into specialized routines based upon the type of object dropped (addNPC, addPC)

Within those specialized routines is the code that sets the windowreference (and everything else). It should just be a matter of getting the shortcut information from the dragdata (see https://www.fantasygrounds.com/refdoc/dragdata.xcp#getShortcutData) and setting that on the newly created entry.

Tarostar
November 10th, 2008, 14:54
Your description is correct, but I am already setting the class and record of the dragdata exactly like it's done in the standard d20 rules example.

So in addPC(source, token):


newentry.link.setValue("charsheet", source.getNodeName()); newentry.link.setVisible(true);


and in onDrop(x, y, draginfo):


if source and class == "npc" then
local newentry = addNpc(source);
newentry.link.setValue(class, datasource);
newentry.link.setVisible(true);
end


I used print statments and the class and datasource is being set correctly for the <windowreferencecontrol name="link">, but when I click on the link it does not use that data as explained in my initial post.

I think it is something about the nature of a windowreferencecontrol, according to the refdoc (https://www.fantasygrounds.com/refdoc/windowreferencecontrol.xcp): "the windowclass and data source of the created window will match the ones specified in the definition, or the ones in the contained shortcut value." It seems it is ignoring my setValue and just using the current database node of the entry instead. I'm just not sure why as I've not closed the window or done anything that should cause it to overwrite the data.

Tenian
November 10th, 2008, 15:25
I vaguely remember having a similar problem. I believe I used dragdata to get around it.

Your XML for link doesn't include a datasource element does it?

Also the code you posted seems to come from 2 different sections, the addPC function and then a block that calls the addNPC function.

Tarostar
November 10th, 2008, 15:59
I vaguely remember having a similar problem. I believe I used dragdata to get around it.

Your XML for link doesn't include a datasource element does it?

Aha! Thanks for hammering the point home I thought you were talking about setting the windowreferencecontrol with the dragdata from onDrop, but now I understand that is not what you meant. So if I understand you correct (this time) you are suggesting I add a script to the windowreferencecontrol for onDrag, something like this:



function onDrag(button, x, y, draginfo)
draginfo.setType("shortcut");

local base = draginfo.createBaseData("shortcut");
base.setShortcutData(getValue());

draginfo.resetType();

return true;
end


I looked at the code in reference_spells.xml in <windowreferencefield name="link"> and modified it to get the above. I don't understand yet how this will help it to open the correct node though, so probably I'm missing something...

Annoying to not be able to test this, so thanks for your help so far. :)

Tarostar
November 10th, 2008, 19:05
Well I figured it out.

Removed the <class>npc</class> and changed it to a windowreferencefield and it now works like a dream.