mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-28 10:26:02 +00:00
buff: add buff frames
This commit is contained in:
+214
-112
@@ -1,125 +1,227 @@
|
||||
pfUI:RegisterModule("buff", function ()
|
||||
pfUI.buff = CreateFrame("Frame")
|
||||
-- Hide Blizz
|
||||
BuffFrame:Hide()
|
||||
BuffFrame:UnregisterAllEvents()
|
||||
TemporaryEnchantFrame:Hide()
|
||||
TemporaryEnchantFrame:UnregisterAllEvents()
|
||||
|
||||
local function RefreshBuffButton(buff)
|
||||
buff.id = buff.gid - (buff.btype == "HELPFUL" and pfUI.buff.buffs.offset or 0)
|
||||
buff.bid = GetPlayerBuff(buff.id-1, buff.btype)
|
||||
|
||||
-- detect weapon buffs
|
||||
if buff.gid <= pfUI.buff.buffs.offset and buff.btype == "HELPFUL" then
|
||||
local mh, mhtime, mhcharge, oh, ohtime, ohcharge = GetWeaponEnchantInfo()
|
||||
if pfUI.buff.buffs.offset == 2 then
|
||||
if buff.gid == 1 then
|
||||
buff.mode = "MAINHAND"
|
||||
else
|
||||
buff.mode = "OFFHAND"
|
||||
end
|
||||
else
|
||||
buff.mode = oh and "OFFHAND" or mh and "MAINHAND"
|
||||
end
|
||||
|
||||
-- Set Weapon Texture and Border
|
||||
if buff.mode == "MAINHAND" then
|
||||
buff.texture:SetTexture(GetInventoryItemTexture("player", 16))
|
||||
buff.backdrop:SetBackdropBorderColor(GetItemQualityColor(GetInventoryItemQuality("player", 16) or 1))
|
||||
elseif buff.mode == "OFFHAND" then
|
||||
buff.texture:SetTexture(GetInventoryItemTexture("player", 17))
|
||||
buff.backdrop:SetBackdropBorderColor(GetItemQualityColor(GetInventoryItemQuality("player", 17) or 1))
|
||||
end
|
||||
elseif buff.bid >= 0 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))
|
||||
CreateBackdrop(buff)
|
||||
|
||||
if buff.btype == "HARMFUL" then
|
||||
local dtype = GetPlayerBuffDispelType(buff.bid)
|
||||
if dtype == "Magic" then
|
||||
buff.backdrop:SetBackdropBorderColor(0,1,1,1)
|
||||
elseif dtype == "Poison" then
|
||||
buff.backdrop:SetBackdropBorderColor(0,1,0,1)
|
||||
elseif dtype == "Curse" then
|
||||
buff.backdrop:SetBackdropBorderColor(1,0,1,1)
|
||||
elseif dtype == "Disease" then
|
||||
buff.backdrop:SetBackdropBorderColor(1,1,0,1)
|
||||
else
|
||||
buff.backdrop:SetBackdropBorderColor(1,0,0,1)
|
||||
end
|
||||
end
|
||||
else
|
||||
buff:Hide()
|
||||
return
|
||||
end
|
||||
|
||||
buff:Show()
|
||||
end
|
||||
|
||||
local function CreateBuffButton(i, btype)
|
||||
local buff = CreateFrame("Button", ( btype == "HELPFUL" and "pfBuffFrameBuff" or "pfDebuffFrameBuff" ) .. i, ( btype == "HARMFUL" and pfUI.buff.debuffs or pfUI.buff.buffs ))
|
||||
buff.texture = buff:CreateTexture("BuffIcon" .. i, "BACKGROUND")
|
||||
buff.texture:SetTexCoord(.07,.93,.07,.93)
|
||||
buff.texture:SetAllPoints(buff)
|
||||
|
||||
buff.timer = buff:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
buff.timer:SetTextColor(1,1,1,1)
|
||||
buff.timer:SetJustifyH("CENTER")
|
||||
buff.timer:SetJustifyV("CENTER")
|
||||
|
||||
buff.stacks = buff:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
buff.stacks:SetTextColor(1,1,1,1)
|
||||
buff.stacks:SetJustifyH("RIGHT")
|
||||
buff.stacks:SetJustifyV("BOTTOM")
|
||||
buff.stacks:SetAllPoints(buff)
|
||||
|
||||
buff.btype = btype
|
||||
buff.gid = i
|
||||
|
||||
buff:SetScript("OnUpdate", function()
|
||||
if not this.next then this.next = GetTime() + .1 end
|
||||
if this.next > GetTime() then return end
|
||||
this.next = GetTime() + .1
|
||||
|
||||
local timeleft = 0
|
||||
local stacks = 0
|
||||
|
||||
if this.mode == this.btype then
|
||||
timeleft = GetPlayerBuffTimeLeft(this.bid, this.btype)
|
||||
stacks = GetPlayerBuffApplications(this.bid, this.btype)
|
||||
elseif this.mode == "MAINHAND" then
|
||||
local _, mhtime, mhcharge = GetWeaponEnchantInfo()
|
||||
timeleft = mhtime/1000
|
||||
stacks = mhcharge
|
||||
elseif this.mode == "OFFHAND" then
|
||||
local _, _, _, _, ohtime, ohcharge = GetWeaponEnchantInfo()
|
||||
timeleft = ohtime/1000
|
||||
charge = ohcharge
|
||||
end
|
||||
|
||||
this.timer:SetText(timeleft > 0 and GetColoredTimeString(timeleft) or "")
|
||||
this.stacks:SetText(stacks > 1 and stacks or "")
|
||||
end)
|
||||
|
||||
buff:SetScript("OnEnter", function()
|
||||
GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT")
|
||||
if this.mode == this.btype then
|
||||
GameTooltip:SetPlayerBuff(GetPlayerBuff(this.bid, this.btype))
|
||||
elseif this.mode == "MAINHAND" then
|
||||
GameTooltip:SetInventoryItem("player", 16)
|
||||
elseif this.mode == "OFFHAND" then
|
||||
GameTooltip:SetInventoryItem("player", 17)
|
||||
end
|
||||
end)
|
||||
|
||||
buff:SetScript("OnLeave", function()
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
|
||||
buff:SetScript("OnClick", function()
|
||||
CancelPlayerBuff(GetPlayerBuff(this.bid, this.btype))
|
||||
end)
|
||||
|
||||
CreateBackdrop(buff)
|
||||
RefreshBuffButton(buff)
|
||||
|
||||
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(i-1, "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")
|
||||
pfUI.buff:RegisterEvent("UNIT_AURA")
|
||||
pfUI.buff:RegisterEvent("UNIT_MODEL_CHANGED")
|
||||
pfUI.buff:SetScript("OnEvent", function ()
|
||||
if event == "UNIT_AURA" and arg1 ~= "player" then return end
|
||||
pfUI.buff:UpdateSkin()
|
||||
end)
|
||||
|
||||
-- weapon enchant stacks
|
||||
TempEnchant1.stacks = TempEnchant1:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
TempEnchant1.stacks:SetFont(pfUI.font_default, 14, "OUTLINE")
|
||||
TempEnchant1.stacks:SetTextColor(1,1,1,1)
|
||||
TempEnchant1.stacks:ClearAllPoints()
|
||||
TempEnchant1.stacks:SetAllPoints(TempEnchant1)
|
||||
TempEnchant1.stacks:SetJustifyH("RIGHT")
|
||||
TempEnchant1.stacks:SetJustifyV("BOTTOM")
|
||||
TempEnchant2.stacks = TempEnchant2:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
TempEnchant2.stacks:SetFont(pfUI.font_default, 14, "OUTLINE")
|
||||
TempEnchant2.stacks:SetTextColor(1,1,1,1)
|
||||
TempEnchant2.stacks:ClearAllPoints()
|
||||
TempEnchant2.stacks:SetAllPoints(TempEnchant2)
|
||||
TempEnchant2.stacks:SetJustifyH("RIGHT")
|
||||
TempEnchant2.stacks:SetJustifyV("BOTTOM")
|
||||
|
||||
-- This hack is used to update the border again and again up to 10 seconds.
|
||||
-- On a reload the item rarity can not be detected instantly. It requries
|
||||
-- some seconds after the correct border color will be shown.
|
||||
pfUI.buff.lastUpdate = 0
|
||||
pfUI.buff.updateInterval = .05
|
||||
pfUI.buff:SetScript("OnUpdate", function()
|
||||
if pfUI.buff.lastUpdate + pfUI.buff.updateInterval < GetTime() then
|
||||
pfUI.buff:UpdateSkin()
|
||||
pfUI.buff.lastUpdate = GetTime()
|
||||
pfUI.buff.updateInterval = pfUI.buff.updateInterval + pfUI.buff.updateInterval
|
||||
pfUI.buff:SetScript("OnEvent", function()
|
||||
if C.buffs.weapons == "1" then
|
||||
local mh, mhtime, mhcharge, oh, ohtime, ohcharge = GetWeaponEnchantInfo()
|
||||
pfUI.buff.buffs.offset = (mh and 1 or 0) + (oh and 1 or 0)
|
||||
else
|
||||
pfUI.buff.buffs.offset = 0
|
||||
end
|
||||
if pfUI.buff.updateInterval > 10 then
|
||||
pfUI.buff:Hide()
|
||||
|
||||
for i=1,32 do
|
||||
RefreshBuffButton(pfUI.buff.buffs.buttons[i])
|
||||
end
|
||||
|
||||
for i=1,16 do
|
||||
RefreshBuffButton(pfUI.buff.debuffs.buttons[i])
|
||||
end
|
||||
end)
|
||||
|
||||
function pfUI.buff:UpdateSkin()
|
||||
-- buff positions
|
||||
TemporaryEnchantFrame:ClearAllPoints()
|
||||
TemporaryEnchantFrame:SetPoint("TOPRIGHT", pfUI.minimap or Minimap, "TOPLEFT", -25,0)
|
||||
-- Buff Frame
|
||||
pfUI.buff.buffs = CreateFrame("Frame", "pfBuffFrame", UIParent)
|
||||
pfUI.buff.buffs.offset = 0
|
||||
pfUI.buff.buffs.buttons = {}
|
||||
for i=1,32 do
|
||||
pfUI.buff.buffs.buttons[i] = CreateBuffButton(i, "HELPFUL")
|
||||
end
|
||||
|
||||
if C.global.hidewbuff == "1" then
|
||||
TemporaryEnchantFrame:Hide()
|
||||
BuffFrame:SetPoint("TOPRIGHT", pfUI.minimap or Minimap, "TOPLEFT", -25,0)
|
||||
-- Debuffs
|
||||
pfUI.buff.debuffs = CreateFrame("Frame", "pfDebuffFrame", UIParent)
|
||||
pfUI.buff.debuffs.buttons = {}
|
||||
for i=1,16 do
|
||||
pfUI.buff.debuffs.buttons[i] = CreateBuffButton(i, "HARMFUL")
|
||||
end
|
||||
|
||||
-- config loading
|
||||
function pfUI.buff:UpdateConfigBuffButton(buff)
|
||||
local fontsize = C.buffs.fontsize == "-1" and C.global.font_size or C.buffs.fontsize
|
||||
local rowcount = floor((buff.gid-1) / tonumber(C.buffs.rowsize))
|
||||
buff:SetWidth(tonumber(C.buffs.size))
|
||||
buff:SetHeight(tonumber(C.buffs.size))
|
||||
buff:ClearAllPoints()
|
||||
buff:SetPoint("TOPRIGHT", ( buff.btype == "HARMFUL" and pfUI.buff.debuffs or pfUI.buff.buffs ), "TOPRIGHT", -(buff.gid-1-rowcount*tonumber(C.buffs.rowsize))*(tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)), -(rowcount) * ((C.buffs.textinside == "1" and 0 or (fontsize*1.5))+tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
|
||||
|
||||
buff.timer:SetFont(pfUI.font_default, fontsize, "OUTLINE")
|
||||
buff.stacks:SetFont(pfUI.font_default, fontsize+1, "OUTLINE")
|
||||
|
||||
buff.timer:SetHeight(fontsize * 1.3)
|
||||
|
||||
buff.timer:ClearAllPoints()
|
||||
if C.buffs.textinside == "1" then
|
||||
buff.timer:SetAllPoints(buff)
|
||||
else
|
||||
-- weapon enchants
|
||||
for _,buff in pairs ({TempEnchant1,TempEnchant2}) do
|
||||
local icon = _G[buff:GetName().."Icon"]
|
||||
local border = _G[buff:GetName().."Border"]
|
||||
local text = _G[buff:GetName().."Duration"]
|
||||
text:SetPoint("TOP", buff, "BOTTOM", 0 , -C.appearance.border.default*2)
|
||||
|
||||
local _, _, mainhand, _, _, offhand = GetWeaponEnchantInfo()
|
||||
if buff then
|
||||
CreateBackdrop(buff)
|
||||
icon:SetTexCoord(.08, .92, .08, .92)
|
||||
border:Hide()
|
||||
end
|
||||
|
||||
if buff:GetID() == 16 then
|
||||
local link = GetInventoryItemLink("player", 16)
|
||||
if not link then break end
|
||||
local _, _, itemLink = string.find(link, "(item:%d+:%d+:%d+:%d+)")
|
||||
local _, _, itemRarity, itemLevel, _, _, _, itemEquipLoc, _ = GetItemInfo(itemLink)
|
||||
if itemRarity then buff.backdrop:SetBackdropBorderColor(GetItemQualityColor(itemRarity)) end
|
||||
|
||||
if mainhand and mainhand > 0 then
|
||||
buff.stacks:SetText(mainhand)
|
||||
buff.stacks:Show()
|
||||
else
|
||||
buff.stacks:Hide()
|
||||
end
|
||||
elseif buff:GetID() == 17 then
|
||||
local link = GetInventoryItemLink("player", 17)
|
||||
if not link then break end
|
||||
local _, _, itemLink = string.find(link, "(item:%d+:%d+:%d+:%d+)")
|
||||
local _, _, itemRarity, itemLevel, _, _, _, itemEquipLoc, _ = GetItemInfo(itemLink)
|
||||
if itemRarity then buff.backdrop:SetBackdropBorderColor(GetItemQualityColor(itemRarity)) end
|
||||
if offhand and offhand > 0 then
|
||||
buff.stacks:SetText(offhand)
|
||||
buff.stacks:Show()
|
||||
else
|
||||
buff.stacks:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if C.global.hidebuff == "1" then
|
||||
BuffFrame:Hide()
|
||||
else
|
||||
-- buffs
|
||||
for i=0,32 do
|
||||
local buff = _G["BuffButton" .. i]
|
||||
if buff then
|
||||
local icon = _G[buff:GetName().."Icon"]
|
||||
local border = _G[buff:GetName().."Border"]
|
||||
local text = _G[buff:GetName().."Duration"]
|
||||
|
||||
if i < 8 and i > 0 then
|
||||
buff:SetPoint("TOPRIGHT", _G["BuffButton" .. i-1], "TOPLEFT", -7, 0)
|
||||
elseif i < 16 and i > 8 then
|
||||
buff:SetPoint("TOPRIGHT", _G["BuffButton" .. i-1], "TOPLEFT", -7, 0)
|
||||
elseif i > 16 then
|
||||
buff:SetPoint("TOPRIGHT", _G["BuffButton" .. i-1], "TOPLEFT", -7, 0)
|
||||
end
|
||||
CreateBackdrop(buff)
|
||||
text:SetPoint("TOP", buff, "BOTTOM", 0 , -C.appearance.border.default*2)
|
||||
icon:SetTexCoord(.08, .92, .08, .92)
|
||||
if border then
|
||||
buff.backdrop:SetBackdropBorderColor(border:GetVertexColor())
|
||||
border:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
buff.timer:SetPoint("TOP", buff, "BOTTOM", 0, -3)
|
||||
end
|
||||
end
|
||||
|
||||
function pfUI.buff:UpdateConfig()
|
||||
local fontsize = C.buffs.fontsize == "-1" and C.global.font_size or C.buffs.fontsize
|
||||
|
||||
pfUI.buff.buffs:SetWidth(tonumber(C.buffs.rowsize) * (tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
|
||||
pfUI.buff.buffs:SetHeight(ceil(32/tonumber(C.buffs.rowsize)) * ((C.buffs.textinside == "1" and 0 or (fontsize*1.5))+tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
|
||||
pfUI.buff.buffs:SetPoint("TOPRIGHT", pfUI.minimap or UIParent, "TOPLEFT", -2*tonumber(C.buffs.spacing), 0)
|
||||
UpdateMovable(pfUI.buff.buffs)
|
||||
|
||||
pfUI.buff.debuffs:SetWidth(tonumber(C.buffs.rowsize) * (tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
|
||||
pfUI.buff.debuffs:SetHeight(ceil(16/tonumber(C.buffs.rowsize)) * ((C.buffs.textinside == "1" and 0 or (fontsize*1.5))+tonumber(C.buffs.size)+2*tonumber(C.buffs.spacing)))
|
||||
pfUI.buff.debuffs:SetPoint("TOPRIGHT", pfUI.buff.buffs, "BOTTOMRIGHT", 0, 0)
|
||||
UpdateMovable(pfUI.buff.debuffs)
|
||||
|
||||
for i=1,32 do
|
||||
pfUI.buff:UpdateConfigBuffButton(pfUI.buff.buffs.buttons[i])
|
||||
end
|
||||
|
||||
for i=1,16 do
|
||||
pfUI.buff:UpdateConfigBuffButton(pfUI.buff.debuffs.buttons[i])
|
||||
end
|
||||
|
||||
pfUI.buff:GetScript("OnEvent")()
|
||||
end
|
||||
|
||||
pfUI.buff:UpdateConfig()
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user