PDA

View Full Version : Need an assist with my first extension (3.5/PFRPG)



nickabbey
August 28th, 2016, 18:56
I'm new to LUA and FG, but I've been programming for a long time and I am ready to jump in.

Per my original question (https://www.fantasygrounds.com/forums/showthread.php?33802-Can-this-idea-be-built-as-an-extension&p=286777&posted=1#post286777) in the 3.5/PFRPG forum, I want to add a check box to the character sheet titled

"Receives XP"

And then I want to override the awardXP method of manager_ps2.lua to check the state of that box when determining the members of the party for xp calculation and awarding.

so, I know I need to modify the record_char_main.xml to add the new title and check box.
I presume I also need to somehow persist the state of this check box to the database.

Then over in the lua script for the manager, when I override the awardXP function, I need to modify the conditional:

local nodePC = DB.findNode(sRecord);
if nodePC then
local sName = DB.getValue(v, "name", "");
table.insert(aParty, { name = sName, node = nodePC } );
end

with something like

local nodePC = DB.findNode(sRecord);
local nodeXP = <whtever it takes to lookup the check box I created>
if nodePC and nodeXP then
local sName = DB.getValue(v, "name", "");
table.insert(aParty, { name = sName, node = nodePC } );
end


This should really do exactly what I want in the least invasive way possible.

I'm struggling with the learning curve, however.

I'm taking it in small chunks, and the first thing I'm struggling with is adding the label and checkbox.
Can I get some advise on where to find the right documentation, and maybe an example?
I've been picking apart existing extensions but haven't quite nailed it down yet.

Trenloe
August 28th, 2016, 19:34
This thread gives some good background (and further links): https://www.fantasygrounds.com/forums/showthread.php?19033-Modifying-the-3-5e-PFRPG-ruleset

Have a look at the "Windows and Controls" page of the Ruleset modification guide (linked in post #1 of the above referenced thread). Control positioning covers the basics of how to position controls within the FG XML. Most standard rulesets will use a lot of "relative" anchoring, so you'll need to understand this.

If you want to put it on the "Main" tab, then you're looking in the right file (campaign\record_char_main.xml in the 3.5e ruleset). I'm not sure where you're going to put it, there isn't much usable space on the main tab. Perhaps try to squeeze it into the level/XP frame (starting at <frame_char name="levelframe">), but you'll need to rearrange/resize the current controls there.

For the checkbox, have a search through the 3.5E ruleset (use "find in files" in your text editor) for button_checkbox and see how it's been used within the ruleset itself (there's a couple of examples in record_char_skills.xml). button_checkbox is defined in the CoreRPG ruleset (remember that 3.5E is built on top of CoreRPG, so you sometimes have to search on CoreRPG for templates/definitions used in 3.5E) and is built on the buttonfield control, which is the database sourced version of buttoncontrol: https://www.fantasygrounds.com/refdoc/buttoncontrol.xcp So, we know that button_checkbox is sourced on a database field, which will use the same name set for the control in the FG XML. For example: <button_checkbox name="receivesxp"> would store the state of the button in a database field in the character DB entry called "receivesxp".

Hope this gets you started... :)

nickabbey
August 28th, 2016, 19:41
Perfect!

I've gotten the label on there and I see what you mean re: the relative positioning and the lack of real estate.
I was just digging in to resizing those controls when you posted, so the recommendation is super timely.

I am thinking I might try to squeeze the button in to the left of the word "Experience" (below "Total Level") without a label, but give it a tooltip description.
This probably won't look too forced, and will keep me from spending a lot of time making minute movements of relative positions.

Thanks!

nickabbey
August 28th, 2016, 21:04
So I think I have an idea that will work, but I've been fiddling for over an hour without any luck. I want to modify the label for the experience field that appears on the character main tab to contain the checkbox, with a tooltip explaining what it does.
For this, I want to replace just the label field. However, since it's declared as a label_fieldtop control relative to the number_dropadd control named "exp" I think I need to redefine the "exp" control and the label attached to it, inserting the button.

I'm trying to grok the object hierarchies, and making some headway but I'm missing some things.
First, is it even possible to put a checkmark inside a label?
Second, if so, how do I override the number_dropadd control named "exp" with my new label containing the check box?

I thought it had something to do with the windowclass property merge="join", perhaps there's a different value that allows me to overwrite an existing named control?
I looked at the definition for windowclass and the page for windowinstance, but I couldn't find info on that property and was having trouble determining if there is a parent class that might define it.

Trenloe
August 28th, 2016, 21:40
First, is it even possible to put a checkmark inside a label?
In general you can't put a base control inside another base control. You will need to add the checkbox as a new control.

Try the attached extension, this adds a button_checkbox control into the existing "charsheet_main" windowclass. It's position is anchored to the "levelframe" control.

https://www.fantasygrounds.com/forums/attachment.php?attachmentid=15150

damned
August 28th, 2016, 23:11
As a general comment Id do it the other way - you check the box not to receive XP for this character so that you dont omit awarding XP to a new Character because you forgot to check the box.

Trenloe
August 28th, 2016, 23:15
As a general comment Id do it the other way - you check the box not to receive XP for this character so that you dont omit awarding XP to a new Character because you forgot to check the box.
Or, you could set the code to automatically default to checking the box when a new character is created.

Oh look, I did! ;)


<windowclass name="charsheet_main" merge="join">
<sheetdata>
<!--New-->
<button_checkbox name="receivesxp">
<anchored to="levelframe" position="insidetopleft" offset="20,35" width="10" height="10"/>
<default>1</default>
</button_checkbox>
<!--End New-->
</sheetdata>
</windowclass>

damned
August 28th, 2016, 23:23
Or, you could set the code to automatically default to checking the box when a new character is created.

Oh look, I did! ;)


<windowclass name="charsheet_main" merge="join">
<sheetdata>
<!--New-->
<button_checkbox name="receivesxp">
<anchored to="levelframe" position="insidetopleft" offset="20,35" width="10" height="10"/>
<default>1</default>
</button_checkbox>
<!--End New-->
</sheetdata>
</windowclass>


Of course you did! Thanks Trenloe :)

nickabbey
August 28th, 2016, 23:32
What did that take you, like 5 minutes?

Facepalm... I've been messing with this for hours, and I've come SO close.

With your guidance though, I was able to see that I was VERY close.
Thanks for taking the time to show me the ropes on this!