Advertisement
Guest User

castbar

a guest
Dec 10th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.04 KB | None | 0 0
  1. -- init + holder
  2. local addon, ns = ...
  3. local cfg = ns.cfg
  4. local castbar = CreateFrame('Frame')  
  5.  
  6. local channelingTicks = {
  7.     -- warlock
  8.     [GetSpellInfo(1120)] = 5, -- drain soul
  9.     [GetSpellInfo(689)] = 5, -- drain life
  10.     [GetSpellInfo(5740)] = 4, -- rain of fire
  11.     [GetSpellInfo(79268)] = 4, -- soul harvest
  12.     -- druid
  13.     [GetSpellInfo(740)] = 4, -- Tranquility
  14.     [GetSpellInfo(16914)] = 10, -- Hurricane
  15.     -- priest
  16.     [GetSpellInfo(15407)] = 3, -- mind flay
  17.     [GetSpellInfo(48045)] = 5, -- mind sear
  18.     [GetSpellInfo(47540)] = 2, -- penance
  19.     -- mage
  20.     [GetSpellInfo(5143)] = 5, -- arcane missiles
  21.     [GetSpellInfo(10)] = 5, -- blizzard
  22.     [GetSpellInfo(12051)] = 4, -- evocation
  23.     -- shaman
  24.     [GetSpellInfo(61882)] = 8 -- earthquake
  25. }
  26.  
  27. local ticks = {}
  28.  
  29. castbar.setBarTicks = function(castBar, ticknum)
  30.     if ticknum and ticknum > 0 then
  31.         local delta = castBar:GetWidth() / ticknum
  32.         for k = 1, ticknum do
  33.             if not ticks[k] then
  34.                 ticks[k] = castBar:CreateTexture(nil, 'OVERLAY')
  35.                 ticks[k]:SetTexture(cfg.TexturePower)
  36.                 ticks[k]:SetBlendMode('ADD')
  37.                 ticks[k]:SetVertexColor(1, 1, 1, 1)
  38.                 ticks[k]:SetHeight(castBar:GetHeight())
  39.                 ticks[k]:SetWidth(2)
  40.             end
  41.             ticks[k]:ClearAllPoints()
  42.             ticks[k]:SetPoint('CENTER', castBar, 'LEFT', delta * k, 0 )
  43.             ticks[k]:Show()
  44.         end
  45.     else
  46.         for k, v in pairs(ticks) do
  47.             v:Hide()
  48.         end
  49.     end
  50. end
  51.  
  52. -- Castbar
  53. function addCastbar(self)
  54.     self.Castbar = CreateFrame('StatusBar', 'PlayerCastbar', self)
  55.     self.Castbar:SetHeight(16)
  56.     self.Castbar:SetWidth(self:GetWidth() - 21)
  57.     if (self.Style == 'player') then
  58.         self.Castbar:SetPoint('BOTTOMRIGHT', self.Power, 'TOPRIGHT', 0, 6)
  59.     else
  60.         self.Castbar:SetPoint('BOTTOMRIGHT', self.Power, 'TOPRIGHT', 10, 6)
  61.     end
  62.     self.Castbar:SetStatusBarTexture(cfg.TexturePower)
  63.     self.Castbar:SetStatusBarColor(95/255, 182/255, 255/255, 1)
  64.     self.Castbar:SetFrameLevel(9)
  65.     self.Castbar.CastingColor = {95/255, 182/255, 255/255}
  66.     self.Castbar.CompleteColor = {20/255, 208/255, 0/255}
  67.     self.Castbar.FailColor = {255/255, 12/255, 0/255}
  68.     self.Castbar.ChannelingColor = {95/255, 182/255, 255/255}
  69.     -- Helper
  70.     self.Castbar.Helper = CreateFrame('Frame', nil, self.Castbar)
  71.     self.Castbar.Helper:SetFrameLevel(8)
  72.     self.Castbar.Helper:SetPoint('TOPLEFT', -5, 5)
  73.     self.Castbar.Helper:SetPoint('BOTTOMRIGHT', 5, -5)
  74.     self.Castbar.Helper:SetBackdrop(cfg.TextureHelper);
  75.     self.Castbar.Helper:SetBackdropColor(0, 0, 0, 0.6)
  76.     self.Castbar.Helper:SetBackdropBorderColor(0, 0, 0, 1)
  77.     -- Spark
  78.     self.Castbar.Spark = self.Castbar:CreateTexture(nil, 'OVERLAY')
  79.     self.Castbar.Spark:SetBlendMode('ADD')
  80.     self.Castbar.Spark:SetVertexColor(1, 1, 1, 1)
  81.     self.Castbar.Spark:SetHeight(self.Castbar:GetHeight() * 2.5)
  82.     self.Castbar.Spark:SetWidth(self.Castbar:GetWidth() / 18)
  83.     -- Spell Text
  84.     self.Castbar.Text = self.Castbar:CreateFontString(nil, 'OVERLAY')
  85.     self.Castbar.Text:SetFont(cfg.FontNeuro, 16, 'THINOUTLINE')
  86.     self.Castbar.Text:SetShadowColor(0, 0, 0, 0.8)
  87.     self.Castbar.Text:SetShadowOffset(1, -1)
  88.     self.Castbar.Text:SetPoint('LEFT', 2, 10)
  89.     self.Castbar.Text:SetJustifyH('LEFT')
  90.     -- Spell Time
  91.     self.Castbar.Time = self.Castbar:CreateFontString(nil, 'OVERLAY')
  92.     self.Castbar.Time:SetFont(cfg.FontNeuro, 12, 'THINOUTLINE')
  93.     self.Castbar.Time:SetShadowColor(0, 0, 0, 0.8)
  94.     self.Castbar.Time:SetShadowOffset(1, -1)
  95.     self.Castbar.Time:SetPoint('RIGHT', -2, 1)
  96.     -- Icon
  97.     self.Castbar.Icon = self.Castbar:CreateTexture(nil, 'ARTWORK')
  98.     self.Castbar.Icon:SetSize(24, 24)
  99.     self.Castbar.Icon:SetPoint('BOTTOMRIGHT', self.Castbar, 'BOTTOMLEFT', -6, 0)
  100.     self.Castbar.Icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
  101.     -- Helper for Icon
  102.     self.Castbar.IconHelper = CreateFrame('Frame', nil, self.Castbar)
  103.     self.Castbar.IconHelper:SetFrameLevel(8)
  104.     self.Castbar.IconHelper:SetPoint('TOPLEFT', self.Castbar.Icon, 'TOPLEFT', -5, 5)
  105.     self.Castbar.IconHelper:SetPoint('BOTTOMRIGHT', self.Castbar.Icon, 'BOTTOMRIGHT', 5, -5)
  106.     self.Castbar.IconHelper:SetBackdrop(cfg.TextureHelper);
  107.     self.Castbar.IconHelper:SetBackdropColor(0, 0, 0, 1)
  108.     self.Castbar.IconHelper:SetBackdropBorderColor(0, 0, 0, 0.8)
  109.     if (self.Style == 'player') then
  110.         -- Latency
  111.         self.Castbar.SafeZone = self.Castbar:CreateTexture(nil, 'OVERLAY')
  112.         self.Castbar.SafeZone:SetTexture(cfg.TexturePower)
  113.         self.Castbar.SafeZone:SetVertexColor(1, 0.1, 0, 0.6)
  114.         self.Castbar.SafeZone:SetPoint('TOPRIGHT')
  115.         self.Castbar.SafeZone:SetPoint('BOTTOMRIGHT')
  116.     end
  117.     -- Register Events
  118.     self:RegisterEvent('UNIT_SPELLCAST_SENT', castbar.OnCastSent)
  119.     self.Castbar.OnUpdate = castbar.OnCastbarUpdate
  120.     self.Castbar.PostCastStart = castbar.PostCastStart
  121.     self.Castbar.PostChannelStart = castbar.PostCastStart
  122.     self.Castbar.PostCastStop = castbar.PostCastStop
  123.     self.Castbar.PostChannelStop = castbar.PostChannelStop
  124.     self.Castbar.PostCastFailed = castbar.PostCastFailed
  125.     self.Castbar.PostCastInterrupted = castbar.PostCastFailed
  126. end
  127.  
  128. castbar.OnCastbarUpdate = function(self, elapsed)
  129.     local currentTime = GetTime()
  130.     if self.casting or self.channeling then
  131.         local parent = self:GetParent()
  132.         local duration = self.casting and self.duration + elapsed or self.duration - elapsed
  133.         if (self.casting and duration >= self.max) or (self.channeling and duration <= 0) then
  134.             self.casting = nil
  135.             self.channeling = nil
  136.             return
  137.         end
  138.         if parent.unit == 'player' then
  139.             if self.delay ~= 0 then
  140.                 self.Time:SetFormattedText('|cff000000(%.1f)|r %.2f / |cffff0000%.2f|r', self.delay, duration, self.casting and self.max + self.delay or self.max - self.delay)
  141.             else
  142.                 self.Time:SetFormattedText('%.2f / %.2f', duration, self.max)
  143.             end
  144.         else
  145.             if self.delay ~= 0 then
  146.                 self.Time:SetFormattedText('|cffff0000(%.1f)|r %.2f / %.2f', self.delay, duration, self.casting and self.max + self.delay or self.max - self.delay)
  147.             else
  148.                 self.Time:SetFormattedText('%.2f / %.2f', duration, self.casting and self.max + self.delay or self.max - self.delay)
  149.             end
  150.         end
  151.         self.duration = duration
  152.         self:SetValue(duration)
  153.         self.Spark:SetPoint('CENTER', self, 'LEFT', (duration / self.max) * self:GetWidth(), 0)
  154.     else
  155.         self.Spark:Hide()
  156.         local alpha = self:GetAlpha() - 0.02
  157.         if alpha > 0 then
  158.             self:SetAlpha(alpha)
  159.         else
  160.             self.fadeOut = nil
  161.             self:Hide()
  162.         end
  163.     end
  164. end
  165.  
  166. castbar.OnCastSent = function(self, event, unit, spell, rank)
  167.     if self.unit ~= unit or not self.Castbar.SafeZone then return end
  168.     self.Castbar.SafeZone.sendTime = GetTime()
  169. end
  170.  
  171. castbar.PostCastStart = function(self, unit, name, rank, text)
  172.     local pcolor = {255/255, 128/255, 128/255}
  173.     local interruptcb = {95/255, 182/255, 255/255}
  174.     self:SetAlpha(1)
  175.     self.Spark:Show()
  176.     self:SetStatusBarColor(unpack(self.casting and self.CastingColor or self.ChannelingColor))
  177.     if (unit == 'player') then
  178.         if self.SafeZone then
  179.             local sf = self.SafeZone
  180.             sf.timeDiff = GetTime() - sf.sendTime
  181.             sf.timeDiff = sf.timeDiff > self.max and self.max or sf.timeDiff
  182.             sf:SetWidth(self:GetWidth() * sf.timeDiff / self.max)
  183.             sf:Show()
  184.         end
  185.         if self.casting then
  186.             castbar.setBarTicks(self, 0)
  187.         else
  188.             local spell = UnitChannelInfo(unit)
  189.             self.channelingTicks = channelingTicks[spell] or 0
  190.             castbar.setBarTicks(self, self.channelingTicks)
  191.         end
  192.     elseif (unit == 'target' or unit == 'focus') and not self.interrupt then
  193.         self:SetStatusBarColor(interruptcb[1], interruptcb[2], interruptcb[3],1)
  194.     else
  195.         self:SetStatusBarColor(pcolor[1], pcolor[2], pcolor[3],1)
  196.     end
  197. end
  198.  
  199. castbar.PostCastStop = function(self, unit, name, rank, castid)
  200.     if not self.fadeOut then
  201.         self:SetStatusBarColor(unpack(self.CompleteColor))
  202.         self.fadeOut = true
  203.     end
  204.     self:SetValue(self.max)
  205.     self:Show()
  206. end
  207.  
  208. castbar.PostChannelStop = function(self, unit, name, rank)
  209.     self.fadeOut = true
  210.     self:SetValue(0)
  211.     self:Show()
  212. end
  213.  
  214. castbar.PostCastFailed = function(self, event, unit, name, rank, castid)
  215.     self:SetStatusBarColor(unpack(self.FailColor))
  216.     self:SetValue(self.max)
  217.     if not self.fadeOut then
  218.         self.fadeOut = true
  219.     end
  220.     self:Show()
  221. end
  222.  
  223. ns.castbar = castbar
  224.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement