Thread: Merging confusion
-
February 18th, 2021, 18:08 #1
Merging confusion
Looking at:
https://fantasygroundsunity.atlassia...or+code+re-use
\
I cannot seem to figure out a basic thing. I want to redo a windowclass laying things out differently.
My initial plan was to copy the one in MoreCore then to modify with delete or replace the ones I needed to adjust.
This worked so far, eventually I'll decide if should depart completely or do join/replace/delete type edits.
When I got to the XP, XP-Needed and Level controls (number+widget) I wanted to center the widget label. I looked and found the template in MoreCore's template_campaign.xml:
Code:<template name="number_labeled"> <basicnumber> <frame mergerule="replace" name="fielddark" offset="4,2,4,2" /> <font>sheettext</font> <lineoffset default="on">1</lineoffset> <script> labelwidget = nil; function onInit() if labelres then labelwidget = addTextWidget("sheetlabelinline", string.upper(Interface.getString(labelres[1]))); else labelwidget = addTextWidget("sheetlabelinline", string.upper(label[1])); end if labelwidget then local w,h = labelwidget.getSize(); labelwidget.setPosition("bottomleft", w/2, h/2-4); end end </script> </basicnumber> </template>
I am sure I just don't understand the whole XML rules as "simple" as they seem to be.
In all versions of the documentation - I often get confused with the terms used to describe the parent/child base/derived relationships and I often think that it is saying the thing you are USING (preexisting definition) needs to have "replace", for example, for it to work - I'm just still all confused. Normally, I have gotten the far by just ... trying stuff until works way I expect then I do it that way.
Right now, my first attempt was to take one of the controls and simply add (nothing was there before) the <script> section, taking it from the template just so I can test the layout before engaging in "merges":
Code:<number_labeled name="exp"> <anchored to="weight" position="right" offset="10,0" width="60" /> <labelres>char_label_experience</labelres> <script> labelwidget = nil function onInit() if labelres then labelwidget = addTextWidget("sheetlabelinline", string.upper(Interface.getString(labelres[1]))) else labelwidget = addTextWidget("sheetlabelinline", string.upper(label[1])) end if labelwidget then local w,h = labelwidget.getSize() labelwidget.setPosition("bottom", 0, h/2-2) end end </script> </number_labeled>
So I tried changing the next one:
Code:<number_labeled name="expneeded"> <anchored to="exp" position="right" offset="5,0" width="60" /> <labelres>char_label_expneeded</labelres> </number_labeled>
Code:<number_labeled2 name="expneeded" merge="replace"> <anchored to="exp" position="right" offset="5,0" width="60" /> <labelres>char_label_expneeded</labelres> </number_labeled2>
Any idea what I am doing wrong? I mean, I can just use the explicit (copy paste ) script but...
-
February 19th, 2021, 15:49 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,412
When using a windowclass merge, the controls are matched using a two-part key of the template/control tag as well as the name. You cannot replace only by name.
If you really need to change a template, you have to copy the template, and replace.
If you just want to make minor changes, then use a windowclass merge, and specify the additional tags.
If you really want to fully replace a control with a different template, you would have to use a merge="delete" to remove the original one; and an insertbefore="<name>" to add a new one in the right position.
It's almost always easier to do the windowclass merge:
Code:<windowclass name="charsheet_classes" merge="join"> <sheetdata> <basicnumber name="expneeded"> <script> function onInit() if super and super.onInit then super.onInit(); end [CUSTOM CODE] end </script> </basicnumber> </sheetdata> </windowclass>
-
February 19th, 2021, 16:29 #3
Thanks for the explanation
The last thing you typed is what I ended up doing as I mentioned in the prior post (in bold) - only I had to do it in 3 places and I wanted to see if I could avoid cut and paste in 3 places.
I do not think there would be anything wrong with copying the template and replacing it since I prefer the aesthetic I chose (of course I'd have to see where it is used elsewhere to see if it holds as my choice for those places too if any exist) but I liked the idea of an "alternate" one better.
I tried the delete and then add thing you described - BUT I did not do insertbefore - I'll try that fast later tonight because I am the type to want to see how stuff works - I already committed the "copy-paste" version but if the insert before alt template thing works - that's probably "prettier" way.
Thanks for all that info,
Dan
-
February 19th, 2021, 16:51 #4
Bah - I switch work and personal Macs and tried it ;P
Code:... <number_labeled name="expneeded" merge="delete" /> <number_centered_labeled name="expneeded" insertbefore="level"> <anchored to="exp" position="right" offset="5,0" width="60" /> <labelres>char_label_expneeded</labelres> </number_centered_labeled> ...
Code:... <template name="number_centered_labeled"> <number_labeled> <script> labelwidget = nil; function onInit() if labelres then labelwidget = addTextWidget("sheetlabelinline", string.upper(Interface.getString(labelres[1]))); else labelwidget = addTextWidget("sheetlabelinline", string.upper(label[1])); end if labelwidget then local w,h = labelwidget.getSize(); labelwidget.setPosition("bottom", 0, h/2-2); end end </script> </number_labeled> </template> ...
Thanks,
Dan
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks