-
March 16th, 2020, 00:33 #1
Change order of items in a window list by Drag and Drop possible?
Greetings,
I've just added basic Spacecraft data into the Traveller 2E ruleset, you can simply add a line item for a ship detail, ie want to add in the Weapons, click the + and then enter it.
But I would like to be able to change the window order, ie move that newly added weapon line upto the bottom of the existing weapon lines.
Drag and drop would be ace, for some reason my brain tells me there's something out there already, but I just can't think of it.
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
March 16th, 2020, 00:37 #2
window lists sort on whatever you tell them to. If the underlying items had an item that specified the order, then changing it would change the display order. Think of changing initiative in the CT for instance.
so you could have 'groups', such as the weapon list you were mentioning, have a common 100s or 1000s digit, and use the lower order digits to specify sorting within the group.
-
March 16th, 2020, 00:39 #3Ruleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
March 16th, 2020, 07:19 #4
You could base some ordering code on what Darren mentions (a hidden field) and expand on that to have code attached to a drag/drop to calculate the new order by values when an entry is drag/dropped within the list.
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
March 16th, 2020, 22:01 #5
I've been wanting to do something with re-ordering for a while but this thread for me thinking last night and I did some proof of concept work.
This is the target onDrop() code.
Code:function onDrop(x, y, draginfo) if draginfo.isType("reorder") then local sClass, sRecord = draginfo.getShortcutData(); if sClass == "reorder_power" and sRecord ~= "" then local win = getWindowAt(x,y); if win then local nodeActionTarget = win.getDatabaseNode(); local nodeActionSource = DB.findNode(sRecord); local nOrderSource = DB.getValue(nodeActionSource,"order",0); local nOrderTarget = DB.getValue(nodeActionTarget,"order",0); DB.setValue(nodeActionSource,"order","number",nOrderTarget); DB.setValue(nodeActionTarget,"order","number",nOrderSource); return true; end end end end
Code:function action(draginfo) local node = window.getDatabaseNode(); draginfo.setDescription(DB.getValue(node,"name","")); draginfo.setShortcutData("reorder_power",node.getPath()) draginfo.setIcon("ct_select_right"); draginfo.setType("reorder"); return true; end function onDragStart(button, x, y, draginfo) return action(draginfo); end
---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
March 17th, 2020, 03:03 #6
I've tweaked the onDrop() with some better logic. This will reorder a bit smarter without bloating number values. This presumes that your code sets "order" on a new entry to the last order+1 when added.
Code:function setNewOrder(node,nTarget,nSource) for _,v in pairs(DB.getChildren(getDatabaseNode(), "")) do local nCurrent = DB.getValue(v, "order", 0); if v.getPath() == node.getPath() then DB.setValue(v, "order", "number", nTarget) elseif nTarget > nSource and nCurrent > nSource and nCurrent <= nTarget then DB.setValue(v, "order", "number", nCurrent-1) elseif nTarget < nSource and nCurrent >= nTarget and nCurrent < nSource then DB.setValue(v, "order", "number", nCurrent+1) end end end function onDrop(x, y, draginfo) if draginfo.isType("reorder") then local sClass, sRecord = draginfo.getShortcutData(); if sClass == "reorder_power" and sRecord ~= "" then local win = getWindowAt(x,y); if win then local nodeActionTarget = win.getDatabaseNode(); local nodeActionSource = DB.findNode(sRecord); if nodeActionTarget ~= nodeActionSource then local nOrderSource = DB.getValue(nodeActionSource,"order",0); local nOrderTarget = DB.getValue(nodeActionTarget,"order",0); setNewOrder(nodeActionSource, nOrderTarget, nOrderSource); end return true; end end end end
---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
March 18th, 2020, 10:07 #7
Morning Celestian,
That's super awesome of you to have first written it, and second shared it.
I'll make use of this and see what results. I do like your animated example, I should invest some time in attaching pictures to my posts so folks can see it clearer.
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
March 22nd, 2020, 19:15 #8
Hi @Celestian,
Just a word to say 'Thanks!'. I have this working inside the Traveller 2E ruleset, still pretty clunky but the drag and drop work excellently.
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
March 22nd, 2020, 20:13 #9---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks