PDA

View Full Version : Dragging module entries to a sheet - last big hurdle



nezzir
May 4th, 2007, 12:52
The only thing I haven't been able to figure out so far is the ability to drag a module entry to a sheet and have it stick and link. It's my last big hurdle with this ruleset.

There's an example on the d20 spell sheet, but there's so much other code (tracking class, level, prepared spells, spells per level, etc.) that I can't seem to pick the code out.

If anyone has any idea how I can accomplish that, I'd appreciate it.

Goblin-King
May 4th, 2007, 13:46
This is a simplified version of what the d20 spell system does (didn't test this for typos). Put this into the windowlist control script block.



function onDrop(x, y, draginfo)
if draginfo.isType("shortcut") then
-- Check for valid window class
if draginfo.getShortcutData() == "myspellclass" then
-- Get entries from the data the dragged shortcut points to
local sourcenode = draginfo.getDatabaseNode();

-- Create a new window for the data
local newwin = createWindow();

-- Copy fields, e.g. name
newwin.name.setValue(sourcenode.getChild("name").getValue());

-- Copy the link into a windowreferencecontrol
newwin.shortcut.setValue(draginfo.getShortcutData( ));

return true;
end
end
end

You would need to replace the "myspellclass" string with the windowclass you use for spells and add any other fields in addition to name you want to copy over.

There are some limitations to this simple system.
Doesn't track classes or such
Does not put the new entry into a specific level similar to the d20 version that tracks each level in a separate nested windowlist
Only accepts shortcuts pointing to the one window class

nezzir
May 4th, 2007, 16:09
There are some limitations to this simple system.
Doesn't track classes or such
Does not put the new entry into a specific level similar to the d20 version that tracks each level in a separate nested windowlist
Only accepts shortcuts pointing to the one window class

Thank you very much! I'll get on this asap.

I don't need to track class or level (there are no levels in this system and the classes are more like schools which are a given and not necessary to track). I just want a simple drag and drop. This can also be adapted to inventory/equipment items :)

I'll post my results when I have some.

nezzir
May 5th, 2007, 14:26
See if you can tell where I'm borking this up...



<root>

<windowclass name="charsheet_spellitem">
<sizelimits>
<minimum>
<height>10</height>
</minimum>
</sizelimits>
<sheetdata>

<textlistitemvalue name="name">
<anchored>
<left>
<anchor>left</anchor>
<offset>2</offset>
</left>
<right>
<anchor>right</anchor>
<offset>-310</offset>
</right>
<top>
<anchor>top</anchor>
<offset>5</offset>
</top>
</anchored>
</textlistitemvalue>

<numberfield name="castnum">
<anchored>
<left>
<parent>name</parent>
<anchor>right</anchor>
<offset>10</offset>
</left>
<top>
<anchor>top</anchor>
<offset>7</offset>
</top>
<size>
<width>25</width>
<height>14</height>
</size>
</anchored>
<frame>
<name>textlinesmall</name>
<offset>0,0,0,0</offset>
</frame>
<keyeditframe>
<name>sheetfocus</name>
<offset>6,5,6,5</offset>
</keyeditframe>
<font>sheetnumbersmall</font>
<hideonvalue>0</hideonvalue>
</numberfield>

<textlistitemvalue name="shortdescription">
<anchored>
<left>
<parent>castnum</parent>
<anchor>right</anchor>
<offset>10</offset>
</left>
<top>
<anchor>top</anchor>
<offset>10</offset>
</top>
<size>
<width>250</width>
</size>
</anchored>
<font>sheetlabelsmall</font>
<multilinespacing>15</multilinespacing>
<frame>
<name>textline</name>
<offset>0,5,0,0</offset>
</frame>
</textlistitemvalue>

</sheetdata>
</windowclass>


<windowclass name="charsheet_spells">
<datasource name="spellsheet" />
<placement>
<size>
<width>252</width>
<height>611</height>
</size>
</placement>
<sheetdata>
<genericcontrol name="spelllistframe">
<bounds>15,20,485,405</bounds>
<frame>
<name>sheetgroup</name>
</frame>
</genericcontrol>


<stringcontrol>
<anchored>
<to>spelllistframe</to>
<position>insidetop</position>
<offset>0,11</offset>
</anchored>
<center />
<font>sheetlabel</font>
<static>Frequently Used Spells</static>
</stringcontrol>

<stringcontrol>
<anchored>
<to>spelllistframe</to>
<position>insidetopleft</position>
<offset>13,25</offset>
</anchored>
<font>sheetlabelsmall</font>
<static>Name</static>
</stringcontrol>
<stringcontrol>
<anchored>
<to>spelllistframe</to>
<position>insidetopleft</position>
<offset>175,25</offset>
</anchored>
<font>sheetlabelsmall</font>
<static>Cast</static>
</stringcontrol>
<stringcontrol>
<anchored>
<to>spelllistframe</to>
<position>insidetopleft</position>
<offset>208,25</offset>
</anchored>
<font>sheetlabelsmall</font>
<static>Short Description</static>
</stringcontrol>

<windowlist name="spelllist">
<anchored>
<to>spelllistframe</to>
<position>over</position>
<offset>-12,-9</offset>
<top>
<parent>spelllistframe</parent>
<offset>30</offset>
</top>
</anchored>
<datasource>.spelllist</datasource>
<class>charsheet_spellitem</class>
<allowcreate />
<allowdelete />
<script>
function onDrop(x, y, draginfo)
if draginfo.isType("shortcut") then
if draginfo.getShortcutData() == "charsheet_spellitem" then
local sourcenode = draginfo.getDatabaseNode();
local newwin = createWindow();
newwin.name.setValue(sourcenode.getChild("name").getValue());
newwin.shortcut.setValue(draginfo.getShortcutData( ));
return true;
end
end
end
</script>
</windowlist>

</sheetdata>
</windowclass>
</root>

Goblin-King
May 7th, 2007, 08:42
What is the bit you posted currently doing/not doing?

The only funny thing that I can spot not knowing exactly what is going on is that windows of the class "charsheet_spellitem" are contained in the list, and also the shortcuts that are accepted. If you want to drag in something else from another source, replace the class in the script.

nezzir
May 7th, 2007, 12:10
What is the bit you posted currently doing/not doing?

The only funny thing that I can spot not knowing exactly what is going on is that windows of the class "charsheet_spellitem" are contained in the list, and also the shortcuts that are accepted. If you want to drag in something else from another source, replace the class in the script.

What is it doing:
Nothing really (that I can see). It creates a field. In the field is a header and a short description line. Below that is a "create item" list that matches the description line.

Essentially, you have to manually enter the data. I could never figure out how to drag something onto it. It was the last thing on the character sheet, so I just released it in its current form, till I had time to go back to it: https://www.wrath.co.za/files/wfrp2-fg2-v0.1a.zip
(The databases are bare in this release, so no copyright issues)
(Oh, and the graphics are placeholder till my artist finishes up)

I put this issue, and the issue I was working on with the skills page on the back burner while I work on the database population.