vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | CandyDice = AceLibrary("AceAddon-2.0"):new( |
2 | "AceEvent-2.0","AceHook-2.0","AceDebug-2.0", |
||
3 | "AceDB-2.0","AceConsole-2.0","CandyBar-2.0" |
||
4 | ) |
||
5 | |||
6 | local cd = CandyDice |
||
7 | cd.revision = tonumber(string.sub("$Revision: 129 $", 12, -3)) |
||
8 | |||
9 | cd.textures = {} -- they'll get registered in OnInitialize |
||
10 | cd.texturenames = {} -- instead of storing this I should just update the options table in RegisterTexture() |
||
11 | |||
12 | local compost = AceLibrary:HasInstance("Compost-2.0") and AceLibrary("Compost-2.0") |
||
13 | local function GetTable() return compost and compost:Acquire() or {} end |
||
14 | local function RecycleTable(t) if compost then compost:Reclaim(t) end end |
||
15 | |||
16 | cd:RegisterDB("CandyDiceDBPerChar") |
||
17 | cd.cmdtable = {type="group",handler=CandyDice,args = { |
||
18 | timers = { |
||
19 | type="group", |
||
20 | name="Timers", |
||
21 | desc="Commands for the ability timers", |
||
22 | args = { |
||
23 | show = { |
||
24 | type="toggle", |
||
25 | name="Show Anchor", |
||
26 | desc="Show the timer anchor", |
||
27 | get=function() return CandyDiceAnchorFrame:IsShown() end, |
||
28 | set=function(show) if show then CandyDiceAnchorFrame:Show() else CandyDiceAnchorFrame:Hide() end end |
||
29 | }, |
||
30 | center = { |
||
31 | type="toggle", |
||
32 | name="Center Timers", |
||
33 | desc="Center the timer bars on the screen rather than anchoring them", |
||
34 | get=function() return CandyDice.db.profile.options["center"] end, |
||
35 | set="SetCentered" |
||
36 | }, |
||
37 | enable = { |
||
38 | type="toggle", |
||
39 | name="Enabled", |
||
40 | desc="Enable showing of ability timer bars", |
||
41 | get=function() return CandyDice.db.profile.options["buffs"] end, |
||
42 | set=function(v) if v then CandyDice:EnableBuffs() else CandyDice:DisableBuffs() end end |
||
43 | }, |
||
44 | grow = { |
||
45 | type="toggle", |
||
46 | name="Grow Upward", |
||
47 | desc="When enabled, the bars will grow upward from the anchor. Otherwise, they will grow down", |
||
48 | get=function() return CandyDice.db.profile.options.grow end, |
||
49 | set=function(v) |
||
50 | CandyDice:Debug(v) |
||
51 | CandyDice.db.profile.options.grow = v |
||
52 | CandyDice:UpdateGrowth() |
||
53 | end |
||
54 | }, |
||
55 | scale = { |
||
56 | type="range", |
||
57 | name="Scale", |
||
58 | min=.1, |
||
59 | max=10, |
||
60 | desc="Scale factor for the timer bars", |
||
61 | get=function() return CandyDice.db.profile.options.scale end, |
||
62 | set=function(v) |
||
63 | CandyDice.db.profile.options.scale = v |
||
64 | CandyDice:Setup() |
||
65 | end |
||
66 | }, |
||
67 | icon = { |
||
68 | type="toggle", |
||
69 | name="Show Icon", |
||
70 | desc="Toggle the showing of icons on timer bars", |
||
71 | get=function() |
||
72 | return CandyDice.db.profile.options.icon |
||
73 | end, |
||
74 | set=function(v) |
||
75 | if v then |
||
76 | CandyDice.db.profile.options.icon = true |
||
77 | else |
||
78 | CandyDice.db.profile.options.icon = false |
||
79 | end |
||
80 | CandyDice:Setup() |
||
81 | end, |
||
82 | }, |
||
83 | }, |
||
84 | }, |
||
85 | cooldowns = { |
||
86 | type="group", |
||
87 | name="Cooldowns", |
||
88 | desc="Commands for the cooldown timers", |
||
89 | args = { |
||
90 | show = { |
||
91 | type="toggle", |
||
92 | name="Show Anchor", |
||
93 | desc="Show the cooldown anchor", |
||
94 | get=function() return CandyDiceCooldownAnchorFrame:IsShown() end, |
||
95 | set=function(show) if show then CandyDiceCooldownAnchorFrame:Show() else CandyDiceCooldownAnchorFrame:Hide() end end |
||
96 | }, |
||
97 | enable = { |
||
98 | type="toggle", |
||
99 | name="Enabled", |
||
100 | desc="Enable or disable cooldown scanning", |
||
101 | get=function() return CandyDice.db.profile.options.cooldowns end, |
||
102 | set=function(v) if v then CandyDice:EnableCooldowns() else CandyDice:DisableCooldowns() end end |
||
103 | }, |
||
104 | grow = { |
||
105 | type="toggle", |
||
106 | name="Grow Upward", |
||
107 | desc="When enabled, the bars will grow upward from the anchor. Otherwise, they will grow down", |
||
108 | get=function() return CandyDice.db.profile.options.growcd end, |
||
109 | set=function(v) |
||
110 | CandyDice:Debug(v) |
||
111 | CandyDice.db.profile.options.growcd = v; |
||
112 | CandyDice:UpdateGrowth(); |
||
113 | end |
||
114 | }, |
||
115 | scale = { |
||
116 | type="range", |
||
117 | name="Scale", |
||
118 | min=.1, |
||
119 | max=10, |
||
120 | desc="Scale factor for the cooldown bars", |
||
121 | get=function() return CandyDice.db.profile.options.scalecd end, |
||
122 | set=function(v) |
||
123 | CandyDice.db.profile.options.scalecd = v |
||
124 | CandyDice:Setup() |
||
125 | end |
||
126 | }, |
||
127 | reversed = { |
||
128 | type="toggle", |
||
129 | name="Reversed", |
||
130 | desc="Controls whether the cooldown bars move from empty to filled or filled to empty", |
||
131 | get=function() |
||
132 | return CandyDice.db.profile.options.reversecd |
||
133 | end, |
||
134 | set=function(v) |
||
135 | if (v) then |
||
136 | CandyDice.db.profile.options.reversecd = true |
||
137 | else |
||
138 | CandyDice.db.profile.options.reversecd = false |
||
139 | end |
||
140 | CandyDice:Setup() |
||
141 | end |
||
142 | }, |
||
143 | icon = { |
||
144 | type="toggle", |
||
145 | name="Show Icon", |
||
146 | desc="Toggle the showing of icons on cooldown bars", |
||
147 | get=function() |
||
148 | return CandyDice.db.profile.options.iconcd |
||
149 | end, |
||
150 | set=function(v) |
||
151 | if v then |
||
152 | CandyDice.db.profile.options.iconcd = true |
||
153 | else |
||
154 | CandyDice.db.profile.options.iconcd = false |
||
155 | end |
||
156 | CandyDice:Setup() |
||
157 | end, |
||
158 | } |
||
159 | }, |
||
160 | }, |
||
161 | reset = { |
||
162 | type="execute", |
||
163 | name="Reset Settings", |
||
164 | desc="Resets all settings to the default", |
||
165 | func=function() CandyDice:ResetDB("profile");CandyDice:Setup() end, |
||
166 | order=5000 |
||
167 | }, |
||
168 | version = { |
||
169 | type="execute", |
||
170 | name="Report Version", |
||
171 | desc="Prints the CandyDice version", |
||
172 | func=function() CandyDice:Print(CandyDice.revision) end |
||
173 | }, |
||
174 | texture = { |
||
175 | type="text", |
||
176 | name="Bar Texture", |
||
177 | desc="The texture used for the Candy Bars", |
||
178 | validate=CandyDice.texturenames, |
||
179 | set=function(v) |
||
180 | CandyDice.db.profile.options.texture = v |
||
181 | CandyDice:Setup() |
||
182 | end, |
||
183 | get=function() |
||
184 | return CandyDice.db.profile.options.texture |
||
185 | end, |
||
186 | } |
||
187 | } |
||
188 | } |
||
189 | |||
190 | cd.defaults = {} |
||
191 | cd:RegisterDefaults( |
||
192 | 'profile', |
||
193 | { |
||
194 | tracked = nil, |
||
195 | options = { |
||
196 | center = true, -- center the timer bars |
||
197 | cooldowns = true, -- scan for cooldowns |
||
198 | buffs = true, -- scan for buffs |
||
199 | grow = true, -- timer bars grow vertically |
||
200 | growcd = true, -- cd bars grow vertically |
||
201 | scale=1, -- timer bar scale |
||
202 | scalecd=1, -- cd bar scale |
||
203 | reversecd = true, -- cooldowns count up instead of down |
||
204 | iconcd = true, -- show icons in cooldowns |
||
205 | icon = true, -- show icons on timers |
||
206 | texture= 'Default' |
||
207 | } |
||
208 | } |
||
209 | ) |
||
210 | |||
211 | |||
212 | local gratuity = AceLibrary("Gratuity-2.0") |
||
213 | local cb = CandyDice |
||
214 | local pc = AceLibrary("PaintChips-2.0") |
||
215 | |||
216 | cd:RegisterChatCommand({"/cd", "/cdice", "/candydice"}, CandyDice.cmdtable) |
||
217 | |||
218 | function CandyDice:OnInitialize() |
||
219 | --- erase all the class/race specific defaults |
||
220 | --- except the ones in the players race/class |
||
221 | local _,class = UnitClass("player") |
||
222 | local _,race = UnitRace("Player") |
||
223 | for category, buffs in self.defaults do |
||
224 | if category ~= race and category ~= class then |
||
225 | self.defaults[category] = nil |
||
226 | end |
||
227 | end |
||
228 | self:RegisterTexture('Default','Interface\\Addons\\CandyDice\\Textures\\bar.tga') |
||
229 | --~ self:SetDebugging(true) |
||
230 | self.debugFrame = ChatFrame3 |
||
231 | end |
||
232 | |||
233 | function CandyDice:OnEnable() |
||
234 | -- CandyBar setup |
||
235 | self:RegisterCandyBarGroup("CandyDice") |
||
236 | self:RegisterCandyBarGroup("CandyDiceCooldowns") |
||
237 | |||
238 | -- Load the class specific defaults into the profile |
||
239 | local _,class = UnitClass("player") |
||
240 | local _,race = UnitRace("Player") |
||
241 | if not self.db.profile.tracked then |
||
242 | self.db.profile.tracked = {} |
||
243 | self:Print("No tracking data found, loading defaults for %s/%s", race, class) |
||
244 | local classbuffs = self.defaults[class] |
||
245 | if classbuffs then |
||
246 | for buff, info in pairs(classbuffs) do |
||
247 | self.db.profile.tracked[buff] = info |
||
248 | end |
||
249 | end |
||
250 | local racebuffs = self.defaults[race] |
||
251 | if racebuffs then |
||
252 | for buff, info in pairs(self.defaults[race]) do |
||
253 | self.db.profile.tracked[buff] = info |
||
254 | end |
||
255 | end |
||
256 | end |
||
257 | |||
258 | self:UpdateGrowth() |
||
259 | |||
260 | -- Make PaintChip not suck |
||
261 | self:RegisterColors() |
||
262 | |||
263 | -- Scan the spellbook and create a index/icon cache |
||
264 | self:RegisterEvent("SPELLS_CHANGED", "ScanSpellbook") |
||
265 | self:RegisterEvent("PLAYER_PET_CHANGED", "ScanSpellbook") |
||
266 | self:ScanSpellbook() |
||
267 | |||
268 | -- Push the tracked buffs into the options table so they can be manipulated from the command line |
||
269 | self:PushTrackedToOptions() |
||
270 | |||
271 | if self.db.profile.options.cooldowns then |
||
272 | self:EnableCooldowns() -- turn on the cooldown scanning |
||
273 | end |
||
274 | if self.db.profile.options.buffs then |
||
275 | self:EnableBuffs() -- turn on the buff scanning |
||
276 | end |
||
277 | end |
||
278 | |||
279 | function CandyDice:OnDisable() |
||
280 | -- I'm sure theres something I should do here. |
||
281 | end |
||
282 | |||
283 | function CandyDice:GetFuncsForBuff(buff) |
||
284 | --- Creates closures that we can feed to the option table to get/set the various buff options |
||
285 | local ftable = {} |
||
286 | if not self.db.profile.tracked[buff] then return end |
||
287 | ftable["GetFGColor"] = function() |
||
288 | local c = unpack(CandyDice.db.profile.tracked[buff].colors) |
||
289 | local r,g,b=unpack(pc:GetRGB(c)) |
||
290 | return r/255,g/255,b/255 |
||
291 | end |
||
292 | ftable["SetFGColor"]=function(r,g,b) |
||
293 | local hex = string.format("%02x%02x%02x", r*255, g*255, b*255) |
||
294 | -- Stupid paintchips |
||
295 | pc:RegisterHex(hex) |
||
296 | CandyDice.db.profile.tracked[buff].colors[1] = hex |
||
297 | self:SetCandyBarColor(buff, hex) |
||
298 | self:SetCandyBarColor(buff.."CD", hex) |
||
299 | |||
300 | end |
||
301 | ftable["GetBGColor"]=function() |
||
302 | local fg,bg= unpack(CandyDice.db.profile.tracked[buff].colors) |
||
303 | local c = bg or fg |
||
304 | local r,g,b=unpack(pc:GetRGB(c)) |
||
305 | return r/255,g/255,b/255 |
||
306 | end |
||
307 | ftable["SetBGColor"]=function(r,g,b) |
||
308 | CandyDice:Debug("R:"..tostring(r).."G:"..tostring(g).."B:"..tostring(b)) |
||
309 | local hex = string.format("%02x%02x%02x", r*255, g*255, b*255) |
||
310 | CandyDice:Debug(hex) |
||
311 | -- Stupid paintchips |
||
312 | pc:RegisterHex(hex) |
||
313 | CandyDice.db.profile.tracked[buff].colors[2] = hex |
||
314 | cb:SetCandyBarBackgroundColor(buff, hex) |
||
315 | cb:SetCandyBarBackgroundColor(buff.."CD", hex) |
||
316 | end |
||
317 | ftable["GetScanBuff"]= function() return CandyDice.db.profile.tracked[buff]["buff"] end |
||
318 | ftable["SetScanBuff"]= function(v) |
||
319 | if (v) then CandyDice.db.profile.tracked[buff]["buff"] = true else CandyDice.db.profile.tracked[buff]["buff"]=false end |
||
320 | CandyDice:StopCandyBar(buff) |
||
321 | end |
||
322 | ftable["GetScanCD"]= function() return CandyDice.db.profile.tracked[buff]["cooldown"] end |
||
323 | ftable["SetScanCD"]= function(v) |
||
324 | if (v) then |
||
325 | CandyDice.db.profile.tracked[buff]["cooldown"] = true |
||
326 | else |
||
327 | CandyDice.db.profile.tracked[buff]["cooldown"]=false |
||
328 | end |
||
329 | CandyDice:StopCandyBar(buff.."CD") |
||
330 | end |
||
331 | ftable["delete"] = function() |
||
332 | CandyDice.db.profile.tracked[buff] = nil |
||
333 | CandyDice:UnregisterCandyBar(buff) |
||
334 | CandyDice:UnregisterCandyBar(buff.."CD") |
||
335 | CandyDice:PushTrackedToOptions() |
||
336 | end |
||
337 | return ftable |
||
338 | end |
||
339 | |||
340 | function CandyDice:PushTrackedToOptions() |
||
341 | local header = { |
||
342 | name="Abilities", |
||
343 | desc="Abilities and buffs scanned", |
||
344 | type="group", |
||
345 | args = { |
||
346 | addnew={ |
||
347 | type="text", |
||
348 | name="Add New", |
||
349 | usage="/cdice abilities addnew <ability name>", |
||
350 | order=1, |
||
351 | desc="Add a new ability to be tracked", |
||
352 | get=false, |
||
353 | set=function(v) |
||
354 | CandyDice:AddNewAbility(v) |
||
355 | end, |
||
356 | message="[%s]: %s has been added to tracked abilities." |
||
357 | }, |
||
358 | spacer={ |
||
359 | type="header", |
||
360 | order=2, |
||
361 | }, |
||
362 | } |
||
363 | } |
||
364 | for buff in self.db.profile.tracked do |
||
365 | if self.db.profile.tracked[buff] then |
||
366 | local ftable = self:GetFuncsForBuff(buff) |
||
367 | local btable = { |
||
368 | name=buff, |
||
369 | type="group", |
||
370 | desc=buff, |
||
371 | args = { |
||
372 | fgcolor= { |
||
373 | type="color", |
||
374 | name="Foreground color", |
||
375 | desc="Foreground color", |
||
376 | get=ftable["GetFGColor"], |
||
377 | set=ftable["SetFGColor"] |
||
378 | }, |
||
379 | bgcolor= { |
||
380 | type="color", |
||
381 | name="Background color", |
||
382 | desc="Background color", |
||
383 | get=ftable["GetBGColor"], |
||
384 | set=ftable["SetBGColor"] |
||
385 | }, |
||
386 | scanbuff={ |
||
387 | type="toggle", |
||
388 | name="Scan Buffs", |
||
389 | desc="Scan your buffs for this ability", |
||
390 | get=ftable.GetScanBuff, |
||
391 | set=ftable.SetScanBuff, |
||
392 | }, |
||
393 | scancd={ |
||
394 | type="toggle", |
||
395 | name="Scan Cooldowns", |
||
396 | desc="Scan for an ability cooldown", |
||
397 | get=ftable.GetScanCD, |
||
398 | set=ftable.SetScanCD, |
||
399 | }, |
||
400 | delete={ |
||
401 | type="execute", |
||
402 | name="Delete", |
||
403 | desc="Remove the ability from the list of tracked abilities", |
||
404 | func=ftable.delete |
||
405 | } |
||
406 | } |
||
407 | } |
||
408 | local key = string.lower(buff) |
||
409 | key = string.gsub(key, ' ', '_') |
||
410 | header.args[key] = btable |
||
411 | end --if self.db.profile.tracked[buff] then |
||
412 | end --for buff in self.db.profile.tracked |
||
413 | self.cmdtable.args["abilities"] = header |
||
414 | end |
||
415 | |||
416 | function CandyDice:RegisterColors() |
||
417 | for buff, info in pairs(self.db.profile.tracked) do |
||
418 | if info then |
||
419 | local fgcolor, bgcolor = unpack(info.colors) |
||
420 | if fgcolor then pc:RegisterHex(fgcolor) end |
||
421 | if bgcolor then pc:RegisterHex(bgcolor) end |
||
422 | end |
||
423 | end |
||
424 | end |
||
425 | |||
426 | function CandyDice:GetTrackedIcon(name) |
||
427 | --- Returns the icon to use for a tracked buff/cooldown |
||
428 | local t = self.db.profile.tracked |
||
429 | if t[name] and t.texture then return t.texture end |
||
430 | if self.spellcache[name] then return self.spellcache[name].texture end |
||
431 | return nil |
||
432 | end |
||
433 | |||
434 | |||
435 | |||
436 | function CandyDice:ScanSpellbook() |
||
437 | -- returns a table formated with |
||
438 | -- spellname - {spellIndex, texture} |
||
439 | -- Only need to scan the cooldowns |
||
440 | local cache = {} |
||
441 | self.shoot = nil |
||
442 | local p = self.db.profile |
||
443 | for ii =1,MAX_SPELLS do |
||
444 | local name = GetSpellName(ii, BOOKTYPE_SPELL) |
||
445 | if name == BabbleSpell["Shoot"] then |
||
446 | self.shoot = ii |
||
447 | end |
||
448 | if name and p.tracked[name] then |
||
449 | local texture = GetSpellTexture(ii, BOOKTYPE_SPELL) |
||
450 | cache[name] = {["id"]=ii, ["texture"]=texture, ["type"] = BOOKTYPE_SPELL} |
||
451 | end |
||
452 | end |
||
453 | local pspellcount = HasPetSpells() |
||
454 | if pspellcount then |
||
455 | for ii = 1, pspellcount do |
||
456 | local name = GetSpellName(ii, BOOKTYPE_PET) |
||
457 | if name and p.tracked[name] then |
||
458 | local texture = GetSpellTexture(ii, BOOKTYPE_PET) |
||
459 | cache[name] = {["id"]=ii, ["texture"]=texture, ["type"] = BOOKTYPE_PET} |
||
460 | end |
||
461 | end |
||
462 | end |
||
463 | self.spellcache = cache |
||
464 | end |
||
465 | |||
466 | |||
467 | --~ memtrack = { |
||
468 | --~ calls = 0, |
||
469 | --~ memory = 0, |
||
470 | --~ time = 0, |
||
471 | --~ } |
||
472 | |||
473 | function CandyDice:ScanBuffs() |
||
474 | --~ local time = GetTime() |
||
475 | --~ local mem = gcinfo() |
||
476 | local tracked = self.db.profile.tracked |
||
477 | local cbuffs = GetTable() |
||
478 | |||
479 | if self.db.profile.options.buffs then |
||
480 | for ii = 0,15 do |
||
481 | local bidx = GetPlayerBuff(ii, "HELPFUL") |
||
482 | gratuity:SetPlayerBuff(bidx) |
||
483 | local buff = gratuity:GetLine(1) |
||
484 | if buff and tracked[buff] and tracked[buff].buff then |
||
485 | cbuffs[buff] = buff |
||
486 | self:UpdateBuff(buff, bidx, GetPlayerBuffTimeLeft(bidx)) |
||
487 | end |
||
488 | end |
||
489 | end |
||
490 | for buff, info in pairs(tracked) do |
||
491 | if not cbuffs[buff] then |
||
492 | local registered,bartime,elapsed,running = cb:CandyBarStatus(buff) |
||
493 | if running then |
||
494 | cd:StopCandyBar(buff) |
||
495 | end |
||
496 | end |
||
497 | end |
||
498 | RecycleTable(cbuffs) |
||
499 | |||
500 | --~ memtrack.calls = memtrack.calls + 1 |
||
501 | --~ memtrack.time = memtrack.time + (GetTime()-time) |
||
502 | --~ local mem2 = gcinfo() |
||
503 | --~ memtrack.memory = memtrack.memory + (mem2 - mem) |
||
504 | --~ if math.mod(memtrack.calls, 10) == 0 then |
||
505 | --~ self:PrintComma(memtrack.calls, memtrack.time, memtrack.memory) |
||
506 | --~ end |
||
507 | end |
||
508 | |||
509 | function CandyDice:ScanCooldowns() |
||
510 | local tracked = self.db.profile.tracked |
||
511 | self:Debug("Scanning Cooldowns") |
||
512 | if self.db.profile.options.cooldowns then |
||
513 | for buff, info in pairs(tracked) do |
||
514 | if info.cooldown then |
||
515 | self:UpdateCooldown(buff, info) |
||
516 | end |
||
517 | end |
||
518 | end |
||
519 | end |
||
520 | |||
521 | function CandyDice:UpdateBuff(buff, bidx, bufftime) |
||
522 | -- Updates a buff bar to match the state of the buff. Be prepared for bidx/bufftime to be null |
||
523 | --self:Debug("Updating buff"..tostring(buff)) |
||
524 | local info = self.db.profile.tracked[buff] |
||
525 | if not info and info.buff then return end |
||
526 | local registered,bartime,elapsed,running = cb:CandyBarStatus(buff) |
||
527 | if running then |
||
528 | if (not (bufftime or bidx)) or bufftime == 0 then |
||
529 | cd:StopCandyBar(buff) |
||
530 | else |
||
531 | cd:SetCandyBarTimeLeft(buff, bufftime) |
||
532 | end |
||
533 | elseif bufftime and bufftime > 0 then-- bar not running, but with bufftime,so start the bar |
||
534 | if not registered then |
||
535 | self:Debug("Registering bar for "..buff) |
||
536 | local fgcolor, bgcolor = unpack(info.colors) |
||
537 | local icon = CandyDice.db.profile.options.icon and (GetPlayerBuffTexture(bidx) or GetPlayerBuffTexture(ii)) or '' |
||
538 | self:RegisterTimerBar(buff, fgcolor, bgcolor, icon) |
||
539 | |||
540 | end |
||
541 | cb:SetCandyBarTime(buff, bufftime) |
||
542 | cb:StartCandyBar(buff) |
||
543 | else |
||
544 | -- This would be a buff with no time, and a bar that isn't running |
||
545 | end |
||
546 | end |
||
547 | |||
548 | function CandyDice:UpdateCooldown(ability, info, doublecheck) |
||
549 | local cache = self.spellcache[ability] |
||
550 | if not (cache and cache.id and cache.type) then return end --- not in the spellcache |
||
551 | if not info and info.cooldown then return end -- not set for cooldown scanning, probably redundant |
||
552 | local cbn = ability..'CD' |
||
553 | local now = GetTime() |
||
554 | local start, duration = GetSpellCooldown(cache.id, cache.type) |
||
555 | local registered,bartime,elapsed,running = cb:CandyBarStatus(cbn) |
||
556 | if now == start then |
||
557 | --- Stealth, natures swiftness, or something else that doesn't actually start its CD until it's buff is gone. |
||
558 | --- Remotely possible this could misdetect a regular cooldown. |
||
559 | --- To catch any regular CDs we miss, we schedule one (just one) check 1/10th of a second from now |
||
560 | --~ self:Print("Skipping CD check for "..ability) |
||
561 | if not doublecheck then |
||
562 | --~ self:Print("Doublecheck scheduled") |
||
563 | self:ScheduleEvent(self.UpdateCooldown, 0.1, self, ability, info, true) |
||
564 | end |
||
565 | return |
||
566 | end |
||
567 | if not running then |
||
568 | local skipdur = 1.5 |
||
569 | if self.shoot then |
||
570 | local speed, lowDmg, hiDmg, posBuff, negBuff, percent = UnitRangedDamage("player") |
||
571 | if speed > skipdur then skipdur = speed end |
||
572 | end |
||
573 | if duration <= skipdur then return end -- ignore global CD |
||
574 | if not registered then |
||
575 | self:Debug("Registering bar for "..cbn) |
||
576 | local fgcolor, bgcolor = unpack(info.colors) |
||
577 | self:RegisterCooldownBar(ability, fgcolor, bgcolor, cache.texture) |
||
578 | end |
||
579 | local left = duration - (now - start) |
||
580 | self:SetCandyBarTime(cbn, duration) |
||
581 | self:StartCandyBar(cbn) |
||
582 | cb:SetCandyBarTimeLeft(cbn, left) |
||
583 | else -- currently running, stop if CD is gone or update time if not |
||
584 | if start == 0 or duration == 0 then |
||
585 | self:StopCandyBar(cbn) |
||
586 | return |
||
587 | end |
||
588 | local left = duration - (now - start) |
||
589 | cb:SetCandyBarTimeLeft(cbn, left) |
||
590 | end |
||
591 | end |
||
592 | |||
593 | -- command handlers |
||
594 | function CandyDice:SetCentered(v) |
||
595 | self.db.profile.options["center"] = v |
||
596 | self:UpdateGrowth() |
||
597 | end |
||
598 | |||
599 | function CandyDice:EnableCooldowns() |
||
600 | self.db.profile.options.cooldowns = true |
||
601 | self:RegisterEvent("SPELL_UPDATE_COOLDOWN", "ScanCooldowns") |
||
602 | self:ScanCooldowns() -- pick up any current ones |
||
603 | end |
||
604 | |||
605 | function CandyDice:DisableCooldowns() |
||
606 | self.db.profile.options.cooldowns = false |
||
607 | for cd, info in pairs(self.db.profile.tracked) do |
||
608 | -- Stop all our bars. |
||
609 | if info.cooldown then |
||
610 | cb:UnregisterCandyBar(cd.."CD") |
||
611 | end |
||
612 | end |
||
613 | self:UnregisterEvent("SPELL_UPDATE_COOLDOWN") |
||
614 | end |
||
615 | |||
616 | function CandyDice:EnableBuffs() |
||
617 | self.db.profile.options.buffs = true |
||
618 | -- PLAYER_ARUAS_CHANGED only fires when you actually gain or lose a debuff, |
||
619 | -- not when you re-apply one |
||
620 | self:RegisterEvent("PLAYER_AURAS_CHANGED", "ScanBuffs") |
||
621 | |||
622 | -- To keep the durations accurate if you re-apply a buff |
||
623 | self:ScheduleRepeatingEvent("CandyDice", self.ScanBuffs, 0.3, self) |
||
624 | end |
||
625 | |||
626 | function CandyDice:DisableBuffs() |
||
627 | self.db.profile.options.buffs = false |
||
628 | for cd, info in pairs(self.db.profile.tracked) do |
||
629 | -- Stop all our bars. |
||
630 | if info.buff then |
||
631 | cb:UnregisterCandyBar(cd) |
||
632 | end |
||
633 | end |
||
634 | self:UnregisterEvent("PLAYER_AURAS_CHANGED") |
||
635 | self:CancelScheduledEvent("CandyDice") |
||
636 | end |
||
637 | |||
638 | function CandyDice:UpdateGrowth() |
||
639 | local o = self.db.profile.options |
||
640 | if o.center then |
||
641 | cb:SetCandyBarGroupPoint("CandyDice", "CENTER", "UIParent", "CENTER", 0, 0) |
||
642 | else |
||
643 | if (o.grow) then |
||
644 | cb:SetCandyBarGroupPoint("CandyDice", "BOTTOM", "CandyDiceAnchorFrame", "TOP", 0, 0) |
||
645 | cb:SetCandyBarGroupGrowth("CandyDice", true) |
||
646 | else |
||
647 | cb:SetCandyBarGroupPoint("CandyDice", "TOP", "CandyDiceAnchorFrame", "BOTTOM", 0, 0) |
||
648 | cb:SetCandyBarGroupGrowth("CandyDice", false) |
||
649 | end |
||
650 | end |
||
651 | if (o.growcd) then |
||
652 | cb:SetCandyBarGroupPoint("CandyDiceCooldowns", "BOTTOM", "CandyDiceCooldownAnchorFrame", "TOP", 0, 0) |
||
653 | cb:SetCandyBarGroupGrowth("CandyDiceCooldowns", true) |
||
654 | else |
||
655 | cb:SetCandyBarGroupPoint("CandyDiceCooldowns", "TOP", "CandyDiceCooldownAnchorFrame", "BOTTOM", 0, 0) |
||
656 | cb:SetCandyBarGroupGrowth("CandyDiceCooldowns", false) |
||
657 | end |
||
658 | end |
||
659 | |||
660 | |||
661 | function CandyDice:AddNewAbility(name) |
||
662 | local info = { |
||
663 | colors = {"FFFFFF"}, |
||
664 | buff = true, |
||
665 | cooldown = true |
||
666 | } |
||
667 | local p = self.db.profile |
||
668 | p.tracked[name] = info |
||
669 | self:ScanSpellbook() |
||
670 | self:UpdateCooldown(name, info) |
||
671 | self:PushTrackedToOptions() |
||
672 | end |
||
673 | |||
674 | |||
675 | function CandyDice:Setup() |
||
676 | -- Cheat for right now & just enable/disable |
||
677 | if CandyDice:IsActive() then |
||
678 | self:ToggleActive() |
||
679 | self:ToggleActive() |
||
680 | end |
||
681 | end |
||
682 | |||
683 | |||
684 | function CandyDice:RegisterTexture(name, file) |
||
685 | self.textures[name] = file |
||
686 | table.insert(self.texturenames, name) |
||
687 | end |
||
688 | |||
689 | function CandyDice:RegisterCooldownBar(ability, fgcolor, bgcolor, icon) |
||
690 | --- register a CandyBar respecting all the CandyDice settings like show icon, texture, scaling, etc |
||
691 | --- Returns the name of the bar |
||
692 | local cbn = ability.."CD" |
||
693 | local icon = CandyDice.db.profile.options.iconcd and icon or '' |
||
694 | local o = self.db.profile.options |
||
695 | local texture = self.textures[o.texture] |
||
696 | -- register bar |
||
697 | cb:RegisterCandyBar(cbn, 1, ability, icon) |
||
698 | if fgcolor then |
||
699 | cb:SetCandyBarColor(cbn, fgcolor, 0.5) |
||
700 | cb:SetCandyBarBackgroundColor(cbn, bgcolor or fgcolor, 0.2) |
||
701 | end |
||
702 | cb:RegisterCandyBarWithGroup(cbn,"CandyDiceCooldowns") |
||
703 | cb:SetCandyBarScale(cbn, o.scalecd) |
||
704 | if texture then cb:SetCandyBarTexture(cbn, texture) end |
||
705 | if CandyDice.db.profile.options.reversecd then |
||
706 | cb:SetCandyBarReversed(cbn, true) |
||
707 | end |
||
708 | return cbn |
||
709 | end |
||
710 | |||
711 | function CandyDice:RegisterTimerBar(buff, fgcolor, bgcolor, icon) |
||
712 | -- register a CandyBar respecting all the CandyDice settings for timers |
||
713 | -- Returns the name of the bar |
||
714 | local o = self.db.profile.options |
||
715 | local icon = o.icon and icon or '' |
||
716 | local texture = self.textures[o.texture] |
||
717 | -- register bar |
||
718 | cb:RegisterCandyBar(buff, 1, buff, icon) |
||
719 | if fgcolor then |
||
720 | cb:SetCandyBarColor(buff, fgcolor, 0.5) |
||
721 | cb:SetCandyBarBackgroundColor(buff, bgcolor or fgcolor, 0.2) |
||
722 | end |
||
723 | cb:RegisterCandyBarWithGroup(buff,"CandyDice") |
||
724 | cb:SetCandyBarScale(buff, o.scale) |
||
725 | if texture then cb:SetCandyBarTexture(buff, texture) end |
||
726 | return buff |
||
727 | end |