Thread Tools Display Modes
04-11-13, 01:03 PM   #1
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Help Creating Textures, Frames, etc in Lua. And some questions!

Greetings,

Okay, so i'm trying to create a complete working AddOn using lua only! I know how to create a few using .XML to make the graphics and add event handlers. But i'm not sure in lua. As an example i'm going to use BagBuddy.

Allright, first i would like to ask if this is considered readable or if it can be written in an better way:

Lua Code:
  1. -------------------
  2. --BagBuddy Frames--
  3. -------------------
  4.  
  5.     -- The parent frame to add textures and fontstrings to
  6.     local frame = CreateFrame("Frame", "BagBuddy", UIParent)
  7.     frame:SetWidth(425)
  8.     frame:SetHeight(425)
  9.     frame:SetPoint("CENTER", UIParent, "CENTER")
  10.    
  11.     -- The body texture of BagBuddy
  12.     frame.skeleton = frame:CreateTexture("BagBuddy_Skeleton", "BORDER")
  13.     frame.skeleton:SetPoint("TOPLEFT")
  14.     frame.skeleton:SetTexture("Interface\\BankFrame\\UI-BankFrame")
  15.    
  16.     -- The portrait texture of BagBuddy
  17.     frame.icon = frame:CreateTexture("BagBuddy_Icon", "BACKGROUND")
  18.     frame.icon:SetWidth(60)
  19.     frame.icon:SetHeight(60)
  20.     frame.icon:SetPoint("TOPLEFT", 7, -6)
  21.     frame.icon:SetTexture("Interface\\Icons\\INV_Misc_EngGizmos_17")
  22.     SetPortraitToTexture(frame.icon, "Interface\\Icons\\INV_Misc_EngGizmos_17")
  23.    
  24.     -- The title fontstring of BagBuddy
  25.     frame.title = frame:CreateFontString("BagBuddy_Title", "OVERLAY", "GameFontNormal")
  26.     frame.title:SetPoint("TOP", 0, -18)
  27.     frame.title:SetText("BagBuddy")
  28.    
  29.     -- The button that allows BagBuddy to be hidden
  30.     frame.close = CreateFrame("Button", "BagBuddy_Close", frame, "UIPanelCloseButton")
  31.     frame.close:SetPoint("TOPRIGHT", -22, -8)
  32.    
  33. ----------------------
  34. --BagBuddy Functions--
  35. ----------------------
  36.  
  37.     function BagBuddy_OnLoad(self)
  38.  
  39.     end
  40.  
  41.     function BagBuddy_MakeMovable(self, motion)
  42.         self:EnableMouse(true)
  43.         self:SetMovable(true)
  44.         self:SetClampedToScreen(true)
  45.         self:RegisterForDrag("LeftButton")
  46.         self:SetScript("OnDragStart", self.StartMoving)
  47.         self:SetScript("OnDragStop", self.StopMovingOrSizing)
  48.     end
  49.  
  50.     BagBuddy_MakeMovable(frame)

the function BagBuddy_OnLoad(self) is empty because i'm not sure on how i would add 28 x buttons to the frame without using an XML template.

The template for the original BagBuddy looks like this:

XML Code:
  1. <Button name="BagBuddyItemTemplate" inherits="SecureActionButtonTemplate" virtual="true">
  2.     <Size>
  3.       <AbsDimension x="37" y="37"/>
  4.     </Size>
  5.     <Layers>
  6.       <Layer level="BORDER">
  7.         <Texture name="$parentIconTexture" parentKey="icon"/>
  8.         <FontString name="$parentCount" parentKey="count" inherits="NumberFontNormal" justifyH="RIGHT" hidden="true">
  9.           <Anchors>
  10.             <Anchor point="BOTTOMRIGHT">
  11.               <Offset>
  12.                 <AbsDimension x="-5" y="2"/>
  13.               </Offset>
  14.             </Anchor>
  15.           </Anchors>
  16.         </FontString>
  17.       </Layer>
  18.       <Layer level="OVERLAY">
  19.         <Texture name="$parentGlow" parentKey="glow" alphaMode="ADD" file="Interface\Buttons\UI-ActionButton-Border">
  20.           <Size x="70" y="70"/>
  21.           <Anchors>
  22.             <Anchor point="CENTER"/>
  23.           </Anchors>
  24.           <Color r="1.0" g="1.0" b="1.0" a="0.6"/>
  25.         </Texture>
  26.       </Layer>
  27.     </Layers>
  28.     <Attributes>
  29.       <Attribute name="type2" type="string" value="item"/>
  30.     </Attributes>
  31.     <Scripts>
  32.       <OnEnter function="BagBuddy_Button_OnEnter"/>
  33.       <OnLeave function="BagBuddy_Button_OnLeave"/>
  34.     </Scripts>
  35.     <NormalTexture name="$parentNormalTexture" file="Interface\Buttons\UI-Quickslot2">
  36.       <Size>
  37.         <AbsDimension x="64" y="64"/>
  38.       </Size>
  39.       <Anchors>
  40.         <Anchor point="CENTER">
  41.           <Offset>
  42.             <AbsDimension x="0" y="-1"/>
  43.           </Offset>
  44.         </Anchor>
  45.       </Anchors>
  46.     </NormalTexture>
  47.     <PushedTexture file="Interface\Buttons\UI-Quickslot-Depress"/>
  48.     <HighlightTexture file="Interface\Buttons\ButtonHilight-Square" alphaMode="ADD"/>
  49.   </Button>

Using the above template i would add each button to the frame like this:

Lua Code:
  1. function BagBuddy_OnLoad(self)
  2.     self.items = {}
  3.     for idx = 1, 28 do
  4.         local item = CreateFrame("Button", "BagBuddy_Item" .. idx, self, "BagBuddyItemTemplate")
  5.         self.items[idx] = item
  6.         if idx == 1 then
  7.             item:SetPoint("TOPLEFT", 40, -73)
  8.         elseif idx == 8 or idx == 15 or idx == 22 then
  9.             item:SetPoint("TOPLEFT", self.items[idx - 7], "BOTTOMLEFT", 0, -7)
  10.         else
  11.             item:SetPoint("TOPLEFT", self.items[idx - 1], "TOPRIGHT", 12, 0)
  12.         end
  13.     end
  14. end

but this is easy because i can inherit the item's from BagBuddyItemTemplate in my XML document. How can i create something similar using lua only?

Also how do i set alphaMode="ADD" in lua?

Hope you guys understand what i'm trying to accomplish, if not, please ask me and i'll try to explain
  Reply With Quote
04-11-13, 03:09 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
We already discussed "templates" in Lua here: http://www.wowinterface.com/forums/s...ad.php?t=46184
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
04-11-13, 03:40 PM   #3
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
First of all, your code looks good, but you're making your functions global. They should either be local or part of the frame's table, like you do with the frame's regions/children.

Your BagBuddy_MakeMovable function is not needed, since you're only calling it once (at least so far). Just use the function's body, replacing 'self' with 'frame', your local variable.

OnLoad functions don't actually work in lua, because after calling CreateFrame(), the frame's (non-existing) OnLoad handler will have run already. Just put the code directly in the source file.

As for the alpha mode, that would be SetBlendMode.

Last edited by Haleth : 04-11-13 at 03:45 PM.
  Reply With Quote
04-11-13, 08:25 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
You pretty much have the framework down for transferring your template into Lua, All you really need to do is put in the code for Lua to create the objects within the loop that the template would've done.

Lua Code:
  1. local item=CreateFrame("Button","BagBuddy_Item"..idx,frame,"SecureActionButtonTemplate");
  2. item:SetSize(37,37);
  3. item:SetAttribute("type2","item");
  4. item:SetScript("OnEnter",BagBuddy_Button_OnEnter);
  5. item:SetScript("OnLeave",BagBuddy_Button_OnLeave);
  6.  
  7. item:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2");
  8. item:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress");
  9. item:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square","ADD");
  10. do local tex=item:GetNormalTexture();-- Hack to modify the existing texture object
  11.     tex:ClearAllPoints();
  12.     tex:SetPoint("CENTER",0,-1);
  13.     tex:SetSize(64,64);
  14. end
  15.  
  16. item.icon=item:CreateTexture("$parentIconTexture","BORDER");
  17.  
  18. item.count=item:CreateFontString("$parentCount","BORDER","NumberFontNormal");
  19. item.count:SetPoint("BOTTOMRIGHT",-5,2);
  20. item.count:SetJustifyH("RIGHT");
  21. item.count:Hide();
  22.  
  23. item.glow=item:CreateTexture("$parentGlow","OVERLAY");
  24. item.glow:SetPoint("CENTER");
  25. item.glow:SetSize(70,70);
  26. item.glow:SetTexture("Interface\\Buttons\\UI-ActionButton-Border");
  27. item.glow:SetBlendMode("ADD");
  28. item.glow:SetAlpha(0.6);

If there aren't any errors I missed, that should create the exact frame your template is making. Just replace the line where you create the item button with this and as Haleth suggested, move the contents of the OnLoad function to the main chunk and replace all references of self with frame.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-11-13 at 08:31 PM.
  Reply With Quote
04-12-13, 04:43 AM   #5
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Originally Posted by Seerah View Post
We already discussed "templates" in Lua here: http://www.wowinterface.com/forums/s...ad.php?t=46184
I'm sorry for the double post, but i had more questions for my lua code than in that topic - i should have edited the post.

Originally Posted by Haleth View Post
First of all, your code looks good, but you're making your functions global. They should either be local or part of the frame's table, like you do with the frame's regions/children.

Your BagBuddy_MakeMovable function is not needed, since you're only calling it once (at least so far). Just use the function's body, replacing 'self' with 'frame', your local variable.

OnLoad functions don't actually work in lua, because after calling CreateFrame(), the frame's (non-existing) OnLoad handler will have run already. Just put the code directly in the source file.

As for the alpha mode, that would be SetBlendMode.
Thank you for the answer! I'll make my functions local instead. I decided to use the BagBuddy_MakeMovable function as i was not sure to wether i was going to develop the bagbuddy abit and maybe add some new feutures which would maybe require a new frame - if this is not the case i will ofc add the movable scripts directly to the frame created.

Originally Posted by SDPhantom View Post
You pretty much have the framework down for transferring your template into Lua, All you really need to do is put in the code for Lua to create the objects within the loop that the template would've done.

Lua Code:
  1. local item=CreateFrame("Button","BagBuddy_Item"..idx,frame,"SecureActionButtonTemplate");
  2. item:SetSize(37,37);
  3. item:SetAttribute("type2","item");
  4. item:SetScript("OnEnter",BagBuddy_Button_OnEnter);
  5. item:SetScript("OnLeave",BagBuddy_Button_OnLeave);
  6.  
  7. item:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2");
  8. item:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress");
  9. item:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square","ADD");
  10. do local tex=item:GetNormalTexture();-- Hack to modify the existing texture object
  11.     tex:ClearAllPoints();
  12.     tex:SetPoint("CENTER",0,-1);
  13.     tex:SetSize(64,64);
  14. end
  15.  
  16. item.icon=item:CreateTexture("$parentIconTexture","BORDER");
  17.  
  18. item.count=item:CreateFontString("$parentCount","BORDER","NumberFontNormal");
  19. item.count:SetPoint("BOTTOMRIGHT",-5,2);
  20. item.count:SetJustifyH("RIGHT");
  21. item.count:Hide();
  22.  
  23. item.glow=item:CreateTexture("$parentGlow","OVERLAY");
  24. item.glow:SetPoint("CENTER");
  25. item.glow:SetSize(70,70);
  26. item.glow:SetTexture("Interface\\Buttons\\UI-ActionButton-Border");
  27. item.glow:SetBlendMode("ADD");
  28. item.glow:SetAlpha(0.6);

If there aren't any errors I missed, that should create the exact frame your template is making. Just replace the line where you create the item button with this and as Haleth suggested, move the contents of the OnLoad function to the main chunk and replace all references of self with frame.
Thank you so much! Imma look this code through and see what youve done! Also thank you for showing how to give the ADD alphaMode in lua, i tried: SetHighlightTexture("Source", SetAlpha="ADD") haha now i get why that didn't work

imma update the full script soon, and tell you guys if i got any errors.

$parent works for lua aswell? or is that XML only?

Last edited by fRodzet : 04-12-13 at 04:46 AM.
  Reply With Quote
04-12-13, 05:46 AM   #6
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Allright here is my code, but it ain't working.. Doesn't create a button. Sorry - but as of now i'm still not good enough to figure out myself how to get it working, so some more help would be Lovely!

Lua Code:
  1. -------------------
  2. --BagBuddy Frames--
  3. -------------------
  4.  
  5.     -- The parent frame of BagBuddy
  6.     local frame = CreateFrame("Frame", "BagBuddy", UIParent)
  7.     frame:SetSize(425, 425)
  8.     frame:SetPoint("CENTER", UIParent, "CENTER")
  9.  
  10.     -- The Body frame of BagBuddy (the border itself)
  11.     frame.body = frame:CreateTexture("BagBuddy_Body", "BORDER")
  12.     frame.body:SetPoint("TOPLEFT")
  13.     frame.body:SetTexture("Interface\\BankFrame\\UI-BankFrame")
  14.    
  15.     -- Making BagBuddy movable
  16.     frame:EnableMouse(true)
  17.     frame:SetMovable(true)
  18.     frame:SetClampedToScreen(true)
  19.     frame:RegisterForDrag("LeftButton")
  20.     frame:SetScript("OnDragStart", frame.StartMoving)
  21.     frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
  22.  
  23.     -- The icon(portrait) texture of BagBuddy
  24.     frame.icon = frame:CreateTexture("BagBuddy_Icon", "BACKGROUND")
  25.     frame.icon:SetSize(60, 60)
  26.     frame.icon:SetPoint("TOPLEFT", 7, -6)
  27.     frame.icon:SetTexture("Interface\\Icons\\INV_Misc_EngGizmos_17")
  28.     SetPortraitToTexture(frame.icon, "Interface\\Icons\\INV_Misc_EngGizmos_17")
  29.  
  30.     -- The title fontstring of BagBuddy.
  31.     frame.title = frame:CreateFontString("BagBuddy_Title", "OVERLAY", "GameFontNormal")
  32.     frame.title:SetPoint("TOP", 0, -18)
  33.     frame.title:SetText("BagBuddy")
  34.  
  35.     -- The close button for BagBuddy.
  36.     frame.close = CreateFrame("Button", "BagBuddy_Close", frame, "UIPanelCloseButton")
  37.     frame.close:SetPoint("TOPRIGHT", -22, -8)
  38.  
  39. -----------------------
  40. --BagBuddy Loop Items--
  41. -----------------------
  42.  
  43. frame.items = {}
  44. for idx = 1, 28 do
  45.     local item = CreateFrame("Button", "BagBuddy_Item" .. idx, frame, "SecureActionButtonTemplate")
  46.     item:SetSize(37, 37)
  47.    
  48.     item:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
  49.     item:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress")
  50.     item:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", "ADD")
  51.     do local tex = item:GetNormalTexture()
  52.         tex:ClearAllPoints()
  53.         tex:SetPoint("CENTER", 0, -1)
  54.         tex:SetSize(64, 64)
  55.     end
  56.    
  57.     item.icon = item:CreateTexture("$parentIconTexture", "BORDER")
  58.    
  59.     item.count = item:CreateFontString("$parentCount", "BORDER", "NumberFontNormal")
  60.     item.coun:SetPoint("BOTTOMRIGHT", -5, 2)
  61.     item.count:SetJustifyH("RIGHT")
  62.     item.count:Hide()
  63.    
  64.     item.glow = item:CreateTexture("$parentGlow", "OVERLAY")
  65.     item.glow:SetPoint("CENTER")
  66.     item.glow:SetSize(70, 70)
  67.     item.glow:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
  68.     item.glow:SetBlendMode("ADD")
  69.     item.glow:SetAlpha(0.6)
  70.    
  71.     frame.items[idx] = item
  72.    
  73.     if idx == 1 then
  74.         item:SetPoint("TOPLEFT", 40, -73)
  75.     elseif idx == 8 or idx == 15 or idx == 22 then
  76.         item:SetPoint("TOPLEFT", frame.items[idx - 7], "BOTTOMLEFT", 0, -7)
  77.     else
  78.         item:SetPoint("TOPLEFT", frame.items[idx - 1], "TOPRIGHT", 12, 0)
  79.     end
  80. end
  81.  
  82.  
  83. ----------------------
  84. --BagBuddy Functions--
  85. ----------------------

I looked it through and doesn't seem like a typing mistake.

Last edited by fRodzet : 04-12-13 at 05:55 AM.
  Reply With Quote
04-12-13, 05:59 AM   #7
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Your problem was "self" on icon setpoint.

I added some suggestions.

Lua Code:
  1. -------------------
  2.     --BagBuddy Frames--
  3.     -------------------
  4.  
  5.     -- The parent frame of BagBuddy
  6.     local frame = CreateFrame("Frame", "BagBuddy", UIParent)
  7.     frame:SetSize(425, 425)
  8.     frame:SetPoint("CENTER")
  9.  
  10.     -- Making BagBuddy movable
  11.  
  12.     -- I suggest you create a drag frame and redirect the drag event on the that frame to the parent frame
  13.     frame:EnableMouse(true)
  14.     frame:SetClampedToScreen(true)
  15.     frame:SetMovable(true)
  16.     frame:SetUserPlaced(true)
  17.  
  18.     frame.drag = CreateFrame("Frame", "$parentDragFrame", frame)
  19.     frame.drag:SetHeight(22)
  20.     frame.drag:SetPoint("TOPLEFT",60,0)
  21.     frame.drag:SetPoint("TOPRIGHT",-30,0)
  22.     frame.drag:EnableMouse(true)
  23.     frame.drag:RegisterForDrag("LeftButton")
  24.     frame.drag:SetScript("OnDragStart", function(self)
  25.       self:GetParent():StartMoving()
  26.     end)
  27.     frame.drag:SetScript("OnDragStop", function(self)
  28.       self:GetParent():StopMovingOrSizing()
  29.     end)
  30.  
  31.     -- The Body frame of BagBuddy (the border itself)
  32.     frame.body = frame:CreateTexture(nil, "BACKGROUND", nil, -8) --name, strata, inherit, texturelevel
  33.     frame.body:SetAllPoints() --take the size of the parent element
  34.     frame.body:SetTexture("Interface\\BankFrame\\UI-BankFrame")
  35.  
  36.     -- The icon(portrait) texture of BagBuddy
  37.     frame.icon = frame:CreateTexture("BagBuddy_Icon", "BACKGROUND")
  38.     frame.icon:SetSize(60, 60)
  39.     frame.icon:SetPoint("TOPLEFT", 7, -6)
  40.     frame.icon:SetTexture("Interface\\Icons\\INV_Misc_EngGizmos_17")
  41.     SetPortraitToTexture(frame.icon, "Interface\\Icons\\INV_Misc_EngGizmos_17")
  42.  
  43.     -- The title fontstring of BagBuddy.
  44.     frame.title = frame:CreateFontString("BagBuddy_Title", "OVERLAY", "GameFontNormal")
  45.     frame.title:SetPoint("TOP", 0, -18)
  46.     frame.title:SetText("BagBuddy")
  47.  
  48.     -- The close button for BagBuddy.
  49.     frame.close = CreateFrame("Button", "BagBuddy_Close", frame, "UIPanelCloseButton")
  50.     frame.close:SetPoint("TOPRIGHT", -22, -8)
  51.  
  52.     -----------------------
  53.     --BagBuddy Loop Items--
  54.     -----------------------
  55.  
  56.     frame.items = {}
  57.     for idx = 1, 28 do
  58.       local item = CreateFrame("Button", "BagBuddy_Item" .. idx, frame, "SecureActionButtonTemplate")
  59.       item:SetSize(37, 37)
  60.  
  61.       item:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
  62.       item:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress")
  63.       item:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", "ADD")
  64.       do
  65.         local tex = item:GetNormalTexture()
  66.         tex:ClearAllPoints()
  67.         tex:SetPoint("CENTER", 0, -1)
  68.         tex:SetSize(64, 64)
  69.       end
  70.  
  71.       item.icon = item:CreateTexture("$parentIconTexture", "BORDER")
  72.  
  73.       item.count = item:CreateFontString("$parentCount", "BORDER", "NumberFontNormal")
  74.       item.coun:SetPoint("BOTTOMRIGHT", -5, 2)
  75.       item.count:SetJustifyH("RIGHT")
  76.       item.count:Hide()
  77.  
  78.       item.glow = item:CreateTexture("$parentGlow", "OVERLAY")
  79.       item.glow:SetPoint("CENTER")
  80.       item.glow:SetSize(70, 70)
  81.       item.glow:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
  82.       item.glow:SetBlendMode("ADD")
  83.       item.glow:SetAlpha(0.6)
  84.  
  85.       frame.items[idx] = item
  86.  
  87.       if idx == 1 then
  88.           item:SetPoint("TOPLEFT", 40, 200)
  89.       elseif idx == 8 or idx == 15 or idx == 22 then
  90.           item:SetPoint("TOPLEFT", frame.items[idx - 7], "BOTTOMLEFT", 0, -7)
  91.       else
  92.           item:SetPoint("TOPLEFT", frame.items[idx - 1], "TOPRIGHT", 12, 0)
  93.       end
  94.     end

Not sure how your panel should look.

But do a quick test. Is this your panel?

Lua Code:
  1. --setup panel
  2.   do
  3.     local panel = CreateFrame("Frame", "MyConfigPanel", UIParent, "ButtonFrameTemplate")
  4.     --panel:SetFrameStrata("HIGH")
  5.     panel:SetSize(600,600)
  6.     panel:SetPoint("CENTER")
  7.     panel.title = _G["MyConfigPanelTitleText"]
  8.     panel.title:SetText("ButtonFrameTemplate Panel")
  9.   end

If yes you can use the "ButtonFrameTemplate" to create your panel. It will have all the buttons already included. There are ton of other templates.

Hmm I just checked. BankFrame.xml is using "PortraitFrameTemplate". So you can probably use that instead.

https://github.com/tekkub/wow-ui-sou...kFrame.xml#L94

.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 04-12-13 at 06:10 AM.
  Reply With Quote
04-12-13, 06:09 AM   #8
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Originally Posted by zork View Post
Your problem was "self" on icon setpoint.

I added some suggestions.

Lua Code:
  1. -------------------
  2.     --BagBuddy Frames--
  3.     -------------------
  4.  
  5.     -- The parent frame of BagBuddy
  6.     local frame = CreateFrame("Frame", "BagBuddy", UIParent)
  7.     frame:SetSize(425, 425)
  8.     frame:SetPoint("CENTER")
  9.  
  10.     -- Making BagBuddy movable
  11.  
  12.     -- I suggest you create a drag frame and redirect the drag event on the that frame to the parent frame
  13.     frame:EnableMouse(true)
  14.     frame:SetClampedToScreen(true)
  15.     frame:SetMovable(true)
  16.     frame:SetUserPlaced(true)
  17.  
  18.     frame.drag = CreateFrame("Frame", "$parentDragFrame", frame)
  19.     frame.drag:SetHeight(22)
  20.     frame.drag:SetPoint("TOPLEFT",60,0)
  21.     frame.drag:SetPoint("TOPRIGHT",-30,0)
  22.     frame.drag:EnableMouse(true)
  23.     frame.drag:RegisterForDrag("LeftButton")
  24.     frame.drag:SetScript("OnDragStart", function(self)
  25.       self:GetParent():StartMoving()
  26.     end)
  27.     frame.drag:SetScript("OnDragStop", function(self)
  28.       self:GetParent():StopMovingOrSizing()
  29.     end)
  30.  
  31.     -- The Body frame of BagBuddy (the border itself)
  32.     frame.body = frame:CreateTexture(nil, "BACKGROUND", nil, -8) --name, strata, inherit, texturelevel
  33.     frame.body:SetAllPoints() --take the size of the parent element
  34.     frame.body:SetTexture("Interface\\BankFrame\\UI-BankFrame")
  35.  
  36.     -- The icon(portrait) texture of BagBuddy
  37.     frame.icon = frame:CreateTexture("BagBuddy_Icon", "BACKGROUND")
  38.     frame.icon:SetSize(60, 60)
  39.     frame.icon:SetPoint("TOPLEFT", 7, -6)
  40.     frame.icon:SetTexture("Interface\\Icons\\INV_Misc_EngGizmos_17")
  41.     SetPortraitToTexture(frame.icon, "Interface\\Icons\\INV_Misc_EngGizmos_17")
  42.  
  43.     -- The title fontstring of BagBuddy.
  44.     frame.title = frame:CreateFontString("BagBuddy_Title", "OVERLAY", "GameFontNormal")
  45.     frame.title:SetPoint("TOP", 0, -18)
  46.     frame.title:SetText("BagBuddy")
  47.  
  48.     -- The close button for BagBuddy.
  49.     frame.close = CreateFrame("Button", "BagBuddy_Close", frame, "UIPanelCloseButton")
  50.     frame.close:SetPoint("TOPRIGHT", -22, -8)
  51.  
  52.     -----------------------
  53.     --BagBuddy Loop Items--
  54.     -----------------------
  55.  
  56.     frame.items = {}
  57.     for idx = 1, 28 do
  58.       local item = CreateFrame("Button", "BagBuddy_Item" .. idx, frame, "SecureActionButtonTemplate")
  59.       item:SetSize(37, 37)
  60.  
  61.       item:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
  62.       item:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress")
  63.       item:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", "ADD")
  64.       do
  65.         local tex = item:GetNormalTexture()
  66.         tex:ClearAllPoints()
  67.         tex:SetPoint("CENTER", 0, -1)
  68.         tex:SetSize(64, 64)
  69.       end
  70.  
  71.       item.icon = item:CreateTexture("$parentIconTexture", "BORDER")
  72.  
  73.       item.count = item:CreateFontString("$parentCount", "BORDER", "NumberFontNormal")
  74.       item.coun:SetPoint("BOTTOMRIGHT", -5, 2)
  75.       item.count:SetJustifyH("RIGHT")
  76.       item.count:Hide()
  77.  
  78.       item.glow = item:CreateTexture("$parentGlow", "OVERLAY")
  79.       item.glow:SetPoint("CENTER")
  80.       item.glow:SetSize(70, 70)
  81.       item.glow:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
  82.       item.glow:SetBlendMode("ADD")
  83.       item.glow:SetAlpha(0.6)
  84.  
  85.       frame.items[idx] = item
  86.  
  87.       if idx == 1 then
  88.           item:SetPoint("TOPLEFT", 40, 200)
  89.       elseif idx == 8 or idx == 15 or idx == 22 then
  90.           item:SetPoint("TOPLEFT", frame.items[idx - 7], "BOTTOMLEFT", 0, -7)
  91.       else
  92.           item:SetPoint("TOPLEFT", frame.items[idx - 1], "TOPRIGHT", 12, 0)
  93.       end
  94.     end

Not sure how your panel should look.

But do a quick test. Is this your panel?

Lua Code:
  1. --setup panel
  2.   do
  3.     local panel = CreateFrame("Frame", "MyConfigPanel", UIParent, "ButtonFrameTemplate")
  4.     --panel:SetFrameStrata("HIGH")
  5.     panel:SetSize(600,600)
  6.     panel:SetPoint("CENTER")
  7.     panel.title = _G["MyConfigPanelTitleText"]
  8.     panel.title:SetText("ButtonFrameTemplate Panel")
  9.   end

If yes you can use the "ButtonFrameTemplate" to create your panel. It will have all the buttons already included.
Yeah i saw that, and i did change that myself as you see in my edited post, however thanks for the drag thing - thats nice.

But still the buttons ain't created. hmm
  Reply With Quote
04-12-13, 06:13 AM   #9
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Please don't quote full posts.

You have "lua errors" enabled right?
Have you seen my texture change? You used "OVERLAY". It may "overlay" all your buttons .
Addtionally check my panel template edit.

It is good practice to use already given Blizzard templates. Especially if you want to copy-cat the BankUI. Normally you don't have to create your panel manually. There are basic templates that wil do this for you.

Btw there is a button template for bank icons aswell. That is: "BankItemButtonGenericTemplate"

So you could change your button to:

Lua Code:
  1. local item = CreateFrame("Button", "BagBuddy_Item" .. idx, frame, "BankItemButtonGenericTemplate, SecureActionButtonTemplate")

First use templates for stuff. If sth is missing or you need changes you can still do that afterwards. You don't have to reprogram templates.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 04-12-13 at 06:21 AM.
  Reply With Quote
04-12-13, 06:23 AM   #10
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Thank you!!! It sort of worked, just have to change a few options as the frame itself got kinda ****ed ^^ But the buttons is now shown as expected!

Also i didn't have LUA Errors enabled till now... OMG :P

Is there any smart AddOn/Tool/w.e to help you get the anchor point of something? Like i keep testing anchor points and then use /reload ingame to see the result?

Last edited by fRodzet : 04-12-13 at 06:35 AM.
  Reply With Quote
04-12-13, 07:40 AM   #11
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Well...you can make inline frame dragable aswell. You listen to DragStop.

Once that fires you calculate the point diffenrence of the parent element to your current frame.

I used this function somewhere. I can be changed to deliver the offset you need for your stuff. But actually I do resize/reloading. You only need a couple of tries to get stuff right and don't need to do it again.
Lua Code:
  1. local calcPoint = function(s)
  2.     if s:GetParent():GetName() ~= "UIParent" then
  3.       local Hx, Hy = s:GetParent():GetCenter()
  4.       local W, H = s:GetParent():GetSize()
  5.       local Ox, Oy = s:GetCenter()
  6.       if(not Ox) then return end
  7.       local scale = s:GetScale()
  8.       Hx, Hy = floor(Hx), floor(Hy)
  9.       Ox, Oy = floor(Ox*scale), floor(Oy*scale)
  10.       local Tx, Ty = (Hx-Ox)*(-1), (Hy-Oy)*(-1)
  11.       s:ClearAllPoints()
  12.       s:SetPoint("CENTER",s:GetParent(),Tx/scale,Ty/scale)
  13.     end
  14.   end
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 04-12-13 at 07:43 AM.
  Reply With Quote
04-12-13, 09:24 AM   #12
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
Originally Posted by fRodzet View Post
Lua Code:
  1. -------------------
  2. --BagBuddy Frames--
  3. -------------------
  4.  
  5.     -- The parent frame of BagBuddy
  6.     local frame = CreateFrame("Frame", "BagBuddy", UIParent)
  7.     frame:SetSize(425, 425)
  8.     frame:SetPoint("CENTER", UIParent, "CENTER")
  9.  
  10.     -- The Body frame of BagBuddy (the border itself)
  11.     frame.body = frame:CreateTexture("BagBuddy_Body", "BORDER")
  12.     frame.body:SetPoint("TOPLEFT")
  13.     frame.body:SetTexture("Interface\\BankFrame\\UI-BankFrame")
  14.    
  15.     -- Making BagBuddy movable
  16.     frame:EnableMouse(true)
  17.     frame:SetMovable(true)
  18.     frame:SetClampedToScreen(true)
  19.     frame:RegisterForDrag("LeftButton")
  20.     frame:SetScript("OnDragStart", frame.StartMoving)
  21.     frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
  22.  
  23.     -- The icon(portrait) texture of BagBuddy
  24.     frame.icon = frame:CreateTexture("BagBuddy_Icon", "BACKGROUND")
  25.     frame.icon:SetSize(60, 60)
  26.     frame.icon:SetPoint("TOPLEFT", 7, -6)
  27.     frame.icon:SetTexture("Interface\\Icons\\INV_Misc_EngGizmos_17")
  28.     SetPortraitToTexture(frame.icon, "Interface\\Icons\\INV_Misc_EngGizmos_17")
  29.  
  30.     -- The title fontstring of BagBuddy.
  31.     frame.title = frame:CreateFontString("BagBuddy_Title", "OVERLAY", "GameFontNormal")
  32.     frame.title:SetPoint("TOP", 0, -18)
  33.     frame.title:SetText("BagBuddy")
  34.  
  35.     -- The close button for BagBuddy.
  36.     frame.close = CreateFrame("Button", "BagBuddy_Close", frame, "UIPanelCloseButton")
  37.     frame.close:SetPoint("TOPRIGHT", -22, -8)
  38.  
  39. -----------------------
  40. --BagBuddy Loop Items--
  41. -----------------------
  42.  
  43. frame.items = {}
  44. for idx = 1, 28 do
  45.     local item = CreateFrame("Button", "BagBuddy_Item" .. idx, frame, "SecureActionButtonTemplate")
  46.     item:SetSize(37, 37)
  47.    
  48.     item:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
  49.     item:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress")
  50.     item:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", "ADD")
  51.     do local tex = item:GetNormalTexture()
  52.         tex:ClearAllPoints()
  53.         tex:SetPoint("CENTER", 0, -1)
  54.         tex:SetSize(64, 64)
  55.     end
  56.    
  57.     item.icon = item:CreateTexture("$parentIconTexture", "BORDER")
  58.    
  59.     item.count = item:CreateFontString("$parentCount", "BORDER", "NumberFontNormal")
  60.     item.coun:SetPoint("BOTTOMRIGHT", -5, 2)
  61.     item.count:SetJustifyH("RIGHT")
  62.     item.count:Hide()
  63.    
  64.     item.glow = item:CreateTexture("$parentGlow", "OVERLAY")
  65.     item.glow:SetPoint("CENTER")
  66.     item.glow:SetSize(70, 70)
  67.     item.glow:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
  68.     item.glow:SetBlendMode("ADD")
  69.     item.glow:SetAlpha(0.6)
  70.    
  71.     frame.items[idx] = item
  72.    
  73.     if idx == 1 then
  74.         item:SetPoint("TOPLEFT", 40, -73)
  75.     elseif idx == 8 or idx == 15 or idx == 22 then
  76.         item:SetPoint("TOPLEFT", frame.items[idx - 7], "BOTTOMLEFT", 0, -7)
  77.     else
  78.         item:SetPoint("TOPLEFT", frame.items[idx - 1], "TOPRIGHT", 12, 0)
  79.     end
  80. end
Line 60:
Code:
item.coun:SetPoint("BOTTOMRIGHT", -5, 2)


Originally Posted by fRodzet View Post
$parent works for lua aswell? or is that XML only?
$parent works for any function in the Widget API and CreateFrame() that can reference a frame by its name. Just think of Lua as a backend for the XML. Using the right functions, you can just plug in the values directly.



More information on these functions is available in the Widget API page on WoWPedia. Note CreateFrame() is in the WoW API section.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help Creating Textures, Frames, etc in Lua. And some questions!

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