When you call ADDON.SpellRow:CreateRow(parent, index, spell) the self inside that function refers to the ADDON.SpellRow table. You're saving each new row as ADDON.SpellRow.frame and overwriting the previous reference. Then funtion returns ADDON.SpellRow (self).
ie.
row[1] will = ADDON.SpellRow
row[2] will = ADDON.SpellRow
row[3] will = ADDON.SpellRow
...
and ADDON.SpellRow.frame will always contain the last row created.
The functions should look a bit more like the following so they can identify which row they should act on.
Lua Code:
function ADDON.SpellRow:CreateRow(parent, index, spell)
-- create a distinct new local reference to a new frame each time
local frame = CreateFrame('BUTTON', 'spellIdRow' .. index, parent)
frame:SetSize(ADDON:Scale(290), ADDON:Scale(16))
frame.background = frame:CreateTexture(nil, 'BACKGROUND')
frame.background:SetAllPoints(frame)
frame.background:SetTexture([[Interface\AddOns\AstralAnalytics\Media\Texture\Flat.tga]])
frame.background:SetAlpha(.6)
frame.background:Show()
frame.name = frame:CreateFontString(nil, 'OVERLAY', 'GameFontNormal')
frame.name:SetPoint('LEFT', frame, 'LEFT', 4, -1)
frame.name:SetTextColor(1, 1, 1)
ADDON.SpellRow:SetSpell(frame, spell)
return frame
end
function ADDON.SpellRow:SetSpell(self, spell)
local name, rank, icon = GetSpellInfo(spell)
self.name:SetText(name .. " (" .. spell .. ")")
self:Show()
end
function ADDON.SpellRow:ClearSpell(self)
self.name:SetText('')
self:Hide()
end
local function CreateSpellList()
for key, value in pairs(row) do
ADDON.Print("Hiding")
ADDON.SpellRow:ClearSpell(value)
end
row[1] = ADDON.SpellRow:CreateRow(listScrollFrame, 1, 1)
row[1]:SetPoint('TOPLEFT', parentListContainer, 'TOPLEFT', 25, -10)
local currentRow = 1
for spellId, _ in pairs(AstralAnalytics.spellIds[currentDropdownValue]) do
if row[currentRow] == nil then
ADDON.Print('new row for ' .. currentRow .. ' with id ' .. spellId)
row[currentRow] = ADDON.SpellRow:CreateRow(listScrollFrame, currentRow, spellId)
row[currentRow]:SetPoint('TOPLEFT', 'spellIdRow' .. currentRow-1, 'BOTTOMLEFT', 0, 0)
else
print('setting existing row for ' .. currentRow .. ' with id ' .. spellId)
ADDON.SpellRow:SetSpell(row[currentRow], spellId)
row[currentRow]:Show()
end
currentRow = currentRow + 1
end
ADDON.Print(table.getn(row))
end
I didn't change all the code because the CreateSpellList() shouldn't work this way (continually replacing the entries in row[] and losing the old ones) so this is not really a fix, just an explanation as to why you weren't seeing the rows refresh as you expected.