WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How to create a Template using lua? (https://www.wowinterface.com/forums/showthread.php?t=46184)

fRodzet 04-06-13 04:40 AM

How to create a Template using lua?
 
Hi there guys.

Pretty much every guide i read and learned includes XML, however nowadays everyone prefers/recommends using lua only.

Creating a Template i XML is rather simple, however i would like to learn how to create one in lua.. I searched the web abit but couldn't seem to find any guides on how to do so. Can anyone give me an example of a Template made with lua.. Ty :)

Resike 04-06-13 05:05 AM

Quote:

Originally Posted by fRodzet (Post 275868)
Hi there guys.

Pretty much every guide i read and learned includes XML, however nowadays everyone prefers/recommends using lua only.

Creating a Template i XML is rather simple, however i would like to learn how to create one in lua.. I searched the web abit but couldn't seem to find any guides on how to do so. Can anyone give me an example of a Template made with lua.. Ty :)

I dont think you can do it atm.

fRodzet 04-06-13 05:19 AM

Quote:

Originally Posted by Resike (Post 275869)
I dont think you can do it atm.

So templates is XML only? :)

Well it was worth the try.. then imma stick to creating frames etc in lua and keep the xml file as low as possible by only creating templates in xml.

Resike 04-06-13 05:27 AM

Quote:

Originally Posted by fRodzet (Post 275872)
So templates is XML only? :)

Well it was worth the try.. then imma stick to creating frames etc in lua and keep the xml file as low as possible by only creating templates in xml.

Also you have to create the inhertited frame/button which points to the template in xml too.

fRodzet 04-06-13 05:31 AM

Quote:

Originally Posted by Resike (Post 275873)
Also you have to create the inhertited frame/button which points to the template in xml too.

True that is! :)

Creating Templates in XML is easy anyways, but for longer codes i think XML gets really messy and adding comments (<!-- xxx -->) in XML doesn't seem to make it more readable to me.

Resike 04-06-13 05:38 AM

Quote:

Originally Posted by fRodzet (Post 275874)
True that is! :)

Creating Templates in XML is easy anyways, but for longer codes i think XML gets really messy and adding comments (<!-- xxx -->) in XML doesn't seem to make it more readable to me.

True that, i recently formatted a 4000+ line xml file, was fun, but at the end i could do it with closed eyes too. Some addons even use 14000-15000+ line xml codes too.

Ailae 04-06-13 05:50 AM

Couldn't you create a function that creates the frame and then call on that function every time you create such a frame?

Lua Code:
  1. -- Creates an ordinary frame, just more awesome
  2. function CreateAwesomeFrame(name)
  3.     local f = CreateFrame("Frame", name, UIParent)
  4.     f:SetSize(128, 128) -- this is the really awesome bit
  5.     f:SetBackdrop({
  6.         bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  7.         insets = {top = 0, left = 0, bottom = 0, right = 0},
  8.     })
  9.     f:SetBackdropColor(1, 1, 1, 0)
  10.     f:SetPoint("CENTER")
  11.    
  12.     return f
  13. end
  14.  
  15. local AwesomeFrame = CreateAwesomeFrame()

Resike 04-06-13 06:03 AM

Quote:

Originally Posted by Ailae (Post 275876)
Couldn't you create a function that creates the frame and then call on that function every time you create such a frame?

Lua Code:
  1. -- Creates an ordinary frame, just more awesome
  2. function CreateAwesomeFrame(name)
  3.     local f = CreateFrame("Frame", name, UIParent)
  4.     f:SetSize(128, 128) -- this is the really awesome bit
  5.     f:SetBackdrop({
  6.         bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  7.         insets = {top = 0, left = 0, bottom = 0, right = 0},
  8.     })
  9.     f:SetBackdropColor(1, 1, 1, 0)
  10.     f:SetPoint("CENTER")
  11.    
  12.     return f
  13. end
  14.  
  15. local AwesomeFrame = CreateAwesomeFrame()

Intresting, but i'm not sure it would work with all UI elements.

fRodzet 04-06-13 06:22 AM

Quote:

Originally Posted by Resike (Post 275875)
True that, i recently formatted a 4000+ line xml file, was fun, but at the end i could do it with closed eyes too. Some addons even use 14000-15000+ line xml codes too.

Chill dude! Did your eyes pop out?

fRodzet 04-06-13 06:24 AM

Quote:

Originally Posted by Ailae (Post 275876)
Couldn't you create a function that creates the frame and then call on that function every time you create such a frame?

Lua Code:
  1. -- Creates an ordinary frame, just more awesome
  2. function CreateAwesomeFrame(name)
  3.     local f = CreateFrame("Frame", name, UIParent)
  4.     f:SetSize(128, 128) -- this is the really awesome bit
  5.     f:SetBackdrop({
  6.         bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  7.         insets = {top = 0, left = 0, bottom = 0, right = 0},
  8.     })
  9.     f:SetBackdropColor(1, 1, 1, 0)
  10.     f:SetPoint("CENTER")
  11.    
  12.     return f
  13. end
  14.  
  15. local AwesomeFrame = CreateAwesomeFrame()

Imma try that when i get home! :)

Ill tell you if it works :)

Seerah 04-06-13 12:48 PM

Quote:

Originally Posted by Ailae (Post 275876)
Couldn't you create a function that creates the frame and then call on that function every time you create such a frame?

Yes, we call that a frame factory or a factory function. You can see an example of its usage with my sStats addon. The core sStats addon has the factory function, while the display modules use it to create their frames.

However, iirc, if you want to create secure frames/buttons you need to use XML.

Ailae 04-06-13 01:57 PM

Quote:

Originally Posted by Seerah (Post 275900)
Yes, we call that a frame factory or a factory function. You can see an example of its usage with my sStats addon. The core sStats addon has the factory function, while the display modules use it to create their frames.

However, iirc, if you want to create secure frames/buttons you need to use XML.

Yeah, I too use them just like that. I find it much easier then mucking about with XML-files. :)

I'm fairly sure you don't even need to use XML for secure stuff either.

Rilgamon 04-06-13 02:01 PM

XML is not required for secure buttons/frames. You can use templates (which are xml).
http://www.wowpedia.org/SecureActionButtonTemplate

Phanx 04-06-13 06:17 PM

1 Attachment(s)
The only time you need to use XML is if you are creating secure templates (virtual frames), and the only time you need to do that is if you are working with the secure header system -- for example, setting up a secure header for party frames where each unit frame will include an attached child unit frame for the party member's pet. See attached awesome MSPaint drawing for a better explanation.

Resike 04-07-13 10:00 AM

Quote:

Originally Posted by Phanx (Post 275923)
The only time you need to use XML is if you are creating secure templates (virtual frames), and the only time you need to do that is if you are working with the secure header system -- for example, setting up a secure header for party frames where each unit frame will include an attached child unit frame for the party member's pet. See attached awesome MSPaint drawing for a better explanation.

And how can you import blizzard templates by only using lua?

Dridzt 04-07-13 12:21 PM

Quote:

Originally Posted by Resike (Post 275954)
And how can you import blizzard templates by only using lua?

You use the 'inherit' parameter of CreateFrame("frameType"[, "frameName"[, parentFrame[, "inheritsFrame"[, id]]]])

asett 09-23-13 07:50 PM

Template Named: "MyCloseButtonTemplate"
In Lua:
Code:

NoTemplate = CreateFrame
CreateFrame = function(arg1,arg2,arg3,arg4,...)
if arg4 == "MyCloseButtonTemplate" then
        local x = NoTemplate(arg1,arg2,arg3,nil,...)
        x:SetScript("OnClick", function(self) self:GetParent():Hide() end)
        x:SetNormalTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Up")
        x:SetPushedTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Down")
        x:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight")
        x:SetSize(32,32)
        x:SetFrameLevel(50);
        return x
else
return NoTemplate(arg1,arg2,arg3,arg4,...)
end
end

in XML

Code:

<Button name="MyCloseButtonTemplate" virtual="true">
                <Size>
                        <AbsDimension x="32" y="32"/>
                </Size>
                <Scripts>
                        <OnClick>
                                HideUIPanel(this:GetParent());
                        </OnClick>
                </Scripts>
                <NormalTexture file="Interface\Buttons\UI-Panel-MinimizeButton-Up"/>
                <PushedTexture file="Interface\Buttons\UI-Panel-MinimizeButton-Down"/>
                <HighlightTexture file="Interface\Buttons\UI-Panel-MinimizeButton-Highlight" alphaMode="ADD"/>
 </Button>


zork 09-24-13 04:23 AM

Nifty. Are you sure that this is taint-secure?

Phanx 09-24-13 04:51 PM

It overwrites the global CreateFrame function with an insecure function, so it will definitely cause taint. I'd imagine this would cause major problems with the default raid frames, and probably any addons that use group headers, when someone joins your group in combat, for example.

There's not really any reason to fake a named template like that anyway, even if it could be done securely. Just write a standard factory function, as shown earlier in the thread.

asett 09-24-13 06:53 PM

Quote:

Originally Posted by Phanx (Post 285075)
There's not really any reason to fake a named template like that anyway, even if it could be done securely. Just write a standard factory function, as shown earlier in the thread.

Agree.
Templates are virtual xml frames and inheriting those frames is just copying their properties and scripts to your frame.
I am using my own function to create frames that allows me to customize my frames just like inheriting xml templates and "templates" are additional lua commands to the newly created frame. When you create "SimpleHTML" frame, you can even specify to automatically add font:

Lua Code:
  1. BuildFrame = function(Frame, Name, parent, xmlVirtualFrame, id, ...)
  2. local frame = CreateFrame(Frame, Name, parent, xmlVirtualFrame, id)
  3.  
  4. if Name == "SimpleHTML" then
  5.     frame:SetFont("Fonts\\FRIZQT__.TTF", 12)
  6. end
  7.  
  8. if tContains({...}, "MyMovingBarTemplate") then -- here you specify your own template
  9. frame:SetSize(self:GetParent():GetWidth(), 15) -- commands to edit your frame, I want to create template of moving bars for my frames
  10. frame:SetPoint("TOPLEFT", self:GetParent(), "TOPLEFT",0,0)
  11. frame:EnableMouse()
  12. frame:RegisterForDrag("LeftButton","RightButton")
  13. frame:SetScript("OnDragStart", function(self) self:GetParent():SetMovable();self:GetParent():StartMoving(); end)
  14. frame:SetScript("OnDragStop", function(self)  self:GetParent():StopMovingOrSizing(); end)
  15. end
  16. if tContains({...}, "MyCloseButtonTemplate") then
  17. -- another commands to edit a frame
  18. end
  19. return frame;
  20. end

I am beginner in lua and xml and I like this more than templates in xml. :(
You can inherit more than just one template. :o


All times are GMT -6. The time now is 05:37 AM.

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