Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- init + holder
- local addon, ns = ...
- local cfg = ns.cfg
- local castbar = CreateFrame('Frame')
- local channelingTicks = {
- -- warlock
- [GetSpellInfo(1120)] = 5, -- drain soul
- [GetSpellInfo(689)] = 5, -- drain life
- [GetSpellInfo(5740)] = 4, -- rain of fire
- [GetSpellInfo(79268)] = 4, -- soul harvest
- -- druid
- [GetSpellInfo(740)] = 4, -- Tranquility
- [GetSpellInfo(16914)] = 10, -- Hurricane
- -- priest
- [GetSpellInfo(15407)] = 3, -- mind flay
- [GetSpellInfo(48045)] = 5, -- mind sear
- [GetSpellInfo(47540)] = 2, -- penance
- -- mage
- [GetSpellInfo(5143)] = 5, -- arcane missiles
- [GetSpellInfo(10)] = 5, -- blizzard
- [GetSpellInfo(12051)] = 4, -- evocation
- -- shaman
- [GetSpellInfo(61882)] = 8 -- earthquake
- }
- local ticks = {}
- castbar.setBarTicks = function(castBar, ticknum)
- if ticknum and ticknum > 0 then
- local delta = castBar:GetWidth() / ticknum
- for k = 1, ticknum do
- if not ticks[k] then
- ticks[k] = castBar:CreateTexture(nil, 'OVERLAY')
- ticks[k]:SetTexture(cfg.TexturePower)
- ticks[k]:SetBlendMode('ADD')
- ticks[k]:SetVertexColor(1, 1, 1, 1)
- ticks[k]:SetHeight(castBar:GetHeight())
- ticks[k]:SetWidth(2)
- end
- ticks[k]:ClearAllPoints()
- ticks[k]:SetPoint('CENTER', castBar, 'LEFT', delta * k, 0 )
- ticks[k]:Show()
- end
- else
- for k, v in pairs(ticks) do
- v:Hide()
- end
- end
- end
- -- Castbar
- function addCastbar(self)
- self.Castbar = CreateFrame('StatusBar', 'PlayerCastbar', self)
- self.Castbar:SetHeight(16)
- self.Castbar:SetWidth(self:GetWidth() - 21)
- if (self.Style == 'player') then
- self.Castbar:SetPoint('BOTTOMRIGHT', self.Power, 'TOPRIGHT', 0, 6)
- else
- self.Castbar:SetPoint('BOTTOMRIGHT', self.Power, 'TOPRIGHT', 10, 6)
- end
- self.Castbar:SetStatusBarTexture(cfg.TexturePower)
- self.Castbar:SetStatusBarColor(95/255, 182/255, 255/255, 1)
- self.Castbar:SetFrameLevel(9)
- self.Castbar.CastingColor = {95/255, 182/255, 255/255}
- self.Castbar.CompleteColor = {20/255, 208/255, 0/255}
- self.Castbar.FailColor = {255/255, 12/255, 0/255}
- self.Castbar.ChannelingColor = {95/255, 182/255, 255/255}
- -- Helper
- self.Castbar.Helper = CreateFrame('Frame', nil, self.Castbar)
- self.Castbar.Helper:SetFrameLevel(8)
- self.Castbar.Helper:SetPoint('TOPLEFT', -5, 5)
- self.Castbar.Helper:SetPoint('BOTTOMRIGHT', 5, -5)
- self.Castbar.Helper:SetBackdrop(cfg.TextureHelper);
- self.Castbar.Helper:SetBackdropColor(0, 0, 0, 0.6)
- self.Castbar.Helper:SetBackdropBorderColor(0, 0, 0, 1)
- -- Spark
- self.Castbar.Spark = self.Castbar:CreateTexture(nil, 'OVERLAY')
- self.Castbar.Spark:SetBlendMode('ADD')
- self.Castbar.Spark:SetVertexColor(1, 1, 1, 1)
- self.Castbar.Spark:SetHeight(self.Castbar:GetHeight() * 2.5)
- self.Castbar.Spark:SetWidth(self.Castbar:GetWidth() / 18)
- -- Spell Text
- self.Castbar.Text = self.Castbar:CreateFontString(nil, 'OVERLAY')
- self.Castbar.Text:SetFont(cfg.FontNeuro, 16, 'THINOUTLINE')
- self.Castbar.Text:SetShadowColor(0, 0, 0, 0.8)
- self.Castbar.Text:SetShadowOffset(1, -1)
- self.Castbar.Text:SetPoint('LEFT', 2, 10)
- self.Castbar.Text:SetJustifyH('LEFT')
- -- Spell Time
- self.Castbar.Time = self.Castbar:CreateFontString(nil, 'OVERLAY')
- self.Castbar.Time:SetFont(cfg.FontNeuro, 12, 'THINOUTLINE')
- self.Castbar.Time:SetShadowColor(0, 0, 0, 0.8)
- self.Castbar.Time:SetShadowOffset(1, -1)
- self.Castbar.Time:SetPoint('RIGHT', -2, 1)
- -- Icon
- self.Castbar.Icon = self.Castbar:CreateTexture(nil, 'ARTWORK')
- self.Castbar.Icon:SetSize(24, 24)
- self.Castbar.Icon:SetPoint('BOTTOMRIGHT', self.Castbar, 'BOTTOMLEFT', -6, 0)
- self.Castbar.Icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
- -- Helper for Icon
- self.Castbar.IconHelper = CreateFrame('Frame', nil, self.Castbar)
- self.Castbar.IconHelper:SetFrameLevel(8)
- self.Castbar.IconHelper:SetPoint('TOPLEFT', self.Castbar.Icon, 'TOPLEFT', -5, 5)
- self.Castbar.IconHelper:SetPoint('BOTTOMRIGHT', self.Castbar.Icon, 'BOTTOMRIGHT', 5, -5)
- self.Castbar.IconHelper:SetBackdrop(cfg.TextureHelper);
- self.Castbar.IconHelper:SetBackdropColor(0, 0, 0, 1)
- self.Castbar.IconHelper:SetBackdropBorderColor(0, 0, 0, 0.8)
- if (self.Style == 'player') then
- -- Latency
- self.Castbar.SafeZone = self.Castbar:CreateTexture(nil, 'OVERLAY')
- self.Castbar.SafeZone:SetTexture(cfg.TexturePower)
- self.Castbar.SafeZone:SetVertexColor(1, 0.1, 0, 0.6)
- self.Castbar.SafeZone:SetPoint('TOPRIGHT')
- self.Castbar.SafeZone:SetPoint('BOTTOMRIGHT')
- end
- -- Register Events
- self:RegisterEvent('UNIT_SPELLCAST_SENT', castbar.OnCastSent)
- self.Castbar.OnUpdate = castbar.OnCastbarUpdate
- self.Castbar.PostCastStart = castbar.PostCastStart
- self.Castbar.PostChannelStart = castbar.PostCastStart
- self.Castbar.PostCastStop = castbar.PostCastStop
- self.Castbar.PostChannelStop = castbar.PostChannelStop
- self.Castbar.PostCastFailed = castbar.PostCastFailed
- self.Castbar.PostCastInterrupted = castbar.PostCastFailed
- end
- castbar.OnCastbarUpdate = function(self, elapsed)
- local currentTime = GetTime()
- if self.casting or self.channeling then
- local parent = self:GetParent()
- local duration = self.casting and self.duration + elapsed or self.duration - elapsed
- if (self.casting and duration >= self.max) or (self.channeling and duration <= 0) then
- self.casting = nil
- self.channeling = nil
- return
- end
- if parent.unit == 'player' then
- if self.delay ~= 0 then
- 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)
- else
- self.Time:SetFormattedText('%.2f / %.2f', duration, self.max)
- end
- else
- if self.delay ~= 0 then
- self.Time:SetFormattedText('|cffff0000(%.1f)|r %.2f / %.2f', self.delay, duration, self.casting and self.max + self.delay or self.max - self.delay)
- else
- self.Time:SetFormattedText('%.2f / %.2f', duration, self.casting and self.max + self.delay or self.max - self.delay)
- end
- end
- self.duration = duration
- self:SetValue(duration)
- self.Spark:SetPoint('CENTER', self, 'LEFT', (duration / self.max) * self:GetWidth(), 0)
- else
- self.Spark:Hide()
- local alpha = self:GetAlpha() - 0.02
- if alpha > 0 then
- self:SetAlpha(alpha)
- else
- self.fadeOut = nil
- self:Hide()
- end
- end
- end
- castbar.OnCastSent = function(self, event, unit, spell, rank)
- if self.unit ~= unit or not self.Castbar.SafeZone then return end
- self.Castbar.SafeZone.sendTime = GetTime()
- end
- castbar.PostCastStart = function(self, unit, name, rank, text)
- local pcolor = {255/255, 128/255, 128/255}
- local interruptcb = {95/255, 182/255, 255/255}
- self:SetAlpha(1)
- self.Spark:Show()
- self:SetStatusBarColor(unpack(self.casting and self.CastingColor or self.ChannelingColor))
- if (unit == 'player') then
- if self.SafeZone then
- local sf = self.SafeZone
- sf.timeDiff = GetTime() - sf.sendTime
- sf.timeDiff = sf.timeDiff > self.max and self.max or sf.timeDiff
- sf:SetWidth(self:GetWidth() * sf.timeDiff / self.max)
- sf:Show()
- end
- if self.casting then
- castbar.setBarTicks(self, 0)
- else
- local spell = UnitChannelInfo(unit)
- self.channelingTicks = channelingTicks[spell] or 0
- castbar.setBarTicks(self, self.channelingTicks)
- end
- elseif (unit == 'target' or unit == 'focus') and not self.interrupt then
- self:SetStatusBarColor(interruptcb[1], interruptcb[2], interruptcb[3],1)
- else
- self:SetStatusBarColor(pcolor[1], pcolor[2], pcolor[3],1)
- end
- end
- castbar.PostCastStop = function(self, unit, name, rank, castid)
- if not self.fadeOut then
- self:SetStatusBarColor(unpack(self.CompleteColor))
- self.fadeOut = true
- end
- self:SetValue(self.max)
- self:Show()
- end
- castbar.PostChannelStop = function(self, unit, name, rank)
- self.fadeOut = true
- self:SetValue(0)
- self:Show()
- end
- castbar.PostCastFailed = function(self, event, unit, name, rank, castid)
- self:SetStatusBarColor(unpack(self.FailColor))
- self:SetValue(self.max)
- if not self.fadeOut then
- self.fadeOut = true
- end
- self:Show()
- end
- ns.castbar = castbar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement