vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- CountDoom 0.46
2 -- CountDoomTimer stuff
3 -- Author: Scrum
4  
5  
6 CDTimer_maxButtons = 5;
7 CDTimer_numTimers = 0;
8  
9  
10 CDTIMERPRIORITY_LOW = 2;
11 CDTIMERPRIORITY_MEDIUM = 1;
12 CDTIMERPRIORITY_HIGH = 0;
13  
14 CDTIMEREVENT_ONUPDATE = 1;
15 CDTIMEREVENT_ONTIMERWARNING = 2;
16 CDTIMEREVENT_ONTIMEREND = 3;
17 CDTIMEREVENT_ONMOVETIMER = 4;
18 CDTIMEREVENT_ONENTER = 5;
19 CDTIMEREVENT_ONLEAVE = 6;
20 CDTIMEREVENT_ONMOUSEDOWN = 7;
21 CDTIMEREVENT_ONMOUSEUP = 8;
22 CDTIMEREVENT_ONCLICK = 9;
23 CDTIMEREVENT_MAXEVENTS = 10;
24  
25  
26  
27 CDTimers = {};
28  
29 --Internal members
30 --userHandle - custom object to store anything in a timer
31 --startTime - time timer was created
32 --warningTime - number of seconds before warning is signaled
33 --duration - lifetime of timer. -1 is infinite
34 --icon - cache of texture to be displayed
35 --text - cache of text to be displayed
36 --flashInterval - flash period in seconds. 0 = disabled
37 --flashTime - time within flash period [0 .. flashInterval]
38 --funcHandlers - table of callbacks based on events
39 --priority - determines button priority {HIGH, NORMAL, LOW}
40 --countDown - true if display a countdown versus a countup
41 --prefix - text added to beginning of timer countdown text
42 --suffix - text added to end of timer countdown text
43  
44 --Public methods
45 --CDTimer_Create( priority, duration, warningTime, handle )
46 --CDTimer_Destroy( timerIndex )
47 --CDTimer_SetFunctionHandler( timerIndex, handlerName, funcHandler )
48 --CDTimer_GetRemainingTime( timerIndex )
49 --CDTimer_SetText( timerIndex, timerText )
50 --CDTimer_GetText( timerIndex )
51 --CDTimer_SetIcon( timerIndex, timerIcon )
52 --CDTimer_GetIcon( timerIndex )
53 --CDTimer_SetWarningTime( timerIndex, warningTime )
54 --CDTimer_GetWarningTime( timerIndex )
55 --CDTimer_SetUserHandle( timerIndex, userHandle )
56 --CDTimer_GetUserHandle( timerIndex )
57 --CDTimer_SetCountDown( timerIndex, countDown );
58 --CDTimer_GetCountDown( timerIndex );
59 --CDTimer_EnableFlash( timerIndex, interval )
60 --CDTimer_DisableFlash( timerIndex )
61 --CDTimer_SetPriority( timerIndex, priority );
62 --CDTimer_Copy( destIndex, srcIndex );
63 --CDTimer_SetTimerPrefix( timerPrefix, prefixStr )
64 --CDTimer_SetTimerSuffix( timerPrefix, suffixStr )
65  
66 --Private methods
67 --CDTimer_GenericHandler( timerIndex, eventName, arg1 )
68 --CDTimer_OnUpdate(arg1)
69 --CDTimer_OnEnter(arg1)
70 --CDTimer_OnLeave(arg1)
71 --CDTimer_OnMouseDown(arg1)
72 --CDTimer_OnMouseUp(arg1)
73 --CDTimer_OnClick(arg1)
74 --CDTimer_ShowButton( timerIndex, showButton )
75 --CDTimer_SetAlpha( timerIndex, alpha ) - NOTE: This is used by the flashing logic and shouldn't be called directly
76 --CDTimer_UpdateFlash( timerIndex, timeDelta )
77  
78  
79 local function CDTimer_Dump( timerIndex )
80 CountDoom.dpf( "Timer: " .. timerIndex );
81 CountDoom.dpf( "userHandle: " .. CDTimers[ timerIndex ].userHandle );
82 CountDoom.dpf( "startTime: " .. CDTimers[ timerIndex ].startTime );
83 CountDoom.dpf( "warningTime: " .. CDTimers[ timerIndex ].warningTime );
84 CountDoom.dpf( "duration: " .. CDTimers[ timerIndex ].duration );
85 CountDoom.dpf( "icon: " .. CountDoom.ToStr( CDTimers[ timerIndex ].icon ) );
86 CountDoom.dpf( "text: " .. CountDoom.ToStr( CDTimers[ timerIndex ].text ) );
87 CountDoom.dpf( "flashInterval: " .. CDTimers[ timerIndex ].flashInterval );
88 CountDoom.dpf( "flashTime: " .. CDTimers[ timerIndex ].flashTime );
89 CountDoom.dpf( "priority: " .. CDTimers[ timerIndex ].priority );
90 end
91  
92  
93 local function CDTimer_DumpAll()
94 local timerIndex;
95 for timerIndex = 0, CDTimer_numTimers - 1, 1 do
96 CDTimer_Dump( timerIndex );
97 end
98 end
99  
100  
101 local function CDTimer_SetAlpha( timerIndex, alpha )
102 if CDTimers[ timerIndex ] == nil then
103 CountDoom.dpf( "Invalid timerIndex in CDTimer_SetAlpha" );
104 return;
105 end
106  
107 local buttonName = "CDTimerButton" .. timerIndex .. "_DurationText";
108 local buttonItem = getglobal( buttonName );
109 if( buttonItem ~= nil ) then
110 buttonItem:SetAlpha( alpha );
111 elseif timerIndex < CDTimer_maxButtons then
112 CountDoom.dpf( "Unable to call " .. buttonName .. ":SetAlpha()" );
113 end
114  
115 --TODO set the icon alpha also
116 end
117  
118  
119 local function CDTimer_ShowButton( timerIndex, showButton )
120 CountDoom.dpf( "CDTimer_ShowButton(" .. CountDoom.ToStr( timerIndex ) .. ")" );
121  
122 if timerIndex >= CDTimer_numTimers then
123 CountDoom.dpf( "CDTimer_ShowButton: Invalid index " .. timerIndex );
124 return
125 end
126  
127 local buttonName = "CDTimerButton" .. timerIndex;
128 local buttonItem = getglobal( buttonName );
129 if( buttonItem ~= nil ) then
130 if( showButton ) then
131 CountDoom.dpf( "CDTimer_ShowButton: calling Show() " );
132 buttonItem:Show();
133 else
134 CountDoom.dpf( "CDTimer_ShowButton: calling Hide() " );
135 buttonItem:Hide();
136 end
137 elseif timerIndex < CDTimer_maxButtons then
138 CountDoom.dpf( "Unable to call " .. buttonName .. ":Show()" );
139 end
140 end
141  
142  
143 local function CDTimer_UpdateFlash( timerIndex, timeDelta )
144 if CDTimers[ timerIndex ] == nil then
145 CountDoom.dpf( "Invalid timerIndex in CDTimer_UpdateFlash" );
146 return -1;
147 end
148  
149 if CDTimers[ timerIndex ].flashInterval <= 0.0 then
150 return
151 end
152  
153 CDTimers[ timerIndex ].flashTime = CDTimers[ timerIndex ].flashTime + timeDelta;
154 while CDTimers[ timerIndex ].flashTime > CDTimers[ timerIndex ].flashInterval do
155 CDTimers[ timerIndex ].flashTime = CDTimers[ timerIndex ].flashTime - CDTimers[ timerIndex ].flashInterval;
156 end
157  
158 local alpha = 2.0 * CDTimers[ timerIndex ].flashTime / CDTimers[ timerIndex ].flashInterval;
159 if( alpha > 1.0 ) then
160 alpha = 2.0 - alpha;
161 end
162  
163 CDTimer_SetAlpha( timerIndex, alpha );
164 end
165  
166  
167 local function CDTimer_GenericHandler( timerIndex, eventName, arg1 )
168  
169 if timerIndex == nil then
170 --CountDoom.dpf( "ButtonID doesn't map to a valid timerIndex in CDTimer_" .. eventName );
171 return nil;
172 end
173  
174 if CDTimers[ timerIndex ] == nil then
175 CountDoom.dpf( "Invalid timerIndex in CDTimer_" .. eventName );
176 return nil;
177 end
178  
179 -- Call the callback function
180 if CDTimers[ timerIndex ].funcHandlers ~= nil then
181 local funcHandler = CDTimers[ timerIndex ].funcHandlers[ eventName ];
182 if funcHandler ~= nil then
183 funcHandler( timerIndex, arg1 );
184 end
185 end
186  
187 return timerIndex;
188 end
189  
190  
191 function CDTimer_UpdateTimer( timerIndex )
192  
193 if( CDTimers[ timerIndex ] == nil ) then
194 CountDoom.dpf( "Invalid timerIndex in CDTimer_OnUpdate: " .. timerIndex );
195 return;
196 end
197  
198 local currentTime = GetTime();
199 local rawDelta = currentTime - CDTimers[ timerIndex ].startTime;
200 local duration = CDTimers[ timerIndex ].duration;
201 local warningTime = CDTimers[ timerIndex ].warningTime;
202 local finished = false;
203  
204 local delta = floor(rawDelta);
205 if( delta > duration ) then
206 delta = duration;
207 finished = true;
208 end
209  
210 -- Update the timer
211 local flashAlpha = 1.0;
212  
213 local textColor = {};
214 local alpha = 1.0;
215  
216 if (rawDelta > duration) then
217 textColor["r"] = 1.0;
218 textColor["g"] = 0.0;
219 textColor["b"] = 0.0;
220 elseif (rawDelta > warningTime) then
221 alpha = (rawDelta - warningTime) / (duration - warningTime);
222 textColor["r"] = 1.0;
223 textColor["g"] = 1.0 - alpha;
224 textColor["b"] = 0.0;
225 else
226 alpha = rawDelta / warningTime;
227 textColor["r"] = 1.0;
228 textColor["g"] = 1.0;
229 textColor["b"] = 1.0 - alpha;
230 end
231  
232 -- Invert for count down situations
233 local timeDelta = rawDelta;
234 if( CDTimers[ timerIndex ].countDown ) then
235 timeDelta = duration - rawDelta;
236 end
237  
238 local signStr = "";
239 if timeDelta < 0 then
240 signStr = "-";
241 timeDelta = -timeDelta;
242 end
243  
244 local minutes = floor(timeDelta/60);
245 local seconds = floor(math.mod(timeDelta, 60));
246 local hseconds = floor(math.mod(floor(rawDelta*100), 100));
247  
248 local htimeText = "";
249  
250 if (CountDoom.config.hseconds == true) then
251 if (hseconds >= 10) then
252 htimeText = "." .. hseconds;
253 else
254 htimeText = ".0" .. hseconds;
255 end
256 end
257  
258 local timeText = "";
259 if (seconds >= 10) then
260 timeText = signStr .. minutes .. ":" .. seconds .. htimeText;
261 else
262 timeText = signStr .. minutes .. ":0" .. seconds .. htimeText;
263 end
264  
265 -- Add any prefix or suffix
266 if CDTimers[ timerIndex ].prefix ~= nil then
267 timeText = CDTimers[ timerIndex ].prefix .. timeText;
268 end
269  
270 if CDTimers[ timerIndex ].suffix ~= nil then
271 timeText = timeText .. CDTimers[ timerIndex ].suffix;
272 end
273  
274 -- Set the timer text
275 CDTimer_SetText( timerIndex, timeText, textColor );
276  
277 -- Update flash time
278 local flashRate = 0.1;
279 if CDTimers[ timerIndex ].flashInterval ~= 0.0 then
280 CDTimer_UpdateFlash( timerIndex, flashRate );
281 else
282 CDTimer_SetAlpha( timerIndex, 1.0 );
283 end
284  
285 -- Callback for custom OnUpdate calls
286 CDTimer_GenericHandler( timerIndex, CDTIMEREVENT_ONUPDATE, arg1 );
287  
288 if( finished ) then
289 --CountDoom.dpf( "Calling OnTimerEnd for timer #" .. timerIndex );
290 CDTimer_GenericHandler( timerIndex, CDTIMEREVENT_ONTIMEREND, delta );
291 elseif( delta >= warningTime ) then
292 --CountDoom.dpf( "Calling OnTimerWarning for timer #" .. timerIndex );
293 CDTimer_GenericHandler( timerIndex, CDTIMEREVENT_ONTIMERWARNING, delta );
294 end
295 end
296  
297  
298 function CDTimer_OnUpdate( arg1 )
299 local timerIndex = this:GetID();
300  
301 CDTimer_UpdateTimer( timerIndex );
302 end
303  
304  
305 function CDTimer_OnEnter( arg1 )
306 local timerIndex = this:GetID();
307  
308 -- put the tool tip in the default position
309 GameTooltip_SetDefaultAnchor(GameTooltip, this);
310  
311 -- set the tool tip text
312 GameTooltip:SetText(COUNTDOOM_TITLE, 255/255, 209/255, 0/255);
313  
314 CDTimer_GenericHandler( timerIndex, CDTIMEREVENT_ONENTER, arg1 );
315  
316 GameTooltip:AddLine(COUNTDOOM_DESCRIPTION, 80/255, 143/255, 148/255);
317 GameTooltip:Show();
318 end
319  
320  
321 function CDTimer_OnLeave( arg1 )
322 local timerIndex = this:GetID();
323 CDTimer_GenericHandler( timerIndex, CDTIMEREVENT_ONLEAVE, arg1 );
324  
325 GameTooltip:Hide(arg1);
326 end
327  
328  
329 function CDTimer_OnMouseDown( arg1 )
330 -- if not loaded yet then get out
331 if (CountDoom.initialized == false) then
332 return;
333 end
334  
335 local timerIndex = this:GetID();
336 CDTimer_GenericHandler( timerIndex, CDTIMEREVENT_ONMOUSEDOWN, arg1 );
337 end
338  
339  
340 function CDTimer_OnMouseUp( arg1 )
341 -- if not loaded yet then get out
342 if CountDoom.initialized == false then
343 return;
344 end
345  
346 local timerIndex = this:GetID();
347 CDTimer_GenericHandler( timerIndex, CDTIMEREVENT_ONMOUSEUP, arg1 );
348 end
349  
350  
351 function CDTimer_OnClick( arg1 )
352 -- if not loaded yet then get out
353 if CountDoom.initialized == false then
354 return;
355 end
356  
357 local timerIndex = this:GetID();
358 CDTimer_GenericHandler( timerIndex, CDTIMEREVENT_ONCLICK, arg1 );
359 end
360  
361  
362 local function CDTimer_Constructor( timerIndex )
363 if CDTimers[ timerIndex ] == nil then
364 CDTimers[ timerIndex ] = {};
365 end
366  
367 CDTimers[ timerIndex ].userHandle = nil;
368 CDTimers[ timerIndex ].priority = nil;
369 CDTimers[ timerIndex ].startTime = GetTime();
370 CDTimers[ timerIndex ].warningTime = nil;
371 CDTimers[ timerIndex ].duration = nil;
372 CDTimers[ timerIndex ].icon = nil;
373 CDTimers[ timerIndex ].text = nil;
374 CDTimers[ timerIndex ].flashInterval = 0.0;
375 CDTimers[ timerIndex ].flashTime = 0.0;
376 CDTimers[ timerIndex ].countDown = true;
377 CDTimers[ timerIndex ].prefix = nil;
378 CDTimers[ timerIndex ].suffix = nil;
379  
380 CDTimers[ timerIndex ].funcHandlers = nil;
381 CDTimers[ timerIndex ].funcHandlers = {};
382 end
383  
384  
385 local function CDTimer_GetInsertionIndex( priority, duration )
386 local foundIndex = CDTimer_numTimers;
387  
388 if( CDTimer_numTimers > 0 ) then
389  
390 local currentTime = GetTime();
391  
392 -- Loop through all items stopping at first button less than
393 local timerIndex;
394 for timerIndex = 0, CDTimer_numTimers - 1, 1 do
395  
396 if( CDTimers[ timerIndex ] ~= nil ) then
397  
398 -- Check for priority is a lower number (higher priority)
399 if( priority < CDTimers[ timerIndex ].priority ) then
400 foundIndex = timerIndex;
401 break;
402 end
403  
404 -- If equivalent, check remaining time
405 local elapsed = currentTime - CDTimers[ timerIndex ].startTime;
406 local remaining = CDTimers[ timerIndex ].duration - elapsed;
407  
408 if( duration <= remaining ) then
409 foundIndex = timerIndex;
410 break;
411 end
412 else
413 foundIndex = timerIndex;
414 break;
415 end
416 end
417  
418 -- if it's the last index, we're done
419 if( foundIndex <= CDTimer_numTimers ) then
420  
421 -- Slide all the items to the next slots
422 CountDoom.dpf( "CDTimer_numTimers " .. CDTimer_numTimers );
423 CountDoom.dpf( "foundIndex " .. foundIndex );
424  
425 for newID = CDTimer_numTimers, foundIndex + 1, -1 do
426  
427 local oldID = newID - 1;
428  
429 CountDoom.dpf( "oldID: " .. oldID .. " newID: " .. newID );
430  
431 CDTimer_Copy( newID, oldID );
432 end
433 end
434 end
435  
436 local buttonToEnable = CDTimer_numTimers;
437  
438 CDTimer_numTimers = CDTimer_numTimers + 1;
439  
440 -- Enable the last button
441 CDTimer_ShowButton( buttonToEnable, true );
442  
443  
444 return foundIndex;
445 end
446  
447  
448 function CDTimer_Create( priority, duration )
449 local timerIndex = -1;
450  
451 timerIndex = CDTimer_GetInsertionIndex( priority, duration );
452 CountDoom.dpf( "CDTimer_Create: Insertion Index is " .. timerIndex );
453  
454 CDTimer_Constructor( timerIndex );
455 CDTimers[ timerIndex ].priority = priority;
456 CDTimers[ timerIndex ].warningTime = duration;
457 CDTimers[ timerIndex ].duration = duration;
458  
459 CDTimer_ShowButton( timerIndex, true );
460  
461 CountDoomFrame:Show();
462  
463 return timerIndex;
464 end
465  
466  
467 function CDTimer_Destroy( removeID )
468 CountDoom.dpf( "Destroy: " .. removeID );
469  
470 if CDTimers[ removeID ] == nil then
471 CountDoom.dpf( "Invalid index(" .. timerIndex .. ") in CDTimer_Destroy. " .. CDTimer_numTimers );
472 return;
473 end
474  
475 CDTimer_DumpAll();
476  
477 if( removeID ~= ( CDTimer_numTimers - 1 ) ) then
478  
479 -- shift all buttons down by one
480 local oldID;
481 for oldID = removeID + 1, CDTimer_numTimers - 1, 1 do
482 local newID = oldID - 1;
483  
484 CountDoom.dpf( "oldID: " .. oldID .. " newID: " .. newID );
485  
486 CDTimer_Copy( newID, oldID );
487 end
488 end
489  
490 -- Erase the button
491 local deleteID = CDTimer_numTimers - 1;
492 CDTimers[ deleteID ] = nil;
493  
494 -- And hide the last one
495 CDTimer_ShowButton( deleteID, false );
496  
497 CDTimer_numTimers = CDTimer_numTimers - 1;
498  
499 if CDTimer_numTimers <= 0 then
500 if CountDoom.config.isLocked == true then
501 CountDoomFrame:Hide();
502 end
503 end
504  
505 CDTimer_DumpAll();
506 end
507  
508  
509 function CDTimer_SetFunctionHandler( timerIndex, handlerName, funcHandler )
510 if CDTimers[ timerIndex ] == nil then
511 CountDoom.dpf( "Invalid timerIndex in CDTimer_SetFunctionHandler" );
512 return;
513 end
514  
515 CountDoom.dpf( "SetFunctionHandler before: " .. table.getn( CDTimers[ timerIndex ].funcHandlers ) );
516  
517 CDTimers[ timerIndex ].funcHandlers[ handlerName ] = funcHandler;
518  
519 CountDoom.dpf( "SetFunctionHandler after: " .. table.getn( CDTimers[ timerIndex ].funcHandlers ) );
520 end
521  
522  
523 function CDTimer_GetRemainingTime( timerIndex )
524 if CDTimers[ timerIndex ] == nil then
525 CountDoom.dpf( "Invalid timerIndex in CDTimer_GetRemainingTime" );
526 return nil;
527 end
528  
529 return CDTimers[ timerIndex ].duration - (GetTime() - CDTimers[ timerIndex ].startTime);
530 end
531  
532  
533 function CDTimer_SetWarningTime( timerIndex, warningTime )
534 if CDTimers[ timerIndex ] == nil then
535 CountDoom.dpf( "Invalid timerIndex in CDTimer_SetWarningTime" );
536 return;
537 end
538  
539 CDTimers[ timerIndex ].warningTime = warningTime;
540 end
541  
542  
543 function CDTimer_GetWarningTime( timerIndex )
544 if CDTimers[ timerIndex ] == nil then
545 CountDoom.dpf( "Invalid timerIndex in CDTimer_GetWarningTime" );
546 return nil;
547 end
548  
549 return CDTimers[ timerIndex ].warningTime;
550 end
551  
552  
553 function CDTimer_SetUserHandle( timerIndex, userHandle )
554 if CDTimers[ timerIndex ] == nil then
555 CountDoom.dpf( "Invalid timerIndex in CDTimer_SetUserHandle" );
556 return;
557 end
558  
559 CDTimers[ timerIndex ].userHandle = userHandle;
560 end
561  
562  
563 function CDTimer_GetUserHandle( timerIndex )
564 if CDTimers[ timerIndex ] == nil then
565 CountDoom.dpf( "Invalid timerIndex in CDTimer_GetUserHandle" );
566 return nil;
567 end
568  
569 return CDTimers[ timerIndex ].userHandle;
570 end
571  
572  
573 function CDTimer_SetCountDown( timerIndex, countDown )
574 if CDTimers[ timerIndex ] == nil then
575 CountDoom.dpf( "Invalid timerIndex in CDTimer_SetCountDown" );
576 return;
577 end
578  
579 CDTimers[ timerIndex ].countDown = countDown;
580 end
581  
582  
583 function CDTimer_GetCountDown( timerIndex )
584 if CDTimers[ timerIndex ] == nil then
585 CountDoom.dpf( "Invalid timerIndex in CDTimer_GetCountDown" );
586 return nil;
587 end
588  
589 return CDTimers[ timerIndex ].countDown;
590 end
591  
592  
593 function CDTimer_SetText( timerIndex, timerText, textColor )
594 if CDTimers[ timerIndex ] == nil then
595 CountDoom.dpf( "Invalid timerIndex in CDTimer_SetText" );
596 return;
597 end
598  
599 local red = 1.0;
600 local green = 1.0;
601 local blue = 1.0;
602  
603 if textColor ~= nil then
604 red = textColor["r"];
605 green = textColor["g"];
606 blue = textColor["b"];
607 end
608  
609 CDTimers[ timerIndex ].text = timerText;
610  
611 local buttonName = "CDTimerButton" .. timerIndex .. "_DurationText";
612 local buttonItem = getglobal( buttonName );
613 if( buttonItem ~= nil ) then
614 buttonItem:SetTextColor( red, green, blue );
615 buttonItem:SetText( timerText );
616 elseif timerIndex < CDTimer_maxButtons then
617 CountDoom.dpf( "Unable to call " .. buttonName .. ":SetText()" );
618 end
619 end
620  
621  
622 function CDTimer_GetText( timerIndex )
623 if CDTimers[ timerIndex ] == nil then
624 CountDoom.dpf( "Invalid timerIndex in CDTimer_GetText" );
625 return nil;
626 end
627  
628 return CDTimers[ timerIndex ].text;
629 end
630  
631  
632 function CDTimer_SetIcon( timerIndex, timerIcon )
633 if CDTimers[ timerIndex ] == nil then
634 CountDoom.dpf( "Invalid timerIndex in CDTimer_SetIcon" );
635 return;
636 end
637  
638 CDTimers[ timerIndex ].icon = timerIcon;
639  
640 local buttonName = "CDTimerButton" .. timerIndex .. "_Icon";
641 local buttonItem = getglobal( buttonName );
642 if( buttonItem ~= nil ) then
643 buttonItem:SetTexture( timerIcon );
644 elseif timerIndex < CDTimer_maxButtons then
645 CountDoom.dpf( "Unable to call " .. buttonName .. ":SetTexture()" );
646 end
647 end
648  
649  
650 function CDTimer_GetIcon( timerIndex )
651 if CDTimers[ timerIndex ] == nil then
652 CountDoom.dpf( "Invalid timerIndex in CDTimer_GetIcon" );
653 return nil;
654 end
655  
656 return CDTimers[ timerIndex ].icon;
657 end
658  
659  
660 function CDTimer_EnableFlash( timerIndex, interval )
661 if CDTimers[ timerIndex ] == nil then
662 CountDoom.dpf( "Invalid timerIndex in CDTimer_EnableFlash" );
663 return;
664 end
665  
666 if interval <= 0 then
667 interval = 0.0;
668 end
669  
670 CDTimers[ timerIndex ].flashTime = 0.0;
671 CDTimers[ timerIndex ].flashInterval = interval;
672 end
673  
674  
675 function CDTimer_SetTimerPrefix( timerIndex, prefixStr )
676 if CDTimers[ timerIndex ] == nil then
677 CountDoom.dpf( "Invalid timerIndex in CDTimer_SetTimerPrefix" );
678 return;
679 end
680  
681 CDTimers[ timerIndex ].prefix = prefixStr;
682 end
683  
684  
685 function CDTimer_SetTimerSuffix( timerIndex, suffixStr )
686 if CDTimers[ timerIndex ] == nil then
687 CountDoom.dpf( "Invalid timerIndex in CDTimer_SetTimerSuffix" );
688 return;
689 end
690  
691 CDTimers[ timerIndex ].suffix = suffixStr;
692 end
693  
694  
695 function CDTimer_DisableFlash( timerIndex )
696 if CDTimers[ timerIndex ] == nil then
697 CountDoom.dpf( "Invalid timerIndex in CDTimer_DisableFlash" );
698 return;
699 end
700  
701 CDTimers[ timerIndex ].flashTime = 0.0;
702 CDTimers[ timerIndex ].flashInterval = 0.0;
703 end
704  
705  
706 function CDTimer_Copy( destIndex, srcIndex )
707 CountDoom.dpf( "CDTimer_Copy(" .. CountDoom.ToStr( destIndex ) .. ", " .. CountDoom.ToStr( srcIndex ) .. ")" );
708  
709 if CDTimers[ srcIndex ] == nil then
710 CDTimers[ destIndex ] = nil;
711 else
712 if CDTimers[ destIndex ] == nil then
713 CDTimers[ destIndex ] = {};
714 end
715 CDTimers[ destIndex ].userHandle = CDTimers[ srcIndex ].userHandle;
716 CDTimers[ destIndex ].priority = CDTimers[ srcIndex ].priority;
717 CDTimers[ destIndex ].startTime = CDTimers[ srcIndex ].startTime;
718 CDTimers[ destIndex ].warningTime = CDTimers[ srcIndex ].warningTime;
719 CDTimers[ destIndex ].duration = CDTimers[ srcIndex ].duration;
720 CDTimers[ destIndex ].icon = CDTimers[ srcIndex ].icon;
721 CDTimers[ destIndex ].text = CDTimers[ srcIndex ].text;
722 CDTimers[ destIndex ].flashInterval = CDTimers[ srcIndex ].flashInterval;
723 CDTimers[ destIndex ].flashTime = CDTimers[ srcIndex ].flashTime;
724 CDTimers[ destIndex ].countDown = CDTimers[ srcIndex ].countDown;
725 CDTimers[ destIndex ].prefix = CDTimers[ srcIndex ].prefix;
726 CDTimers[ destIndex ].suffix = CDTimers[ srcIndex ].suffix;
727  
728 -- Copy the event table
729 CDTimers[ destIndex ].funcHandlers = {};
730 if CDTimers[ srcIndex ].funcHandlers ~= nil then
731  
732 local index;
733 for index=1, CDTIMEREVENT_MAXEVENTS, 1 do
734 CDTimers[ destIndex ].funcHandlers[ index ] = CDTimers[ srcIndex ].funcHandlers[ index ];
735 end
736  
737 CDTimers[ srcIndex ].funcHandlers = nil;
738 end
739  
740 -- Move the visual items
741 CDTimer_SetText( destIndex, CDTimers[ destIndex ].text );
742 CDTimer_SetIcon( destIndex, CDTimers[ destIndex ].icon );
743 end
744  
745 -- Notify client of new timer index
746 CDTimer_GenericHandler( destIndex, CDTIMEREVENT_ONMOVETIMER, srcIndex );
747 end
748  
749  
750 function CDTimers_GetButtonSize()
751 if CountDoom.config.scale == "large" then
752 return 50;
753 elseif CountDoom.config.scale == "small" then
754 return 30;
755 end;
756 return 40;
757 end
758  
759  
760 function CDTimers_LayoutHorizontal()
761 local buttonID = 0;
762 local prevButton = nil;
763  
764 local buttonSize = CDTimers_GetButtonSize();
765  
766 for buttonID = 0, CDTimer_maxButtons - 1 do
767 local button = getglobal( "CDTimerButton" .. buttonID);
768  
769 if button ~= nil then
770 if prevButton ~= nil then
771 button:ClearAllPoints();
772 button:SetPoint("TOPLEFT", prevButton, "TOPRIGHT", 0, 0);
773 end
774  
775 local buttonTexture = getglobal( "CDTimerButton" .. buttonID .. "_Icon" );
776 if buttonTexture ~= nil then
777 buttonTexture:Show();
778 end
779  
780 button:SetHeight(buttonSize);
781 button:SetWidth(buttonSize);
782 end
783  
784 local buttonText = getglobal( "CDTimerButton" .. buttonID .. "_DurationText" );
785 if buttonText ~= nil then
786 if button ~= nil then
787 buttonText:ClearAllPoints();
788 buttonText:SetPoint("LEFT", button, "LEFT", 0, -(5 + (buttonSize/2)));
789 end
790 end
791  
792 prevButton = button;
793 end
794  
795 local numTimers = CDTimer_maxButtons;
796 if numTimers == 0 then
797 numTimers = 1;
798 end
799  
800 CountDoomFrame:SetWidth( 5 + 5 + (buttonSize * numTimers) );
801 CountDoomFrame:SetHeight( 5 + 5 + buttonSize + 12 );
802 end
803  
804  
805 function CDTimers_LayoutVertical()
806 local buttonID = 0;
807 local prevButton = nil;
808  
809 local buttonSize = CDTimers_GetButtonSize();
810  
811 for buttonID = 0, CDTimer_maxButtons - 1 do
812 local button = getglobal( "CDTimerButton" .. buttonID);
813  
814 if button ~= nil then
815 if prevButton ~= nil then
816 button:ClearAllPoints();
817 button:SetPoint("TOPLEFT", prevButton, "BOTTOMLEFT", 0, 0);
818 end
819  
820 local buttonTexture = getglobal( "CDTimerButton" .. buttonID .. "_Icon" );
821 if buttonTexture ~= nil then
822 buttonTexture:Show();
823 end
824  
825 button:SetHeight(buttonSize);
826 button:SetWidth(buttonSize);
827 end
828  
829 local buttonText = getglobal( "CDTimerButton" .. buttonID .. "_DurationText" );
830 if buttonText ~= nil then
831 if button ~= nil then
832 buttonText:ClearAllPoints();
833 buttonText:SetPoint("LEFT", button, "LEFT", buttonSize + 10, -7);
834 end
835 end
836  
837 prevButton = button;
838 end
839  
840 local numTimers = CDTimer_maxButtons;
841 if numTimers == 0 then
842 numTimers = 1;
843 end
844  
845 CountDoomFrame:SetWidth( 5 + 5 + buttonSize + 40 );
846 CountDoomFrame:SetHeight( 5 + 5 + ( buttonSize * numTimers ) );
847 end
848  
849  
850 function CDTimers_LayoutTextOnly()
851 local buttonID = 0;
852 local prevButton = nil;
853 local prevButtonText = nil;
854  
855 for buttonID = 0, CDTimer_maxButtons - 1 do
856 local button = getglobal( "CDTimerButton" .. buttonID);
857  
858 if button ~= nil then
859 if prevButton ~= nil then
860 button:ClearAllPoints();
861 button:SetPoint("TOPLEFT", prevButton, "BOTTOMLEFT", 0, 0);
862 end
863 end
864  
865 if button ~= nil then
866 local buttonTexture = getglobal( "CDTimerButton" .. buttonID .. "_Icon" );
867 if buttonTexture ~= nil then
868 buttonTexture:Hide();
869 end
870  
871 button:SetHeight(15);
872 button:SetWidth(30);
873 end
874  
875 local buttonText = getglobal( "CDTimerButton" .. buttonID .. "_DurationText" );
876 if buttonText ~= nil then
877 buttonText:ClearAllPoints();
878 buttonText:SetPoint("LEFT", button, "LEFT", 0, 0);
879 end
880  
881 prevButtonText = buttonText;
882 prevButton = button;
883 end
884  
885 local numTimers = CDTimer_maxButtons;
886 if numTimers == 0 then
887 numTimers = 1;
888 end
889  
890 CountDoomFrame:SetWidth( 5 + 5 + 250 );
891 CountDoomFrame:SetHeight( 5 + 5 + ( 15 * numTimers ) );
892 end