PDA

View Full Version : WindowReferenceControl problem?



neilgfoster
December 15th, 2010, 20:28
Hi there, I am wondering if anyone has experienced the following issue, or if its just me!

I have a character sheet which features a windowslist. The classes within the windowlist contain nothing more than a name and a windowreferencecontrol. The windowreferencecontrol opens a new window which simply shows the name.

This all works fine when hosting a campaign, creating a new character and creating new items in the windowlist. The problem appears when creating a character locally - the window opened by the windowreferencecontrol does not appear to link correctly so changing the name in the window that is opened is not reflected back in the charactersheet.

The windowreferencecontrol works fine when running locally if placed straight in the charactersheet (like the minisheets in the 3.5e ruleset) - it just doesn't seem to work when in a windowlist and running locally.

any ideas?

Moon Wizard
December 15th, 2010, 23:21
The challenge is that the windowreferencecontrol data is the link path saved when the link was created. Currently, the data path for the primary database is different when in host mode versus local mode. (i.e. in local mode, the character list node is the root, whereas in host mode, the character list node is a child of the root.)

This is the root of most of the issues when running any ruleset in local mode, and something that is on my list to look at. Due to backward compatibility issues, any fix will probably require a minor ruleset update to enable the changes.

Regards,
JPG

neilgfoster
December 16th, 2010, 09:33
Hi Moon_Wizard, thanks for the reply.

I suspected as much. Do you have any ideas whether a work-around is possible? Either writing my own WindowReferenceControl or even a 'local' version of a charactersheet? I'm very familiar with Lua so scripting isnt a problem, just wondering if its even possible or not.

Thanks.

Moon Wizard
December 16th, 2010, 19:37
You can potentially write a custom control that checks whether you are in local mode or not, and then handles clicks/drops differently depending on the situation. Basically, you are either going to append or drop "charsheet." at the beginning of any link you accept, or window you open.

Cheers,
JPG

neilgfoster
December 17th, 2010, 08:37
Think Ive found a solution.

I changed my windowreferencecontrol to a buttoncontrol in order to simplify the problem, calling Interface.openWindow(class, datasource) in the onButtonClick event.

Now, the documentation states that datasource should be the name of the datasoure to use - so I used the node name and experienced the same issue (works in host, not in local) I tried prefixing the node name with "character." as characters in local mode are stored under under 'character' elements in the xml file - stll no luck.

So I tried something else - instead of passing the node name, I passed the actual node (window.getDatabaseNode) - and it works!

Not sure if this is an 'official' way of opening windows (passing a node rather than a node path) but it works for now.

All I need to do now is add the drag/drop functionality into my control.

Thanks for your help moon_wizard

neilgfoster
December 17th, 2010, 10:28
Right, heres a stab at a working control. I have replicated the functionality of the windowreferencecontrol, with the following limitations :

1) Drag/Drop does not work in local mode
2) CloseToggle does not work in local mode
3) Does not support AcceptDrop

The reasons these do not work in local mode stems back to the fact that the API expects a node path yet, as moon_wizard mentions, in local mode the retrieval of a database node based on its path fails.

Still, this works fine in host mode, and well enough in local mode for most things.



<template name="windowreference">
<buttoncontrol>
<icon>
<normal>button_openwindow</normal>
<pressed>button_emptytarget</pressed>
</icon>
<script>
local dragging = false;

function onButtonPress()
if class then
local node = window.getDatabaseNode();
local openwindow = true;
if not User.isLocal() then
if closetoggle then
local w = Interface.findWindow(class[1], node.getNodeName());
if w then
w.close();
openwindow = false;
end
end
end
if openwindow then
if node then
Interface.openWindow(class[1], node);
end
end
end
end

function onDrag(button, x, y, draginfo)
if User.isLocal() then
return nil;
end
if nodrag then
return nil;
end
if not dragging then
if class then
local node = window.getDatabaseNode();
if recordname then
draginfo.setShortcutData(class[1], recordname[1]);
else
draginfo.setShortcutData(class[1], node.getNodeName());
end
if description then
if description[1].field then
local descriptionnode = node.getChild(description[1].field[1]);
if descriptionnode then
draginfo.setDescription(descriptionnode.getValue() );
end
else
if description[1].text then
draginfo.setDescription(description[1].text[1]);
end
end
end
draginfo.setType("shortcut");
draginfo.setIcon("button_openwindow");
end
end
return true;
end

function onDragEnd(draginfo)
dragging = false;
end

function onInit()
if not User.isLocal() then
setHoverCursor("hand");
end
end
</script>
</buttoncontrol>
</template>