performance: rewrite of buff.lua

This commit is contained in:
shagu
2016-10-05 22:52:28 +02:00
parent 24112825de
commit e54e4ff631
+82 -97
View File
@@ -1,70 +1,52 @@
pfUI:RegisterModule("buff", function ()
pfUI.buff = CreateFrame("Frame")
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 ()
pfUI.buff:UpdateSkin()
end)
-- weapon enchant (main hand)
pfUI.buff.mainHand = CreateFrame("Frame", nil, UIParent)
pfUI.buff.mainHand.stacks = pfUI.buff.mainHand:CreateFontString(nil, "OVERLAY", "GameFontNormal")
pfUI.buff.mainHand.stacks:SetFont(STANDARD_TEXT_FONT, 14, "OUTLINE")
pfUI.buff.mainHand.stacks:SetTextColor(1,1,1,1)
pfUI.buff.mainHand.stacks:ClearAllPoints()
pfUI.buff.mainHand.stacks:SetPoint("TOPLEFT", pfUI.buff.mainHand ,"TOPLEFT", 2, -2)
pfUI.buff.mainHand.stacks:SetPoint("BOTTOMRIGHT", pfUI.buff.mainHand ,"BOTTOMRIGHT", -2, 2)
pfUI.buff.mainHand.stacks:SetJustifyH("RIGHT")
pfUI.buff.mainHand.stacks:SetJustifyV("BOTTOM")
-- weapon enchant stacks
TempEnchant1.stacks = TempEnchant1:CreateFontString(nil, "OVERLAY", "GameFontNormal")
TempEnchant1.stacks:SetFont(STANDARD_TEXT_FONT, 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(STANDARD_TEXT_FONT, 14, "OUTLINE")
TempEnchant2.stacks:SetTextColor(1,1,1,1)
TempEnchant2.stacks:ClearAllPoints()
TempEnchant2.stacks:SetAllPoints(TempEnchant2)
TempEnchant2.stacks:SetJustifyH("RIGHT")
TempEnchant2.stacks:SetJustifyV("BOTTOM")
-- weapon enchant (off hand)
pfUI.buff.offHand = CreateFrame("Frame", nil, UIParent)
pfUI.buff.offHand.stacks = pfUI.buff.offHand:CreateFontString(nil, "OVERLAY", "GameFontNormal")
pfUI.buff.offHand.stacks:SetFont(STANDARD_TEXT_FONT, 14, "OUTLINE")
pfUI.buff.offHand.stacks:SetTextColor(1,1,1,1)
pfUI.buff.offHand.stacks:ClearAllPoints()
pfUI.buff.offHand.stacks:SetPoint("TOPLEFT", pfUI.buff.offHand ,"TOPLEFT", 2, -2)
pfUI.buff.offHand.stacks:SetPoint("BOTTOMRIGHT", pfUI.buff.offHand ,"BOTTOMRIGHT", -2, 2)
pfUI.buff.offHand.stacks:SetJustifyH("RIGHT")
pfUI.buff.offHand.stacks:SetJustifyV("BOTTOM")
-- hook buff update
if not Hook_BuffButton_OnUpdate then
Hook_BuffButton_OnUpdate = BuffButton_OnUpdate
end
function BuffButton_OnUpdate (arg1)
TemporaryEnchantFrame:ClearAllPoints()
TemporaryEnchantFrame:SetPoint("TOPRIGHT", pfUI.minimap, "TOPLEFT", -25,0)
local buff = this
local icon = getglobal(buff:GetName().."Icon");
local border = getglobal(buff:GetName().."Border")
if border then
buff:SetBackdrop({
bgFile = icon:GetTexture(), tile = false, tileSize = 16,
edgeFile = "Interface\\AddOns\\pfUI\\img\\border_col", edgeSize = 8,
insets = { left = 0, right = 0, top = 0, bottom = 0}
})
buff:SetBackdropBorderColor(border:GetVertexColor())
border:Hide()
else
buff:SetBackdrop({
bgFile = icon:GetTexture(), tile = false, tileSize = 16,
edgeFile = "Interface\\AddOns\\pfUI\\img\\border", edgeSize = 8,
insets = { left = 0, right = 0, top = 0, bottom = 0}
})
-- 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
end
Hook_BuffButton_OnUpdate(arg1)
end
if pfUI.buff.updateInterval > 10 then
pfUI.buff:Hide()
end
end)
-- hook weapon update
if not Hook_BuffFrame_Enchant_OnUpdate then
Hook_BuffFrame_Enchant_OnUpdate = BuffFrame_Enchant_OnUpdate
end
function BuffFrame_Enchant_OnUpdate (arg1)
function pfUI.buff:UpdateSkin()
-- buff positions
TemporaryEnchantFrame:ClearAllPoints()
TemporaryEnchantFrame:SetPoint("TOPRIGHT", pfUI.minimap, "TOPLEFT", -25,0)
for _,frame in pairs ({TempEnchant1,TempEnchant2}) do
local buff = frame
-- weapon enchants
for _,buff in pairs ({TempEnchant1,TempEnchant2}) do
local icon = getglobal(buff:GetName().."Icon");
local border = getglobal(buff:GetName().."Border")
local _, _, mainhand, _, _, offhand = GetWeaponEnchantInfo()
@@ -78,49 +60,52 @@ pfUI:RegisterModule("buff", function ()
border:Hide()
end
if mainhand then
if buff:GetID() == 16 then
local link = GetInventoryItemLink("player", 16)
local _, _, itemLink = string.find(link, "(item:%d+:%d+:%d+:%d+)");
local _, _, itemRarity, itemLevel, _, _, _, itemEquipLoc, _ = GetItemInfo(itemLink)
if buff:GetID() == 16 then
local link = GetInventoryItemLink("player", 16)
local _, _, itemLink = string.find(link, "(item:%d+:%d+:%d+:%d+)");
local _, _, itemRarity, itemLevel, _, _, _, itemEquipLoc, _ = GetItemInfo(itemLink)
if itemRarity then buff:SetBackdropBorderColor(GetItemQualityColor(itemRarity)) end
if itemRarity then
buff:SetBackdropBorderColor(GetItemQualityColor(itemRarity))
end
if mainhand > 0 then
pfUI.buff.mainHand.stacks:SetText(mainhand)
pfUI.buff.mainHand:SetAllPoints(buff)
pfUI.buff.mainHand:Show()
else
pfUI.buff.mainHand:Hide()
end
if mainhand and mainhand > 0 then
buff.stacks:SetText(mainhand)
buff.stacks:Show()
else
buff.stacks:Hide()
end
else
pfUI.buff.mainHand:Hide()
end
if offhand then
if buff:GetID() == 17 then
local link = GetInventoryItemLink("player", 17)
local _, _, itemLink = string.find(link, "(item:%d+:%d+:%d+:%d+)");
local _, _, itemRarity, itemLevel, _, _, _, itemEquipLoc, _ = GetItemInfo(itemLink)
if itemRarity then
buff:SetBackdropBorderColor(GetItemQualityColor(itemRarity))
end
if offhand > 0 then
pfUI.buff.offHand.stacks:SetText(offhand)
pfUI.buff.offHand:SetAllPoints(buff)
pfUI.buff.offHand:Show()
else
pfUI.buff.offHand:Hide()
end
elseif buff:GetID() == 17 then
local link = GetInventoryItemLink("player", 17)
local _, _, itemLink = string.find(link, "(item:%d+:%d+:%d+:%d+)");
local _, _, itemRarity, itemLevel, _, _, _, itemEquipLoc, _ = GetItemInfo(itemLink)
if itemRarity then buff:SetBackdropBorderColor(GetItemQualityColor(itemRarity)) end
if offhand and offhand > 0 then
buff.stacks:SetText(offhand)
buff.stacks:Show()
else
buff.stacks:Hide()
end
else
pfUI.buff.offHand:Hide()
end
end
Hook_BuffFrame_Enchant_OnUpdate(arg1)
-- buffs
for i=0,15,1 do
local buff = getglobal("BuffButton" .. i)
local icon = getglobal(buff:GetName().."Icon");
local border = getglobal(buff:GetName().."Border")
if border then
buff:SetBackdrop({
bgFile = icon:GetTexture(), tile = false, tileSize = 16,
edgeFile = "Interface\\AddOns\\pfUI\\img\\border_col", edgeSize = 8,
insets = { left = 0, right = 0, top = 0, bottom = 0}
})
buff:SetBackdropBorderColor(border:GetVertexColor())
border:Hide()
else
buff:SetBackdrop({
bgFile = icon:GetTexture(), tile = false, tileSize = 16,
edgeFile = "Interface\\AddOns\\pfUI\\img\\border", edgeSize = 8,
insets = { left = 0, right = 0, top = 0, bottom = 0}
})
end
end
end
end)