diff --git a/api/config.lua b/api/config.lua index df310f1a..74392291 100644 --- a/api/config.lua +++ b/api/config.lua @@ -208,6 +208,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("unitframes", nil, "portraittexture", "1") pfUI:UpdateConfig("unitframes", nil, "layout", "default") pfUI:UpdateConfig("unitframes", nil, "rangecheck", "0") + pfUI:UpdateConfig("unitframes", nil, "buffdetect", "0") pfUI:UpdateConfig("unitframes", nil, "rangechecki", "4") pfUI:UpdateConfig("unitframes", nil, "combosize", "6") pfUI:UpdateConfig("unitframes", nil, "abbrevnum", "1") diff --git a/api/unitframes.lua b/api/unitframes.lua index 74fcd96e..2eee066c 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -204,6 +204,59 @@ function pfUI.uf.glow.UpdateGlowAnimation() this:SetAlpha(pfUI.uf.glow.val) end +local detect_icon, detect_name +function pfUI.uf:DetectBuff(name, id) + if not name or not id then return end + + -- skip here if disabled + if pfUI_config.unitframes.buffdetect == "0" then + return UnitBuff(name, id) + end + + -- clear previously assigned + detect_icon, detect_name = nil, nil + + -- register tooltip scanner + scanner = scanner or libtipscan:GetScanner("unitframes") + + -- make sure the icon cache exists + pfUI_cache.buff_icons = pfUI_cache.buff_icons or {} + + -- check the regular way + detect_icon = UnitBuff(name, id) + if detect_icon then + if not pfUI_cache.buff_icons[detect_icon] then + -- read buff name and cache it + scanner:SetUnitBuff(name, id) + detect_name = scanner:Line(1) + + if detect_name then + pfUI_cache.buff_icons[detect_icon] = detect_name + end + end + + -- return the regular function + return UnitBuff(name, id) + end + + -- try to guess the buff based on tooltips and icon caches + scanner:SetUnitBuff(name, id) + detect_name = scanner:Line(1) + + if detect_name then + -- return icon if name was already cached + for icon, name in pairs(pfUI_cache.buff_icons) do + if name == detect_name then return icon, 1 end + end + + -- return fallback image + return "interface\\icons\\inv_misc_questionmark", 1 + end + + -- nothing found + return nil +end + function pfUI.uf:UpdateVisibility() local self = self or this @@ -1425,7 +1478,7 @@ function pfUI.uf:RefreshUnit(unit, component) stacks = GetPlayerBuffApplications(GetPlayerBuff(PLAYER_BUFF_START_ID+i,"HELPFUL")) texture = GetPlayerBuffTexture(GetPlayerBuff(PLAYER_BUFF_START_ID+i,"HELPFUL")) else - texture, stacks = UnitBuff(unitstr, i) + texture, stacks = pfUI.uf:DetectBuff(unitstr, i) end unit.buffs[i].texture:SetTexture(texture) diff --git a/modules/gui.lua b/modules/gui.lua index ff9b9277..fff656b8 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -1591,6 +1591,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function () CreateConfig(nil, T["Enable Energy Ticks"], C.unitframes.player, "energy", "checkbox") CreateConfig(nil, T["Enable Mana Ticks"], C.unitframes.player, "manatick", "checkbox") CreateConfig(nil, T["Abbreviate Unit Names"], C.unitframes, "abbrevname", "checkbox") + CreateConfig(nil, T["Detect Enemy Buffs"], C.unitframes, "buffdetect", "checkbox", nil, nil, nil, nil, "vanilla" ) CreateConfig(U[c], T["Font Options"], nil, nil, "header") CreateConfig(nil, T["Unit Frame Text Font"], C.global, "font_unit", "dropdown", pfUI.gui.dropdowns.fonts)