View Single Post
10-15-21, 08:59 AM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
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:
  1. function ADDON.SpellRow:CreateRow(parent, index, spell)
  2.   -- create a distinct new local reference to a new frame each time  
  3.     local frame = CreateFrame('BUTTON', 'spellIdRow' .. index, parent)
  4.     frame:SetSize(ADDON:Scale(290), ADDON:Scale(16))
  5.  
  6.     frame.background = frame:CreateTexture(nil, 'BACKGROUND')
  7.     frame.background:SetAllPoints(frame)
  8.     frame.background:SetTexture([[Interface\AddOns\AstralAnalytics\Media\Texture\Flat.tga]])
  9.     frame.background:SetAlpha(.6)
  10.     frame.background:Show()
  11.  
  12.     frame.name = frame:CreateFontString(nil, 'OVERLAY', 'GameFontNormal')
  13.     frame.name:SetPoint('LEFT', frame, 'LEFT', 4, -1)
  14.     frame.name:SetTextColor(1, 1, 1)
  15.     ADDON.SpellRow:SetSpell(frame, spell)
  16.     return frame
  17. end
  18.  
  19. function ADDON.SpellRow:SetSpell(self, spell)
  20.     local name, rank, icon = GetSpellInfo(spell)
  21.     self.name:SetText(name .. " (" .. spell .. ")")
  22.     self:Show()
  23. end
  24.  
  25. function ADDON.SpellRow:ClearSpell(self)
  26.     self.name:SetText('')
  27.     self:Hide()
  28. end
  29.  
  30. local function CreateSpellList()
  31.     for key, value in pairs(row) do
  32.         ADDON.Print("Hiding")
  33.         ADDON.SpellRow:ClearSpell(value)
  34.     end
  35.  
  36.     row[1] = ADDON.SpellRow:CreateRow(listScrollFrame, 1, 1)
  37.     row[1]:SetPoint('TOPLEFT', parentListContainer, 'TOPLEFT', 25, -10)
  38.     local currentRow = 1
  39.     for spellId, _ in pairs(AstralAnalytics.spellIds[currentDropdownValue]) do
  40.         if row[currentRow] == nil then
  41.             ADDON.Print('new row for ' .. currentRow .. ' with id ' .. spellId)
  42.             row[currentRow] = ADDON.SpellRow:CreateRow(listScrollFrame, currentRow, spellId)
  43.             row[currentRow]:SetPoint('TOPLEFT', 'spellIdRow' .. currentRow-1, 'BOTTOMLEFT', 0, 0)
  44.         else
  45.             print('setting existing row for ' .. currentRow .. ' with id ' .. spellId)
  46.             ADDON.SpellRow:SetSpell(row[currentRow], spellId)
  47.             row[currentRow]:Show()
  48.         end
  49.         currentRow = currentRow + 1
  50.     end
  51.     ADDON.Print(table.getn(row))
  52. 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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 10-15-21 at 10:04 AM.
  Reply With Quote