mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-10 15:40:01 +00:00
UnitAUra cleanup
This commit is contained in:
+26
-9
@@ -181,20 +181,37 @@ function pfUI.api.RunOOC(func)
|
||||
end
|
||||
|
||||
-- [ UnitHasBuff ]
|
||||
-- Returns whether a unit has the given buff or not.
|
||||
-- Returns whether a unit has the named buff or not.
|
||||
-- unit [string] A unit to query (string, unitID)
|
||||
-- buff [string] The texture of the buff.
|
||||
-- name [string] The localized name of the buff.
|
||||
-- return: [bool] true if unit has buff otherwise "nil"
|
||||
function pfUI.api.UnitHasBuff(unit, buff)
|
||||
local hasbuff = nil
|
||||
for i=1,32 do
|
||||
if UnitBuff(unit, i) == buff then
|
||||
hasbuff = true
|
||||
break
|
||||
function pfUI.api.UnitHasBuff(unit, name)
|
||||
for _, aura in ipairs(C_UnitAuras.GetUnitAuras(unit, "HELPFUL")) do
|
||||
if aura.name == name then return true end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- [ GetUnbuffedRoster ]
|
||||
-- Returns a comma-joined, colored list of group members missing the named aura.
|
||||
-- name [string] the localized aura name to check for
|
||||
-- return: [string] comma-joined list, empty string if everyone has it
|
||||
function pfUI.api.GetUnbuffedRoster(name)
|
||||
local missing = {}
|
||||
local function check(unit)
|
||||
if UnitName(unit) and not pfUI.api.UnitHasBuff(unit, name) then
|
||||
table.insert(missing, GetUnitColor(unit) .. UnitName(unit) .. "|r")
|
||||
end
|
||||
end
|
||||
|
||||
return hasbuff
|
||||
if UnitInRaid("player") then
|
||||
for i=1,40 do check("raid"..i) end
|
||||
else
|
||||
check("player")
|
||||
for i=1,4 do check("party"..i) end
|
||||
end
|
||||
|
||||
return table.concat(missing, ", ")
|
||||
end
|
||||
|
||||
-- [[ GetUnitColor ]]
|
||||
|
||||
+4
-36
@@ -99,45 +99,13 @@ local function BuffOnEnter()
|
||||
local parent = this:GetParent()
|
||||
if not parent.label then return end
|
||||
|
||||
local unit = parent.label .. parent.id
|
||||
GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT")
|
||||
if parent.label == "player" then
|
||||
GameTooltip:SetPlayerBuff(GetPlayerBuff(PLAYER_BUFF_START_ID+this.id,"HELPFUL"))
|
||||
else
|
||||
GameTooltip:SetUnitBuff(parent.label .. parent.id, this.id)
|
||||
end
|
||||
GameTooltip:SetUnitAura(unit, this.id, "HELPFUL")
|
||||
|
||||
if IsShiftKeyDown() then
|
||||
local texture = parent.label == "player" and GetPlayerBuffTexture(GetPlayerBuff(PLAYER_BUFF_START_ID+this.id,"HELPFUL")) or UnitBuff(parent.label .. parent.id, this.id)
|
||||
|
||||
-- slot is empty, nothing to compare against
|
||||
if not texture then return end
|
||||
|
||||
local playerlist = ""
|
||||
local first = true
|
||||
|
||||
if UnitInRaid("player") then
|
||||
for i=1,40 do
|
||||
local unitstr = "raid" .. i
|
||||
if not UnitHasBuff(unitstr, texture) and UnitName(unitstr) then
|
||||
playerlist = playerlist .. ( not first and ", " or "") .. GetUnitColor(unitstr) .. UnitName(unitstr) .. "|r"
|
||||
first = nil
|
||||
end
|
||||
end
|
||||
else
|
||||
if not UnitHasBuff("player", texture) then
|
||||
playerlist = playerlist .. ( not first and ", " or "") .. GetUnitColor("player") .. UnitName("player") .. "|r"
|
||||
first = nil
|
||||
end
|
||||
|
||||
for i=1,4 do
|
||||
local unitstr = "party" .. i
|
||||
if not UnitHasBuff(unitstr, texture) and UnitName(unitstr) then
|
||||
playerlist = playerlist .. ( not first and ", " or "") .. GetUnitColor(unitstr) .. UnitName(unitstr) .. "|r"
|
||||
first = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local aura = C_UnitAuras.GetAuraDataByIndex(unit, this.id, "HELPFUL")
|
||||
local playerlist = aura and GetUnbuffedRoster(aura.name) or ""
|
||||
if strlen(playerlist) > 0 then
|
||||
GameTooltip:AddLine(" ")
|
||||
GameTooltip:AddLine(T["Unbuffed"] .. ":", .3, 1, .8)
|
||||
|
||||
+15
-50
@@ -17,13 +17,14 @@ pfUI:RegisterModule("buff", "vanilla:tbc", function ()
|
||||
else
|
||||
buff.id = buff.gid
|
||||
end
|
||||
buff.bid = GetPlayerBuff(PLAYER_BUFF_START_ID+buff.id, buff.btype)
|
||||
|
||||
if not buff.backdrop then
|
||||
CreateBackdrop(buff)
|
||||
CreateBackdropShadow(buff)
|
||||
end
|
||||
|
||||
local aura = C_UnitAuras.GetAuraDataByIndex("player", buff.id, buff.btype)
|
||||
|
||||
--detect weapon buffs
|
||||
if buff.btype == "HELPFUL" and ((C.buffs.separateweapons == "0" and buff.gid <= pfUI.buff.wepbuffs.count) or (pfUI.buff.wepbuffs.count > 0 and buff.weapon ~= nil)) then
|
||||
local mh, mhtime, mhcharge, oh, ohtime, ohcharge = GetWeaponEnchantInfo()
|
||||
@@ -54,13 +55,15 @@ pfUI:RegisterModule("buff", "vanilla:tbc", function ()
|
||||
buff.texture:SetTexture(GetInventoryItemTexture("player", 17))
|
||||
buff.backdrop:SetBackdropBorderColor(GetItemQualityColor(GetInventoryItemQuality("player", 17) or 1))
|
||||
end
|
||||
elseif GetPlayerBuffTexture(buff.bid) and (( buff.btype == "HARMFUL" and C.buffs.debuffs == "1" ) or ( buff.btype == "HELPFUL" and C.buffs.buffs == "1" )) then
|
||||
elseif aura and (( buff.btype == "HARMFUL" and C.buffs.debuffs == "1" ) or ( buff.btype == "HELPFUL" and C.buffs.buffs == "1" )) then
|
||||
-- Set Buff Texture and Border
|
||||
buff.mode = buff.btype
|
||||
buff.texture:SetTexture(GetPlayerBuffTexture(buff.bid))
|
||||
buff.expirationTime = aura.expirationTime
|
||||
buff.stackCount = aura.applications
|
||||
buff.texture:SetTexture(aura.icon)
|
||||
|
||||
if buff.btype == "HARMFUL" then
|
||||
local dtype = GetPlayerBuffDispelType(buff.bid)
|
||||
local dtype = aura.dispelName
|
||||
if dtype == "Magic" then
|
||||
buff.backdrop:SetBackdropBorderColor(0,1,1,1)
|
||||
elseif dtype == "Poison" then
|
||||
@@ -128,34 +131,8 @@ pfUI:RegisterModule("buff", "vanilla:tbc", function ()
|
||||
GameTooltip:SetUnitAura("player", this.id, this.btype)
|
||||
|
||||
if IsShiftKeyDown() then
|
||||
local texture = GetPlayerBuffTexture(this.bid)
|
||||
|
||||
local playerlist = ""
|
||||
local first = true
|
||||
|
||||
if UnitInRaid("player") then
|
||||
for i=1,40 do
|
||||
local unitstr = "raid" .. i
|
||||
if not UnitHasBuff(unitstr, texture) and UnitName(unitstr) then
|
||||
playerlist = playerlist .. ( not first and ", " or "") .. GetUnitColor(unitstr) .. UnitName(unitstr) .. "|r"
|
||||
first = nil
|
||||
end
|
||||
end
|
||||
else
|
||||
if not UnitHasBuff("player", texture) then
|
||||
playerlist = playerlist .. ( not first and ", " or "") .. GetUnitColor("player") .. UnitName("player") .. "|r"
|
||||
first = nil
|
||||
end
|
||||
|
||||
for i=1,4 do
|
||||
local unitstr = "party" .. i
|
||||
if not UnitHasBuff(unitstr, texture) and UnitName(unitstr) then
|
||||
playerlist = playerlist .. ( not first and ", " or "") .. GetUnitColor(unitstr) .. UnitName(unitstr) .. "|r"
|
||||
first = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local aura = C_UnitAuras.GetAuraDataByIndex("player", this.id, this.btype)
|
||||
local playerlist = aura and GetUnbuffedRoster(aura.name) or ""
|
||||
if strlen(playerlist) > 0 then
|
||||
GameTooltip:AddLine(" ")
|
||||
GameTooltip:AddLine(T["Unbuffed"] .. ":", .3, 1, .8)
|
||||
@@ -180,7 +157,8 @@ pfUI:RegisterModule("buff", "vanilla:tbc", function ()
|
||||
elseif CancelItemTempEnchantment and this.mode and this.mode == "OFFHAND" then
|
||||
CancelItemTempEnchantment(2)
|
||||
else
|
||||
CancelPlayerBuff(this.bid)
|
||||
local bid = GetPlayerBuff(PLAYER_BUFF_START_ID + this.id, this.btype)
|
||||
if bid >= 0 then CancelPlayerBuff(bid) end
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -189,19 +167,6 @@ pfUI:RegisterModule("buff", "vanilla:tbc", function ()
|
||||
return buff
|
||||
end
|
||||
|
||||
local function GetNumBuffs()
|
||||
local mh, mhtime, mhcharge, oh, ohtime, ohcharge = GetWeaponEnchantInfo()
|
||||
local offset = (mh and 1 or 0) + (oh and 1 or 0)
|
||||
|
||||
for i=1,32 do
|
||||
local bid, untilCancelled = GetPlayerBuff(PLAYER_BUFF_START_ID+i, "HELPFUL")
|
||||
if bid < 0 then
|
||||
return i - 1 + offset
|
||||
end
|
||||
end
|
||||
return 0 + offset
|
||||
end
|
||||
|
||||
pfUI.buff = CreateFrame("Frame", "pfGlobalBuffFrame", UIParent)
|
||||
pfUI.buff:RegisterEvent("PLAYER_AURAS_CHANGED")
|
||||
pfUI.buff:RegisterEvent("UNIT_INVENTORY_CHANGED")
|
||||
@@ -247,8 +212,8 @@ pfUI:RegisterModule("buff", "vanilla:tbc", function ()
|
||||
if buff:IsShown() then
|
||||
local timeleft, stacks = 0, 0
|
||||
if buff.mode == buff.btype then
|
||||
timeleft = GetPlayerBuffTimeLeft(buff.bid, buff.btype)
|
||||
stacks = GetPlayerBuffApplications(buff.bid, buff.btype)
|
||||
timeleft = buff.expirationTime > 0 and (buff.expirationTime - now) or 0
|
||||
stacks = buff.stackCount or 0
|
||||
elseif buff.mode == "MAINHAND" then
|
||||
timeleft = mhtime and mhtime / 1000 or 0
|
||||
stacks = mhcharge or 0
|
||||
@@ -266,8 +231,8 @@ pfUI:RegisterModule("buff", "vanilla:tbc", function ()
|
||||
for i = 1, 16 do
|
||||
local buff = buttons[i]
|
||||
if buff:IsShown() then
|
||||
local timeleft = GetPlayerBuffTimeLeft(buff.bid, buff.btype)
|
||||
local stacks = GetPlayerBuffApplications(buff.bid, buff.btype)
|
||||
local timeleft = buff.expirationTime > 0 and (buff.expirationTime - now) or 0
|
||||
local stacks = buff.stackCount or 0
|
||||
buff.timer:SetText(timeleft > 0 and GetColoredTimeString(timeleft) or "")
|
||||
buff.stacks:SetText(stacks > 1 and stacks or "")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user