Quantcast WoWInterface - View Single Post - Problem setting XML Spell Button Attributes
View Single Post
05-20-18, 06:01 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,144
Resolved Problem

Whew .. finally .. I suspect I messed up a validation step somewhere as I can't see anything specific being different from before rofl.

This is generated when a map button is clicked
Lua Code:
  1. --[[ Generate list of spells available for the requested map ]]
  2. function addonData:GenerateMapSpellList(mapID, mapButton)
  3.     local portalOffsetIdx = 1
  4.     local teleportOffsetIdx = 1
  5.     local factionGroup, factionName = UnitFactionGroup("player")
  6.     mapButton.Spells = {}
  7.     for spellID,spellData in pairs(addonData.Spells) do
  8.         local rightMap = spellData.map == addonData.activePage
  9.         local rightFaction = spellData.faction == factionName
  10.         local neutralFaction = spellData.faction == "Neutral"
  11.         local isPortal = spellData.isPortal
  12.         if rightMap and (rightFaction or neutralFaction) then
  13.             local index = teleportOffsetIdx
  14.             if isPortal then
  15.                 index = portalOffsetIdx
  16.             end
  17.             mapButton.Spells = mapButton.Spells or {}
  18.             mapButton.Spells[spellID] = index
  19.             if isPortal then
  20.                 portalOffsetIdx = portalOffsetIdx + 1
  21.             else
  22.                 teleportOffsetIdx = teleportOffsetIdx + 1
  23.             end            
  24.         end
  25.     end    
  26. end

This is called when the selected button frame is being displayed ( it is actually one frame with the button attribute values changing and the unused buttons being hidden as required)
Lua Code:
  1. --[[ Set the Buttons up with what is available for the maps ]]
  2. local function XMP_SetMapSpells()
  3.     local teleportIdx = 0
  4.     local portalIdx = 5
  5.     local usedButtons = {}    
  6.    
  7.     for spellID, buttonOffset in pairs(addonData.activeButton.Spells) do
  8.         local isPortal = addonData.Spells[spellID].isPortal
  9.         local index = teleportIdx + buttonOffset
  10.         if isPortal then index = portalIdx + buttonOffset end
  11.         local spellName,textureID = addonData:GetSpellInfo(spellID)
  12.         local button = XMP_Main.ButtonFrame.Buttons[index]
  13.         button:SetAttribute("type","spell")
  14.         button:SetAttribute("spell",spellID)
  15.         button.Icon:SetTexture(textureID)
  16.         button.NormalTexture:SetTexture("")
  17.         table.insert(usedButtons,index)
  18.         currentIdx = currentIdx + 1            
  19.     end
  20.  
  21.     for i = 1,#XMP_Main.ButtonFrame.Buttons do
  22.         if ( tContains(usedButtons,i) ) then
  23.             XMP_Main.ButtonFrame.Buttons[i]:Show()
  24.         else
  25.             XMP_Main.ButtonFrame.Buttons[i]:Hide()
  26.         end
  27.     end
  28. end

And this is what I did to get the spell data loaded in memory
Lua Code:
  1. --[[ Get the required information for the spellID ]]
  2. function addonData:GetSpellInfo(spellID)
  3.    
  4.     local spell = Spell:CreateFromSpellID(spellID)
  5.    
  6.     local spellName = nil
  7.     local textureID = nil
  8.    
  9.     spell:ContinueOnSpellLoad(function()
  10.         spellName = GetSpellInfo(spellID)
  11.         local id,fileID = GetSpellTexture(spellID)
  12.         textureID = fileID
  13.     end)
  14.     return spellName,textureID
  15.    
  16. end

Definitely looking better than my current version of the addon. A few more additions and it should be ready

Hopefully some of this will help other's trying to do something similar and hitting problems
__________________
  Reply With Quote