View Single Post
02-24-19, 04:24 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
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"
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-24-19 at 04:30 PM.
  Reply With Quote