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:
elseif (self.unlockType == UNLOCKTYPE_SPELL) then
local spellName = self.SpellName:GetText();
local success, slot = OpenSpellBookAtSpell(spellName);
if success then
ILW_SpellBookHighlight:ClearAllPoints();
ILW_SpellBookHighlight:SetPoint("TOPLEFT", slot, "TOPRIGHT");
ILW_SpellBookHighlight:Show();
ILW_SpellBookHighlight.increasing = true;
ILW_SpellBookHighlight:SetAlpha(0);
else
print("|cFFFFD100ILWhat:|r |cFFFF5555" .. spellName .." is not in the spellbook. It might be hidden.|r");
SpellBookSkillLineTab_OnClick(_G["SpellBookSkillLineTab2"]);
while (SpellBookPrevPageButton:IsEnabled()) do
SpellBookPrevPageButton_OnClick();
end
end
if (not SpellBookFrame:IsShown()) then
ToggleSpellBook(BOOKTYPE_SPELL);
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:
local function OpenSpellBookAtSpell(searchName)
local tabNr = 1;
local maxTabs = 2;
local buttonNr = 1;
local buttonPerPage = 12;
local spellName = "";
local firsTimeInTab = false;
SpellBookSkillLineTab_OnClick(_G["SpellBookSkillLineTab"..tabNr]);
while (tabNr <= maxTabs) do
-- go to the first page
if (not firsTimeInTab) then
while (SpellBookPrevPageButton:IsEnabled()) do
SpellBookPrevPageButton_OnClick();
end
firsTimeInTab = true;
end
-- if target slot has a spell in it
if _G["SpellButton"..buttonNr.."SpellName"] ~= nil and _G["SpellButton"..buttonNr.."SpellName"]:IsShown() then
-- if the current tab still has unchecked spells
if (buttonNr <= buttonPerPage) then
spellName = _G["SpellButton"..buttonNr.."SpellName"]:GetText();
if (spellName == searchName) then
-- Found the spell, end the world
return true, _G["SpellButton"..buttonNr];
end
buttonNr = buttonNr + 2;
-- reached limit on uneven, go even
-- Needed because slotNr goes L->R U->D while spells go U->D L->R
if (buttonNr > 12 and buttonNr %2 == 1) then
buttonNr = 2;
end
end
else -- else check for next page
-- has next page, flip page
if (SpellBookNextPageButton:IsEnabled() ) then
SpellBookNextPageButton_OnClick();
buttonNr = 1;
else -- else next tab
buttonNr = 1;
tabNr = tabNr + 1;
SpellBookSkillLineTab_OnClick(_G["SpellBookSkillLineTab"..tabNr]);
firsTimeInTab = false;
end
end
end
return false;
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.