Thanks Phanks.
I got a follow up question on that part that I need to get answered for my current project.
I have a model frame. Each model lives on the same canvas. The canvas can hold a lot of models (200+) in extreme cases.
How should I define functions that work on my model frame? Should they be defined on the canvas or can I add them to each model.
Currently my implementation is like this:
Lua Code:
--canvas
local canvas = CreateFrame("Frame", nil, UIParent)
canvas.models = {}
function canvas:ModelOnMouseDown(model,...)
print(model.name,...)
model:Reset()
end
function canvas:ModelOnMouseUp(model,...)
print(model.name,...)
end
function canvas:CreateModel(id)
local m = CreateFrame("PlayerModel", nil, self)
m:EnableMouse(true)
m.id = id
m.name = "model"..id
function m:Reset()
--stuff to reset model data
self:PortraitZoom(0)
print(self.name,"reseting values")
end
m:SetScript("OnMouseDown", self.ModelOnMouseDown)
m:SetScript("OnMouseUp", self.ModelOnMouseUp)
return m
end
for i=1, 50 do
canvas.models[i] = canvas:CreateModel(i)
end
My question is about model specific functions like m:Reset().
Should they be defined on the canvas aswell?
Currently I would define model specific funtions directly on the model. But I could create them on the canvas instead.
So the above would change to sth like this
Lua Code:
--canvas
local canvas = CreateFrame("Frame", nil, UIParent)
canvas.models = {}
function canvas:ModelOnMouseDown(model,...)
print(model.name,...)
self:ResetModel(model,...) --not sure if self is available in this context otherwise model:GetParent()
end
function canvas:ResetModel(model,...)
--stuff to reset model data
model:PortraitZoom(0)
print(model.name,"reseting values")
end
function canvas:ModelOnMouseUp(model,...)
print(model.name,...)
end
function canvas:CreateModel(id)
local m = CreateFrame("PlayerModel", nil, self)
m:EnableMouse(true)
m.id = id
m.name = "model"..id
m:SetScript("OnMouseDown", self.ModelOnMouseDown)
m:SetScript("OnMouseUp", self.ModelOnMouseUp)
return m
end
for i=1, 50 do
canvas.models[i] = canvas:CreateModel(i)
end
Which version is better and why?