vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local elapsed = 0 |
2 | |||
3 | -- dIsInSeconds is passed by custom clients if they want to save on maths |
||
4 | -- dontRegister is passed by custom clients if they need to call Stop/Failed/Delayed manually |
||
5 | function oCB:SpellStart(s, d, dIsInSeconds, dontRegister) |
||
6 | self:Debug(string.format("SpellStart - %s | %s (%s)%s", s, d, dIsInSeconds and "s" or "ms", dontRegister and " | Not Registering" or "")) |
||
7 | |||
8 | if not dontRegister then |
||
9 | self:RegisterEvent("SPELLCAST_STOP", "SpellStop") |
||
10 | self:RegisterEvent("SPELLCAST_INTERRUPTED","SpellFailed") |
||
11 | self:RegisterEvent("SPELLCAST_FAILED", "SpellFailed") |
||
12 | self:RegisterEvent("SPELLCAST_DELAYED", "SpellDelayed") |
||
13 | end |
||
14 | |||
15 | local c = self.db.profile.Colors.Casting |
||
16 | |||
17 | self.startTime = GetTime() |
||
18 | |||
19 | if not dIsInSeconds then |
||
20 | d = d/1000 |
||
21 | end |
||
22 | self.maxValue = self.startTime + d |
||
23 | |||
24 | self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b) |
||
25 | self.frames.CastingBar.Bar:SetMinMaxValues(self.startTime, self.maxValue ) |
||
26 | self.frames.CastingBar.Bar:SetValue(0) |
||
27 | self.frames.CastingBar.Spell:SetText(s) |
||
28 | self.frames.CastingBar:SetAlpha(1) |
||
29 | self.frames.CastingBar.Time:SetText("") |
||
30 | self.frames.CastingBar.Delay:SetText("") |
||
31 | |||
32 | self.holdTime = 0 |
||
33 | self.delay = 0 |
||
34 | self.casting = 1 |
||
35 | self.fadeOut = nil |
||
36 | |||
37 | self.frames.CastingBar:Show() |
||
38 | self.frames.CastingBar.Spark:Show() |
||
39 | end |
||
40 | |||
41 | -- Arg is for custom clients |
||
42 | function oCB:SpellStop(dontUnregister) |
||
43 | self:Debug("SpellStop - Stopping cast") |
||
44 | local c = self.db.profile.Colors.Complete |
||
45 | |||
46 | self.frames.CastingBar.Bar:SetValue(self.maxValue) |
||
47 | |||
48 | if not self.channeling then |
||
49 | self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b) |
||
50 | self.frames.CastingBar.Spark:Hide() |
||
51 | end |
||
52 | |||
53 | self.delay = 0 |
||
54 | self.casting = nil |
||
55 | self.fadeOut = 1 |
||
56 | |||
57 | if not dontUnregister then |
||
58 | self:UnregisterEvent("SPELLCAST_STOP") |
||
59 | self:UnregisterEvent("SPELLCAST_FAILED") |
||
60 | self:UnregisterEvent("SPELLCAST_INTERRUPTED") |
||
61 | self:UnregisterEvent("SPELLCAST_DELAYED") |
||
62 | end |
||
63 | end |
||
64 | |||
65 | function oCB:SpellFailed(dontUnregister) |
||
66 | local c = self.db.profile.Colors.Failed |
||
67 | |||
68 | self.frames.CastingBar.Bar:SetValue(self.maxValue) |
||
69 | self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b) |
||
70 | self.frames.CastingBar.Spark:Hide() |
||
71 | |||
72 | if (event == "SPELLCAST_FAILED") then |
||
73 | self.frames.CastingBar.Spell:SetText(FAILED) |
||
74 | else |
||
75 | self.frames.CastingBar.Spell:SetText(INTERRUPTED) |
||
76 | end |
||
77 | |||
78 | self.casting = nil |
||
79 | self.channeling = nil |
||
80 | self.fadeOut = 1 |
||
81 | self.holdTime = GetTime() + 1 |
||
82 | |||
83 | if not dontUnregister then |
||
84 | self:UnregisterEvent("SPELLCAST_STOP") |
||
85 | self:UnregisterEvent("SPELLCAST_FAILED") |
||
86 | self:UnregisterEvent("SPELLCAST_INTERRUPTED") |
||
87 | self:UnregisterEvent("SPELLCAST_DELAYED") |
||
88 | end |
||
89 | end |
||
90 | |||
91 | function oCB:SpellDelayed(d) |
||
92 | self:Debug(string.format("SpellDelayed - Spell delayed with %s", d/1000)) |
||
93 | d = d / 1000 |
||
94 | |||
95 | if(self.frames.CastingBar:IsShown()) then |
||
96 | if self.delay == nil then self.delay = 0 end |
||
97 | |||
98 | self.startTime = self.startTime + d |
||
99 | self.maxValue = self.maxValue + d |
||
100 | self.delay = self.delay + d |
||
101 | |||
102 | self.frames.CastingBar.Bar:SetMinMaxValues(self.startTime, self.maxValue) |
||
103 | end |
||
104 | end |
||
105 | |||
106 | function oCB:SpellChannelStart(d) |
||
107 | self:Debug("SpellChannelStart - Starting channel") |
||
108 | d = d / 1000 |
||
109 | local c = self.db.profile.Colors.Channel |
||
110 | |||
111 | self.startTime = GetTime() |
||
112 | self.endTime = self.startTime + d |
||
113 | self.maxValue = self.endTime |
||
114 | |||
115 | self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b) |
||
116 | self.frames.CastingBar.Bar:SetMinMaxValues(self.startTime, self.endTime) |
||
117 | self.frames.CastingBar.Bar:SetValue(self.endTime) |
||
118 | self.frames.CastingBar.Spell:SetText(arg2) |
||
119 | self.frames.CastingBar.Time:SetText("") |
||
120 | self.frames.CastingBar.Delay:SetText("") |
||
121 | self.frames.CastingBar:SetAlpha(1) |
||
122 | |||
123 | self.holdTime = 0 |
||
124 | self.casting = nil |
||
125 | self.channeling = 1 |
||
126 | self.fadeOut = nil |
||
127 | |||
128 | self.frames.CastingBar:Show() |
||
129 | self.frames.CastingBar.Spark:Show() |
||
130 | end |
||
131 | |||
132 | function oCB:SpellChannelStop() |
||
133 | self:Debug("SpellChannelStop - Stopping channel") |
||
134 | if not self.channeling then return end |
||
135 | local c = self.db.profile.Colors.Complete |
||
136 | |||
137 | self.frames.CastingBar.Bar:SetValue(self.endTime) |
||
138 | self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b) |
||
139 | self.frames.CastingBar.Spark:Hide() |
||
140 | |||
141 | self.delay = 0 |
||
142 | self.casting = nil |
||
143 | self.channeling = nil |
||
144 | self.fadeOut = 1 |
||
145 | end |
||
146 | |||
147 | function oCB:SpellChannelUpdate(d) |
||
148 | self:Debug("SpellChannelUpdate - Updating channel") |
||
149 | d = d / 1000 |
||
150 | |||
151 | if(self.frames.CastingBar:IsShown()) then |
||
152 | local origDuration = self.endTime - self.startTime |
||
153 | |||
154 | if self.delay == nil then self.delay = 0 end |
||
155 | |||
156 | self.delay = self.delay + d |
||
157 | self.endTime = GetTime() + d |
||
158 | self.maxValue = self.endTime |
||
159 | self.startTime = self.endTime - origDuration |
||
160 | |||
161 | self.frames.CastingBar.Bar:SetMinMaxValues(self.startTime, self.endTime) |
||
162 | end |
||
163 | end |
||
164 | |||
165 | function oCB:OnCasting() |
||
166 | elapsed= elapsed + arg1 |
||
167 | if(oCB.casting) then |
||
168 | local delay, n, sp = false, GetTime(), 0 |
||
169 | |||
170 | if ( n > oCB.maxValue ) then n = oCB.maxValue end |
||
171 | |||
172 | oCB.frames.CastingBar.Time:SetText(string.format( "%.1f", math.max(oCB.maxValue - n, 0.0))) |
||
173 | |||
174 | if (oCB.delay ~= 0) then delay = 1 end |
||
175 | if (delay) then |
||
176 | oCB.frames.CastingBar.Delay:SetText("+"..string.format("%.1f", oCB.delay or "" )) |
||
177 | else |
||
178 | oCB.frames.CastingBar.Delay:SetText("") |
||
179 | end |
||
180 | |||
181 | oCB.frames.CastingBar.Bar:SetValue(n) |
||
182 | |||
183 | local w = oCB.frames.CastingBar.Bar:GetWidth() |
||
184 | sp = ((n - oCB.startTime) / (oCB.maxValue - oCB.startTime)) * w |
||
185 | if( sp < 0 ) then sp = 0 end |
||
186 | |||
187 | oCB.frames.CastingBar.Spark:SetPoint("CENTER", oCB.frames.CastingBar.Bar, "LEFT", sp, 0) |
||
188 | elseif (oCB.channeling) then |
||
189 | local delay, n, sp = false, GetTime(), 0 |
||
190 | |||
191 | if (n > oCB.endTime) then n = oCB.endTime end |
||
192 | if (n == oCB.endTime) then |
||
193 | oCB.channeling = nil |
||
194 | oCB.fadeOut = 1 |
||
195 | return |
||
196 | end |
||
197 | |||
198 | local b = oCB.startTime + (oCB.endTime - n) |
||
199 | |||
200 | oCB.frames.CastingBar.Time:SetText(string.format( "%.1f", math.max(oCB.maxValue - n, 0.0))) |
||
201 | |||
202 | if (oCB.delay and oCB.delay ~= 0) then delay = 1 end |
||
203 | if (delay) then |
||
204 | oCB.frames.CastingBar.Delay:SetText("-"..string.format("%.1f", oCB.delay )) |
||
205 | else |
||
206 | oCB.frames.CastingBar.Delay:SetText("") |
||
207 | end |
||
208 | |||
209 | oCB.frames.CastingBar.Bar:SetValue(b) |
||
210 | |||
211 | local w = oCB.frames.CastingBar.Bar:GetWidth() |
||
212 | sp = ((b - oCB.startTime) / (oCB.endTime - oCB.startTime)) * w |
||
213 | |||
214 | oCB.frames.CastingBar.Spark:SetPoint("CENTER", oCB.frames.CastingBar.Bar, "LEFT", sp, 0) |
||
215 | elseif(GetTime() < oCB.holdTime) then |
||
216 | return |
||
217 | elseif(oCB.fadeOut) then |
||
218 | local a = this:GetAlpha() - .05 |
||
219 | |||
220 | if (a > 0) then |
||
221 | oCB.frames.CastingBar:SetAlpha(a) |
||
222 | else |
||
223 | oCB.fadeOut = nil |
||
224 | oCB.frames.CastingBar:Hide() |
||
225 | oCB.frames.CastingBar.Time:SetText("") |
||
226 | oCB.frames.CastingBar.Delay:SetText("") |
||
227 | oCB.frames.CastingBar:SetAlpha(1) |
||
228 | end |
||
229 | end |
||
230 | end |