View Single Post
04-14-11, 03:17 PM   #2
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
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:
  1. PredatorArchy:RegisterEvent('PLAYER_ENTERING_WORLD')
  2. PredatorArchy:SetScript('OnEvent', function(self)
  3.     local _, _, hasArch = GetProfessions()
  4.     self:UnregisterAllEvents()
  5.     if not hasArch then
  6.         self:SetScript('OnEvent', nil)
  7.         return
  8.     end
  9.     local numArchRaces = GetNumArchaeologyRaces()
  10.  
  11.     -- Setting up the main frame
  12.     self:SetBackdrop( {
  13.         bgFile = solidTex,
  14.         edgeFile = borderTex,
  15.         edgeSize = 8,
  16.         insets = { left = 4, right = 4, top = 4, bottom = 4 }
  17.     } )
  18.     self:SetBackdropColor(0, 0, 0, 0.7)
  19.     self:SetWidth(300)
  20.     self:SetHeight(numArchRaces * 26 + 40)
  21.     self:EnableMouse(true)
  22.     self:RegisterForDrag('LeftButton', 'RightButton')
  23.     self:SetMovable(true)
  24.     self:SetUserPlaced(true)
  25.     self:SetScript('OnDragStart', function(self)
  26.         if not IsAltKeyDown() then return end
  27.         self:StartMoving()
  28.     end)
  29.     self:SetScript('OnDragStop', self.StopMovingOrSizing)
  30.     self:SetPoint('CENTER')
  31.  
  32.     local skillRank = CreateFrame('StatusBar', nil, self)
  33.     skillRank:SetPoint('TOPLEFT', 15, -10)
  34.     skillRank:SetPoint('BOTTOMRIGHT', self, 'TOPRIGHT', -15, -30)
  35.     skillRank:SetStatusBarTexture(barTex)
  36.     skillRank:SetStatusBarColor(0, 0.7, 0)
  37.     skillRank:RegisterEvent('ARTIFACT_COMPLETE')
  38.     skillRank:SetScript('OnEvent', function()
  39.         core.UpdateSkill(true)
  40.         core.UpdateArtifacts()
  41.     end)
  42.     self.SkillRank = skillRank
  43.  
  44.     local back = skillRank:CreateTexture(nil, 'BACKGROUND')
  45.     back:SetAllPoints()
  46.     back:SetTexture(barTex)
  47.     back:SetVertexColor(0.3, 0.3, 0.3, 1)
  48.     skillRank.back = back
  49.  
  50.     local text = lib.CreateFontObject(skillRank, 14, font)
  51.     text:SetPoint('CENTER', 0, 1)
  52.     text:SetText('INIT')
  53.     text:SetJustifyH('CENTER')
  54.     skillRank.text = text
  55.  
  56.     local function OnClick(self)
  57.         lib.debugging(self.raceName)
  58.         -- core.SolveArtifact(self.raceName)
  59.     end
  60.  
  61.     local list = { }
  62.     self.List = list
  63.     for index = 1, numArchRaces do
  64.         local name, texture = GetArchaeologyRaceInfo(index)
  65.  
  66.         local icon = self:CreateTexture(nil, 'OVERLAY')
  67.         icon:SetSize(36, 36)
  68.         icon:SetTexture(texture)
  69.         icon:SetPoint('TOPLEFT', skillRank, 'TOPLEFT', 0, index * -25)
  70.  
  71.         local artifact = CreateFrame('Button', nil, self)
  72.         artifact:SetSize(21, 21)
  73.         artifact:SetPoint('RIGHT', self, 'RIGHT', -15, 0)
  74.         artifact:SetPoint('TOP', icon, 'TOP', 0, -1)
  75.         artifact:SetScript('OnClick', OnClick)
  76.         artifact.raceName = name
  77.  
  78.         local progress = CreateFrame('StatusBar', nil, self)
  79.         progress:SetStatusBarTexture(barTex)
  80.         progress:SetPoint('TOPLEFT', icon, 'TOPRIGHT', -10, -1)
  81.         progress:SetPoint('BOTTOM', icon, 'TOP', 0, -22)
  82.         progress:SetPoint('RIGHT', artifact, 'LEFT', -10, 0)
  83.         progress:SetMinMaxValues(0, 1)
  84.         progress:SetValue(0)
  85.  
  86.         local back = progress:CreateTexture(nil, 'BACKGROUND')
  87.         back:SetAllPoints()
  88.         back:SetTexture(barTex)
  89.         back:SetVertexColor(0.3, 0.3, 0.3, 1)
  90.         progress.back = back
  91.  
  92.         local text = lib.CreateFontObject(progress, 14, font)
  93.         text:SetPoint('LEFT', 10, 1)
  94.         text:SetText('INIT')
  95.         progress.text = text
  96.  
  97.         list[name] = {
  98.             raceName = name,
  99.             raceIcon = icon,
  100.             artifactIcon = artifact,
  101.             progress = progress
  102.         }
  103.     end
  104.  
  105.     self:RegisterEvent('CHAT_MSG_CURRENCY')
  106.     self:SetScript('OnEvent', core.UpdateArtifacts)
  107.  
  108.     core.UpdateSkill(true)
  109.     core.UpdateArtifacts()
  110. end)
  Reply With Quote