View Single Post
10-29-08, 09:34 AM   #171
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
This should do it:
Code:
  
  --happiness table  
  
  local colors2 = {
    happiness = {
      [0] = {r = 1, g = 1, b = 1}, -- bla test
      [1] = {r = 1, g = 0, b = 0}, -- need.... | unhappy
      [2] = {r = 1, g = 1, b = 0}, -- new..... | content
      [3] = {r = 0, g = 1, b = 0}, -- colors.. | happy
    },
  }    
    
  --update health func
  
  local function updateHealth(self, event, unit, bar, min, max)
  
    local d = floor(min/max*100)
    local value = min/max
    
    local color, smooth_r, smooth_g, smooth_b
    
    -- gradient color        
    if(value > 0.5) then
      smooth_r = (1 - value) * 2
      smooth_g = 1
    else
      smooth_r = 1
      smooth_g = value * 2
    end
    smooth_b = 0
    
    --background color
    self.Health.bg:SetVertexColor(0.15,0.15,0.15,1)
    
    --if percentage = 100 
    if d == 100 then
    
      if UnitIsPlayer(unit) then
        if RAID_CLASS_COLORS[select(2, UnitClass(unit))] then
          color = RAID_CLASS_COLORS[select(2, UnitClass(unit))]
        end
      elseif unit == "pet" and UnitExists("pet") and GetPetHappiness() then
        local happiness, _, _ = GetPetHappiness()
        color = colors2.happiness[happiness]
      else
        color = FACTION_BAR_COLORS[UnitReaction(unit, "player")]
      end
      
      if color then
        self.Health:SetStatusBarColor(color.r,color.g,color.b)
        self.Name:SetTextColor(color.r,color.g,color.b)
        bar.value:SetTextColor(color.r,color.g,color.b)  
      end
    
    --if percentage < 100
    else
      self.Health:SetStatusBarColor(smooth_r,smooth_g,smooth_b)
      self.Name:SetTextColor(smooth_r,smooth_g,smooth_b)
      bar.value:SetTextColor(smooth_r,smooth_g,smooth_b)
      
    end
    
    --set hp value
    bar.value:SetText(d.."%")
  
  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-29-08 at 09:46 AM.