Hello,
a little CastingBarTimer modification.
If you get damge while casting you see additional the delay
Code:
## Interface: 20000
## Title: Casting Bar Timer
## Version: 2.0
## Notes: Displays the time left in your spellcast on the casting bar when Casting or Channeling.
CastingBarTimer.lua
Code:
CastingBarTimer_DisplayString = " (%0.1fs)";
local eventFrame = CreateFrame("Frame");
eventFrame:Hide();
eventFrame.castingInfo = {};
eventFrame:RegisterEvent("UNIT_SPELLCAST_START");
eventFrame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START");
eventFrame:RegisterEvent("UNIT_SPELLCAST_STOP");
eventFrame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP");
eventFrame.lastCastTime = {};
eventFrame.delaySpell = {};
eventFrame.delayChannel = {};
eventFrame:SetScript("OnEvent",
function( --[[self, event, arg1--]] ) local self = this;
self.lastCastTime[arg1] = nil;
if ( event == "UNIT_SPELLCAST_START" ) then
self.delaySpell[arg1] = 0;
local _, _, text = UnitCastingInfo(arg1);
self.castingInfo[arg1] = text..CastingBarTimer_DisplayString;
elseif ( event == "UNIT_SPELLCAST_CHANNEL_START" ) then
self.delayChannel[arg1] = 0;
local _, _, text = UnitChannelInfo(arg1);
self.castingInfo[arg1] = text..CastingBarTimer_DisplayString;
else
self.castingInfo[arg1] = nil;
self.lastCastTime[arg1] = nil;
self.delaySpell[arg1] = 0;
self.delayChannel[arg1] = 0;
end
end
);
local OLD_CastingBarFrame_OnUpdate = CastingBarFrame_OnUpdate;
function CastingBarFrame_OnUpdate( ... )
OLD_CastingBarFrame_OnUpdate(...);
local timeLeft = nil;
if ( this.casting ) then
timeLeft = this.maxValue - this:GetValue();
if (eventFrame.lastCastTime[this.unit] == nil) then
eventFrame.lastCastTime[this.unit] = timeLeft;
end
if(timeLeft > eventFrame.lastCastTime[this.unit]) then
eventFrame.delaySpell[this.unit] = eventFrame.delaySpell[this.unit] + (timeLeft - eventFrame.lastCastTime[this.unit]);
end
eventFrame.lastCastTime[this.unit] = timeLeft;
elseif ( this.channeling ) then
timeLeft = this.duration + this:GetValue() - this.endTime;
if (eventFrame.lastCastTime[this.unit] == nil) then
eventFrame.lastCastTime[this.unit] = timeLeft;
end
if((eventFrame.lastCastTime[this.unit] - timeLeft) > 0.05 ) then
eventFrame.delayChannel[this.unit] = eventFrame.delayChannel[this.unit] + (eventFrame.lastCastTime[this.unit] - timeLeft);
end
eventFrame.lastCastTime[this.unit] = timeLeft;
end
if ( timeLeft ) then
local textDisplay = getglobal(this:GetName().."Text")
timeleft = (timeLeft < 0.1) and 0.01 or timeLeft;
local displayName = eventFrame.castingInfo[this.unit];
if not ( displayName ) then
local _, text;
if ( this.casting ) then
_, _, text = UnitCastingInfo(this.unit);
elseif ( this.channeling ) then
_, _, text = UnitChannelInfo(this.unit);
end
if ( text ) then
displayName = text..CastingBarTimer_DisplayString;
eventFrame.castingInfo[this.unit] = displayName;
else
displayName = (textDisplay:GetText() or "")..CastingBarTimer_DisplayString;
end
end
delay_txt = "";
if not (eventFrame.delaySpell[this.unit] == nil) and (eventFrame.delaySpell[this.unit] > 0) then
delay_txt = "+"..format("%0.1fs",eventFrame.delaySpell[this.unit]);
elseif not (eventFrame.delayChannel[this.unit] == nil) and (eventFrame.delayChannel[this.unit] > 0) then
delay_txt = "-"..format("%0.1fs",eventFrame.delayChannel[this.unit])
end
textDisplay:SetText( format(displayName, timeLeft)..delay_txt );
end
end
cya
Sandarium