Starfinder Playlist
  1. #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,
    MBM
    Ruleset and much more content built for FGU.
    Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!

  2. #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.

  3. #3
    Quote Originally Posted by darrenan View Post
    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.
    I did think of adding an 'order' value on entry (and then hiding it when not editing), but wondered if there was another way, but what you mention makes me think what I think can work, will work.

    So in a very long wordy statement, cheers!

    MBM
    Ruleset and much more content built for FGU.
    Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    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!

  5. #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
    This is the onDrag start code

    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
    Just need to make sure you're working from the same windowlist. For this It was a bit more complicated because it's windowlist within windowlists but once I figure out the right locations it was pretty easy. Just make sure the windowlist sorted by "order".
    ---
    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.

  6. #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.

  7. #7
    Quote Originally Posted by celestian View Post
    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
    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,
    MBM
    Ruleset and much more content built for FGU.
    Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!

  8. #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,
    MBM
    Ruleset and much more content built for FGU.
    Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!

  9. #9
    Quote Originally Posted by MadBeardMan View Post
    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,
    MBM
    Glad to hear it I've been making use of it myself. I did notice some very sluggish behavior during a online game on the CT "reorder" but everything else seems to be working good so far.
    ---
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in