--[[-------------------------------------------------------------------- |
CoolLine Fix |
Hides CoolLine in pet battles, and adds support for spell charges. |
Copyright (c) 2014 Phanx <addons@phanx.net>. All rights reserved. |
See the accompanying README and LICENSE files for more information. |
http://www.wowinterface.com/downloads/info22791-CoolLineFix.html |
http://www.curse.com/wow/addons/coolline-fix |
----------------------------------------------------------------------]] |
-- Hide in pet battles |
|
CoolLine:RegisterEvent("PET_BATTLE_OPENING_START") |
CoolLine:RegisterEvent("PET_BATTLE_CLOSE") |
|
CoolLine.PET_BATTLE_OPENING_START = CoolLine.Hide |
CoolLine.PET_BATTLE_CLOSE = CoolLine.Show |
|
if C_PetBattles.IsInBattle() then |
CoolLine:Hide() |
end |
|
------------------------------------------------------------------------ |
-- Show spell charges |
|
local CoolLineFix = CreateFrame("Frame") |
CoolLineFix:SetScript("OnEvent", function(f, e, ...) return (f[e] or f["SPELLS_CHANGED"])(f, ...) end) |
CoolLineFix:RegisterEvent("PLAYER_LOGIN") |
CoolLineFix:RegisterEvent("SPELLS_CHANGED") |
CoolLineFix:RegisterEvent("SPELL_UPDATE_CHARGES") |
|
local chargeSpells = { |
[BOOKTYPE_SPELL] = {}, |
[BOOKTYPE_PET] = {}, |
} |
|
do -- cache spells that have a cooldown |
local last |
local GetSpellBookItemName, GetSpellBookItemInfo, GetSpellCharges = GetSpellBookItemName, GetSpellBookItemInfo, GetSpellCharges |
local function CacheBook(bookType) |
local t = chargeSpells[bookType] |
local _, _, offset, numSpells = GetSpellTabInfo(2) |
for i = 1, offset + numSpells do |
local name = GetSpellBookItemName(i, bookType) |
if not name then break end |
local slotType, id = GetSpellBookItemInfo(i, bookType) |
if id and slotType ~= "FLYOUT" and slotType ~= "FUTURESPELL" and id ~= last then |
last = id |
local currentCharges, maxCharges, cooldownStart, cooldownDuration = GetSpellCharges(id) |
if maxCharges and maxCharges > 0 then |
t[id] = name |
end |
end |
end |
end |
|
function CoolLineFix:SPELLS_CHANGED() |
CacheBook(BOOKTYPE_SPELL) |
if not CoolLineDB.hidepet then |
CacheBook(BOOKTYPE_PET) |
end |
end |
end |
|
do |
local AVAILABLE = 2^32 / 1000 |
local GetSpellCharges, GetSpellTexture = GetSpellCharges, GetSpellTexture |
local function CheckSpellBook(bookType) |
for id, name in pairs(chargeSpells[bookType]) do |
local currentCharges, maxCharges, cooldownStart, cooldownDuration = GetSpellCharges(id) |
if cooldownStart and cooldownDuration and currentCharges < maxCharges and not CoolLineDB.block[name] then |
local _, _, texture = GetSpellInfo(id) |
CoolLine.NewCooldown(name, texture, cooldownStart + cooldownDuration, bookType == BOOKTYPE_SPELL) |
else |
CoolLine.ClearCooldown(nil, name) |
end |
end |
end |
|
function CoolLineFix:SPELL_UPDATE_CHARGES() |
CheckSpellBook(BOOKTYPE_SPELL) |
if not CoolLineDB.hidepet and HasPetUI() then |
CheckSpellBook(BOOKTYPE_PET) |
end |
end |
end |