Thread Tools Display Modes
11-19-10, 06:09 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
How to prevent self.Health.bg from shining through in raid

If a raid unit is out of range and you are using bright backgrounds the background will shine through and the whole frame will glow in light background color.

Example:


You can prevent this with two textures and some math.

createHealth
lua Code:
  1. --create health frames
  2. local createHealthFrame = function(self)
  3.  
  4.   -- health statusbar
  5.   local h = CreateFrame("StatusBar", nil, self)
  6.   h:SetAllPoints(self)
  7.   h:SetStatusBarTexture("") --use transparent texture
  8.   --save the width of the healthbar, important for later
  9.   h.w = self:GetWidth()
  10.  
  11.   --new bg texture
  12.   local t = h:CreateTexture(nil,"BACKGROUND",nil,-6)
  13.   t:SetPoint("TOPRIGHT",h,"TOPRIGHT",0,0)
  14.   t:SetPoint("BOTTOMRIGHT",h,"BOTTOMRIGHT",0,0)
  15.   t:SetWidth(0.01)
  16.   t:SetTexture(self.cfg.health.texture)
  17.   h.back = t
  18.  
  19.   --new fake statusbar
  20.   local n = h:CreateTexture(nil,"BACKGROUND",nil,-6)
  21.   n:SetPoint("TOPLEFT",h,"TOPLEFT",0,0)
  22.   n:SetPoint("BOTTOMLEFT",h,"BOTTOMLEFT",0,0)
  23.   n:SetPoint("RIGHT", t, "LEFT", 0, 0) --right point of n will anchor left point of t
  24.   n:SetTexture(self.cfg.health.texture)
  25.   h.new = n
  26.  
  27.   h.new:SetVertexColor(0.15,0.15,0.15,1)
  28.   h.back:SetVertexColor(1,0,0,1)
  29.  
  30.   self.Health = h
  31.  
  32. end

postUpdateHealth
lua Code:
  1. --post update health func
  2. local postUpdateHealth = function(bar, unit, min, max)
  3.  
  4.   local d = floor(min/max*100)
  5.  
  6.   --apply bar width
  7.   if d == 100 then
  8.     bar.back:SetWidth(0.01) --fix (0) makes the bar go anywhere
  9.   elseif d < 100 then
  10.     local w = bar.w
  11.     bar.back:SetWidth(w-(w*d/100)) --calc new width of bar based on size of healthbar
  12.   end
  13.  
  14. end

Result:
__________________
| 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 : 11-19-10 at 06:15 AM.
  Reply With Quote
11-19-10, 07:29 AM   #2
drakull
A Cyclonian
 
drakull's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 49
Good solution, thanks for sharing it! I can see a couple of other uses for this fix.

This is the solution I came up with, change bg's color when not in range:

lua Code:
  1. -- Create health bar
  2. lib.addHealthBar = function(self)
  3.     local health = CreateFrame('StatusBar', nil, self)
  4.     health:SetStatusBarTexture(cfg.statusbar)
  5.     health:GetStatusBarTexture():SetHorizTile(true)
  6.     health:SetStatusBarColor(42/255,48/255,50/255)
  7.  
  8.     local healthBG = health:CreateTexture(nil, 'BORDER')
  9.     healthBG:SetAllPoints(health)
  10.     healthBG:SetTexture(cfg.statusbar)
  11.     healthBG:SetVertexColor(1, 0.1, 0.1,1)
  12.     health.bg = healthBG
  13.  
  14.     self.Health = health
  15. end
  16.  
  17. -- Health Post Update
  18. lib.PostUpdateRaidFrame = function(Health, unit, min, max)
  19.     if not UnitInRange(unit) then
  20.         Health.bg:SetVertexColor(0.6, 0.3, 0.3,1)
  21.     else
  22.         Health.bg:SetVertexColor(1, 0.1, 0.1,1)
  23.     end
  24. end

Not so classy, but works.

Last edited by drakull : 11-19-10 at 07:52 AM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » How to prevent self.Health.bg from shining through in raid


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