Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bCastBars = _G['bCastBars'] or CreateFrame('frame', 'bCastBars', UIParent)
- local addonName, ns = ...
- local BACKDROP = {
- bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=], insets = {top = -1, bottom = -1, left = -1, right = -1}
- }
- local castbars = {
- player = true,
- target = true,
- focus = true,
- pet = true,
- }
- local CastingBarFinishSpell = function(self)
- self.bar:SetStatusBarColor(1,1,1)
- self.fadeOut = 1
- self.casting = nil
- self.channeling = nil
- end
- local MakeCastBar = function(unit, enable)
- local frame = _G[unit.."bCastBar"] or CreateFrame("frame", unit.."bCastBar", UIParent)
- frame:SetSize(250,20)
- frame:SetBackdrop(BACKDROP)
- frame:SetBackdropColor(0,0,0)
- frame:SetPoint('CENTER', UIParent, 'CENTER')
- local bar = CreateFrame('StatusBar', nil, frame)
- bar:SetStatusBarTexture([=[Interface\ChatFrame\ChatFrameBackground]=])
- bar:SetSize(250,20)
- bar:SetStatusBarColor(.2, .2, .2)
- bar:SetAllPoints()
- local bg = bar:CreateTexture('castbarbgframe', 'BACKGROUND')
- bg:SetTexture([=[Interface\ChatFrame\ChatFrameBackground]=])
- bg:SetVertexColor(.2, .2, .2)
- bg:SetAllPoints()
- local text = bar:CreateFontString(nil, 'OVERLAY')
- text:SetFont([=[Interface\AddOns\oUF_P3lim\pixel.ttf]=], 11, 'OUTLINE')
- text:SetPoint('CENTER', bar, 'CENTER')
- local timer = bar:CreateFontString(nil, 'OVERLAY')
- timer:SetFont([=[Interface\AddOns\oUF_P3lim\pixel.ttf]=], 11, 'OUTLINE')
- timer:SetJustifyH('RIGHT')
- timer:SetPoint('RIGHT', bar, 'RIGHT', -3, 0)
- local icon = frame:CreateTexture(nil, 'ARTWORK')
- icon:SetSize(22,22)
- icon:SetPoint('TOPRIGHT', frame, 'TOPLEFT', -1, 1)
- icon:SetPoint('BOTTOMRIGHT', frame, 'BOTTOMLEFT', -1, -1)
- icon:SetTexCoord(.06, .94, .06, .94)
- frame.bar = bar
- bar.timer = timer
- bar.text = text
- frame.icon = icon
- if unit == "player" then
- frame.lag = _G[frame:GetName().."Lag"] or frame.bar:CreateTexture(frame:GetName().."Lag", "BORDER")
- frame.lag:SetPoint("TOPRIGHT")
- frame.lag:SetPoint("BOTTOMRIGHT")
- frame.lag:SetTexture("Interface\\RAIDFRAME\\Raid-Bar-Hp-Fill", "BACKGROUND")
- frame.lag:SetVertexColor(1, 0, 0)
- frame.lag:SetBlendMode("ADD")
- end
- frame.timerUpdate = .1
- frame:RegisterEvent("PLAYER_TARGET_CHANGED")
- frame:RegisterEvent("UNIT_SPELLCAST_START")
- frame:RegisterEvent("UNIT_SPELLCAST_STOP")
- frame:RegisterEvent("UNIT_SPELLCAST_FAILED")
- frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
- frame:RegisterEvent("UNIT_SPELLCAST_DELAYED")
- frame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
- frame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
- frame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
- frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE")
- frame:RegisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE")
- frame:RegisterEvent("PLAYER_ENTERING_WORLD")
- frame.unit = unit
- frame.casting = nil
- frame.channeling = nil
- frame.holdTime = 0
- frame.showCastbar = castbars[unit]
- frame.locked = true
- frame:Hide()
- frame:SetScript("OnShow", function(self)
- if not self.locked then return end
- if self.casting then
- local _, _, _, _, st = UnitCastingInfo(self.unit)
- if st then
- self.value = (GetTime() - (st / 1000))
- end
- else
- local _, _, _, _, _, et = UnitChannelInfo(self.unit)
- if et then
- self.value = ((et / 1000) - GetTime())
- end
- end
- end)
- frame:SetScript("OnEvent", function(self, event, ...)
- local arg1 = ...
- if not self.locked then return end
- local unit = self.unit
- if event == "PLAYER_ENTERING_WORLD" or event == "PLAYER_TARGET_CHANGED" then
- local spellChannel = UnitChannelInfo(unit)
- local spellName = UnitCastingInfo(unit)
- if spellChannel then
- event = "UNIT_SPELLCAST_CHANNEL_START"
- arg1 = unit
- elseif spellName then
- event = "UNIT_SPELLCAST_START"
- arg1 = unit
- else
- CastingBarFinishSpell(self)
- end
- end
- if arg1 ~= unit then return end
- if event == "UNIT_SPELLCAST_START" then
- local name, _, text, texture, startTime, endTime, _, castID, notInterruptible = UnitCastingInfo(unit)
- if not name then
- self:Hide()
- return
- end
- if self.lag then self.lag:Show() end
- self.value = GetTime() - (startTime / 1000)
- self.maxValue = (endTime - startTime) / 1000
- self.bar:SetMinMaxValues(0, self.maxValue)
- self.bar:SetValue(self.value)
- self.bar.text:SetText(text)
- self.icon:SetTexture(texture)
- self:SetAlpha(1)
- self.holdTime = 0
- self.casting = 1
- self.castID = castID
- self.channeling = nil
- self.fadeOut = nil
- if notInterruptible then
- self.bar:SetStatusBarColor(.65, .1, .1)
- else
- self.bar:SetStatusBarColor(0, .8, 0)
- end
- if self.showCastbar then self:Show() end
- elseif event == "UNIT_SPELLCAST_STOP" or event == "UNIT_SPELLCAST_CHANNEL_STOP" then
- if not self:IsVisible() then
- self:Hide()
- end
- if (self.casting and event == "UNIT_SPELLCAST_STOP" and select(4, ...) == self.castID) or (self.channeling and event == "UNIT_SPELLCAST_CHANNEL_STOP") then
- self.bar:SetValue(self.maxValue)
- if event == "UNIT_SPELLCAST_STOP" then
- self.casting = nil
- self.bar:SetStatusBarColor(.8, .8, 0)
- else
- self.channeling = nil
- end
- self.fadeOut = 1
- self.holdTime = 0
- end
- elseif event == "UNIT_SPELLCAST_FAILED" or event == "UNIT_SPELLCAST_INTERRUPTED" then
- if self:IsShown() and (self.casting and select(4, ...) == self.castID) and not self.fadeOut then
- self.bar:SetValue(self.maxValue)
- self.bar:SetStatusBarColor(.8, .8, 0)
- if event == "UNIT_SPELLCAST_FAILED" then
- self.bar.text:SetText(FAILED)
- else
- self.bar.text:SetText(INTERRUPTED)
- end
- if self.lag then self.lag:Hide() end
- self.casting = nil
- self.channeling = nil
- self.fadeOut = 1
- self.holdTime = GetTime()
- end
- elseif event == "UNIT_SPELLCAST_DELAYED" then
- if self:IsShown() then
- local name, _, text, texture, startTime, endTime = UnitCastingInfo(unit)
- if not name then
- self:Hide()
- return
- end
- self.value = (GetTime() - (startTime / 1000))
- self.maxValue = (endTime - startTime) / 1000
- self.bar:SetMinMaxValues(0, self.maxValue)
- if not self.casting then
- self.bar:SetStatusBarColor(0, .8, 0)
- self.casting = 1
- self.channeling = nil
- self.fadeOut = 0
- end
- end
- elseif event == "UNIT_SPELLCAST_CHANNEL_START" then
- local name, _, text, texture, startTime, endTime, isTradeSkill, notInterruptible = UnitChannelInfo(unit)
- if not name then
- self:Hide()
- return
- end
- if self.lag then self.lag:Hide() end
- self.value = (endTime / 1000) - GetTime()
- self.maxValue = (endTime - startTime) / 1000
- self.bar:SetMinMaxValues(0, self.maxValue)
- self.bar:SetValue(self.value)
- self.bar.text:SetText(text)
- self.icon:SetTexture(texture)
- self:SetAlpha(1)
- self.holdTime = 0
- self.casting = nil
- self.channeling = 1
- self.fadeOut = nil
- if notInterruptible then
- self.bar:SetStatusBarColor(.65, .1, .1)
- else
- self.bar:SetStatusBarColor(0, .8, 0)
- end
- if self.showCastbar then self:Show() end
- elseif event == "UNIT_SPELLCAST_CHANNEL_UPDATE" then
- if self:IsShown() then
- local name, _, text, texture, startTime, endTime, isTradeSkill, notInterruptible = UnitChannelInfo(unit)
- if not name then
- self:Hide()
- return
- end
- self.value = (endTime / 1000) - GetTime()
- self.maxValue = (endTime - startTime) / 1000
- self.bar:SetMinMaxValues(0, self.maxValue)
- self.bar:SetValue(self.value)
- end
- elseif event == "UNIT_SPELLCAST_INTERRUPTIBLE" then
- self.bar:SetStatusBarColor(0, .8, 0)
- elseif event == "UNIT_SPELLCAST_NOT_INTERRUPTIBLE" then
- self.bar:SetStatusBarColor(.65, .1, .1)
- end
- end)
- frame:SetScript("OnUpdate", function(self, elapsed)
- if not self.bar.timer then return end
- if self.timerUpdate and self.timerUpdate < elapsed then
- if self.casting then
- self.bar.timer:SetText(format("%.1f", max(self.maxValue - self.value, 0)))
- elseif self.channeling then
- self.bar.timer:SetText(format("%.1f", max(self.value, 0)))
- else
- self.bar.timer:SetText("")
- end
- self.timerUpdate = .1
- else
- self.timerUpdate = self.timerUpdate - elapsed
- end
- if self.casting then
- self.value = self.value + elapsed
- if self.value >= self.maxValue then
- self.bar:SetValue(self.maxValue)
- CastingBarFinishSpell(self)
- return
- end
- self.bar:SetValue(self.value)
- if self.unit == "player" then
- local down, up, lag = GetNetStats()
- local castingmin, castingmax = self.bar:GetMinMaxValues()
- local lagvalue = ( lag / 1000 ) / ( castingmax - castingmin )
- if ( lagvalue < 0 ) then lagvalue = 0; elseif ( lagvalue > 1 ) then lagvalue = 1 end
- self.lag:ClearAllPoints()
- self.lag:SetPoint("RIGHT")
- self.lag:SetHeight(self.bar:GetHeight())
- self.lag:SetWidth(self.bar:GetWidth() * lagvalue)
- end
- elseif self.channeling then
- self.value = self.value - elapsed
- if self.value <= 0 then
- CastingBarFinishSpell(self)
- return
- end
- self.bar:SetValue(self.value)
- elseif GetTime() < self.holdTime then
- return
- elseif self.fadeOut then
- self.fadeOut = nil
- self:Hide()
- end
- end)
- end
- bCastBars:RegisterEvent('PLAYER_TALENT_UPDATE')
- bCastBars:RegisterEvent('PLAYER_ENTERING_WORLD')
- bCastBars:RegisterEvent('ADDON_LOADED')
- bCastBars:SetScript('OnEvent', function(self, event, arg1, ...)
- if (event=='ADDON_LOADED' and arg1 == addonName) or event == 'PLAYER_ENTERING_WORLD' or event=='PLAYER_TALENT_UPDATE' then
- CastingBarFrame.showCastbar = false
- CastingBarFrame:UnregisterAllEvents()
- CastingBarFrame:SetScript("OnUpdate", function() end)
- TargetFrameSpellBar.showCastbar = false
- TargetFrameSpellBar:UnregisterAllEvents()
- TargetFrameSpellBar:SetScript("OnUpdate", function() end)
- FocusFrameSpellBar.showCastbar = false
- FocusFrameSpellBar:UnregisterAllEvents()
- FocusFrameSpellBar:SetScript("OnUpdate", function() end)
- PetCastingBarFrame.showCastbar = false
- PetCastingBarFrame:UnregisterAllEvents()
- PetCastingBarFrame:SetScript("OnUpdate", function() end)
- for unit, enable in pairs(castbars) do
- if enable then
- MakeCastBar(unit, enable)
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement