PDA

View Full Version : Some Windowlist problems...



Oberoten
January 16th, 2008, 13:25
I have a few small problems with a Windowlist I am using in my character-sheet.

First one would be that there is no description to the values if I drag them from the list... (And while I have the feeling that this is probably pretty EASY to fix... I haven't been able to figure it out. )

The second is more of a oddity, but I think it'd be easy to do a work-around.
If I create several empty lines, the numbers associated with them are not associated. And when I change one, others change as well. I imagine this has to do partially with the sorting algorithm and partially with the index for a blank line.

Either way... Is there any way to surpress the adding of new blank lines when you allready have one?

And finally... How to add all the XP costs together for it all to work properly?




<windowclass name="charsheet_skilllistitem">
<sizelimits>
<minimum>
<height>18</height>
</minimum>
</sizelimits>
<script file="scripts/charsheet_skilllistitem.lua" />
<sheetdata>

<stringfield name="label">
<anchored>
<left>
<anchor>left</anchor>
<offset>15</offset>
</left>
<top>
<anchor>top</anchor>
<offset>5</offset>
</top>
<size>
<width>180</width>
</size>
</anchored>

<font>sheetlabelsmall</font>
<frame>
<name>textline</name>
<offset>0,5,0,0</offset>
</frame>
<script>
function onEnter()
window.windowlist.addNewInstance(window.label.getV alue());
end

function onDeleteUp()
if getValue() == "" and window.ranks.getValue() == 0 then
local target = window.windowlist.getPrevWindow(window);
if target and target.label.getValue() == window.label.getValue() then
target.sublabel.setFocus();
end

window.getDatabaseNode().delete();
end
end
</script>
</stringfield>
<numberfield name="skill.level">
<anchored>
<left>
<anchor>left</anchor>
<offset>200</offset>
</left>
<top>
<anchor>top</anchor>
<offset>2</offset>
</top>
<size>
<width>25</width>
</size>
</anchored>
<script>
function onValueChanged()
local test;
local cost;
cost = window.getDatabaseNode().getChild("skill.cost").getValue()
test = window.getDatabaseNode().getChild("skill.level").getValue()
window.getDatabaseNode().getChild("skill.xp").setValue( cost*((test^2)/2 +(test/2)) );
end


function onEnter()
window.windowlist.addNewInstance(window.label.getV alue());
end


</script>
<stateframe>
<hover>
<name>sheetfocus</name>
<offset>6,7,7,5</offset>
</hover>
<drophilight>
<name>rowshade</name>
<offset>1,1,1,1</offset>
</drophilight>
</stateframe>
</numberfield>

<numberfield name="skill.cost">
<anchored>
<left>
<anchor>left</anchor>
<offset>230</offset>
</left>
<top>
<anchor>top</anchor>
<offset>2</offset>
</top>
<size>
<width>25</width>
</size>
</anchored>
<script>
function onValueChanged()
local test;
local cost;
cost = window.getDatabaseNode().getChild("skill.cost").getValue()
test = window.getDatabaseNode().getChild("skill.level").getValue()
window.getDatabaseNode().getChild("skill.xp").setValue( cost*((test^2)/2 +(test/2)) );
end

function onEnter()
window.windowlist.addNewInstance(window.label.getV alue());
end

</script>
<stateframe>
<hover>
<name>sheetfocus</name>
<offset>6,7,7,5</offset>
</hover>
<drophilight>
<name>rowshade</name>
<offset>1,1,1,1</offset>
</drophilight>
</stateframe>
</numberfield>

<numberfield name="skill.xp">
<anchored>
<left>
<anchor>left</anchor>
<offset>260</offset>
</left>
<top>
<anchor>top</anchor>
<offset>2</offset>
</top>
<size>
<width>25</width>
</size>
</anchored>
<stateframe>
<hover>
<name>sheetfocus</name>
<offset>6,7,7,5</offset>
</hover>
<drophilight>
<name>rowshade</name>
<offset>1,1,1,1</offset>
</drophilight>
</stateframe>
</numberfield>

</sheetdata>
</windowclass>



And then later on the Sheet i call it up with



<windowlist name="skilllist">
<bounds rect="25,200,700,250" />
<datasource>.skilllist</datasource>
<class>charsheet_skilllistitem</class>
<allowcreate />
<columns>
<filldown />
<width>350</width>
</columns>
<script file="scripts/charsheet_skilllist.lua" />
</windowlist>

joshuha
January 16th, 2008, 14:18
Ok first thing I would change is how you have the numberfields.

I would change:
<numberfield name="skill.level">

to
<numberfield name="skilllevel" source="skill.level">

This may be why they are all changing at the same time because I don't think the dot qualifiers are allowed in a name but in the source (i.e. the database) this will group them like you want.

In the windowlist control a <skipempty /> tag will prevent if from creating the default blank lines.

Also to get drag and drop working the easiest, your field names from the items you are trying to drop should be the same as the receiving control. Then add the following in the windowlist control (if your class you are dropping it from is called skill):


<acceptdrop>
<class>skill</class>
<field>label</field>
<field>skilllevel</field>
</acceptdrop>

Oberoten
January 16th, 2008, 14:38
The last problem is more when I drag from the list to the modifier box or chatbox... It will take the level, but not the name.

So the roll becomes nothing but a digit with no annotation on how it ended up so.

joshuha
January 16th, 2008, 14:59
In the numberfield put this:


<description>
<field>label</field>
</description>


That will make it use the label field for the description text when dragged. Alternative you can use a <text> tag instead of <field> if you wanted to hard code something but usually in a list thats not what is intended.

Oberoten
January 16th, 2008, 15:04
THAT did the trick. :)

Thank you EVER so much Joshua. :)

Foen
January 16th, 2008, 15:24
You mentioned in your OP that the name was copied across but not the description. I can't see a description field in the list item windowclass, but if it is formattedtext then you will probably have some difficulties: I don't think formattedtext fields can be copied - least not that I can discover.

Cheers

Stuart

Oberoten
January 16th, 2008, 15:26
Hmmmm...

A secondary question about the description field? Can several values be added to it?

As in the names from Two fields/labels?

Oberoten
January 16th, 2008, 15:31
You mentioned in your OP that the name was copied across but not the description. I can't see a description field in the list item windowclass, but if it is formattedtext then you will probably have some difficulties: I don't think formattedtext fields can be copied - least not that I can discover.

Cheers

Stuart

The name IS the description. Hmm... and for some reason, it didn't work... Agh...

Oberoten
January 16th, 2008, 15:35
In the numberfield put this:


<description>
<field>label</field>
</description>


That will make it use the label field for the description text when dragged. Alternative you can use a <text> tag instead of <field> if you wanted to hard code something but usually in a list thats not what is intended.

... funnily this doesn't seem to work within Windowlists?

Oberoten
January 16th, 2008, 15:41
.... nor did adding this to the script.


function onDrag(button, x, y, draginfo)
draginfo.setDescription(window.getDatabaseNode().g etChild("label").getValue());
end


Gee and I am painfully reminded that I am by NO means a competent LUA coder...

Foen
January 16th, 2008, 15:45
I've had trouble with the name 'label' before, have you tried using a different name like 'skilllabel' instead?

As regards more complex descriptions for dragging values, you need to use the onDrag event to achieve that. Here is some sample code which adds a skill value to d20 (the result of which can be checked against a DC, for example) and creates a more complex description. The code is added to the skilllevel field, and presumes your skill name is called skilllabel:



function onDrag(button, x, y, dragData)
dragData.setType("dice");
dragData.setSlot(1);
dragData.setDieList({"d20"});
dragData.setNumberData(getValue());
dragData.setDescription(window.skilllabel.getValue () .. " (" .. getValue() .. ")");
return true;
end


If the skill was called "Pick Lock" and the skill level was 7, the drag description would be "Pick Lock (7)" and dropping this on the chat window would roll 1d20+7. getValue() is used to return the skilllevel (because the script block is local to skilllevel) and window.skilllabel.getValue() is used to reference the skill name/description.

Hope that helps

Stuart

Oberoten
January 16th, 2008, 17:18
... nope.
That didn't work either.

*sighs* You know I am starting to think that that LUA is designed to create headaches of the bleeding kind. :hurt:




<windowclass name="charsheet_skilllistitem">
<sizelimits>
<minimum>
<height>18</height>
</minimum>
</sizelimits>
<script file="scripts/charsheet_skilllistitem.lua" />
<skipempty />
<sheetdata>

<stringfield name="skillname">
<anchored>
<left>
<anchor>left</anchor>
<offset>15</offset>
</left>
<top>
<anchor>top</anchor>
<offset>5</offset>
</top>
<size>
<width>180</width>
</size>
<script>
function onEnter()
window.windowlist.addNewInstance(window.skillname. getValue());
end
</script>
</anchored>

<font>sheetlabelsmall</font>
<frame>
<name>textline</name>
<offset>0,5,0,0</offset>
</frame>
<script>
function onEnter()
window.windowlist.addNewInstance(window.skillname. getValue());
end

function onDeleteUp()
if getValue() == "" and window.ranks.getValue() == 0 then
local target = window.windowlist.getPrevWindow(window);
if target and target.skillname.getValue() == window.skillname.getValue() then
target.sublabel.setFocus();
end

window.getDatabaseNode().delete();
end
end
</script>
</stringfield>
<numberfield name="skilllevel" source="skill.level">


<anchored>
<left>
<anchor>left</anchor>
<offset>200</offset>
</left>
<top>
<anchor>top</anchor>
<offset>2</offset>
</top>
<size>
<width>25</width>
</size>
</anchored>

<script>
function onValueChanged()
local test;
local cost;
cost = window.getDatabaseNode().getChild("skill.cost").getValue()
test = window.getDatabaseNode().getChild("skill.level").getValue()
window.getDatabaseNode().getChild("skill.xp").setValue( cost*((test^2)/2 +(test/2)) );
end


function onEnter()
window.windowlist.addNewInstance(window.skillname. getValue());
end

function onDrag(button, x, y, dragData)
draginfo.setType("number");
draginfo.setDescription(window.getDatabaseNode().g etChild("skillname").getValue() );
draginfo.setNumberData(getValue());
return true;
end
</script>
<stateframe>
<hover>
<name>sheetfocus</name>
<offset>6,7,7,5</offset>
</hover>
<drophilight>
<name>rowshade</name>
<offset>1,1,1,1</offset>
</drophilight>
</stateframe>
</numberfield>

<numberfield name="skill.cost">
<anchored>
<left>
<anchor>left</anchor>
<offset>230</offset>
</left>
<top>
<anchor>top</anchor>
<offset>2</offset>
</top>
<size>
<width>25</width>
</size>
</anchored>
<script>
function onValueChanged()
local test;
local cost;
cost = window.getDatabaseNode().getChild("skill.cost").getValue()
test = window.getDatabaseNode().getChild("skill.level").getValue()
window.getDatabaseNode().getChild("skill.xp").setValue( cost*((test^2)/2 +(test/2)) );
end

function onEnter()
window.windowlist.addNewInstance(window.skillname. getValue());
end

</script>
<stateframe>
<hover>
<name>sheetfocus</name>
<offset>6,7,7,5</offset>
</hover>
<drophilight>
<name>rowshade</name>
<offset>1,1,1,1</offset>
</drophilight>
</stateframe>
</numberfield>

<numberfield name="skill.xp">
<anchored>
<left>
<anchor>left</anchor>
<offset>260</offset>
</left>
<top>
<anchor>top</anchor>
<offset>2</offset>
</top>
<size>
<width>25</width>
</size>
</anchored>
<stateframe>
<hover>
<name>sheetfocus</name>
<offset>6,7,7,5</offset>
</hover>
<drophilight>
<name>rowshade</name>
<offset>1,1,1,1</offset>
</drophilight>
</stateframe>
</numberfield>

</sheetdata>
</windowclass>




... this is how it currently looks. And for now I will have to leave it there before I erase my FG2 installation.

I am DEEPLY frustrated right now and it is no good for anything when I am like that. Even if it was something I'd normally spot I'd most likely miss it.

joshuha
January 16th, 2008, 17:47
So your issue is still dragging and getting the description from inside of the windowlist right?


function onDrag(button, x, y, dragData)
dragData.setType("number");
dragData.setDescription(window.skillname.getValue( ) );
dragData.setNumberData(getValue());
return true;
end


Does that work? If the value is already on the screen in the windowlist and not some fancy DB updating than going to the DB isn't really necessary.

Oberoten
January 16th, 2008, 17:55
The result is :

attempt to index global 'draginfo' (a nil value)


And no description.

joshuha
January 16th, 2008, 17:57
The result is :

attempt to index global 'draginfo' (a nil value)


And no description.

I just realized in your code you have the incoming dragData called dragData but the variable you are manipulating is called dragInfo. Those need to match (doesn't really matter what you call it).

Editing my code to reflect that.

Oberoten
January 16th, 2008, 18:04
THAT did the trick. :)
Now it keeps the name as well.

The disadvantage from editing from SW's code without fully comprahending WHAT it is that I do no doubt.

- Obe