Thread Tools Display Modes
05-03-13, 06:05 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
TotalAbsorb Element

Has anyone worked with this yet?
http://www.wowpedia.org/API_UnitGetTotalAbsorbs

EVENT: UNIT_ABSORB_AMOUNT_CHANGED

I wrote an oUF element. Not sure how we can fit that in to work with healprediction though. Currently both anchor on self.Health:GetStatusBarTexture().

Lua Code:
  1. --[[ Element: TotalAbsorb Bar
  2.  
  3.   Handle updating and visibility of the total absorb status bars.
  4.  
  5.   Widget
  6.  
  7.     TotalAbsorb - A statusbar
  8.  
  9.   Notes
  10.  
  11.     The default StatusBar texture will be applied if the UI widget does not have a
  12.     status bar texture or color defined.
  13.  
  14.   Options
  15.  
  16.     .maxOverflow - Defines the maximum amount of overflow past the end of the
  17.                    health bar.
  18.  
  19.   Examples
  20.  
  21.     -- Position and size
  22.     local absorbBar = CreateFrame('StatusBar', nil, self.Health)
  23.     absorbBar:SetPoint('TOP')
  24.     absorbBar:SetPoint('BOTTOM')
  25.     absorbBar:SetPoint('LEFT', self.Health:GetStatusBarTexture(), 'RIGHT')
  26.     absorbBar:SetWidth(200)
  27.     absorbBar.maxOverflow = 1.05
  28.  
  29.     -- Register with oUF
  30.     self.TotalAbsorb = absorbBar
  31.  
  32.  
  33.   Hooks
  34.  
  35.   Override(self) - Used to completely override the internal update function.
  36.                    Removing the table key entry will make the element fall-back
  37.                    to its internal function again.
  38. ]]
  39.  
  40. local _, ns = ...
  41. local oUF = ns.oUF
  42.  
  43. local function Update(self, event, unit)
  44.   if(self.unit ~= unit) then return end
  45.  
  46.   local ta = self.TotalAbsorb
  47.   if(ta.PreUpdate) then ta:PreUpdate(unit) end
  48.  
  49.   local allAbsorbs = UnitGetTotalAbsorbs(unit) or 0
  50.   local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
  51.  
  52.   if(health + allAbsorbs > maxHealth * ta.maxOverflow) then
  53.     allAbsorbs = maxHealth * ta.maxOverflow - health
  54.   end
  55.  
  56.   ta:SetMinMaxValues(0, maxHealth)
  57.   ta:SetValue(allAbsorbs)
  58.   ta:Show()
  59.  
  60.   if(ta.PostUpdate) then
  61.     return ta:PostUpdate(unit)
  62.   end
  63. end
  64.  
  65. local function Path(self, ...)
  66.   return (self.TotalAbsorb.Override or Update) (self, ...)
  67. end
  68.  
  69. local ForceUpdate = function(element)
  70.   return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
  71. end
  72.  
  73. local function Enable(self)
  74.   local ta = self.TotalAbsorb
  75.   if(ta) then
  76.     ta.__owner = self
  77.     ta.ForceUpdate = ForceUpdate
  78.  
  79.     self:RegisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path)
  80.     self:RegisterEvent('UNIT_MAXHEALTH', Path)
  81.     self:RegisterEvent('UNIT_HEALTH', Path)
  82.  
  83.     if(not ta.maxOverflow) then
  84.       ta.maxOverflow = 1.05
  85.     end
  86.  
  87.     if(ta and ta:IsObjectType'StatusBar' and not ta:GetStatusBarTexture()) then
  88.       ta:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
  89.     end
  90.  
  91.     return true
  92.   end
  93. end
  94.  
  95. local function Disable(self)
  96.   local ta = self.TotalAbsorb
  97.   if(ta) then
  98.     self:UnregisterEvent('UNIT_ABSORB_AMOUNT_CHANGED', Path)
  99.     self:UnregisterEvent('UNIT_MAXHEALTH', Path)
  100.     self:UnregisterEvent('UNIT_HEALTH', Path)
  101.   end
  102. end
  103.  
  104. oUF:AddElement('TotalAbsorb', Path, Enable, Disable)

spawn
Lua Code:
  1. -- Bar
  2.     local absorbBar = CreateFrame('StatusBar', nil, self.Health)
  3.     absorbBar:SetPoint('TOP')
  4.     absorbBar:SetPoint('BOTTOM')
  5.     absorbBar:SetPoint('LEFT', self.Health:GetStatusBarTexture(), 'RIGHT')
  6.     absorbBar:SetWidth(self.Health:GetWidth())
  7.     absorbBar.maxOverflow = 1.05
  8.  
  9.     -- Register with oUF
  10.     self.TotalAbsorb = absorbBar

*edit*

I tested the element. It is working properly. Added it to my layout.
http://code.google.com/p/rothui/sour...otalAbsorb.lua

__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

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

Last edited by zork : 05-03-13 at 11:45 AM.
  Reply With Quote
05-03-13, 11:40 AM   #2
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Good job, I think this should be part of oUF, too.




Btw, in case anyone wants a text (tag) based solution:

Code:
oUF.Tags.Methods['Absorb'] = function(unit)
	local absorb = UnitGetTotalAbsorbs(unit) or 0
	if absorb == 0 then
		return ' '
	else
		return "|CFFE8E35F"..absorb.."|r"				
	end
end
oUF.Tags.Events['Absorb'] = 'UNIT_ABSORB_AMOUNT_CHANGED'
This will also work for various units (using it on my raid/party frames) and output it as a number. You can also change the text color (E8E35F) by using hexcolor codes.

I'm formatting the value to display something like 117123 as 117k, instead. But left that part of the code out for simplicity reasons. Just mentioning it to show that it's easily possible to clean up the output.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
05-03-13, 08:02 PM   #3
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
It's already done: https://github.com/haste/oUF/pull/176 But it's rather a rework of the heal prediction element as the default ui anchors heal pred to the health bar texture and the absorbs to the heal pred texture. Also same events are used. The problem is that it is an api breakage, so it won't be included in the 1.6 branch. The use of the same code (with some really minor diffences) from a layout can be seen here. Adding the element is here.

Last edited by Rainrider : 05-03-13 at 08:09 PM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » TotalAbsorb Element


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