unitframes: add option to detect enemy buffs

This commit is contained in:
shagu
2023-01-27 18:05:45 +01:00
parent 9f19977fce
commit aa2ca9b232
3 changed files with 56 additions and 1 deletions
+1
View File
@@ -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")
+54 -1
View File
@@ -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)
+1
View File
@@ -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)