WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Frame Factory (https://www.wowinterface.com/forums/showthread.php?t=59489)

Walkerbo 01-27-23 04:38 PM

Frame Factory
 
Hi all

I want to build a little frame factory; I am tired of building each fame template to see which frame I like for various addons; so I figure that I can use a factory to build and then screenshot the frames.

I have a static number 1 frame and I want the following frames using the static frame as the origin.

I want each frame to display its frame template name.

Here is an image of my desired out come.

Here is my code:
Lua Code:
  1. local frameList = {
  2.     UIDropDownCustomMenuEntryTemplate,
  3.     UIDropDownListTemplate,
  4.     UIDropDownMenuButtonTemplate,
  5.     UIDropDownMenuTemplate,
  6.     UIExpandingButtonTemplate,
  7.     UIGoldBorderButtonTemplate,
  8.     UIMenuButtonStretchTemplate,
  9.     UIMenuButtonTemplate,
  10.     UIMenuTemplate,
  11.     UIPanelBorderedButtonTemplate,
  12.     UIPanelButtonGrayTemplate,
  13.     UIPanelButtonNoTooltipResizeToFitTemplate,
  14.     UIPanelButtonNoTooltipTemplate,
  15.     UIPanelButtonTemplate,
  16.     UIPanelCloseButton,
  17.     UIPanelCloseButtonNoScripts,
  18.     UIPanelDialogTemplate,
  19.     UIPanelDynamicResizeButtonTemplate
  20. }
  21.  
  22. local right, down = 50, -50
  23. local width, height = 300, 150
  24. local frameNameTop, frameLast, frameCount = "staticTopFrame", "staticTopFrame", 2
  25.  
  26. local function layoutFrames()
  27.     for k, v in pairs(frameList) do
  28.         f = CreateFrame("Frame", "frame" .. k, UIParent, v)
  29.         f:SetSize(width, height)
  30.         f:SetPoint("TOPLEFT", frameLast, right, down)
  31.  
  32.         ftb = CreateFrame("Frame", "ftb", f)
  33.         ftb:SetSize(width, height / 2)
  34.         ftb:SetPoint("CENTER", frameLast)
  35.  
  36.         ftbt = ftb:CreateFontString("ftbt")
  37.         ftbt:SetAllPoints(ftb)
  38.         ftbt:SetFontObject(FocusFontSmall)
  39.         ftbt:SetText(v)
  40.  
  41.         frameLast = frameLast .. k
  42.         down = down - 310
  43.  
  44.         if k == 4 then
  45.             right = right + 310
  46.             down = -50
  47.             count = 1
  48.             frameNameTop = frameLast
  49.         elseif k == 1 then
  50.             frameNameTop = frameLast .. k
  51.             down = down - 160
  52.         else
  53.             frameLast = frameLast .. k
  54.             down = down - 160
  55.         end
  56.     end
  57. end
  58.  
  59. local staticTopFrame = CreateFrame("Frame", "staticTopFrame", UIParent, "UIPanelDialogTemplate")
  60. staticTopFrame:SetSize(width, height)
  61. staticTopFrame:SetPoint("TOPLEFT", right, down)
  62. staticTopFrame:EnableMouse(true)
  63. staticTopFrame:SetMovable(true)
  64. staticTopFrame:SetClampedToScreen(true)
  65. staticTopFrame:RegisterForDrag("RightButton", "LeftButton")
  66. staticTopFrame:SetScript("OnDragStart", staticTopFrame.StartMoving)
  67. staticTopFrame:SetScript("OnDragStop", staticTopFrame.StopMovingOrSizing)
  68.  
  69. staticTopFrameTextBox = CreateFrame("Frame", "staticTopFrameTextBox", staticTopFrame)
  70. staticTopFrameTextBox:SetSize(width, height / 2)
  71. staticTopFrameTextBox:SetPoint("CENTER", staticTopFrame)
  72.  
  73. staticTopFrameTextBoxText = staticTopFrameTextBox:CreateFontString(staticTopFrameTextBoxText)
  74. staticTopFrameTextBoxText:SetAllPoints(staticTopFrameTextBox)
  75. staticTopFrameTextBoxText:SetFontObject(FocusFontSmall)
  76. staticTopFrameTextBoxText:SetText("UIPanelDialogTemplate")
  77.  
  78. layoutFrames()

When I run it the static frame displays correctly yet nothing else displays and there are no errors.
I am using ReHack to run the code in game.

I have looked at button factories and have followed them without success.

There is obviously an error in my code yet I can't see it, maybe I am too close to the code that I can not see the error that I am making.

Any help would be greatly appreciated.

Fizzlemizz 01-27-23 05:11 PM

To start with, templates a passed as strings. Your frameList is empty because you're really defined it as

Lua Code:
  1. local frameList = {
  2.     [1] = nil,
  3.     [2] = nil,
  4.     [3] = nil,
  5.     [4] = nil,
  6.     [5] = nil,
  7.     [6] = nil,
  8.     -- etc.
  9. }

therefore
Code:

for k, v in pairs(frameList) do
does nothing.

I'm pretty sure you will get plenty of errors once the list contains something ;)

Walkerbo 01-27-23 05:18 PM

Ah, I said it would be an obvious error.

I guarantee that I will have errors, many errors, but this is how I learn. :)

Walkerbo 01-27-23 10:16 PM

Ok, got it going, yes there were so many bugs I pulled it apart and started again.
This time I got rid of the first static frame.
Lua Code:
  1. local frameList = {
  2.     "BaseBasicFrameTemplate",
  3.     "BasicFrameTemplate",
  4.     "BasicFrameTemplateWithInset",
  5.     "ButtonFrameTemplate",
  6.     "ButtonFrameTemplateMinimizable",
  7.     "ChatConfigBorderBoxTemplate",
  8.     "ChatConfigBoxTemplate",
  9.     "ChatConfigBoxWithHeaderTemplate",
  10.     "ChatConfigCheckBoxTemplate",
  11.     "CovenantListWideFrameTemplate",
  12.     "CovenantMissionBaseFrameTemplate",
  13.     "DefaultPanelTemplate",
  14.     "DefaultPanelTemplate",
  15.     "EtherealFrameTemplate",
  16.     "FloatingBorderedFrame",
  17.     "GarrisonMissionBaseFrameTemplate",
  18.     "GlowBorderTemplate",
  19.     "GlowBoxTemplate",
  20.     "HelpFrameContainerFrameTemplate",
  21.     "InsetFrameTemplate",
  22.     "InsetFrameTemplate2",
  23.     "InsetFrameTemplate3",
  24.     "InsetFrameTemplate4",
  25.     "KeyBindingFrameBindingButtonTemplate",
  26.     "KeyBindingFrameBindingButtonTemplateWithLabel",
  27.     "PortraitFrameTemplate",
  28.     "PortraitFrameTemplateMinimizable",
  29.     "PortraitFrameTemplateNoCloseButton",
  30.     "SimplePanelTemplate",
  31.     "ThinBorderTemplate",
  32.     "TooltipBorderedFrameTemplate",
  33.     "TranslucentFrameTemplate",
  34.     "UIPanelDialogTemplate",
  35.  }
  36.  
  37.  local width, height = 300, 150
  38.  local right, down, counter = 20, -20, 0
  39.  
  40.  for k, v in pairs(frameList) do
  41.     f = CreateFrame("Frame", "frame" .. k, UIParent, v)
  42.     f:SetSize(width, height)
  43.     f:SetPoint("TOPLEFT", right, down, counter)
  44.  
  45.     ftb = CreateFrame("Frame", "ftb", f)
  46.     ftb:SetSize(width, height / 2)
  47.     ftb:SetPoint("CENTER", "frame" .. k)
  48.  
  49.     ftbt = ftb:CreateFontString("ftbt")
  50.     ftbt:SetAllPoints(ftb)
  51.     ftbt:SetFontObject(FocusFontSmall)
  52.     ftbt:SetText(v)
  53.  
  54.     down = down - 160
  55.     counter = counter + 1
  56.  
  57.     if counter == 5 then
  58.        right = right + 310
  59.        down = -20
  60.        counter = 0
  61.     end
  62.  end
Here are the frames.

Ketho 01-28-23 05:56 PM

Oh that looks neat :)


All times are GMT -6. The time now is 04:58 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI