View Single Post
02-16-16, 07:27 AM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by zork View Post
That is my point. When using the SecureAuraHeaderTemplate something is triggering an update on any aura attribute for you which makes is possible to have a script for OnAttributeChanged?
I'll give you a more detailed code example.

The attribute is not on the header frame, but on the frame which gets created BY the header frame (SecureActionButtonTemplate), and it has a index and filter attribute changes every time the unit's buffs get updated:

Lua Code:
  1. -- Buffs Header
  2.     frame.buffs = CreateFrame("Frame", "ZPerl2"..name.."BuffFrame", frame, "SecureAuraHeaderTemplate")
  3.     frame.buffs:SetPoint("TopLeft", frame, "BottomLeft", 4, -1)
  4.  
  5.     frame.buffs:SetAttribute("useparent-unit", true)
  6.     frame.buffs:SetAttribute("filter", "HELPFUL")
  7.     frame.buffs:SetAttribute("template", "SecureActionButtonTemplate")
  8.     frame.buffs:SetAttribute("minWidth", 24)
  9.     frame.buffs:SetAttribute("minHeight", 24)
  10.     frame.buffs:SetAttribute("separateOwn", 0)
  11.  
  12.     frame.buffs:SetAttribute("point", "TOPLEFT")
  13.     frame.buffs:SetAttribute("xOffset", 24)
  14.     frame.buffs:SetAttribute("yOffset", 0)
  15.     frame.buffs:SetAttribute("wrapAfter", 8)
  16.     frame.buffs:SetAttribute("wrapXOffset", 0)
  17.     frame.buffs:SetAttribute("wrapYOffset", -24)
  18.     frame.buffs:SetAttribute("maxWraps", 5)
  19.  
  20.     frame.buffs:SetAttribute("sortMethod", "INDEX") -- INDEX or NAME or TIME
  21.     frame.buffs:SetAttribute("sortDir", "+") -- - to reverse
  22.  
  23.     frame.buffs:SetAttribute("style-width", 24)
  24.     frame.buffs:SetAttribute("style-height", 24)
  25.     frame.buffs:SetAttribute("style-scale", 1)
  26.  
  27.     local function CreateBuffFrame(header, frameName)
  28.         local buff = _G[frameName]
  29.  
  30.         buff:RegisterForClicks("RightButtonUp")
  31.         --buff.unit = header:GetParent():GetAttribute("unit") or frame.unit
  32.         --buff.filter = "HELPFUL"
  33.  
  34.         buff.texture = buff:CreateTexture(nil, "Background")
  35.         buff.texture:SetAllPoints(buff)
  36.  
  37.         buff.cooldown = CreateFrame("Cooldown", nil, buff, "CooldownFrameTemplate")
  38.         buff.cooldown:SetReverse(true)
  39.         buff.cooldown:SetDrawEdge(false)
  40.         buff.cooldown:SetDrawBling(false)
  41.         -- Blizzard
  42.         buff.cooldown:SetHideCountdownNumbers(true)
  43.         -- OmniCC
  44.         buff.cooldown.noCooldownCount = true
  45.  
  46.         buff.cooldown:SetAllPoints(buff)
  47.  
  48.         buff.stack = buff:CreateFontString(nil, "Artwork")
  49.         buff.stack:SetFont("Fonts\\ARIALN.TTF", 9, "Outline")
  50.         buff.stack:SetPoint("BottomRight", buff, "BottomRight", 0, 2)
  51.         buff.stack:SetJustifyH("Center")
  52.         buff.stack:SetJustifyV("Center")
  53.         buff.stack:SetWordWrap(false)
  54.  
  55.         buff:SetScript("OnAttributeChanged", function(self, name, value)
  56.             --print(self:GetName(), name, value)
  57.             if name == "index" then
  58.                 --print(self:GetName(), name, value)
  59.                 if value then
  60.                     local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, shouldConsolidate, spellId, canApplyAura, isBossDebuff, isCastByPlayer = UnitAura(header:GetParent():GetAttribute("unit"), header:GetAttribute("filter"))
  61.                     if self.index ~= value or self.spellId ~= spellId or self.count ~= count or self.expirationTime ~= expirationTime then
  62.                         --[[if self.index ~= value then
  63.                             print("INDEX", name, self.index, value)
  64.                         elseif self.spellId ~= spellId then
  65.                             print("ID", value, name, self.spellId, spellId)
  66.                         elseif self.count ~= count then
  67.                             print("COUNT", value, name, self.count, count)
  68.                         elseif self.expirationTime ~= expirationTime then
  69.                             print("EXP", value, name, self.expirationTime, expirationTime)
  70.                         end]]
  71.  
  72.                         if type(module.UpdateBuff) == "function" then
  73.                             module:UpdateBuff(self, value)
  74.                         end
  75.                     end
  76.                 else
  77.                     self.index = nil
  78.                     self.spellId = nil
  79.                     self.count = nil
  80.                     self.expirationTime = nil
  81.                 end
  82.             end
  83.         end)
  84.  
  85.         buff:SetScript("OnEnter", function(self)
  86.             GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
  87.             GameTooltip:SetFrameLevel(self:GetFrameLevel() + 2)
  88.             local s = self.slotID or 0
  89.             if s == 16 or s == 17 then
  90.                 GameTooltip:SetInventoryItem(header:GetParent():GetAttribute("unit"), s)
  91.             else
  92.                 GameTooltip:SetUnitAura(header:GetParent():GetAttribute("unit"), self:GetID(), header:GetAttribute("filter"))
  93.             end
  94.  
  95.             self:SetScript("OnUpdate", function(self, elapsed)
  96.                 self.time = (self.time or 0) + elapsed
  97.                 if self.time < 0.5 then
  98.                     return
  99.                 end
  100.                 self.time = 0
  101.  
  102.                 if GameTooltip:IsOwned(self) then
  103.                     local s = self.slotID or 0
  104.                     if s == 16 or s == 17 or s == 18 then
  105.                         GameTooltip:SetInventoryItem(header:GetParent():GetAttribute("unit"), s)
  106.                     else
  107.                         GameTooltip:SetUnitAura(header:GetParent():GetAttribute("unit"), self:GetID(), header:GetAttribute("filter"))
  108.                     end
  109.                 end
  110.             end)
  111.         end)
  112.         buff:SetScript("OnLeave", function(self)
  113.             self:SetScript("OnUpdate", nil)
  114.             GameTooltip:Hide()
  115.         end)
  116.  
  117.         return buff
  118.     end
  119.  
  120.     frame.buffs:SetAttribute("initialConfigFunction", [[
  121.         local header = self:GetParent()
  122.  
  123.         self:SetHeight(header:GetAttribute("style-height"))
  124.         self:SetWidth(header:GetAttribute("style-width"))
  125.         self:SetScale(header:GetAttribute("style-scale"))
  126.  
  127.         self:SetAttribute("type2", "cancelaura")
  128.  
  129.         self:SetAttribute("isHeaderDriven", true)
  130.  
  131.         header:CallMethod("initialConfigFunction", self:GetName())
  132.     ]])
  133.  
  134.     frame.buffs.initialConfigFunction = CreateBuffFrame
  135.  
  136.     frame.buffs:Show()

It looks kinky to create so many functions for every buffs, but even in a 5 man party we are talking about 400 unit and 400 potential pet buffs and god knows how many UNIT_AURA triggers. And for my initial test this method is better performace wise.

Maybe the thread's name is missleading. My bad.

Last edited by Resike : 02-16-16 at 07:42 AM.
  Reply With Quote