View Single Post
03-08-12, 07:45 PM   #29
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
I'm no pro at this, but I would do is something more like this:

lua Code:
  1. local function CreateCheckboxes(subframe)
  2.     local boxes = AftermathUIFrame.checkboxes or {}
  3.    
  4.     if subframe == 1 then
  5.         boxes[1] = Checkbox(AftermathhUIFrame, 1, 14, -95, "Show PvP Icon.", AftermathhUI.ouf.showpvpicon)
  6.         boxes[2] = Checkbox(AftermathhUIFrame, 2, 14, -115, "Show Buffs.", AftermathhUI.ouf.showbuffs, ShowBuffs_OnClick)
  7.         boxes[3] = Checkbox(AftermathhUIFrame, 3, 14, -135, "Show Debuffs.", AftermathhUI.ouf.showdebuffs)
  8.         -- and so on
  9.     elseif subframe == 2 then
  10.         boxes[1] = Checkbox(whatever)
  11.     elseif
  12.     else
  13.     end
  14.     for i = i, #boxes do
  15.         boxes[i]:Show()
  16.     end
  17.     AftermathUIFrame.checkboxes = checkboxes
  18. end
  19.  
  20. local function ReleaseCheckboxes()
  21.     local boxes = AftermathUIFrame.checkboxes
  22.     local bin = AftermathUIFrame.recyclebin or {}
  23.    
  24.     for i = 1, #boxes do
  25.         boxes[i]:Hide()
  26.         table.insert(bin, boxes[i])
  27.         boxes[i] = nil
  28.     end
  29. end
  30.  
  31. local function DisplayCheckboxes(subframe)
  32.     ReleaseCheckboxes()
  33.     CreateCheckboxes(subframe)
  34. end
  35.  
  36. AftermathhUIFrameSub1:SetScript("OnClick", DisplayCheckboxes(1))

That lets you keep track of the buttons you've created, recycle them when the user switches tabs so you don't just keep making new buttons, and you can reuse the same code for your other subframes, just adding their button configuration options to the creation function.

You would have to set up your Checkbox function to try to pull old buttons out of the recycle bin before creating new ones and to return the CheckButton object.

Last edited by kaels : 03-08-12 at 08:00 PM.
  Reply With Quote