PDA

View Full Version : help needed with linked text window



unimatrixzero
June 2nd, 2008, 21:00
Hi All.
Unsure how to describe this, but I'm looking to have a frame with 2 windows displayed. the first is a window list. the second is a formatted text frame. What I am wanting to do is click an entry in the list and have it bring up text in the formatted text frame related to that entry. For example a list of weapons that when clicked on will show a description in the formatted text window. Attached is the image of my frame i intend to use.
441

Anyone willing to offer a guiding hand? It would be much appreciated.
Regards Uni

Foen
June 3rd, 2008, 01:39
Hi

There are real problems working with formatted text fields at the moment - the functionality exposed in script is very poor. The way I have worked around this issue is to have each frame hosting a window list control which show different views of the same list.

Say your data looks like:



<weaponlist>
<id-00001>
<name type='string'>laser rifle</name>
<id type='number'>1</id>
<description type='formattedtext'>
<p>A <b>very</b> big gun!</p>
</description>
</id-00001>
<id-00002>
<name type='string'>club</name>
<id type='number'>1</id>
<description type='formattedtext'>
<p>A <b>very</b> blunt instrument!</p>
</description>
</id-00002>
</weaponlist>

The left-hand windowlist would show the list of names:



As a window class definition:
<windowclass name='wpnlistitem'>
<sheetdata>
<numberfield name='id'>
<bounds>0,0,0,0</bounds>
<invisible/>
</numberfield>
<stringfield name='name'>
<script>
function onClickDown()
window.windowlist.window.itemSelected(id.getValue( ));
end
</script>
</stringfield>
</sheetdata>
</windowclass>

As the left hand pane:
<windowlist name='list1'>
<class>wpnlistitem</class>
<datasource>weaponlist</datasource>
</windowlist>

The right hand windowlist would show a filtered view of the description:



As a windowclass definition:
<windowclass name='wpndescitem'>
<sheetdata>
<numberfield name='id'>
<bounds>0,0,0,0</bounds>
<invisible/>
</numberfield>
<formattedtextfield name='description'>
</formattedtextfield>
</sheetdata>
</windowclass>

As the right hand pane:
<windowlist name='list2'>
<class>wpndescitem</class>
<datasource>weaponlist</datasource>
<script>
local idfilter = -1;

function onFilter(win)
return (win.id.getValue()==idfilter);
end

function setFilter(id)
idfilter = id;
applyFilter();
end
</script>
</windowlist>

Finally at a window level (which contains the two panes) you need a function that responds to clicks on the left pane by applying the filter on the right pane:



In the containing window script block:
function itemSelected(id)
list2.setFilter(id);
end

I've not tested the exact code above (I am on holiday, away from my workstation) but have used the same technique myself to good effect.

Hope that helps

Stuart

unimatrixzero
June 4th, 2008, 20:37
Cheers for the help. It looks like this will be perfect for what I need. Although after placing the code I am currently getting a Script Error.

Script Error: [string"wpnlistitem.name"]:1 attempt to index global 'id' (a nil value)

Is there something else i might need to change or ensure i have in place?

thanks again
Uni

Foen
June 5th, 2008, 05:19
My mistake, the correct code snippet should be:



<script>
function onClickDown()
window.windowlist.window.itemSelected(window.id.ge tValue());
end
</script>
However, since writing the original post, I think there is a better way to link the two frames rather than using an id number field.

The downside of the id number field is that you have to create it each time a new item is added to the list and make sure it remains unique (and my previous post failed in that respect, as both had an id field set to '1').

There is already a property of each entry which does this automatically: the entry tag name (eg <id-00001>) which FG maintains for you.

Implementing this is fairly straightforward, starting with the window class definition for the left hand pane:



As a window class definition:
<windowclass name='wpnlistitem'>
<sheetdata>
<stringfield name='name'>
<script>
function onClickDown()
local idvalue = window.getDatabaseNode().getName();
window.windowlist.window.itemSelected(idvalue);
end
</script>
</stringfield>
</sheetdata>
</windowclass>


And then changing the window list code in the right hand pane:



As the right hand pane:
<windowlist name='list2'>
<class>wpndescitem</class>
<datasource>weaponlist</datasource>
<script>
local idfilter = "";

function onFilter(win)
return (win.getDatabaseNode().getName()==idfilter);
end

function setFilter(id)
idfilter = id;
applyFilter();
end
</script>
</windowlist>

You should also remove the 'id' number fields from both window class definitions, now they are no longer needed.

Give that a try, and let me know if it helps.

Cheers

Stuart

unimatrixzero
June 5th, 2008, 09:13
thanks for a prompt reply Foen.

After implementing the recent script suggestions I now get the following script error;

Script Error: [string"wpnlistitem.name"]:1 attempt to call field 'itemSelected' (a nil value)

Any ideas what might be causing this?

Regards Uni

Foen
June 5th, 2008, 09:31
It sounds like you haven't put the last piece of code (from my original post) in the containing widow class script block.

Say your left hand and right hand panes are in a window called 'myweapons', then the itemSelected code should be in the script block of myweapons.

If that doesn't work, you might need to post the full xml here.

Stuart

unimatrixzero
June 5th, 2008, 11:34
I made sure i included the script in the windowclass.

here is what i have;



<windowclass name="firstscreen">
<sizelimits>
<minimum>
<height>10</height>
</minimum>
</sizelimits>
<sheetdata>
<stringfield name="name">
<bounds>10,1,-1,20</bounds>
<empty>« New Entry»</empty>
<selectioncolor>#90ffffff</selectioncolor>
<font>chatfont</font>
<script>
function onClickDown()
local idvalue = window.getDatabaseNode().getName();
window.windowlist.window.itemSelected(idvalue);
end
</script>
</stringfield>
</sheetdata>
</windowclass>

<windowclass name="secondscreen">
<sizelimits>
<minimum>
<height>10</height>
</minimum>
</sizelimits>
<sheetdata>
<formattedtextfield name="text">
</formattedtextfield>
</sheetdata>
</windowclass>

<windowclass name="encounterlist">
<frame>padframe</frame>
<s-oftclose />
<placement>
<size>
<width>365</width>
<height>325</height>
</size>
</placement>
<sizelimits>
<dynamic />
<minimum>
<width>315</width>
<height>225</height>
</minimum>
</sizelimits>
<nodelete />
<sheetdata>
<genericcontrol>
<bounds>16,21,30,177</bounds>

</genericcontrol>

<windowlist name="list1">
<bounds>40,85,115,-70</bounds>
<class>firstscreen</class>
<datasource>.</datasource>
<sortfields>name</sortfields>
<footer>footer_narrow</footer>
<allowcreate />
<allowdelete />

</windowlist>
<windowlist name='list2'>
<bounds>175,85,-40,-30</bounds>
<class>secondscreen</class>
<datasource>.</datasource>
<script>
local idfilter = "";

function onFilter(win)
return (win.getDatabaseNode().getName()==idfilter);
end

function setFilter(id)
idfilter = id;
applyFilter();
end
</script>
</windowlist>

<script>
function itemSelected(id)
list2.setFilter(id);
end
</script>

<scrollercontrol>
<bounds>-105,-61,45,27</bounds>
<target>list1</target>
<button>
<normal>button_scroller</normal>
<pressed>button_scroller_down</pressed>
</button>
</scrollercontrol>
<buttoncontrol>
<bounds>5,90,34,25</bounds>
<icon>
<normal>button_newwindow</normal>
<pressed>button_newwindowdown</pressed>
</icon>
<class>encounter</class>
<script>
function onButtonPress()
local node = window.getDatabaseNode();
if node then
node = node.createChild();
if node then
Interface.openWindow(class[1], node.getNodeName());
end
end
end
</script>
</buttoncontrol>
<categoryselectioncontrol>
<bounds>40,-65,-200,-45</bounds>
<targetcontrol>list1</targetcontrol>
</categoryselectioncontrol>

<filter name="filter">
<bounds>25,-60,-170,20</bounds>
<target>list1</target>
<trigger>filtertrigger</trigger>
</filter>
<filtertrigger name="filtertrigger">
<bounds>11,115,21,41</bounds>
<target>filter</target>
</filtertrigger>
</sheetdata>
</windowclass>

thanks again for ur time.
Cheers
Uni

Foen
June 5th, 2008, 11:56
Ok, I see the problem. The script should be at the top level of the encounterlist windowclass, not nested within the sheetdata section:



It should be:
<windowclass name="encounterlist">
<frame>...</frame>
<placement>...</placement>
<sizelimits>...</sizelimits>
<nodelete/>
<script>
function itemSelected(id)
list2.setFilter(id);
end
</script>
<sheetdata>...</sheetdata>
</windowclass>

Instead of:
<windowclass name="encounterlist">
<frame>...</frame>
<placement>...</placement>
<sizelimits>...</sizelimits>
<nodelete/>
<sheetdata>
...
<script>
function itemSelected(id)
list2.setFilter(id);
end
</script>
</sheetdata>
</windowclass>


Hope that helps

Stuart

unimatrixzero
June 5th, 2008, 13:03
Awesome.
I thought it might of been something like that.
Thanks again for your help Foen. It is working just fine now!
You are truly a legend on these boards!! :)

Regards Uni

Foen
June 5th, 2008, 13:29
NP, just glad to help out!

:D