The way you have your OnClick handler set up
PredatorArchy.List[raceName].raceName will always return the last entry because
raceName does not get changed outside of that loop.
A quick fix would be to change line 50 to:
Code:
local raceName, raceTex = GetArchaeologyRaceInfo(i)
That would also allow you to remove line 3 (
local i, raceName, raceTex).
To really just clean it up in general I would suggest something more along the lines of:
lua Code:
PredatorArchy:RegisterEvent('PLAYER_ENTERING_WORLD')
PredatorArchy:SetScript('OnEvent', function(self)
local _, _, hasArch = GetProfessions()
self:UnregisterAllEvents()
if not hasArch then
self:SetScript('OnEvent', nil)
return
end
local numArchRaces = GetNumArchaeologyRaces()
-- Setting up the main frame
self:SetBackdrop( {
bgFile = solidTex,
edgeFile = borderTex,
edgeSize = 8,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
} )
self:SetBackdropColor(0, 0, 0, 0.7)
self:SetWidth(300)
self:SetHeight(numArchRaces * 26 + 40)
self:EnableMouse(true)
self:RegisterForDrag('LeftButton', 'RightButton')
self:SetMovable(true)
self:SetUserPlaced(true)
self:SetScript('OnDragStart', function(self)
if not IsAltKeyDown() then return end
self:StartMoving()
end)
self:SetScript('OnDragStop', self.StopMovingOrSizing)
self:SetPoint('CENTER')
local skillRank = CreateFrame('StatusBar', nil, self)
skillRank:SetPoint('TOPLEFT', 15, -10)
skillRank:SetPoint('BOTTOMRIGHT', self, 'TOPRIGHT', -15, -30)
skillRank:SetStatusBarTexture(barTex)
skillRank:SetStatusBarColor(0, 0.7, 0)
skillRank:RegisterEvent('ARTIFACT_COMPLETE')
skillRank:SetScript('OnEvent', function()
core.UpdateSkill(true)
core.UpdateArtifacts()
end)
self.SkillRank = skillRank
local back = skillRank:CreateTexture(nil, 'BACKGROUND')
back:SetAllPoints()
back:SetTexture(barTex)
back:SetVertexColor(0.3, 0.3, 0.3, 1)
skillRank.back = back
local text = lib.CreateFontObject(skillRank, 14, font)
text:SetPoint('CENTER', 0, 1)
text:SetText('INIT')
text:SetJustifyH('CENTER')
skillRank.text = text
local function OnClick(self)
lib.debugging(self.raceName)
-- core.SolveArtifact(self.raceName)
end
local list = { }
self.List = list
for index = 1, numArchRaces do
local name, texture = GetArchaeologyRaceInfo(index)
local icon = self:CreateTexture(nil, 'OVERLAY')
icon:SetSize(36, 36)
icon:SetTexture(texture)
icon:SetPoint('TOPLEFT', skillRank, 'TOPLEFT', 0, index * -25)
local artifact = CreateFrame('Button', nil, self)
artifact:SetSize(21, 21)
artifact:SetPoint('RIGHT', self, 'RIGHT', -15, 0)
artifact:SetPoint('TOP', icon, 'TOP', 0, -1)
artifact:SetScript('OnClick', OnClick)
artifact.raceName = name
local progress = CreateFrame('StatusBar', nil, self)
progress:SetStatusBarTexture(barTex)
progress:SetPoint('TOPLEFT', icon, 'TOPRIGHT', -10, -1)
progress:SetPoint('BOTTOM', icon, 'TOP', 0, -22)
progress:SetPoint('RIGHT', artifact, 'LEFT', -10, 0)
progress:SetMinMaxValues(0, 1)
progress:SetValue(0)
local back = progress:CreateTexture(nil, 'BACKGROUND')
back:SetAllPoints()
back:SetTexture(barTex)
back:SetVertexColor(0.3, 0.3, 0.3, 1)
progress.back = back
local text = lib.CreateFontObject(progress, 14, font)
text:SetPoint('LEFT', 10, 1)
text:SetText('INIT')
progress.text = text
list[name] = {
raceName = name,
raceIcon = icon,
artifactIcon = artifact,
progress = progress
}
end
self:RegisterEvent('CHAT_MSG_CURRENCY')
self:SetScript('OnEvent', core.UpdateArtifacts)
core.UpdateSkill(true)
core.UpdateArtifacts()
end)