Originally Posted by Grimsin
even though frame is local it can be used through out all my functions if i put those first two in a function?
also just noticed you only use create? not createframe?
|
The "Create" should be "CreateFrame" I just goofed on that.
As for all the other stuff. Its object oriented. You make a generic function that creates your object and have generic functions that work on those object. The idea is to only code specifically to what the object is in general but not to any one particular member of the set.
So you do (just a rough example):
Code:
flocal function ApplyNameColoring(self)
self.nameText:SetTextColor(1, 1, 1, 1)
end
local function PartyStyle1NameTextEvents(self)
if UnitExists(self.unit) == 1 then
self.nameText:SetFormattedText("%s", UnitName(self.unit))
end
self:ApplyNameColoring()
end
function GrimUI.CreatePartyFrame(id)
local frame = CreateFrame('Button', 'GrimUIPartyFrame' .. id, 'SecureUnitButtonTemplate')
frame.healthBar = CreateFrame('StatusBar', nil, frame)
frame.manaBar = CreateFrame('StatusBar', nil, frame)
frame.nameText = CreateFontString(nil, 'ARTWORK')
frame.pedestal = CreateFrame('Frame', nil, frame)
frame.unit = 'party' .. id
frame.ApplyNameColoring = ApplyNameColoring
return frame
end
for id = 1, 4 do
GrimUI.CreatePartyFrame(id)
end
Each party frame is created and is completely separate from the other. The only thing they share is their methods. When you do GrimUIPartyButton1:ApplyNameColoring() the first argument that is passed is the frame for GrimUIPartyFrame1 and in the function for ApplyNameColoring you see that the first argument is named self. So when you do self.unit it will be the value that matches the party frame you called it with.
If you want to access the pedestal frame for party member 3 you would do GrimUIPartyFrame3.pedestal. Or if you wanted to perform roughly the same operation on all four party frame pedestals then:
Code:
for id = 1, 4 do
local frame = _G['GrimUIPartyFrame' .. id]
local pedestal = frame.pedestal
pedestal:ClearAllPoints()
pedestal:SetPoint('BOTTOMLEFT', frame.healthBar, 'BOTTOMRIGHT', 3, 0)
pedestal:SetPoint('BOTTOMRIGHT', frame.manaBar, 'BOTTOMLEFT', -3, 0)
pedestal:SetHeight(20)
end