PDA

View Full Version : Need help with extension coding



Zamirathe
January 31st, 2020, 19:35
So I need a little help. I am not new to programming, but I am new to lua. I expect to learn it pretty quick though. I have unzipped a few extensions looking for how things are done by them to get an idea of what I need to do for what I want. However, I am honestly stuck. Without downloading every extension and unzipping it, I am not even sure if what I want to do is possible with xml and lua without a lot of needless brute forcing it. So if you can point me in the direction to go at with this, please tell me.

I am wanting to create a window with all actors on the combat tracker listed. I want to be able to drag and drop these boxes of each actor around the list to reorder them. This is where I am stuck. I can see how you can create a gui, and how to possibly get them all into the window. I have yet been able to figure out how to do the drag and drop reordering using just xml, lua, and maybe javascript. (Are script calls in the xml files javascript or lua?) I have searched here and on Google, but no luck outside of other games and android apps. Has this been implemented somewhere? A ruleset, extension, or anything where I can see how it has to be coded generically to make a drag and drop list? I have looked at 5e roll for initiative (lifesaver for us!), combat timer, and 5e ruleset a tiny bit. Where else can I look?

JohnD
January 31st, 2020, 19:53
What are you trying to accomplish with the reordering?

Zamirathe
January 31st, 2020, 20:28
It will be used to grab the order of all actors and set their initiative accordingly in the combat tracker. So have allies go right after the pc controlling them, as well as we are trying to use the homebrew initiative rules from The DM Lair 2 enemies/pc, 2 enemies/pc, etc. Basically give a custom order to initiative rather than rolls. (That's not to say there won't be rolls, but DM rolls once and the highest roll of all pcs determines whether pc or enemy goes first. Not the order that everyone attacks.)

Trenloe
January 31st, 2020, 20:46
Welcome to the FG forums Zamirathe!


I have yet been able to figure out how to do the drag and drop reordering using just xml, lua, and maybe javascript. (Are script calls in the xml files javascript or lua?) I have searched here and on Google, but no luck outside of other games and android apps. Has this been implemented somewhere? A ruleset, extension, or anything where I can see how it has to be coded generically to make a drag and drop list?
I don't think this has been coded - it's not easy to do in the FG windowlist structure. The windowlist (https://www.fantasygrounds.com/refdoc/windowlist.xcp)is what stores the type of data you're referring to.

The most straightforward way would be to have a numerical field (a bit like the Initiative field in the Combat Tracker) and change those values to re-order. I know this isn't what you're looking for, but it would be very straightforward to do this. I also don't know exactly what you intend to do with this list, so not sure exactly what your end goal is.

To expand on this: any records in a windowlist have to be ordered on something - even if it's a hidden number field that is used to determine the order. If you wrote some drag/drop code that would determine the numerical position of the entry it's being dropped on and then change the order field for the record being dropped (it can be a hidden field) and change the order field of the record that needs was being dropped on to move it down the list. The onDrop handler could be used to start the code: https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#onDrop But you'll need to have a control from each record that can be dragged from the entry to start the drag/drop process.

Have a look at the targeting button in the CT (Combat Tracker) as this is used to drag a target onto another entry in the CT (windowlist). The <buttoncontrol name="targeting_add_button"> control in CoreRPG (which most other rulesets are layered on top of) in the ct\ct_host.xml file - this has some onDragStart code that sets up the current details of the source record. Then the onDrop handler in ct\scripts\ct.lua handles what to do when the record is dropped - which basically runs the CombatManager.onDrop handler - which is in scripts\manager_combat.lua which gets the source node (set in the onDragStart) and runs the TargetingManager.addCTTarget with the source node and the current CT node - so this should allow you to be able to determine where in the windowlist order they are (by getting the value of the numerical order field for each node) and then set the numerical order field appropriately to trigger a re-order of the records.

This can get pretty complex - hopefully the above will give you some ideas if you want to pursue this kind of thing.

Zamirathe
February 1st, 2020, 01:36
Thank you. I officially feel dumb since I did not search for reference documentation. *headdesk* The specifics of occurrances where ondrag or ondrop has been used will be immensely helpful.