View Single Post
02-24-19, 05:22 PM   #3
wille480
A Wyrmkin Dreamwalker
Join Date: Jan 2017
Posts: 56
Originally Posted by Fizzlemizz View Post
Something to look at and play with. A function to uniformly create all sub-frames (buttons in this case) with the return value being stored in a table attached to the main frame. Not the only way.

Lua Code:
  1. local function CreateSubFrame(self)
  2.     local f = CreateFrame("Button", "$parentSUBFRAME"..#self.SubFrames+1, self)
  3.     f:SetSize(self:GetSize())
  4.     f.texture = f:CreateTexture("ARTWORK")
  5.     f.texture:SetAllPoints()
  6.     f.texture:SetTexture("Interface/BUTTONS/WHITE8X8")
  7.     f.texture:SetVertexColor(0.3, 0.3, 0.3, 0.5)
  8.     f.text = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  9.     f.text:SetPoint("CENTER")
  10.     f.text:SetText(f:GetName())
  11.     local p
  12.     if #self.SubFrames == 0 then
  13.         p = self
  14.     else
  15.         p = self.SubFrames[#self.SubFrames]
  16.     end
  17.     f:SetPoint("TOP", p, "BOTTOM", 0, -5)
  18.     f:SetScript("OnEnter", function(self)
  19.         f.texture:SetVertexColor(0.6, 0.6, 0.6, 0.5)
  20.     end)
  21.     f:SetScript("OnLeave", function(self)
  22.         f.texture:SetVertexColor(0.3, 0.3, 0.3, 0.5)
  23.     end)
  24.     f:SetScript("OnClick", function(self)
  25.         print(self:GetName().." Clicked!!!!")
  26.     end)
  27.     return f
  28. end
  29.  
  30. local mainWindow = CreateFrame("Frame", "wille480DragFrame", UIParent) -- The main window (Orange color)
  31. mainWindow:SetSize(200, 20)
  32. mainWindow:SetPoint("CENTER")
  33. mainWindow.SubFrames = {}
  34.  
  35. for i= 1, 5 do
  36.     tinsert(mainWindow.SubFrames, CreateSubFrame(mainWindow))
  37. end

Frame names are global so you should try and make them unique, hence the addition of "wille480" to "DragFrame"
Wow, nice solution! Tweaked it abit for my likeing =) . Appriciate the help, kinda new to addon programming, made an addon before "HelyaAssist" but trying to learn a new skill as university times are short now! ty for help
  Reply With Quote