View Single Post
10-23-15, 06:43 AM   #1
LanceDH
A Cyclonian
 
LanceDH's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 41
Need help with SpellBook taint

I'm currently working on an addon that interracts with the SpellBook but I seem to taint it which causes errors when trying to cast a spell from the book (because CastSpell() is protected).

The idea is that I have a button showing a spell, and when clicked it opens the SpellBook to the page where the spell is located.
As far as I've seen there's no function for this so I basically go through all the tabs, pages and slots to find the correct spell.
The issue is that this, and even just toggling the SpellBook, will taint it.
So I'm trying to figure out if there's a way I can fix it.
Full code can be found on my GitHub

Once the button is pressed the only relevant code is the following:
(line 122- 141)
It get the name of the spell, then calls the function to scout through the spellbook for that name.
If it's found it plays a highlight animation, else it just opens on the default page.
And then it opens the SpellBook if it's not open yet.
Lua Code:
  1. elseif (self.unlockType == UNLOCKTYPE_SPELL) then
  2.     local spellName = self.SpellName:GetText();
  3.     local success, slot = OpenSpellBookAtSpell(spellName);
  4.     if success then
  5.         ILW_SpellBookHighlight:ClearAllPoints();
  6.         ILW_SpellBookHighlight:SetPoint("TOPLEFT", slot, "TOPRIGHT");
  7.         ILW_SpellBookHighlight:Show();
  8.         ILW_SpellBookHighlight.increasing = true;
  9.         ILW_SpellBookHighlight:SetAlpha(0);
  10.     else
  11.         print("|cFFFFD100ILWhat:|r |cFFFF5555" .. spellName .." is not in the spellbook. It might be hidden.|r");
  12.         SpellBookSkillLineTab_OnClick(_G["SpellBookSkillLineTab2"]);
  13.         while (SpellBookPrevPageButton:IsEnabled()) do
  14.             SpellBookPrevPageButton_OnClick();
  15.         end
  16.     end
  17.        
  18.     if (not SpellBookFrame:IsShown()) then
  19.         ToggleSpellBook(BOOKTYPE_SPELL);
  20.     end

The function to scout works like this:
(line 47 - 105)
It simply starts at the first tab, checks all the slots until it reaches an empty one or the last one.
Goes through the different pages on that tab until it's done and goes to the second tab.
if it finds the spell it stays on that page and returns success and the slot (to archor the highlight to)
Lua Code:
  1. local function OpenSpellBookAtSpell(searchName)
  2.     local tabNr = 1;
  3.     local maxTabs = 2;
  4.     local buttonNr = 1;
  5.     local buttonPerPage = 12;
  6.     local spellName = "";
  7.     local firsTimeInTab = false;
  8.    
  9.     SpellBookSkillLineTab_OnClick(_G["SpellBookSkillLineTab"..tabNr]);
  10.     while (tabNr <= maxTabs) do
  11.    
  12.         -- go to the first page
  13.         if (not firsTimeInTab) then
  14.             while (SpellBookPrevPageButton:IsEnabled()) do
  15.                 SpellBookPrevPageButton_OnClick();
  16.             end
  17.             firsTimeInTab = true;
  18.         end
  19.    
  20.         -- if target slot has a spell in it
  21.         if _G["SpellButton"..buttonNr.."SpellName"] ~= nil and _G["SpellButton"..buttonNr.."SpellName"]:IsShown() then
  22.             -- if the current tab still has unchecked spells
  23.             if (buttonNr <= buttonPerPage) then
  24.                
  25.                 spellName = _G["SpellButton"..buttonNr.."SpellName"]:GetText();
  26.                
  27.                 if (spellName == searchName) then
  28.                     -- Found the spell, end the world
  29.                     return true, _G["SpellButton"..buttonNr];
  30.                 end
  31.                
  32.                 buttonNr = buttonNr + 2;
  33.  
  34.                 -- reached limit on uneven, go even
  35.                 -- Needed because slotNr goes L->R U->D while spells go U->D L->R
  36.                 if (buttonNr > 12 and buttonNr %2 == 1) then
  37.                     buttonNr = 2;
  38.                 end
  39.             end
  40.         else -- else check for next page
  41.            
  42.             -- has next page, flip page
  43.             if (SpellBookNextPageButton:IsEnabled() ) then
  44.                
  45.                 SpellBookNextPageButton_OnClick();
  46.                 buttonNr = 1;
  47.             else -- else next tab
  48.                
  49.                 buttonNr = 1;
  50.                 tabNr = tabNr + 1;
  51.                 SpellBookSkillLineTab_OnClick(_G["SpellBookSkillLineTab"..tabNr]);
  52.                 firsTimeInTab = false;
  53.             end        
  54.         end
  55.     end
  56.    
  57.     return false;
  58.    
  59. end

The template for the buttons are in the XML file.
Template lines 15 to 136
Actual buttons at 242 - 300

So I'm trying to figure out if there is a way to prevent the taint, or if there's just no way to do it correctly.

Last edited by LanceDH : 10-23-15 at 07:05 AM.
  Reply With Quote