/branches
glowRegion:SetTexture(nil) |
-- disable default cast bar |
castBar:SetParent(nil) |
castbarOverlay.Show = function() return end |
castBar:SetScript('OnShow', function() castBar:Hide() end) |
castBar:SetAlpha(0) |
frame.oldCastbar = castBar |
frame.firstChild = overlayChild |
frame.level = levelTextRegion |
frame.icon = raidIconRegion |
frame.spell = spellIconRegion |
frame.shield = shieldedRegion |
frame.oldHealth = healthBar |
frame.oldHealth:Hide() |
mod.uiName = 'Cast bars' |
local castEvents = { |
['UNIT_SPELLCAST_START'] = true, |
['UNIT_SPELLCAST_FAILED'] = true, |
['UNIT_SPELLCAST_STOP'] = true, |
['UNIT_SPELLCAST_INTERRUPTED'] = true, |
['UNIT_SPELLCAST_DELAYED'] = true, |
['UNIT_SPELLCAST_CHANNEL_START'] = true, |
['UNIT_SPELLCAST_CHANNEL_UPDATE'] = true, |
['UNIT_SPELLCAST_CHANNEL_STOP'] = true |
} |
local UnitGUID, GetUnitName, UnitChannelInfo, UnitCastingInfo, GetTime, format = |
UnitGUID, GetUnitName, UnitChannelInfo, UnitCastingInfo, GetTime, format |
------------------------------------------------------------- Script handlers -- |
local function OnCastbarUpdate(bar, elapsed) |
if bar.channel then |
bar.progress = bar.progress - elapsed |
else |
bar.progress = bar.progress + elapsed |
local function OnDefaultCastbarShow(self) |
local frame = self:GetParent():GetParent() |
if frame.castbar.name then |
local spellName = select(4, self:GetRegions()):GetText() |
frame.castbar.name:SetText(spellName) |
end |
if not bar.duration or |
((not bar.channel and bar.progress >= bar.duration) or |
(bar.channel and bar.progress <= 0)) |
then |
-- hide the castbar |
bar:Hide() |
bar.progress = 0 |
return |
-- is cast uninterruptible? |
if frame.shield:IsShown() then |
frame.castbar.bar:SetStatusBarColor(.8, .1, .1) |
frame.castbar.shield:Show() |
else |
frame.castbar.bar:SetStatusBarColor(unpack(mod.db.profile.display.barcolour)) |
frame.castbar.shield:Hide() |
end |
if frame.trivial then |
-- hide text & icon |
if frame.spell then |
frame.spellbg:Hide() |
end |
-- display progress |
if bar.max then |
bar.curr:SetText(format("%.1f", bar.progress)) |
if frame.castbar.name then |
frame.castbar.name:Hide() |
end |
if bar.delay == 0 or not bar.delay then |
bar.max:SetText(format("%.1f", bar.duration)) |
else |
-- display delay |
if bar.channel then |
-- time is removed |
bar.max:SetText(format("%.1f", bar.duration).. |
'|cffff0000-'..format("%.1f", bar.delay)..'|r') |
else |
-- time is added |
bar.max:SetText(format("%.1f", bar.duration).. |
'|cffff0000+'..format("%.1f", bar.delay)..'|r') |
end |
if frame.castbar.curr then |
frame.castbar.curr:Hide() |
frame.castbar.max:Hide() |
end |
else |
if frame.spell then |
frame.spellbg:Show() |
end |
if frame.castbar.name then |
frame.castbar.name:Show() |
end |
if frame.castbar.curr then |
frame.castbar.curr:Show() |
frame.castbar.max:Show() |
end |
end |
bar.bar:SetValue(bar.progress/bar.duration) |
frame.castbar:Show() |
end |
local function OnDefaultCastbarHide(self) |
local frame = self:GetParent():GetParent() |
frame.castbar:Hide() |
end |
local function OnDefaultCastbarUpdate(self, elapsed) |
local frame = self:GetParent():GetParent() |
local min,max = self:GetMinMaxValues() |
if frame.castbar.max then |
frame.castbar.max:SetText(format("%.1f", max)) |
frame.castbar.curr:SetText(format("%.1f", self:GetValue())) |
end |
frame.castbar.bar:SetMinMaxValues(min,max) |
frame.castbar.bar:SetValue(self:GetValue()) |
end |
---------------------------------------------------------------------- create -- |
function mod:CreateCastbar(msg, frame) |
-- container --------------------------------------------------------------- |
frame.castbar = CreateFrame('Frame', nil, frame.parent) |
frame.castbar:Hide() |
-- background -------------------------------------------------------------- |
frame.castbar.bg = frame.castbar:CreateTexture(nil, 'BACKGROUND') |
frame.castbar.bg:SetTexture(kui.m.t.solid) |
if frame.spell then |
-- cast bar icon background ---------------------------------------- |
frame.spellbg = frame.castbar:CreateTexture(nil, 'BACKGROUND') |
frame.spellbg:SetTexture(kui.m.t.solid) |
frame.spellbg = CreateFrame('Frame', nil, frame.castbar) |
frame.spellbg:SetBackdrop({ bgFile = kui.m.t.solid }) |
frame.spellbg:SetBackdropColor(0, 0, 0, .85) |
frame.spellbg:SetSize(addon.sizes.icon, addon.sizes.icon) |
frame.spellbg:SetVertexColor(0, 0, 0, .85) |
frame.spellbg:SetPoint('TOPRIGHT', frame.health, 'TOPLEFT', -2, 1) |
-- cast bar icon --------------------------------------------------- |
frame.spell:ClearAllPoints() |
frame.spell:SetParent(frame.castbar) |
frame.spell:SetParent(frame.spellbg) |
frame.spell:SetSize(addon.sizes.icon - 2, addon.sizes.icon - 2) |
frame.spell:SetPoint('TOPRIGHT', frame.spellbg, -1, -1) |
end |
-- scripts ------------------------------------------------------------- |
frame.castbar:HookScript('OnShow', function(bar) |
if bar.interruptible then |
bar.bar:SetStatusBarColor(unpack(self.db.profile.display.barcolour)) |
bar.shield:Hide() |
else |
bar.bar:SetStatusBarColor(.8, .1, .1) |
bar.shield:Show() |
end |
end) |
frame.castbar:SetScript('OnUpdate', OnCastbarUpdate) |
frame.oldCastbar:HookScript('OnShow', OnDefaultCastbarShow) |
frame.oldCastbar:HookScript('OnHide', OnDefaultCastbarHide) |
frame.oldCastbar:HookScript('OnUpdate', OnDefaultCastbarUpdate) |
end |
------------------------------------------------------------------------ Hide -- |
function mod:HideCastbar(msg, frame) |
frame.castbar:Hide() |
end |
end |
-------------------------------------------------------------- Event handlers -- |
function mod.UnitCastEvent(e, unit, ...) |
if unit == 'player' then return end |
local guid, name, f = UnitGUID(unit), GetUnitName(unit), nil |
--guid, name = UnitGUID('target'), GetUnitName('target') |
-- [debug] |
--print('CastEvent: ['..e..'] from ['..unit..'] (GUID: ['..(guid or 'nil')..']) (Name: ['..(name or 'nil')..'])') |
-- fetch the unit's nameplate |
f = addon:GetNameplate(guid, name) |
if f then |
if not f.castbar or f.trivial then return end |
if e == 'UNIT_SPELLCAST_STOP' or |
e == 'UNIT_SPELLCAST_FAILED' or |
e == 'UNIT_SPELLCAST_INTERRUPTED' |
then |
-- these occasionally fire after a new _START |
local _, _, castID = ... |
if f.castbar.id ~= castID then |
return |
end |
end |
mod[e](mod, f, unit) |
end |
end |
function mod:UNIT_SPELLCAST_START(frame, unit, channel) |
local castbar = frame.castbar |
local name, _, text, texture, startTime, endTime, _, castID, |
notInterruptible |
if channel then |
name, _, text, texture, startTime, endTime, _, castID, notInterruptible |
= UnitChannelInfo(unit) |
else |
name, _, text, texture, startTime, endTime, _, castID, notInterruptible |
= UnitCastingInfo(unit) |
end |
if not name then |
frame.castbar:Hide() |
return |
end |
castbar.id = castID |
castbar.channel = channel |
castbar.interruptible = not notInterruptible |
castbar.duration = (endTime/1000) - (startTime/1000) |
castbar.delay = 0 |
if frame.spell then |
frame.spell:SetTexture(texture) |
end |
if castbar.name then |
castbar.name:SetText(name) |
end |
if castbar.channel then |
castbar.progress = (endTime/1000) - GetTime() |
else |
castbar.progress = GetTime() - (startTime/1000) |
end |
frame.castbar:Show() |
end |
function mod:UNIT_SPELLCAST_DELAYED(frame, unit, channel) |
local castbar = frame.castbar |
local _, name, startTime, endTime |
if channel then |
name, _, _, _, startTime, endTime = UnitChannelInfo(unit) |
else |
name, _, _, _, startTime, endTime = UnitCastingInfo(unit) |
end |
if not name then |
return |
end |
local newProgress |
if castbar.channel then |
newProgress = (endTime/1000) - GetTime() |
else |
newProgress = GetTime() - (startTime/1000) |
end |
castbar.delay = (castbar.delay or 0) + castbar.progress - newProgress |
castbar.progress = newProgress |
end |
function mod:UNIT_SPELLCAST_CHANNEL_START(frame, unit) |
self:UNIT_SPELLCAST_START(frame, unit, true) |
end |
function mod:UNIT_SPELLCAST_CHANNEL_UPDATE(frame, unit) |
self:UNIT_SPELLCAST_DELAYED(frame, unit, true) |
end |
function mod:UNIT_SPELLCAST_STOP(frame, unit) |
frame.castbar:Hide() |
end |
function mod:UNIT_SPELLCAST_FAILED(frame, unit) |
frame.castbar:Hide() |
end |
function mod:UNIT_SPELLCAST_INTERRUPTED(frame, unit) |
frame.castbar:Hide() |
end |
function mod:UNIT_SPELLCAST_CHANNEL_STOP(frame, unit) |
frame.castbar:Hide() |
end |
function mod:IsCasting(msg, frame) |
-- TODO update this for other units (party1target etc) |
if not frame.castbar or not frame.target then return end |
local name = UnitCastingInfo('target') |
local channel = false |
if not name then |
name = UnitChannelInfo('target') |
channel = true |
end |
if name then |
-- if they're casting or channeling, try to show a castbar |
self:UNIT_SPELLCAST_START(frame, 'target', channel) |
end |
end |
-------------------------------------------------------------------- Register -- |
function mod:GetOptions() |
return { |
type = 'toggle', |
order = 3 |
}, |
spellicon = { |
name = 'Show spell icon', |
type = 'toggle', |
order = 2 |
}, |
barcolour = { |
name = 'Bar colour', |
desc = 'The colour of the cast bar (during interruptible casts)', |
}) |
addon:RegisterSize('frame', 'cbheight', 4) |
addon:RegisterSize('frame', 'icon', 16) |
addon:RegisterSize('frame', 'icon', 15) |
addon:InitModuleOptions(self) |
end |
function mod:OnEnable() |
self:RegisterMessage('KuiNameplates_PostCreate', 'CreateCastbar') |
self:RegisterMessage('KuiNameplates_PostHide', 'HideCastbar') |
self:RegisterMessage('KuiNameplates_PostShow', 'IsCasting') |
self:RegisterMessage('KuiNameplates_PostTarget', 'IsCasting') |
for event,_ in pairs(castEvents) do |
self:RegisterEvent(event, self.UnitCastEvent) |
end |
local _,frame |
for _, frame in pairs(addon.frameList) do |
if not frame.castbar then |