
-- Title: CastingBar Time v0.1
-- Notes: Displays remaining casting / channeling time
-- Author: lua@lumpn.de

local function CastingBarTime_toString(end_time)
	return string.format(" (%.1fs)", end_time - GetTime());
end

local function Nurfed_UpdateCastingFrame()
	CastingBarFrame:ClearAllPoints();
	CastingBarFrame:SetPoint("BOTTOM", "Nurfed_CastingBar", "BOTTOM", 0, 0);
	CastingBarFlash:ClearAllPoints();
	CastingBarFlash:SetPoint("CENTER", "Nurfed_CastingBar", "CENTER", 0, -5);
	CastingBarFrameStatusBar:ClearAllPoints();
	CastingBarFrameStatusBar:SetPoint("CENTER", "Nurfed_CastingBar", "CENTER", 0, -5);
	CastingBarText:ClearAllPoints();
	CastingBarText:SetPoint("CENTER", "Nurfed_CastingBar", "CENTER", 0, -5);
end

function CastingBarTime_OnLoad()
	this:RegisterEvent("SPELLCAST_START");
	this:RegisterEvent("SPELLCAST_CHANNEL_START");
	this.SpellName = "";
end


function CastingBarTime_OnEvent()
	if ( event == "SPELLCAST_START" ) then
		this.SpellName = arg1;
		Nurfed_UpdateCastingFrame();
	elseif ( event == "SPELLCAST_CHANNEL_START" ) then
		this.SpellName = arg2;
		Nurfed_UpdateCastingFrame();
	end
end


function CastingBarTime_OnUpdate()
	Nurfed_UpdateCastingFrame();
	if ( CastingBarFrame.casting ) then
		CastingBarText:SetText(this.SpellName..CastingBarTime_toString(CastingBarFrame.maxValue));
	elseif ( CastingBarFrame.channeling ) then
		CastingBarText:SetText(this.SpellName..CastingBarTime_toString(CastingBarFrame.endTime));
	end
	
end

local originalCastingBarFrame_UpdatePosition = CastingBarFrame_UpdatePosition;
function CastingBarFrame_UpdatePosition()
end
