X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/09b59f4581dd8bce3b4c430ea569b7e723a2deef..2cb3a289b5b6b45db36f6d9c722be8a30aedb3e2:/OmaUF/CastBar.lua diff --git a/OmaUF/CastBar.lua b/OmaUF/CastBar.lua index de2544e..6170513 100644 --- a/OmaUF/CastBar.lua +++ b/OmaUF/CastBar.lua @@ -6,19 +6,20 @@ local min = math.min; local ceil = math.ceil; local UnitCastingInfo, UnitChannelInfo = UnitCastingInfo, UnitChannelInfo; local GetTime = GetTime; +local CTimerAfter = C_Timer.After; local barTexture = "Interface\\AddOns\\OmaRF\\images\\minimalist"; local castingColor = {1, 0.49, 0}; -- from Quartz defaults local nointerruptColor = {0.6, 0.6, 0.6}; local channelingColor = {0.32, 0.3, 1}; +local updaters = {}; local M = {}; OmaUFCastBar = M; --- TODO trade skill bar updates as well, check Quartz modules/Tradeskill.lua local function onUpdate(bar) - if not bar:IsShown() then return end - local width = bar.icon:IsShown() and bar.cast.width or bar.cast.width; -- TODO fullwidth + if not bar.updating then return end + --local width = bar.icon:IsShown() and bar.cast.width or bar.cast.width; -- TODO fullwidth local startTime, endTime = bar.startTime, bar.endTime; local currentClamped = min(GetTime(), endTime); local remaining = endTime - currentClamped; @@ -29,23 +30,26 @@ local function onUpdate(bar) percent = (currentClamped - startTime) / (endTime - startTime); end - width = percent*width; + local width = percent*bar.cast.width; if width <= 0 then bar.cast:SetWidth(0.1); else bar.cast:SetWidth(width); end bar.time:SetFormattedText("%.1f", remaining); + CTimerAfter(0.03, updaters[bar]); end +M.OnUpdate = onUpdate; local function showBar(bar) bar:Show(); - bar:SetScript("OnUpdate", onUpdate); + bar.updating = true; + onUpdate(bar); end local function hideBar(bar) bar:Hide(); - bar:SetScript("OnUpdate", nil); + bar.updating = nil; end local function toggleInterruptible(bar, nointr) @@ -62,12 +66,12 @@ end local function startCast(bar, unit, channeling) local name, icon, startTime, endTime, noInterrupt, id; if channeling then - name, _, _, icon, startTime, endTime, _, noInterrupt = UnitChannelInfo(unit); + name, _, icon, startTime, endTime, _, noInterrupt = UnitChannelInfo(unit); if not startTime or not endTime then return nil end bar.channeling = true; bar.cast.color = channelingColor; else - _, _, name, icon, startTime, endTime, _, _, noInterrupt, id = UnitCastingInfo(unit); + _, name, icon, startTime, endTime, _, _, noInterrupt, id = UnitCastingInfo(unit); if not startTime or not endTime then return nil end bar.channeling = nil; bar.cast.color = castingColor; @@ -90,6 +94,7 @@ local function startCast(bar, unit, channeling) toggleInterruptible(bar, noInterrupt); return true; end +M.StartCast = startCast; local function applyDelay(bar, unit, channeling) local startTime, endTime; @@ -103,6 +108,7 @@ local function applyDelay(bar, unit, channeling) bar.endTime = endTime / 1000; -- TODO show delay text end +M.ApplyDelay = applyDelay; local events = { ["UNIT_SPELLCAST_START"] = function(bar, unit) @@ -164,6 +170,7 @@ end function M.UnregisterCastEvents(bar) bar:UnregisterAllEvents(); + hideBar(bar); end function M.CreateCastBar(parent, unit, yoffset) @@ -201,5 +208,6 @@ function M.CreateCastBar(parent, unit, yoffset) bar.time = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); bar.time:SetPoint("RIGHT", bar, "RIGHT", -2, 0); bar:SetScript("OnEvent", onEvent); + updaters[bar] = function() onUpdate(bar) end return bar; end