Thread Tools Display Modes
09-23-19, 10:11 PM   #1
Stressed1
A Kobold Labourer
Join Date: Sep 2019
Posts: 1
Exclamation Creating and Using Framepools

Hi y'all!

Been lurking here awhile and decided it was finally time to post (you know, because I'm selfish and need help).

I'm trying to create a basic Lua tool to help me get guild charter signatures.

I have the following code, which identifies players eligible to sign.

lua Code:
  1. local InviteList={}
  2. local PlayersInvited={}
  3.  
  4. local BACKDROP = {
  5.       bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  6.       edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  7.       tile = true, tileSize = 16, edgeSize = 16,
  8.       insets = { left = 4, right = 4, top = 4, bottom = 4 }
  9.     }
  10.  
  11. --[[    I am beginning to wonder if creating this frame should be sized/implemented diferently  ]]
  12. local GuildCreator = CreateFrame("Frame","GuildCreator", UIParent)
  13. HEIGHT = math.min(PlayerFrame:GetBottom() - QuickJoinToastButton:GetTop() -40, 500)
  14. WIDTH = PlayerFrame:GetRight()-PlayerPortrait:GetLeft()
  15. GuildCreator:SetSize(WIDTH,HEIGHT)  --width, height
  16. --[[I hear BACKDROP is "basically obsolute"...but I haven't spent the time
  17. or figured out how to implement textures well yet, so...guidance appreciatedf]]
  18. GuildCreator:SetBackdrop(BACKDROP)
  19. GuildCreator:SetBackdropColor(0, 0, 0)
  20. GuildCreator:SetPoint("TOPLEFT","PlayerPortrait","BOTTOMLEFT", 0, -20)
  21. GuildCreator:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  22. GuildCreator:SetScript("OnEvent", function(self, event, ...)
  23.       f[event](self, ...)
  24. end)
  25.  
  26. local function CheckSameRealm(unitToken)
  27.    local name, realm = UnitName(unitToken)
  28.    local isSameRealm = false -- defaulting to False
  29.    if realm == nil then isSameRealm = true
  30.    end
  31.    return isSameRealm
  32. end
  33.  
  34. local function CheckHasGuild(unitToken)
  35.    local guildName, guildRankName, guildRankIndex = GetGuildInfo(unitToken)
  36.    local hasGuild = true
  37.    if guildName == nil then hasGuild = false end
  38.    return hasGuild
  39. end
  40.  
  41. local function CheckAlreadyInvited(name) return not not PlayersInvited[name] end --[[HUGE THANKS TO: Meorawr, Icesythe7, and Vlad]]
  42.  
  43. local function CheckAlreadyOnList(name) return not not InviteList[name] end
  44.  
  45. local function CheckIsPlayer(unitToken) return not not UnitIsPlayer(unitToken) end
  46.  
  47. local function CheckElligibility(unitToken)
  48.    local name, realm = UnitName(unitToken)
  49.    local isPlayer = CheckIsPlayer(unitToken)
  50.      local isSameRealm = CheckSameRealm(unitToken)
  51.    local hasGuild = CheckHasGuild(unitToken)
  52.    local alreadyInvited = CheckAlreadyInvited(name)
  53.    local alreadyOnList = CheckAlreadyOnList(name)
  54.    local isElligible = false
  55.    if isSameRealm and isPlayer and not hasGuild and not alreadyInvited and not alreadyOnList then isElligible = true end  
  56.    return isElligible
  57. end

Now I need to use prospects identified to create a frame (or set a frames) that will allow me to:
- Target the prospect (obviously this doesn't need to happen first, but it's the part I currently anticipate being the most difficult)
- Whisper them to ask if they would might signing my guild charter
- Request GuildCharterSig
- Remove the frame(s) for that prospect so that there are always 10 (arbitrary number) of these secure buttons fit to the frame

For this, I'm given to understand FramePools are the way to go...but after browsing the source code and finding frustratingly few examples, I'm still lost on how to implement this.

Currently I'm trying to sort out just how to create the frames...I havn't even really been able to figure out how to keep ten populated at all times.

My attempt to create the "TargetUnit" frame is:
lua Code:
  1. local pool = CreateFramePool("Button", GuildCreator, "SecureUnitButtonTemplate")
  2. -- To create or reuse a button:
  3. local function AddProspect(prospect)
  4.   local button = pool:Acquire()
  5.   button:SetAttribute("unit", prospect)
  6.   button:RegisterForClicks("AnyUp")
  7.   button:SetAttribute("*type1", "target")
  8.   local t = button:CreateFontString()
  9.   t:SetFontObject(GameFontHighlightSmall)
  10.   t:SetText(target)
  11.   t:SetPoint("CENTER")
  12.   button:SetSize(WIDTH-10, HEIGHT/10) -- make the width slightly smaller than it's parent frame and make room for ten active buttons
  13.   local bg = button:CreateTexture()
  14.   bg:SetColorTexture(0.317, 0.317, 0.317, .5) -- Greyish color; half opaque
  15.   bg:SetAllPoints()
  16.   button:Show()
  17.   return button
  18. end

Sorrry for the nooboscity, I'm just out of my depth a bit.

Last edited by Stressed1 : 09-24-19 at 07:58 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Creating and Using Framepools

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off