PDA

View Full Version : Merging a new field into a windowclass



AmadanNaBriona
April 19th, 2020, 01:52
I'm trying to take the basic char_invitem windowclass that exists in CoreRPG's list_charinv template, and add a "cost" field.



<windowclass name="char_invitem" merge="join">
<script>
function onInit()
Debug.chat("char_invitem subclass");
end
</script>
<string_charinvcost name="cost">
<anchored width="80" height="20">
<top offset="2" />
<right parent="rightanchor" anchor="left" relation="relative" offset="-10" />
</anchored>
<tabtarget next="weight" prev="location" />
</string_charinvcost>
</windowclass>


The Debug code in the onInit function I added is just to confirm I am actually invoking my subclass, which I am. But I cannot get the "cost" control to appear.

damned
April 19th, 2020, 02:18
You need to add some additional code when trying to insert a field into other fields using relative positioning.

https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Layering#Example_2

Trenloe
April 19th, 2020, 07:12
And make sure you use a valid control or control template name. I don’t think "string_charinvcost" exists.

AmadanNaBriona
April 19th, 2020, 15:22
And make sure you use a valid control or control template name. I don’t think "string_charinvcost" exists.

It is a template I created:


<template name="string_charinvcost">
<string_textlistitem>
<script>
function onInit()
Debug.chat("string_charinvcost");
end
</script>
<nodrop />
<delaykeyupdate merge="delete" />
</string_textlistitem>
</template>

That second Debug line is not being triggered.

damned
April 19th, 2020, 15:33
Why are you merging changes to a Windowclass in the same package as you define the Windowclass? Just do it all in the Windowclass.

AmadanNaBriona
April 19th, 2020, 15:38
Why are you merging changes to a Windowclass in the same package as you define the Windowclass? Just do it all in the Windowclass.

Perhaps I am very dense this morning, but I'm not following. I am trying to take the existing char_invitem class and add a new field to it. Where else should I be merging if not the definition of the (inherited) class?

AmadanNaBriona
April 19th, 2020, 15:42
Okay, this seems to work: I needed to add the sheetdata tags.


<windowclass name="char_invitem" merge="join">
<sheetdata>
<string_charinvcost name="cost" insertbefore="location">
<anchored width="80" height="20">
<top offset="2" />
<right parent="rightanchor" anchor="left" relation="relative" offset="-10" />
</anchored>
<tabtarget next="weight" prev="location" />
</string_charinvcost>
</sheetdata>
</windowclass>

Are you saying it should be done somewhere else?

damned
April 19th, 2020, 15:45
Sorry I misread what you had posted.

Have you added this yet?
insertbefore="something existing"

as per
https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Layering#Example_2

damned
April 19th, 2020, 15:46
Yes and the sheetdata!

Trenloe
April 19th, 2020, 15:48
As these controls use relative anchoring, you'll need to use the insertbefore property to make sure the new control is joined at the right point with the merged windowclass.

Try: <string_charinvcost name="cost" insertbefore="location">

EDIT: looks like you sorted it all out while I was writing this.

AmadanNaBriona
April 19th, 2020, 15:52
Hah, I guess I figured it out right before you guys posted the correct solution. :) But I'm still not sure damned isn't telling me I have this in the wrong place?

My custom char_invitem class is defined in record_char_inventory.xml. The string_charinvcost field I insert into it is defined in template_char.xml.