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:
-------------------
--BagBuddy Frames--
-------------------
-- The parent frame to add textures and fontstrings to
local frame = CreateFrame("Frame", "BagBuddy", UIParent)
frame:SetWidth(425)
frame:SetHeight(425)
frame:SetPoint("CENTER", UIParent, "CENTER")
-- The body texture of BagBuddy
frame.skeleton = frame:CreateTexture("BagBuddy_Skeleton", "BORDER")
frame.skeleton:SetPoint("TOPLEFT")
frame.skeleton:SetTexture("Interface\\BankFrame\\UI-BankFrame")
-- The portrait texture of BagBuddy
frame.icon = frame:CreateTexture("BagBuddy_Icon", "BACKGROUND")
frame.icon:SetWidth(60)
frame.icon:SetHeight(60)
frame.icon:SetPoint("TOPLEFT", 7, -6)
frame.icon:SetTexture("Interface\\Icons\\INV_Misc_EngGizmos_17")
SetPortraitToTexture(frame.icon, "Interface\\Icons\\INV_Misc_EngGizmos_17")
-- The title fontstring of BagBuddy
frame.title = frame:CreateFontString("BagBuddy_Title", "OVERLAY", "GameFontNormal")
frame.title:SetPoint("TOP", 0, -18)
frame.title:SetText("BagBuddy")
-- The button that allows BagBuddy to be hidden
frame.close = CreateFrame("Button", "BagBuddy_Close", frame, "UIPanelCloseButton")
frame.close:SetPoint("TOPRIGHT", -22, -8)
----------------------
--BagBuddy Functions--
----------------------
function BagBuddy_OnLoad(self)
end
function BagBuddy_MakeMovable(self, motion)
self:EnableMouse(true)
self:SetMovable(true)
self:SetClampedToScreen(true)
self:RegisterForDrag("LeftButton")
self:SetScript("OnDragStart", self.StartMoving)
self:SetScript("OnDragStop", self.StopMovingOrSizing)
end
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:
<Button name="BagBuddyItemTemplate" inherits="SecureActionButtonTemplate" virtual="true">
<Size>
<AbsDimension x="37" y="37"/>
</Size>
<Layers>
<Layer level="BORDER">
<Texture name="$parentIconTexture" parentKey="icon"/>
<FontString name="$parentCount" parentKey="count" inherits="NumberFontNormal" justifyH="RIGHT" hidden="true">
<Anchors>
<Anchor point="BOTTOMRIGHT">
<Offset>
<AbsDimension x="-5" y="2"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
</Layer>
<Layer level="OVERLAY">
<Texture name="$parentGlow" parentKey="glow" alphaMode="ADD" file="Interface\Buttons\UI-ActionButton-Border">
<Size x="70" y="70"/>
<Anchors>
<Anchor point="CENTER"/>
</Anchors>
<Color r="1.0" g="1.0" b="1.0" a="0.6"/>
</Texture>
</Layer>
</Layers>
<Attributes>
<Attribute name="type2" type="string" value="item"/>
</Attributes>
<Scripts>
<OnEnter function="BagBuddy_Button_OnEnter"/>
<OnLeave function="BagBuddy_Button_OnLeave"/>
</Scripts>
<NormalTexture name="$parentNormalTexture" file="Interface\Buttons\UI-Quickslot2">
<Size>
<AbsDimension x="64" y="64"/>
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset>
<AbsDimension x="0" y="-1"/>
</Offset>
</Anchor>
</Anchors>
</NormalTexture>
<PushedTexture file="Interface\Buttons\UI-Quickslot-Depress"/>
<HighlightTexture file="Interface\Buttons\ButtonHilight-Square" alphaMode="ADD"/>
</Button>
Using the above template i would add each button to the frame like this:
Lua Code:
function BagBuddy_OnLoad(self)
self.items = {}
for idx = 1, 28 do
local item = CreateFrame("Button", "BagBuddy_Item" .. idx, self, "BagBuddyItemTemplate")
self.items[idx] = item
if idx == 1 then
item:SetPoint("TOPLEFT", 40, -73)
elseif idx == 8 or idx == 15 or idx == 22 then
item:SetPoint("TOPLEFT", self.items[idx - 7], "BOTTOMLEFT", 0, -7)
else
item:SetPoint("TOPLEFT", self.items[idx - 1], "TOPRIGHT", 12, 0)
end
end
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