vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 -- TODO: some inconsistency with clearcasting, or maybe I'm just stupid. go play more mage.
3 -- TODO: make it possible to localize help
4 -- TODO: SCT support. message when rule begins/end or something, shouldn't be hard to add
5  
6 FiveSec = {
7 version = "2.1.2",
8 supportedbuild = "11000",
9 lastupdate = "May 28, 2006",
10 name = "FiveSec",
11 cmd = "/fs",
12 cmd2 = "/fivesec",
13 frame = "FiveSecBarFrame",
14 author = "Silent",
15 email = "silentaddons@gmail.com",
16 url = "http://www.curse-gaming.com/mod.php?addid=3319",
17 events = {
18 "SPELLCAST_STOP",
19 "SPELLCAST_CHANNEL_START",
20 "SPELLCAST_CHANNEL_STOP",
21 "SPELLCAST_FAILED",
22 "SPELLCAST_INTERRUPTED",
23 "CHAT_MSG_SPELL_SELF_DAMAGE", -- need this one for Raptor Strike
24 "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS", -- need this one to detect Spirit Tap/Innervate/Blue Dragon aura
25 "CHAT_MSG_SPELL_AURA_GONE_SELF", -- ... and for when the buffs fade
26 "UNIT_MANA",
27 },
28 help = {
29 ["reset"] = "$v/fs reset$ev: Moves the bar in position above the casting bar.",
30 ["toggle"] = "$v/fs$ev <$von$ev | $voff$ev>: Toggle the addon on or off.",
31 ["mode"] = "$v/fs mode$ev <$vstandard$ev | $vreverse$ev>: Increasing or decreasing bar.",
32 ["move"] = "$v/fs move$ev <$von$ev | $voff$ev>: Turn on to easily move the bar.",
33 ["hidden"] = "$v/fs hidden$ev <$von$ev | $voff$ev>: Turn on to keep functionality without showing the bar (for Perl users).",
34 ["fraction"] = "$v/fs fraction$ev <$von$ev | $voff$ev>: Turn on to show split seconds in the timer.",
35 ["alpha"] = "$v/fs alpha$ev <$v0.1$ev - $v1.0$ev>: Set opacity.",
36 ["scale"] = "$v/fs scale$ev <$v0.5$ev - $v2.0$ev>: Set scale.",
37 ["about"] = "$v/fs about$ev: Displays infomation about this addon.",
38 },
39 }
40  
41 -- addon loading and initialization
42 --------------------------------------------------------------------------------
43  
44 function FiveSec:Initalize()
45  
46 TNE_FiveSec_Enabled = true
47 TNE_FiveSec_Movable = false
48 TNE_FiveSec_Reverse = false
49 TNE_FiveSec_Hidden = false
50 TNE_FiveSec_Scale = 0.8
51 TNE_FiveSec_Alpha = 1.0
52 TNE_FiveSec_SplitSeconds = false
53 TNE_FiveSec_FIVE_SECONDS = 5 -- duh. but maybe it changes some day
54 TNE_FiveSec_25FPS = 0.025
55 TNE_FiveSec_10FPS = 0.1
56 TOTAL_MANA_REGENERATED = 0 -- this variable can be used to track mana regen from another addon
57 REGENERATING_MANA = true -- globally available boolean, true if mana regeneration is active
58  
59 FiveSec:UpdatePosition()
60  
61 -- setup values
62 local frame = getglobal(FiveSec.frame)
63 frame.active = nil
64 frame.duration = TNE_FiveSec_FIVE_SECONDS
65 frame.timer = 0
66 frame.delay = 0
67 frame.mode = "standard"
68 frame.fadeOutTime = 1.5
69 frame.update = 0
70 frame.updateRate = TNE_FiveSec_25FPS
71 FiveSec.mana = 0
72 FiveSec.activeBuffs = {}
73  
74 -- function hooks
75 TNE_FiveSec_Old_CastSpell = CastSpell
76 CastSpell = TNE_FiveSec_CastSpell
77 TNE_FiveSec_Old_CastSpellByName = CastSpellByName
78 CastSpellByName = TNE_FiveSec_CastSpellByName
79 TNE_FiveSec_Old_UseAction = UseAction
80 UseAction = TNE_FiveSec_UseAction
81 TNE_FiveSec_Old_SpellStopCasting = SpellStopCasting
82 SpellStopCasting = TNE_FiveSec_SpellStopCasting
83 TNE_FiveSec_Old_SpellStopTargeting = SpellStopTargeting
84 SpellStopTargeting = TNE_FiveSec_SpellStopTargeting
85  
86 -- chat commands
87 SlashCmdList["FIVESECCMD"] = TNE_FiveSec_Command
88 SLASH_FIVESECCMD1 = FiveSec.cmd
89 SLASH_FIVESECCMD2 = FiveSec.cmd2
90  
91 -- piggyback ride on blizzards UI management. sweet. -- temporarily disabled
92 --UIPARENT_MANAGED_FRAME_POSITIONS["FiveSecBarFrame"] = {baseY = 120, bottomEither = 40, pet = 40, reputation = 9}
93  
94 TNEUtils.Help(FiveSec, "onload")
95  
96 end
97  
98  
99 function FiveSec:OnLoadToggle()
100  
101 local frame, spark = getglobal(FiveSec.frame), getglobal(FiveSec.frame.. "Spark")
102 frame:SetScale(TNE_FiveSec_Scale)
103 frame:SetAlpha(0)
104 FS_Enabled, FS_ReverseMode = nil, nil -- remove old variables
105 if (TNE_FiveSec_Reverse) then
106 frame.mode = "reverse"
107 end
108 if (TNE_FiveSec_Enabled) then
109 TNEUtils.CombatEcho(FiveSec.name.. ": Addon enabled.")
110 TNEUtils.RegisterEvents(FiveSec.frame, FiveSec.events)
111 frame:Show()
112 else
113 TNEUtils.CombatEcho(FiveSec.name.. ": Addon disabled.")
114 frame:Hide()
115 end
116  
117 frame:SetValue(0)
118 frame:SetMinMaxValues(0, 1)
119 spark:Hide()
120  
121 end
122  
123 function FiveSec:ManaCheck()
124 if (TNE_FiveSec_Enabled and UnitPowerType("player") == 0) then
125 -- player is using mana
126 TNEUtils.RegisterEvents(FiveSec.frame, FiveSec.events)
127 else
128 TNEUtils.UnregisterEvents(FiveSec.frame, FiveSec.events)
129 end
130 end
131  
132  
133 -- hooked functions
134 --------------------------------------------------------------------------------
135  
136 function TNE_FiveSec_SpellStopCasting()
137 if (TNE_FiveSec_Enabled) then
138 FiveSec:ClearTooltip()
139 FiveSec.nextMelee = nil
140 FiveSec.nextSpell = nil
141 end
142 TNE_FiveSec_Old_SpellStopCasting()
143 end
144  
145 function TNE_FiveSec_SpellStopTargeting()
146 if (TNE_FiveSec_Enabled) then
147 FiveSec:ClearTooltip()
148 FiveSec.nextSpell = nil
149 end
150 TNE_FiveSec_Old_SpellStopTargeting()
151 end
152  
153 function TNE_FiveSec_UseAction(actionID, number, onSelf)
154  
155 if (TNE_FiveSec_Enabled and not (IsAutoRepeatAction(actionID) or IsConsumableAction(actionID) or GetActionText(actionID))) then
156 FiveSec:SetTooltipAction(actionID)
157 FiveSec:ProcessTooltip()
158 end
159  
160 TNE_FiveSec_Old_UseAction(actionID, number, onSelf)
161  
162 end
163  
164 function TNE_FiveSec_CastSpell(spellId, spellbookTabNum)
165  
166 --TNEUtils.CombatEcho("CastSpell: ".. spellID) --debug
167 if (TNE_FiveSec_Enabled) then
168 FiveSec:SetTooltipSpell(spellId, spellbookTabNum)
169 FiveSec:ProcessTooltip()
170 end
171  
172 TNE_FiveSec_Old_CastSpell(spellId, spellbookTabNum)
173  
174 end
175  
176 function TNE_FiveSec_CastSpellByName(spellName, onSelf) -- should catch macro'ed spells
177  
178 --TNEUtils.CombatEcho2("CastSpellByName: ".. spellName) --debug
179  
180 -- this loop should break out early most of the times
181 if (TNE_FiveSec_Enabled) then
182  
183 for i=1, 255 do
184 local spell = GetSpellName(i, BOOKTYPE_SPELL)
185 if (spell) then
186 if (spell == spellName) then
187 --TNEUtils.CombatEcho("CastSpellByName found spell ID: ".. 1) --debug
188 FiveSec:SetTooltipSpell(i, BOOKTYPE_SPELL)
189 FiveSec:ProcessTooltip()
190 break;
191 end
192 else
193 break
194 end
195 end
196  
197 end
198  
199 TNE_FiveSec_Old_CastSpellByName(spellName, onSelf)
200  
201 end
202  
203  
204 -- tooltip management
205 --------------------------------------------------------------------------------
206  
207 function FiveSec:ProcessTooltip()
208 if (FiveSec:TooltipSpellHasManaCost()) then
209 if (FiveSec:TooltipSpellIsNextMelee()) then
210 FiveSec.nextMelee = FiveSec:TooltipSpellName()
211 else
212 FiveSec.nextSpell = true
213 end
214 else
215 FiveSec.nextSpell = nil
216 end
217 end
218  
219 function FiveSec:SetTooltipSpell(spellId, spellbookTabNum)
220  
221 FiveSecTooltip:SetOwner(getglobal(FiveSec.frame), "ANCHOR_NONE") -- 1.10 ftw
222  
223 local oldUberTooltips = GetCVar("UberTooltips") -- backup and override ubertooltip settings
224 SetCVar("UberTooltips", 1)
225  
226 if (GetSpellName(spellId, spellbookTabNum)) then
227 FiveSecTooltip:SetSpell(spellId, spellbookTabNum)
228 end
229  
230 SetCVar("UberTooltips", oldUberTooltips) -- restore ubertooltip setting
231  
232 end
233  
234 function FiveSec:SetTooltipAction(index)
235  
236 FiveSecTooltip:SetOwner(getglobal(FiveSec.frame), "ANCHOR_NONE") -- 1.10 ftw
237  
238 local oldUberTooltips = GetCVar("UberTooltips") -- backup and override ubertooltip settings
239 SetCVar("UberTooltips", 1)
240  
241 if (GetActionTexture(index)) then -- skip empty action slots
242 FiveSecTooltip:SetAction(index)
243 end
244  
245 SetCVar("UberTooltips", oldUberTooltips) -- restore ubertooltip setting
246  
247 end
248  
249 function FiveSec:ClearTooltip()
250 FiveSecTooltip:ClearLines()
251 end
252  
253 function FiveSec:TooltipSpellName()
254 return FiveSecTooltipTextLeft1:GetText()
255 end
256  
257 function FiveSec:TooltipSpellHasManaCost()
258 local text = FiveSecTooltipTextLeft2:GetText()
259 if (text) then
260 return string.find(text, MANA)
261 else
262 return nil
263 end
264 end
265  
266 function FiveSec:TooltipSpellIsNextMelee()
267 local text = FiveSecTooltipTextLeft3:GetText()
268 if (text) then
269 return string.find(text, SPELL_ON_NEXT_SWING)
270 end
271 return nil
272 end
273  
274  
275 -- statusbar managment
276 --------------------------------------------------------------------------------
277  
278 function FiveSec:Start()
279  
280 --TNEUtils.CombatEcho("FiveSec:Start() called") --debug
281  
282 --if (table.getn(FiveSec.activeBuffs) > 0) then
283 --return
284 --end
285  
286 local frame, text, spark = getglobal(FiveSec.frame), getglobal(FiveSec.frame.. "Text"), getglobal(FiveSec.frame.. "Spark")
287 local delay, now = 0, GetTime()
288 if (FiveSec.lastGain) then
289 --delay = math.mod(FiveSec.lastGain, 2)
290 delay = 1 - math.mod(now - FiveSec.lastGain, 2) -- not 100% accurate
291 --delay = 2 - math.mod(now - FiveSec.lastGain, 2)
292 --delay = math.mod(now - FiveSec.lastGain, 2)
293 --delay = 1
294 --pxd("Delay by: ".. (delay))
295 --if (delay < -0.2) then
296 -- pxd("Expect tick at (7): ".. now + 7 + delay)
297 --else
298 -- pxd("Expect tick at (5): ".. now + 5 + delay)
299 --end
300 --pxd("Was expected at: ".. now + delay)
301 --pxd("Last tick was: ".. now - delay)
302 end
303  
304 -- set values
305 frame.active = 1
306 frame.startTime = GetTime()
307 frame.lastUpdate = frame.startTime
308 frame.delay = TNEUtils.Select(delay < 0, 2 + delay, delay)
309 --frame.delay = delay
310 --pxd(frame.delay)
311 frame.duration = TNE_FiveSec_FIVE_SECONDS + frame.delay
312 frame.timer = TNEUtils.Select(frame.mode == "reverse", frame.duration, 0)
313  
314 -- color and decoration
315 local color = TNE_FiveSec_BarColors["disabled"]
316 if (table.getn(FiveSec.activeBuffs) > 0) then
317 color = TNE_FiveSec_BarColors["enabled"]
318 end
319 frame:SetStatusBarColor(color.r, color.g, color.b)
320 frame:SetMinMaxValues(0, frame.duration)
321 frame:SetValue(frame.timer)
322 spark:Show()
323 text:SetText(format(TNE_FiveSec_REGENERATION_IN, frame.duration))
324  
325 -- display
326 UIFrameFadeRemoveFrame(frame)
327 frame:SetAlpha(TNEUtils.Select(TNE_FiveSec_Hidden, 0, TNE_FiveSec_Alpha))
328  
329 -- set global flags (used in ManaWatch, Perl)
330 REGENERATING_MANA = false -- global flag: mana regenartion active
331 if (TOTAL_MANA_REGENERATED > 0) then -- global flag: regenerated mana
332 TOTAL_MANA_REGENERATED = 0
333 end
334  
335 end
336  
337 function FiveSec:Stop()
338  
339 --TNEUtils.CombatEcho("FiveSec:Stop() called") --debug
340  
341 local frame, text, spark = getglobal(FiveSec.frame), getglobal(FiveSec.frame.. "Text"), getglobal(FiveSec.frame.. "Spark")
342  
343 frame.active = nil
344  
345 --local color = TNE_FiveSec_BarColors["enabled"]
346 --frame:SetStatusBarColor(color.r, color.g, color.b)
347 frame:SetValue(TNEUtils.Select(frame.mode == "reverse", 0, frame.duration))
348 spark:Hide()
349 text:SetText(format(TNE_FiveSec_REGENERATION_IN_INT, 0))
350  
351 if (TOTAL_MANA_REGENERATED < 0) then
352 TOTAL_MANA_REGENERATED = 0
353 end
354 REGENERATING_MANA = true
355  
356 if (not TNE_FiveSec_Movable) then
357 UIFrameFadeOut(frame, frame.fadeOutTime * TNE_FiveSec_Alpha, frame:GetAlpha(), 0)
358 end
359  
360 end
361  
362 function FiveSec:WaitWhileChanneling(delayedAt)
363 local frame, label, text, delay, spark = getglobal(FiveSec.frame), getglobal(FiveSec.frame.. "Label"), getglobal(FiveSec.frame.. "Text"), getglobal(FiveSec.frame.. "Delay"), getglobal(FiveSec.frame.. "Spark")
364 frame.delayed = delayedAt
365 frame:SetValue(delayedAt)
366 label:Hide()
367 text:Hide()
368 delay:Show()
369 delay:SetAlpha(0)
370 spark:Hide()
371 UIFrameFlash(delay, 0.4, 0.75, -1, nil, 0, 0.5)
372 end
373  
374 function FiveSecBarFrame_OnUpdate(elapsed)
375  
376 local frame = getglobal(FiveSec.frame)
377  
378 -- limiter
379 frame.update = this.update + elapsed
380 if (frame.update < frame.updateRate) then
381 return
382 end
383 this.update = 0
384  
385 local now = GetTime()
386  
387 if (frame.possibleInterruptAt) then
388 if (now > frame.possibleInterruptAt + 0.5) then
389 if (frame.wasActiveOnInterrupt) then
390 FiveSec:Start(now - frame.possibleInterruptAt)
391 end
392 frame.possibleInterruptAt = nil
393 frame.wasActiveOnInterrupt = nil
394 end
395 end
396  
397 if (frame.active) then
398 -- update timer
399 frame.timer = frame.timer + TNEUtils.Select(frame.mode == "reverse", frame.lastUpdate - now, now - frame.lastUpdate)
400 frame.lastUpdate = now
401  
402 if (FiveSec.channeling) then
403 if (frame.delayed) then
404 return -- do nothing until player stops channeling
405 elseif ((frame.mode == "reverse" and frame.timer < frame.delay) or (frame.mode == "standard" and frame.timer > TNE_FiveSec_FIVE_SECONDS)) then
406 FiveSec:WaitWhileChanneling(frame.timer)
407 return
408 end
409 elseif (frame.delayed) then
410 -- restore frame
411 frame.timer = frame.delayed
412 frame.delayed = nil
413 local delayLabel = getglobal(FiveSec.frame.. "Delay")
414 UIFrameFlashRemoveFrame(delayLabel)
415 UIFrameFadeRemoveFrame(delayLabel)
416 delayLabel:Hide()
417 getglobal(FiveSec.frame.. "Label"):Show()
418 getglobal(FiveSec.frame.. "Text"):Show()
419 --frame:SetAlpha(TNEUtils.Select(TNE_FiveSec_Hidden, 0, TNE_FiveSec_Alpha))
420 end
421  
422 if (frame.timer < 0 or frame.timer > frame.duration) then
423 -- time's up, snap to limits and stop
424 frame.timer = TNEUtils.Select(frame.timer < 0, 0, frame.duration)
425 FiveSec:Stop()
426 else
427 if ((frame.mode == "reverse" and frame.timer < frame.delay) or (frame.mode == "standard" and frame.timer > TNE_FiveSec_FIVE_SECONDS)) then
428 REGENERATING_MANA = true
429 end
430 -- keep going, set time remaining
431 local frame, text, spark = getglobal(FiveSec.frame), getglobal(FiveSec.frame.. "Text"), getglobal(FiveSec.frame.. "Spark")
432 frame:SetValue(frame.timer)
433 --local secondsToRegen = math.ceil(TNEUtils.Select(frame.mode == "reverse", frame.timer, frame.duration - frame.timer))
434 local secondsToRegen = TNEUtils.Select(frame.mode == "reverse", frame.timer, frame.duration - frame.timer)
435 if (TNE_FiveSec_SplitSeconds) then
436 text:SetText(format(TNE_FiveSec_REGENERATION_IN, secondsToRegen))
437 else
438 text:SetText(format(TNE_FiveSec_REGENERATION_IN_INT, math.ceil(secondsToRegen)))
439 end
440 -- update the spark. I love the spark
441 local sparkPosition = (frame.timer / frame.duration) * frame:GetWidth()
442 --spark:SetPoint("CENTER", FiveSec.frame, "LEFT", TNEUtils.Select(sparkPosition < 0, 0, sparkPosition), 0)
443 spark:SetPoint("CENTER", FiveSec.frame, "LEFT", sparkPosition, 0)
444 spark:Show()
445 end
446 end
447  
448 end
449  
450  
451  
452 -- addon logic
453 --------------------------------------------------------------------------------
454  
455 function FiveSec:CheckInterrupt()
456  
457 ----pxd("Interrupt call")
458 local frame = getglobal(FiveSec.frame)
459 frame.possibleInterruptAt = GetTime()
460 if (frame.active) then
461 ----pxd(" Already active")
462 frame.wasActiveOnInterrupt = true
463 else
464 ----pxd(" Not active. Starting.")
465 frame.wasActiveOnInterrupt = false
466 FiveSec:Start()
467 end
468  
469 end
470  
471 function FiveSec:Interrupt()
472 --this.timer = TNEUtils.Select(this.mode == "reverse", 0, this.fiveSeconds)
473 FiveSec:Stop()
474 this.possibleInterruptAt = nil
475 this.wasActiveOnInterrupt = nil
476 end
477  
478 function FiveSecBarFrame_OnEvent()
479  
480 --if (arg1) then
481 -- TNEUtils.CombatEcho(event..": ".. arg1) --debug
482 --else
483 -- TNEUtils.CombatEcho(event..": no arg1") --debug
484 --end
485  
486 if (event == "UNIT_MANA") then
487  
488 if not (arg1 == "player") then
489 return
490 end
491  
492 local mana = UnitMana("player")
493 if (mana > FiveSec.mana and FiveSec.mana > 0) then
494 FiveSec.lastGain = GetTime()
495 --pxd("Tick at: ".. FiveSec.lastGain)
496 --else
497 -- local now = GetTime() -- unreliable
498 -- if (FiveSec.lastGain) then
499 -- FiveSec.lastLoss = now
500 --pxd("Loss at: ".. FiveSec.lastLoss)
501 --pxd("Difference: ".. 2-math.mod(FiveSec.lastLoss - FiveSec.lastGain, 2))
502 -- end
503 end
504 FiveSec.mana = mana
505  
506 elseif (event == "SPELLCAST_STOP") then
507  
508 if (FiveSec.channeling) then
509 -- we just finished casting a channeled spell (does not trigger rule)
510 -- do nothing
511 elseif (FiveSec.nextSpell) then
512 -- an expected spell will trigger the rule
513 FiveSec:CheckInterrupt()
514 end
515 -- reset
516 FiveSec.nextSpell = nil
517 FiveSec:ClearTooltip()
518  
519 elseif (event == "SPELLCAST_CHANNEL_START") then
520  
521 -- channeling spell are interesting if they cost mana
522 if (FiveSec:TooltipSpellHasManaCost()) then
523 -- flag it so we don't think it's an instant when it stops
524 FiveSec.channeling = true
525 FiveSec:Start()
526 end
527 FiveSec:ClearTooltip()
528  
529 elseif (event == "SPELLCAST_CHANNEL_STOP") then
530  
531 FiveSec.channeling = false
532  
533 elseif (event == "SPELLCAST_INTERRUPTED" or event == "SPELLCAST_FAILED") then
534  
535 -- spell was interrupted. abort
536 -- SPELLCAST_FAILED is when out of range, out of mana, spell on cooldown, or right-click-to-clear
537 FiveSec.channeling = nil
538 FiveSec.nextSpell = nil
539 if (this.possibleInterruptAt) then
540 --pxd(" EVENT: expected interrupt")
541 if (not this.wasActiveOnInterrupt) then
542 FiveSec:Interrupt()
543 ----pxd(" Was not active: Stopping")
544 --else
545 ----pxd(" Was active: No action")
546 end
547 this.possibleInterruptAt = nil
548 this.wasActiveOnInterrupt = nil
549 else
550 --pxd(" EVENT: unexpected interrupt")
551 end
552 FiveSec:ClearTooltip()
553  
554 elseif (event == "CHAT_MSG_SPELL_SELF_DAMAGE" and FiveSec.nextMelee) then
555  
556 -- Raptor Strike and other hunter abilites are on-next-melee with mana cost. a special bunch, those hunters
557 if (string.find (arg1, FiveSec.nextMelee)) then
558 FiveSec:Start()
559 FiveSec.nextMelee = nil
560 FiveSec:ClearTooltip()
561 end
562  
563 elseif (event == "CHAT_MSG_SPELL_AURA_GONE_SELF") then
564  
565 -- restore the bar when Blue Dragon aura, Innervate, etc fades
566 for i, buff in FiveSec.activeBuffs do
567 if (string.find(arg1, buff)) then
568 local color = TNE_FiveSec_BarColors["disabled"]
569 FiveSecBarFrame:SetStatusBarColor(color.r, color.g, color.b)
570 table.remove(FiveSec.activeBuffs, i)
571 break
572 end
573 end
574  
575 elseif (event == "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS") then
576  
577 -- interrupt the bar when gaining Blue Dragon aura, Innervate, etc
578 for _, buff in TNE_FiveSec_RegenerationBuffs do
579 if (string.find(arg1, buff)) then
580 local color = TNE_FiveSec_BarColors["enabled"]
581 FiveSecBarFrame:SetStatusBarColor(color.r, color.g, color.b)
582 --FiveSec:Interrupt()
583 table.insert(FiveSec.activeBuffs, buff)
584 break
585 end
586 end
587  
588 elseif (event == "UNIT_DISPLAYPOWER") then
589 FiveSec:ManaCheck()
590  
591 elseif (event == "VARIABLES_LOADED") then
592 FiveSec:OnLoadToggle()
593 end
594  
595 end
596  
597  
598 -- addon managment
599 --------------------------------------------------------------------------------
600  
601 function FiveSec:UpdatePosition()
602 FiveSecBarFrame:ClearAllPoints()
603 if (CastingBarReplacementFrame) then
604 FiveSecBarFrame:SetPoint("BOTTOM", "CastingBarReplacementFrame", "TOP", 0, 10)
605 else
606 FiveSecBarFrame:SetPoint("BOTTOM", "CastingBarFrame", "TOP", 0, 10)
607 end
608 UIParent_ManageFramePositions()
609 end
610  
611 function TNE_FiveSec_Command(arg1)
612  
613 if (not arg1) then return end
614  
615 local frame = getglobal(FiveSec.frame)
616  
617 -- reset
618 if (string.find(arg1, "^"..TNE_FiveSec_CMD_RESET.."$")) then
619 FiveSec:UpdatePosition()
620 TNEUtils.PrefixedEcho(FiveSec.name, TNE_FiveSec_HELP_RESET)
621  
622 -- about
623 elseif (string.find(arg1, "^"..TNE_FiveSec_CMD_ABOUT.."$")) then
624 TNEUtils.About(FiveSec)
625  
626 -- mode
627 elseif (string.find(arg1, "^"..TNE_FiveSec_CMD_MODE)) then
628 -- save old mode
629 local oldMode = frame.mode
630 if (string.find(arg1, "^"..TNE_FiveSec_CMD_MODE.." "..TNE_FiveSec_CMD_MODE_STANDARD)) then
631 -- enter standard mode
632 TNE_FiveSec_Reverse = TNEUtils.SetVar(FiveSec, TNE_FiveSec_Reverse, false, TNE_FiveSec_HELP_REVERSE_MODE, nil)
633 frame.mode = "standard"
634 elseif (string.find(arg1, "^"..TNE_FiveSec_CMD_MODE.." "..TNE_FiveSec_CMD_MODE_REVERSE)) then
635 -- enter reverse mode
636 TNE_FiveSec_Reverse = TNEUtils.SetVar(FiveSec, TNE_FiveSec_Reverse, true, TNE_FiveSec_HELP_REVERSE_MODE, nil)
637 frame.mode = "reverse"
638 else
639 -- show help
640 TNEUtils.Help(FiveSec, "mode")
641 end
642 -- convert timer to new mode
643 if (not (frame.mode == oldMode) and (frame.timer > 0)) then
644 frame.timer = frame.duration - frame.timer
645 end
646  
647 -- moving
648 elseif (string.find(arg1, "^"..TNE_FiveSec_CMD_MOVE)) then
649 if (string.find(arg1, "^"..TNE_FiveSec_CMD_MOVE.." "..TNE_FiveSec_CMD_OFF.."$") or string.find(arg1, "^"..TNE_FiveSec_CMD_MOVE.." "..TNE_FiveSec_CMD_ON.."$")) then
650 TNE_FiveSec_Movable = TNEUtils.SetVar(FiveSec, TNE_FiveSec_Movable, string.find(arg1, " "..TNE_FiveSec_CMD_ON.."$"), TNE_FiveSec_HELP_MOVING, nil)
651 frame:EnableMouse(TNE_FiveSec_Movable)
652 if (TNE_FiveSec_Movable) then
653 frame:SetAlpha(TNE_FiveSec_Alpha)
654 elseif (frame.timer == 0 or frame.timer == frame.duration) then
655 UIFrameFadeOut(frame, frame.fadeOutTime, frame:GetAlpha(), 0)
656 end
657 else
658 TNEUtils.Help(FiveSec, "move")
659 end
660  
661 -- hidden on/off
662 elseif (string.find(arg1, "^"..TNE_FiveSec_CMD_HIDDEN)) then
663 if (string.find(arg1, "^"..TNE_FiveSec_CMD_HIDDEN.." "..TNE_FiveSec_CMD_OFF.."$") or string.find(arg1, "^"..TNE_FiveSec_CMD_HIDDEN.." "..TNE_FiveSec_CMD_ON.."$")) then
664 TNE_FiveSec_Hidden = TNEUtils.SetVar(FiveSec, TNE_FiveSec_Hidden, string.find(arg1, " "..TNE_FiveSec_CMD_ON.."$"), TNE_FiveSec_HELP_HIDDEN, nil)
665 frame:SetAlpha(TNEUtils.Select(TNE_FiveSec_Hidden, 0, TNE_FiveSec_Alpha))
666 frame.updateRate = TNEUtils.Select(TNE_FiveSec_Hidden, TNE_FiveSec_10FPS, TNE_FiveSec_25FPS)
667 else
668 TNEUtils.Help(FiveSec, "hidden")
669 end
670  
671 -- fraction on/off
672 elseif (string.find(arg1, "^"..TNE_FiveSec_CMD_FRACTION)) then
673 if (string.find(arg1, "^"..TNE_FiveSec_CMD_FRACTION.." "..TNE_FiveSec_CMD_OFF.."$") or string.find(arg1, "^"..TNE_FiveSec_CMD_FRACTION.." "..TNE_FiveSec_CMD_ON.."$")) then
674 TNE_FiveSec_SplitSeconds = TNEUtils.SetVar(FiveSec, TNE_FiveSec_SplitSeconds, string.find(arg1, " "..TNE_FiveSec_CMD_ON.."$"), TNE_FiveSec_HELP_FRACTION, nil)
675 else
676 TNEUtils.Help(FiveSec, "fraction")
677 end
678  
679 -- alpha
680 elseif (string.find(arg1, "alpha")) then
681 local _, _, alpha = string.find(arg1, "alpha (.+)")
682 alpha = tonumber(alpha)
683 if (alpha >= 0.1 and alpha <= 1.0) then
684 if not (frame.timer == 0 or frame.timer == frame.duration) or TNE_FiveSec_Movable then
685 local fadeFunction = TNEUtils.Select(TNE_FiveSec_Alpha > alpha, UIFrameFadeOut, UIFrameFadeIn)
686 fadeFunction(frame, 0.5, frame:GetAlpha(), alpha)
687 end
688 TNE_FiveSec_Alpha = alpha
689 TNEUtils.PrefixedEcho(FiveSec.name, "Bar alpha value set to $v".. TNE_FiveSec_Alpha.. "$ev.")
690 else
691 TNEUtils.PrefixedEcho(FiveSec.name, "Invalid alpha value (must be between $v0.1$ev and $v1.0$ev)")
692 end
693  
694 -- scale
695 elseif (string.find(arg1, "scale")) then
696 local _, _, scale = string.find(arg1, "scale (.+)")
697 scale = tonumber(scale)
698 if (scale >= 0.5 and scale <= 2.0) then
699 TNE_FiveSec_Scale = scale
700 frame:SetScale(TNE_FiveSec_Scale)
701 TNEUtils.PrefixedEcho(FiveSec.name, "Bar scaled to $v".. TNE_FiveSec_Scale.. "$ev.")
702 else
703 TNEUtils.PrefixedEcho(FiveSec.name, "Invalid scale value (must be between $v0.5$ev and $v2.0$ev)")
704 end
705  
706 -- addon on/off
707 elseif (string.find(arg1, "^"..TNE_FiveSec_CMD_OFF.."$") or string.find(arg1, "^"..TNE_FiveSec_CMD_ON.."$")) then
708 TNE_FiveSec_Enabled = TNEUtils.ToggleAddon(FiveSec, FiveSec.frame, TNE_FiveSec_Enabled, string.find(arg1, "^"..TNE_FiveSec_CMD_ON.."$"), nil)
709 if (TNE_FiveSec_Enabled) then
710 frame:Show()
711 else
712 frame:Hide()
713 REGENERATING_MANA, TOTAL_MANA_REGENERATED = nil, 0
714 end
715 FiveSec:ManaCheck()
716  
717 -- link above a frame
718 elseif (string.find(arg1, "link above")) then
719 local _, _, target = string.find(arg1, "link (.+)")
720 frame:ClearAllPoints()
721 frame:SetPoint("BOTTOM", getglobal(target), "TOP", 0, 10)
722  
723 -- link below a frame
724 elseif (string.find(arg1, "link below")) then
725 local _, _, target = string.find(arg1, "link (.+)")
726 frame:ClearAllPoints()
727 frame:SetPoint("TOP", getglobal(target), "BOTTOM", 0, -10)
728  
729 -- custom anchor to frame
730 elseif (string.find(arg1, "anchor")) then
731 local _, _, anchor, target, targetAnchor, ox, oy = string.find(arg1, "anchor (.+) (.+) (.+) (.+) (.+)")
732 frame:ClearAllPoints()
733 frame:SetPoint(anchor, getglobal(target), targetAnchor, tonumber(ox), tonumber(oy))
734  
735 -- help
736 elseif (string.find(arg1, TNE_FiveSec_CMD_HELP)) then
737 TNEUtils.Help(FiveSec, "list")
738  
739 -- status
740 elseif (arg1 == "") then
741 TNEUtils.PrefixedEcho(FiveSec.name, format(TNE_FiveSec_CMD_ADDON_STATUS, "$v"..TNEUtils.Select(TNE_FiveSec_Enabled, TNE_FiveSec_CMD_ENABLED, TNE_FiveSec_CMD_DISABLED).."$ev", "$v"..FiveSec.cmd.. " "..TNE_FiveSec_CMD_HELP.."$ev"))
742 else
743 TNEUtils.PrefixedEcho(FiveSec.name, format(TNE_FiveSec_CMD_UNKNOWN, "$v"..FiveSec.cmd.. " "..TNE_FiveSec_CMD_HELP.."$ev"))
744 end
745  
746 end