Quantcast
SecureAuraHeaderTemplate - WoWInterface
 
Thread Tools Display Modes
02-15-16, 12:49 PM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,289
SecureAuraHeaderTemplate

I was experimenting to update secure aura headers without the "UNIT_AURA" event and without updating every auras every time unnecessary.

I came up with this:

Lua Code:
  1. buff:SetScript("OnAttributeChanged", function(self, name, value)
  2.     if name == "index" then
  3.         --print(self:GetName(), name, value)
  4.         if value then
  5.             local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, shouldConsolidate, spellId, canApplyAura, isBossDebuff, isCastByPlayer = UnitAura(self.unit, value, buff.filter)
  6.             if self.index ~= value or self.spellId ~= spellId or self.count ~= count or self.expirationTime ~= expirationTime then
  7.                 if self.index ~= value then
  8.                     print("INDEX", name, self.index, value)
  9.                 elseif self.spellId ~= spellId then
  10.                     print("ID", value, name, self.spellId, spellId)
  11.                 elseif self.count ~= count then
  12.                     print("COUNT", value, name, self.count, count)
  13.                 elseif self.expirationTime ~= expirationTime then
  14.                     print("EXP", value, name, self.expirationTime, expirationTime)
  15.                 end
  16.  
  17.                 if type(module.UpdateBuff) == "function" then
  18.                     module:UpdateBuff(self, value)
  19.                 end
  20.             end
  21.         else
  22.             self.index = nil
  23.             self.spellId = nil
  24.             self.count = nil
  25.             self.expirationTime = nil
  26.         end
  27.     end
  28. end)

With this method only the changed buffs are gonna get updated and it will leave out the ones which did not changed, so you can save a lot of unnecessary calls. You only need to do a full force update when you: on a loading screen, or when the unit attribute changes.

So what do you guys think could this be a valid solution?

Last edited by Resike : 02-16-16 at 05:25 AM.
  Reply With Quote
02-16-16, 03:12 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,739
What is triggering the index change?
Does this work if you refresh an aura?
Does this work if you refresh an aura and only have one aura active?
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
02-16-16, 05:04 AM   #3
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,289
Originally Posted by zork View Post
What is triggering the index change?
Does this work if you refresh an aura?
Does this work if you refresh an aura and only have one aura active?
Well you save the checked values in the UpdateBuff function, or you nil them when the buff fades/expires/not exists.

For some reason by default the aura header template updates every buffs on every attribute chanes unlike the group headers, and thats the real issue here. And the UNIT_AURA event doesn't give any valid information about which buffs you should update, so you are kinda forced to update everything there too.

It works on pretty much any buff changes/refresh because of the index/spellID/expirationTime checker.
Additional checkers can be added too, there are just the basic ones, like unitCaster and isCastByPlayer could be usefull too, if someone cast the same buff on you without expiration time, to the same index.

The good thing about this, it skips any unchanges or static buffs, that you did not changed or refreshed.

Last edited by Resike : 02-16-16 at 05:08 AM.
  Reply With Quote
02-16-16, 07:06 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,739
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?
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
02-16-16, 07:27 AM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,289
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
02-16-16, 09:36 AM   #6
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,739
No it is not misleading. I'm just trying to understand what is triggering attribute change. Gonna play around with it myself later.

I think I found what I was looking for:
https://github.com/tekkub/wow-ui-sou...aders.lua#L668

Using the template registers UNIT_AURA.

Have you read this post from sigg?
http://www.wowinterface.com/forums/s...ad.php?t=36117

Btw make sure you implement the cancelaura stuff only for player unit.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 02-16-16 at 09:50 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SecureAuraHeaderTemplate

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off