View Single Post
10-06-09, 07:37 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
This can be done.

Adjust this function with a color calculation: d3o2_updatePlayerHealth

Fully OK (100%) = green color.
Green color is in RGB = 0,1,0

Nearly dead = red color.
Red color is in RGB = 1,0,0

Thus:
Code:
    local calc_perc = min/max
    local calc_red
    local calc_green
    
    -- 100% = 0,1,0
    -- 75%  = 0.5,1,0
    -- 50%  = 1,1,0
    -- 25%  = 1,0.5,0
    -- 0%   = 1,0,0
    
    if calc_perc >= 0.5 then
      calc_green = 1
    else
      calc_green = calc_perc*2
    end
    
    if calc_perc <= 0.5 then
      calc_red = 1
    else
      calc_red = (1-calc_perc)*2
    end   
Now lets apply the color to the orb:
Code:
--colorize the orb filling
self.Health.Filling:SetVertexColor(calc_red,calc_green,0,1)
--add color to the galaxies aswell
self.gal1:SetVertexColor(calc_red,calc_green,0,1)
self.gal2:SetVertexColor(calc_red,calc_green,0,1)
self.gal3:SetVertexColor(calc_red,calc_green,0,1)
Final function could look like:

Code:
  --update player health func
  local function d3o2_updatePlayerHealth(self, event, unit, bar, min, max)
    local d = floor(min/max*100)
    self.Health.Filling:SetHeight((min / max) * self.Health:GetWidth())
    self.Health.Filling:SetTexCoord(0,1,  math.abs(min / max - 1),1)
    if useglow == 1 then
      self.pm1:SetAlpha((min/max)/fog_smoother)
      self.pm2:SetAlpha((min/max)/fog_smoother)
    end
    if usegalaxy == 1 then
      self.gal1:SetAlpha(min/max)
      self.gal2:SetAlpha(min/max)
      self.gal3:SetAlpha(min/max)
    end
    if d <= 25 and min > 1 then
      self.LowHP:Show()
    else
      self.LowHP:Hide()
    end
    
    local calc_perc = min/max
    local calc_red
    local calc_green
    
    -- 100% = 0,1,0
    -- 75%  = 0.5,1,0
    -- 50%  = 1,1,0
    -- 25%  = 1,0.5,0
    -- 0%   = 1,0,0
    
    if calc_perc >= 0.5 then
      calc_green = 1
    else
      calc_green = calc_perc*2
    end
    
    if calc_perc <= 0.5 then
      calc_red = 1
    else
      calc_red = (1-calc_perc)*2
    end    
    
    --colorize the orb filling
    self.Health.Filling:SetVertexColor(calc_red,calc_green,0,1)
    --add color to the galaxies aswell
    self.gal1:SetVertexColor(calc_red,calc_green,0,1)
    self.gal2:SetVertexColor(calc_red,calc_green,0,1)
    self.gal3:SetVertexColor(calc_red,calc_green,0,1)
    
  end
__________________
| 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 : 10-06-09 at 07:58 AM.
  Reply With Quote