Advertisement
Guest User

Coldkil - lib.lua

a guest
Jul 3rd, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.06 KB | None | 0 0
  1. local FormatTime = function(s)
  2.     local day, hour, minute = 86400, 3600, 60
  3.     if s >= day then
  4.         return format("%dd", ceil(s / day))
  5.     elseif s >= hour then
  6.         return format("%dh", ceil(s / hour))
  7.     elseif s >= minute then
  8.         return format("%dm", ceil(s / minute))
  9.     elseif s >= minute / 12 then
  10.         return floor(s)
  11.     end
  12.     return format("%.1f", s)
  13. end
  14.  
  15. local CreateAuraTimer = function(self, elapsed)
  16.     if self.timeLeft then
  17.         self.elapsed = (self.elapsed or 0) + elapsed
  18.         if self.elapsed >= 0.1 then
  19.             if not self.first then
  20.                 self.timeLeft = self.timeLeft - self.elapsed
  21.             else
  22.                 self.timeLeft = self.timeLeft - GetTime()
  23.                 self.first = false
  24.             end
  25.             if self.timeLeft > 0 then
  26.                 local time = FormatTime(self.timeLeft)
  27.                 self.remaining:SetText(time)
  28.                 if self.timeLeft <= 5 then
  29.                     self.remaining:SetTextColor(0.99, 0.31, 0.31)
  30.                 else
  31.                     self.remaining:SetTextColor(1, 1, 1)
  32.                 end
  33.             else
  34.                 self.remaining:Hide()
  35.                 self:SetScript("OnUpdate", nil)
  36.             end
  37.             self.elapsed = 0
  38.         end
  39.     end
  40. end
  41.  
  42. lib.PostCreateAura = function(element, button)
  43.     button:SetBackdrop(backdrop)
  44.     button:SetBackdropBorderColor(0,0,0)
  45.     button.remaining = lib.SetFontString(button, font, fs, "OUTLINE, MONOCHROME")
  46.     button.remaining:SetPoint("CENTER", 1, 0)
  47.    
  48.     button.cd.noOCC = true          -- hide OmniCC CDs
  49.     button.cd.noCooldownCount = true    -- hide CDC CDs
  50.    
  51.     button.cd:SetReverse()
  52.     button.icon:SetPoint("TOPLEFT", 1, -1)
  53.     button.icon:SetPoint("BOTTOMRIGHT", -1, 1)
  54.     button.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
  55.     button.icon:SetDrawLayer('ARTWORK')
  56.    
  57.     button.count:SetPoint("BOTTOMRIGHT", 2, 0)
  58.     button.count:SetJustifyH("RIGHT")
  59.     button.count:SetFont(font, fs, "OUTLINE, MONOCHROME")
  60.     button.count:SetTextColor(0, .8, 0)
  61.    
  62.     button.overlayFrame = CreateFrame("frame", nil, button, nil)
  63.     button.cd:SetFrameLevel(button:GetFrameLevel() + 1)
  64.     button.cd:ClearAllPoints()
  65.     button.cd:SetPoint("TOPLEFT", button, "TOPLEFT", 2, -2)
  66.     button.cd:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -2, 2)
  67.     button.cd:SetAlpha(0)
  68.     button.overlayFrame:SetFrameLevel(button.cd:GetFrameLevel() + 1)       
  69.     button.overlay:SetParent(button.overlayFrame)
  70.     button.count:SetParent(button.overlayFrame)
  71.     button.remaining:SetParent(button.overlayFrame)
  72. end
  73.  
  74. lib.PostUpdateAura = function(icons, unit, icon, index, offset, filter, isDebuff, duration, timeLeft)
  75.     local _, _, _, _, dtype, duration, expirationTime, unitCaster, _ = UnitAura(unit, index, icon.filter)
  76.  
  77.     if(icon.debuff) then
  78.         if(not UnitIsFriend("player", unit) and icon.owner ~= "player" and icon.owner ~= "vehicle") then
  79.             icon:SetBackdropBorderColor(.7, .7, .7)
  80.             icon.icon:SetDesaturated(true)
  81.         else
  82.             local color = DebuffTypeColor[dtype] or DebuffTypeColor.none
  83.             icon:SetBackdropBorderColor(color.r * 0.6, color.g * 0.6, color.b * 0.6)
  84.             icon.icon:SetDesaturated(false)
  85.         end
  86.     end
  87.    
  88.     if duration and duration > 0 then
  89.         icon.remaining:Show()
  90.     else
  91.         icon.remaining:Hide()
  92.     end
  93.  
  94.     icon.duration = duration
  95.     icon.timeLeft = expirationTime
  96.     icon.first = true
  97.     icon:SetScript("OnUpdate", CreateAuraTimer)
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement