bar.time:SetFormattedText("%.1f", remaining);
end
+local function showBar(bar)
+ bar:Show();
+ bar:SetScript("OnUpdate", onUpdate);
+end
+
+local function hideBar(bar)
+ bar:Hide();
+ bar:SetScript("OnUpdate", nil);
+end
+
local function toggleInterruptible(bar, nointr)
if bar.unit == "player" then return end
if nointr then
bar.spell:SetText(ssub(name, 1, bar.spell.count));
bar.time:SetFormattedText("%.1f", (endTime - startTime)/1000);
bar.cast:SetVertexColor(unpack(bar.cast.color));
- bar:Show();
+ showBar(bar);
toggleInterruptible(bar, noInterrupt);
return true;
end
else
_, _, _, _, startTime, endTime = UnitCastingInfo(unit);
end
- if not startTime or not endTime then return bar:Hide() end
+ if not startTime or not endTime then return hideBar(bar) end
bar.startTime = startTime / 1000;
bar.endTime = endTime / 1000;
-- TODO show delay text
startCast(bar, unit);
end,
["PLAYER_TARGET_CHANGED"] = function(bar)
- bar:Hide();
+ hideBar(bar);
if not startCast(bar, bar.unit) then
startCast(bar, bar.unit, true);
end
["UNIT_SPELLCAST_CHANNEL_START"] = function(bar, unit)
startCast(bar, unit, true);
end,
- ["UNIT_SPELLCAST_STOP"] = function(bar, unit)
- bar:Hide();
+ ["UNIT_SPELLCAST_STOP"] = function(bar)
+ hideBar(bar);
end,
["UNIT_SPELLCAST_DELAYED"] = function(bar, unit)
applyDelay(bar, unit);
local function onEvent(bar, event, unit)
if unit == bar.unit or (bar.unit == "player" and unit == "vehicle") then
- --print(unit, event)
events[event](bar, unit);
elseif event == "PLAYER_TARGET_CHANGED" then
events[event](bar);
bar:RegisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE");
bar:RegisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE");
if bar.unit == "target" then bar:RegisterEvent("PLAYER_TARGET_CHANGED") end
- bar:SetScript("OnUpdate", onUpdate);
-- trigger initial check
if not startCast(bar, bar.unit) then
startCast(bar, bar.unit, true);
function M.UnregisterCastEvents(bar)
bar:UnregisterAllEvents();
- bar:SetScript("OnUpdate", nil);
end
function M.CreateCastBar(parent, unit, yoffset)