4 local ssub = string.sub;
6 local ceil = math.ceil;
7 local UnitCastingInfo, UnitChannelInfo = UnitCastingInfo, UnitChannelInfo;
8 local GetTime = GetTime;
10 local barTexture = "Interface\\AddOns\\OmaRF\\images\\minimalist";
11 local castingColor = {1, 0.49, 0}; -- from Quartz defaults
12 local nointerruptColor = {0.6, 0.6, 0.6};
13 local channelingColor = {0.32, 0.3, 1};
18 -- TODO trade skill bar updates as well, check Quartz modules/Tradeskill.lua
19 local function onUpdate(bar)
20 if not bar:IsShown() then return end
21 local width = bar.icon:IsShown() and bar.cast.width or bar.cast.width; -- TODO fullwidth
22 local startTime, endTime = bar.startTime, bar.endTime;
23 local currentClamped = min(GetTime(), endTime);
24 local remaining = endTime - currentClamped;
26 if bar.channeling then
27 percent = remaining / (endTime - startTime);
29 percent = (currentClamped - startTime) / (endTime - startTime);
32 width = percent*width;
34 bar.cast:SetWidth(0.1);
36 bar.cast:SetWidth(width);
38 bar.time:SetFormattedText("%.1f", remaining);
41 local function showBar(bar)
43 bar:SetScript("OnUpdate", onUpdate);
46 local function hideBar(bar)
48 bar:SetScript("OnUpdate", nil);
51 local function toggleInterruptible(bar, nointr)
52 if bar.unit == "player" then return end
54 bar.cast:SetVertexColor(unpack(nointerruptColor));
57 bar.cast:SetVertexColor(unpack(bar.cast.color));
62 local function startCast(bar, unit, channeling)
63 local name, icon, startTime, endTime, noInterrupt, id;
65 name, _, _, icon, startTime, endTime, _, noInterrupt = UnitChannelInfo(unit);
66 if not startTime or not endTime then return nil end
67 bar.channeling = true;
68 bar.cast.color = channelingColor;
70 _, _, name, icon, startTime, endTime, _, _, noInterrupt, id = UnitCastingInfo(unit);
71 if not startTime or not endTime then return nil end
73 bar.cast.color = castingColor;
75 bar.startTime = startTime / 1000;
76 bar.endTime = endTime / 1000;
77 -- don't show samwise for non-existent icons
78 if icon ~= "Interface\\Icons\\Temp" then
79 bar.icon:SetTexture(icon);
81 bar.cast:SetWidth(channeling and bar.cast.width or 0.1);
84 bar.cast:SetWidth(channeling and bar.cast.width or 0.1); -- TODO use fullwidth
86 bar.spell:SetText(ssub(name, 1, bar.spell.count));
87 bar.time:SetFormattedText("%.1f", (endTime - startTime)/1000);
88 bar.cast:SetVertexColor(unpack(bar.cast.color));
90 toggleInterruptible(bar, noInterrupt);
94 local function applyDelay(bar, unit, channeling)
95 local startTime, endTime;
97 _, _, _, _, startTime, endTime = UnitChannelInfo(unit);
99 _, _, _, _, startTime, endTime = UnitCastingInfo(unit);
101 if not startTime or not endTime then return hideBar(bar) end
102 bar.startTime = startTime / 1000;
103 bar.endTime = endTime / 1000;
104 -- TODO show delay text
108 ["UNIT_SPELLCAST_START"] = function(bar, unit)
109 startCast(bar, unit);
111 ["PLAYER_TARGET_CHANGED"] = function(bar)
113 if not startCast(bar, bar.unit) then
114 startCast(bar, bar.unit, true);
117 ["UNIT_SPELLCAST_CHANNEL_START"] = function(bar, unit)
118 startCast(bar, unit, true);
120 ["UNIT_SPELLCAST_STOP"] = function(bar)
123 ["UNIT_SPELLCAST_DELAYED"] = function(bar, unit)
124 applyDelay(bar, unit);
126 ["UNIT_SPELLCAST_CHANNEL_UPDATE"] = function(bar, unit)
127 applyDelay(bar, unit, true);
129 ["UNIT_SPELLCAST_INTERRUPTIBLE"] = function(bar)
130 toggleInterruptible(bar, false);
132 ["UNIT_SPELLCAST_NOT_INTERRUPTIBLE"] = function(bar)
133 toggleInterruptible(bar, true);
136 events["UNIT_SPELLCAST_CHANNEL_STOP"] = events["UNIT_SPELLCAST_STOP"];
138 local function onEvent(bar, event, unit)
139 if unit == bar.unit or (bar.unit == "player" and unit == "vehicle") then
140 events[event](bar, unit);
141 elseif event == "PLAYER_TARGET_CHANGED" then
146 function M.RegisterCastEvents(bar)
147 --bar:RegisterEvent("UNIT_SPELLCAST_SENT");
148 bar:RegisterEvent("UNIT_SPELLCAST_START");
149 bar:RegisterEvent("UNIT_SPELLCAST_STOP");
150 --bar:RegisterEvent("UNIT_SPELLCAST_FAILED");
151 --bar:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED");
152 bar:RegisterEvent("UNIT_SPELLCAST_DELAYED");
153 bar:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START");
154 bar:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP");
155 bar:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE");
156 bar:RegisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE");
157 bar:RegisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE");
158 if bar.unit == "target" then bar:RegisterEvent("PLAYER_TARGET_CHANGED") end
159 -- trigger initial check
160 if not startCast(bar, bar.unit) then
161 startCast(bar, bar.unit, true);
165 function M.UnregisterCastEvents(bar)
166 bar:UnregisterAllEvents();
169 function M.CreateCastBar(parent, unit, yoffset)
170 local bar = CreateFrame("Frame", parent:GetName().."CastBar", parent);
172 bar:SetPoint("BOTTOMLEFT", parent, "TOPLEFT", 0, yoffset);
173 bar:SetPoint("BOTTOMRIGHT", parent, "TOPRIGHT", 0, yoffset);
176 bar.back = bar:CreateTexture(nil, "BACKGROUND");
177 bar.back:SetAllPoints();
178 bar.back:SetColorTexture(0, 0, 0, 0.7);
179 bar.icon = bar:CreateTexture(nil, "ARTWORK", 1);
180 bar.icon:SetPoint("TOPLEFT", bar, "TOPLEFT", 1, -1);
181 bar.icon:SetPoint("BOTTOMRIGHT", bar, "BOTTOMLEFT", 21, 1);
182 bar.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93); -- remove borders (from Quartz)
183 bar.shield = bar:CreateTexture(nil, "ARTWORK");
184 bar.shield:SetPoint("CENTER", bar.icon, "CENTER", -2, -1);
185 bar.shield:SetWidth(28);
186 bar.shield:SetHeight(50);
187 bar.shield:SetTexture("Interface\\CastingBar\\UI-CastingBar-Small-Shield");
188 bar.shield:SetTexCoord(0, 36/256, 0, 1);
190 bar.cast = bar:CreateTexture(nil, "ARTWORK");
191 bar.cast:SetPoint("TOPLEFT", bar.icon, "TOPRIGHT", 1, 0);
192 bar.cast:SetPoint("BOTTOMLEFT", bar.icon, "BOTTOMRIGHT", 1, 0);
193 bar.cast.width = bar:GetWidth() - bar.icon:GetWidth() - 3;
194 bar.cast.fullwidth = bar:GetWidth() - 2; -- for casts without icon
195 bar.cast:SetWidth(bar.cast.width);
196 bar.cast:SetTexture(barTexture);
197 bar.cast.color = castingColor;
198 bar.spell = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
199 bar.spell:SetPoint("LEFT", bar.icon, "RIGHT", 2, 0);
200 bar.spell.count = ceil(bar.cast:GetWidth()/10);
201 bar.time = bar:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
202 bar.time:SetPoint("RIGHT", bar, "RIGHT", -2, 0);
203 bar:SetScript("OnEvent", onEvent);