Harden macros, world map and actionbar panels
This commit is contained in:
+74
-59
@@ -1,5 +1,6 @@
|
||||
local _G = ShaguTweaks.GetGlobalEnv()
|
||||
local T = ShaguTweaks.T
|
||||
local API = ShaguTweaks.API or {}
|
||||
local libspell = ShaguTweaks.libspell
|
||||
|
||||
local module = ShaguTweaks:register({
|
||||
@@ -14,75 +15,86 @@ local module = ShaguTweaks:register({
|
||||
module.enable = function(self)
|
||||
local gfind = string.gmatch or string.gfind
|
||||
|
||||
local function ButtonMacroScan(bar)
|
||||
if not bar:IsVisible() then return end
|
||||
local function BuildMacroCache()
|
||||
local cache = {}
|
||||
for macroSlot = 1, 36 do
|
||||
local name, _, body = GetMacroInfo(macroSlot)
|
||||
if name and body then
|
||||
cache[name] = { id = macroSlot, body = body }
|
||||
end
|
||||
end
|
||||
return cache
|
||||
end
|
||||
|
||||
local button, icon
|
||||
local function GetMacroBody(actionSlot, cache)
|
||||
if API.GetActionInfo then
|
||||
local actionType, id = API.GetActionInfo(actionSlot)
|
||||
if actionType == "macro" and id then
|
||||
local _, _, body = GetMacroInfo(id)
|
||||
if body then return body end
|
||||
end
|
||||
end
|
||||
|
||||
local macroName = GetActionText(actionSlot)
|
||||
local entry = macroName and cache[macroName]
|
||||
return entry and entry.body or nil
|
||||
end
|
||||
|
||||
local function ResolveSpell(body)
|
||||
if not body then return end
|
||||
|
||||
local fallback
|
||||
for line in gfind(body, "[^%\n]+") do
|
||||
local _, _, match = string.find(line, "^#showtooltip%s+(.+)")
|
||||
if match then return match end
|
||||
|
||||
if not fallback then
|
||||
_, _, fallback = string.find(line, "%-%-showtooltip%s+(.+)")
|
||||
end
|
||||
if not fallback then
|
||||
_, _, fallback = string.find(line, "^/cast%s+(.+)")
|
||||
end
|
||||
if not fallback then
|
||||
_, _, fallback = string.find(line, "^/pfcast%s+(.+)")
|
||||
end
|
||||
if not fallback then
|
||||
_, _, fallback = string.find(line, "CastSpellByName%(%\"(.+)%\"%)")
|
||||
end
|
||||
end
|
||||
|
||||
return fallback
|
||||
end
|
||||
|
||||
local function ButtonMacroScan(bar, macroCache)
|
||||
if not bar:IsVisible() then return end
|
||||
|
||||
local prefix = bar:GetName()
|
||||
prefix = bar == MainMenuBar and "Action" or prefix
|
||||
prefix = bar == BonusActionBarFrame and "BonusAction" or prefix
|
||||
|
||||
-- scan all 12 slots in bar
|
||||
for slot = 1, 12 do
|
||||
button = _G[prefix.."Button"..slot]
|
||||
icon = _G[prefix.."Button"..slot.."Icon"]
|
||||
|
||||
for index = 1, 12 do
|
||||
local button = _G[prefix.."Button"..index]
|
||||
local icon = _G[prefix.."Button"..index.."Icon"]
|
||||
if not button then break end
|
||||
local macro = GetActionText(ActionButton_GetPagedID(_G[prefix.."Button"..slot]))
|
||||
|
||||
local spellslot = nil
|
||||
local booktype = nil
|
||||
local actionSlot = ActionButton_GetPagedID(button)
|
||||
local texture = GetActionTexture(actionSlot)
|
||||
button.spellslot, button.booktype = nil, nil
|
||||
|
||||
if macro then
|
||||
local name, body, _
|
||||
for slot = 1, 36 do -- 36 macro slots
|
||||
name, _, body = GetMacroInfo(slot)
|
||||
if name == macro then break end
|
||||
local body = GetMacroBody(actionSlot, macroCache)
|
||||
local match = ResolveSpell(body)
|
||||
if match then
|
||||
local _, _, spell, rank = string.find(match, "(.+)%((.+)%)")
|
||||
spell = spell or match
|
||||
button.spellslot, button.booktype = libspell.GetSpellIndex(spell, rank)
|
||||
|
||||
if button.spellslot and button.booktype then
|
||||
texture = GetSpellTexture(button.spellslot, button.booktype) or texture
|
||||
end
|
||||
end
|
||||
|
||||
if name and body then
|
||||
local match
|
||||
|
||||
for line in gfind(body, "[^%\n]+") do
|
||||
_, _, match = string.find(line, '^#showtooltip (.+)')
|
||||
|
||||
if not match then
|
||||
-- add support to specify custom tooltips via:
|
||||
-- /run --showtooltip SPELLNAME
|
||||
_, _, match = string.find(line, '%-%-showtooltip (.+)')
|
||||
end
|
||||
|
||||
if not match then
|
||||
_, _, match = string.find(line, '^/cast (.+)')
|
||||
end
|
||||
|
||||
if not match then
|
||||
_, _, match = string.find(line, '^/pfcast (.+)')
|
||||
end
|
||||
|
||||
if not match then
|
||||
_, _, match = string.find(line, 'CastSpellByName%(%"(.+)%"%)')
|
||||
end
|
||||
|
||||
if match then
|
||||
local _, _, spell, rank = string.find(match, '(.+)%((.+)%)')
|
||||
spell = spell or match
|
||||
button.spellslot, button.booktype = libspell.GetSpellIndex(spell, rank)
|
||||
|
||||
-- overwrite with spell macro texture where possible
|
||||
local texture = GetActionTexture(slot)
|
||||
if button.spellslot and button.booktype then
|
||||
texture = GetSpellTexture(button.spellslot, button.booktype)
|
||||
end
|
||||
|
||||
-- update button texture
|
||||
if texture and texture ~= icon:GetTexture() then
|
||||
icon:SetTexture(texture)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if icon and texture and texture ~= icon:GetTexture() then
|
||||
icon:SetTexture(texture)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -99,6 +111,9 @@ module.enable = function(self)
|
||||
macroicons:RegisterEvent("UPDATE_BONUS_ACTIONBAR")
|
||||
macroicons:RegisterEvent("ACTIONBAR_SHOWGRID")
|
||||
macroicons:SetScript("OnEvent", function()
|
||||
for _, bar in pairs(bars) do ButtonMacroScan(bar) end
|
||||
local macroCache = BuildMacroCache()
|
||||
for _, bar in pairs(bars) do
|
||||
ButtonMacroScan(bar, macroCache)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user