STAR TREK 2d20
  1. #1

    createControl() with windowreferencecontrol

    I am attempting to use createControl to create a link button that will open a class/record I setValue() on the control.

    Here is the template I use.

    Code:
      <template name="link_inventory_item_ct">
        <linkcontrol>
          <script>
            function onDragStart(button, x, y, draginfo)
              local sClass, sRecord = getValue();
              local node = DB.findNode(sRecord);
              if node then
                local sName = DB.getValue(node,"name","");
                local sPathToItem = node.getPath();
                draginfo.setType("shortcut");
                draginfo.setShortcutData( sClass, sRecord );
                draginfo.setDescription(sName);
                draginfo.setIcon("button_link_down");
                return true;
              end
            end
            
            function onButtonPress()
              local sClass, sRecord = getValue();
              if sClass and sRecord then
                local sPathToItem = node.getPath();
                Interface.openWindow(sClass, sRecord);
                return true;
              end
            end
          </script>
          <anchored >
            <top />
            <left />
          </anchored>
          <icon normal="button_link" pressed="button_link_down" empty="button_link_empty" />
        </linkcontrol>
      </template>
    Here is the lua I use to create the control object.

    Code:
          local controlItemLink = createControl("link_inventory_item_ct", sControlItemLink);
          controlItemLink.setAnchor("top", sControlItemName,"top","absolute",10);
          controlItemLink.setAnchor("left", sControlItemName,"right","absolute",0);
          controlItemLink.setAnchor("right", sControlItemName,"right","absolute",-20);
          controlItemLink.setValue('item',nodeItem.getPath());
    However, the button/link doesn't seem to allow interaction at all. Neither drag or mouse clicks on them work.

    The result of my code is something like this. (I also createControl for the count and name of the items)



    This item list is generated from a single string, not a list of nodes. My use case is to eliminate the inventorylist objects on npcs while in the CT but also be able to "see" the items and link back to the source NPC record that it came from. So far all this works it's just I can't seem to get the link buttons to interact.
    ---
    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.

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    I'm guessing it's a problem with the positioning/anchoring. It looks like your setting the right side of your control to be further to the left than the left side.

    If your control template has a width, then there's no need to set the right anchor - as you've set the left anchor to the same control. If your template doesn't have a width, try setting the control width using setAnchoredWidth - https://www.fantasygrounds.com/refdo...tAnchoredWidth
    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!

  3. #3
    Quote Originally Posted by Trenloe View Post
    I'm guessing it's a problem with the positioning/anchoring. It looks like your setting the right side of your control to be further to the left than the left side.

    If your control template has a width, then there's no need to set the right anchor - as you've set the left anchor to the same control. If your template doesn't have a width, try setting the control width using setAnchoredWidth - https://www.fantasygrounds.com/refdo...tAnchoredWidth
    That was it, more or less, I was placing the "buttons" underneath the label so clicks went to label, not the "button" that was under. I assumed that since it was AFTER the label it would be on top. Got it functional now, thanks for the tip

    What I had to do was "achor" my "left" side of the button to the right side of the "contentanchor" and not the label. Once I did that I was able to use a offset so the button was on the "frame" (shaded/non-shaded variants) and/or on top and the button works.
    Last edited by celestian; June 24th, 2019 at 16:25.
    ---
    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.

  4. #4

    Join Date
    Apr 2008
    Location
    Virginia Beach
    Posts
    3,096
    Thanks for the explanation, Celestian

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
  •  
DICE PACKS BUNDLE

Log in

Log in