vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Re-valued globals from default casting bar
2 -- Leave them global so the casting bar code will use them
3 CASTING_BAR_ALPHA_STEP = 0.01
4 CASTING_BAR_HOLD_TIME = 0
5  
6 -- The addon
7 CastProgress = { version = 11100.03 }
8  
9 -- Saved variables
10 CPVar = {}
11  
12 function CastProgress:OnLoad()
13 this:RegisterEvent("ADDON_LOADED")
14 this:RegisterEvent("PLAYER_ENTERING_WORLD")
15 this:RegisterEvent("PLAYER_LEAVING_WORLD")
16 SLASH_CASTPROGRESS1 = "/castprogress"
17 SlashCmdList["CASTPROGRESS"] = CastProgress.SlashCommands
18 end
19  
20 function CastProgress.SlashCommands(msg)
21 if (strlower(msg) == "home") then
22 CastProgressTitleFrame:ClearAllPoints()
23 CastProgressTitleFrame:SetPoint("TOP", "UIParent", "TOP", 0, -30)
24 CastProgressProgressFrame:ClearAllPoints()
25 CastProgressProgressFrame:SetPoint("TOP", "CastProgressTitleFrame", "BOTTOM", 0, 0)
26 CastProgressBarFrame:ClearAllPoints()
27 CastProgressBarFrame:SetPoint("BOTTOM", "UIParent", "BOTTOM", 0, 60)
28 CastProgressBarFrame:SetPoint("BOTTOM", "UIParent", "BOTTOM", 0, 60)
29 else
30 CastProgress:ShowOptions()
31 end
32 end
33  
34 function CastProgress:Initialise()
35 CastProgress.player = UnitName("player")
36 CastProgress.this = this
37  
38 -- Default settings
39 if not CPVar["version"] then
40 CPVar["version"] = CastProgress.version
41 end
42  
43 if not CPVar[CastProgress.player] then
44 UIErrorsFrame:AddMessage(CastProgress.strings.NEW..CastProgress.player, 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME)
45 CPVar[CastProgress.player] = {}
46 CPVar[CastProgress.player].opacity = 1
47 CPVar[CastProgress.player].uiscale = 1
48 CPVar[CastProgress.player].addonmenu = 1
49 else
50 CastProgress:CheckSavedVars()
51 end
52  
53 -- Update to current version
54 if (tonumber(CPVar["version"]) < CastProgress.version) then
55 UIErrorsFrame:AddMessage(CastProgress.strings.UPDATE..string.format("%.2f|", CastProgress.version), 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME)
56 if (CPVar["version"] < 1900.00) then
57 CPVar[CastProgress.player].uiscale = 1
58 CPVar[CastProgress.player].barScale = nil
59 CPVar[CastProgress.player].progressScale = nil
60 CPVar[CastProgress.player].titleScale = nil
61 end
62 if (CPVar["version"] < 11000.02) then
63 CPVar[CastProgress.player].addonmenu = 1
64 end
65 CPVar["version"] = CastProgress.version
66 end
67  
68 CastProgressProgressFrame:SetBackdropColor(0,0,0,0)
69 CastProgressTitleFrame:SetBackdropColor(0,0,0,0)
70 CastProgressTitleText:SetTextColor(1, 1, 1)
71 CastProgress:InitOptions()
72 end
73  
74 function CastProgress:DoCastingBar()
75 -- Sod the default casting bar, we'll do our own.
76 CastingBarFrame:UnregisterEvent("SPELLCAST_START")
77 CastingBarFrame:UnregisterEvent("SPELLCAST_STOP")
78 CastingBarFrame:UnregisterEvent("SPELLCAST_FAILED")
79 CastingBarFrame:UnregisterEvent("SPELLCAST_INTERRUPTED")
80 CastingBarFrame:UnregisterEvent("SPELLCAST_DELAYED")
81 CastingBarFrame:UnregisterEvent("SPELLCAST_CHANNEL_START")
82 CastingBarFrame:UnregisterEvent("SPELLCAST_CHANNEL_UPDATE")
83  
84 CastProgressBarBorder:SetBackdrop({
85 bgFile = nil,
86 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
87 tile = true,
88 tileSize = 16,
89 edgeSize = 16,
90 insets = {3,3,3,3}
91 })
92 end
93  
94 function CastProgress:AnchorCastBar()
95 end
96  
97 function CastProgress:OnEvent(event)
98 if (event == "PLAYER_ENTERING_WORLD") then
99 CastProgress:DoScale()
100 CastProgress:DoCastingBar()
101 CastProgress:DoUIScale()
102 CastProgress:DoAnchors()
103  
104 CastProgressProgressFrame:SetAlpha(CPVar[CastProgress.player].opacity)
105 CastProgressProgressFrame:Hide()
106 CastProgressTitleFrame:Hide()
107 CastProgressTitleFrame:SetAlpha(CPVar[CastProgress.player].opacity)
108 CastProgressBarFrame:Hide()
109 CastProgressBarFrame:SetAlpha(CPVar[CastProgress.player].opacity)
110 this:RegisterEvent("SPELLCAST_START")
111 this:RegisterEvent("SPELLCAST_STOP")
112 this:RegisterEvent("SPELLCAST_FAILED")
113 this:RegisterEvent("SPELLCAST_INTERRUPTED")
114 this:RegisterEvent("SPELLCAST_DELAYED")
115 this:RegisterEvent("SPELLCAST_CHANNEL_START")
116 this:RegisterEvent("SPELLCAST_CHANNEL_STOP")
117 CastProgress.alphaFrame = CastProgressProgressFrame
118 if CPVar[CastProgress.player].hideProgress then
119 if not CPVar[CastProgress.player].hideTitle then
120 CastProgress.alphaFrame = CastProgressTitleFrame
121 elseif CPVar[CastProgress.player].showBar then
122 CastProgress.alphaFrame = CastProgressBarFrame
123 else
124 CastProgress.alphaFrame = nil
125 end
126 end
127  
128 end
129  
130 if (event == "PLAYER_LEAVING_WORLD") then
131 this:UnregisterEvent("SPELLCAST_START")
132 this:UnregisterEvent("SPELLCAST_STOP")
133 this:UnregisterEvent("SPELLCAST_FAILED")
134 this:UnregisterEvent("SPELLCAST_INTERRUPTED")
135 this:UnregisterEvent("SPELLCAST_DELAYED")
136 this:UnregisterEvent("SPELLCAST_CHANNEL_START")
137 this:UnregisterEvent("SPELLCAST_CHANNEL_UPDATE")
138 this:UnregisterEvent("SPELLCAST_CHANNEL_STOP")
139 end
140  
141 if (event == "ADDON_LOADED") and (arg1 == "CastProgress") then
142 CastProgress:Initialise()
143 return
144 end
145  
146 -- Any events after here are for spellcasting events
147 -- A bit of chicanery to invoke the default casting bar, if the user wants it shown still
148  
149 if (event == "SPELLCAST_START") then
150 CastProgress.elapsedTime = 0
151 CastProgress.progress = 0
152 CastProgress.castTime = arg2
153 CastProgressProgressFrame:SetAlpha(CPVar[CastProgress.player].opacity)
154 CastProgressTitleFrame:SetAlpha(CPVar[CastProgress.player].opacity)
155 CastProgressBarFrame:SetAlpha(CPVar[CastProgress.player].opacity)
156 CastProgressProgressText:SetTextColor(1, 1, 1)
157 CastProgressTitleText:SetText(arg1)
158 if not CPVar[CastProgress.player].hideProgress then
159 CastProgressProgressFrame:Show()
160 end
161 if not CPVar[CastProgress.player].hideTitle then
162 CastProgressTitleFrame:Show()
163 end
164 if CPVar[CastProgress.player].showBar then
165 CastProgressBarFrame:Show()
166 CastProgressBar:SetStatusBarColor(1.0, 0.7, 0.0)
167 CastProgressBarSpark:Show()
168 CastProgressBar:SetMinMaxValues(0, 1)
169 CastProgressBar:SetValue(CastProgress.elapsedTime/CastProgress.castTime)
170 end
171 CastProgress.delay = 0
172 CastProgress.casting = 1
173 CastProgress.fadeOut = nil
174 return
175 end
176  
177 if (event == "SPELLCAST_CHANNEL_START") then
178 CastProgress.elapsedTime = 0
179 CastProgress.castTime = arg1
180 CastProgressProgressFrame:SetAlpha(CPVar[CastProgress.player].opacity)
181 CastProgressTitleFrame:SetAlpha(CPVar[CastProgress.player].opacity)
182 CastProgressBarFrame:SetAlpha(CPVar[CastProgress.player].opacity)
183 CastProgressProgressText:SetTextColor(1, 1, 1)
184 CastProgressTitleText:SetText(arg2)
185 if not CPVar[CastProgress.player].hideProgress then
186 CastProgressProgressFrame:Show()
187 end
188 if not CPVar[CastProgress.player].hideTitle then
189 CastProgressTitleFrame:Show()
190 end
191 if CPVar[CastProgress.player].showBar then
192 CastProgressBarFrame:Show()
193 CastProgressBar:SetStatusBarColor(1.0, 0.7, 0.0)
194 CastProgressBarSpark:Show()
195 CastProgressBar:SetMinMaxValues(0, 1)
196 CastProgressBar:SetValue(CastProgress.elapsedTime/CastProgress.castTime)
197 end
198 CastProgress.casting = 1
199 CastProgress.channeling = 0
200 CastProgress.fadeOut = nil
201 CastProgress.interrupted = nil
202 return
203 end
204  
205 if (event == "SPELLCAST_FAILED") or (event == "SPELLCAST_INTERRUPTED") then
206 CastProgressProgressText:SetTextColor(1, 0, 0)
207 if (event == "SPELLCAST_FAILED") then
208 CastProgressProgressText:SetText(FAILED)
209 else
210 CastProgressProgressText:SetText(INTERRUPTED)
211 end
212 if CPVar[CastProgress.player].showBar then
213 CastProgressBar:SetStatusBarColor(1.0, 0.7, 0.0)
214 end
215 CastProgressBarSpark:Hide()
216 CastProgress.casting = nil
217 CastProgress.fadeOut = 1
218 return
219 end
220  
221 if (event == "SPELLCAST_DELAYED") then
222 if CastProgress.castTime and (CastProgress.elapsedTime < CastProgress.castTime) then
223 CastProgress.delay = CastProgress.delay + arg1
224 CastProgress.elapsedTime = CastProgress.elapsedTime - arg1
225 i = 1 - (CastProgress.delay/CastProgress.castTime)
226 CastProgressProgressText:SetTextColor(1, i, i)
227 end
228 return
229 end
230  
231 if (event == "SPELLCAST_CHANNEL_STOP") then
232 if CastProgress.elapsedTime and CastProgress.castTime and (CastProgress.elapsedTime/CastProgress.castTime < 0.97) then
233 CastProgressProgressText:SetTextColor(1, 0, 0)
234 CastProgressBarSpark:Hide()
235 CastProgressProgressText:SetText(INTERRUPTED)
236 CastProgress.casting = nil
237 CastProgress.fadeOut = 1
238 else
239 CastProgress.elapsedTime = CastProgress.castTime
240 if CPVar[CastProgress.player].showBar then
241 CastProgressBar:SetValue(1)
242 end
243 end
244 return
245 end
246  
247 if (event == "SPELLCAST_STOP") then
248 return
249 end
250 end
251  
252 function CastProgress:OnUpdate(elapsed)
253 if CastProgress.casting then
254 CastProgress.elapsedTime = CastProgress.elapsedTime + (elapsed * 1000)
255 if not CastProgress.castTime or (CastProgress.elapsedTime >= CastProgress.castTime) then
256 CastProgress.casting = nil
257 CastProgress.channeling = nil
258 CastProgress.fadeOut = 1
259 if CPVar[CastProgress.player].showBar then
260 CastProgressBar:SetValue(1)
261 CastProgressBar:SetStatusBarColor(0.0, 1.0, 0.0)
262 CastProgressBarSpark:Hide()
263 end
264 end
265 CastProgress:UpdateProgress()
266 end
267  
268 if CastProgress.alphaFrame and CastProgress.fadeOut and not CastProgress.optionsShown then
269 local alpha = CastProgress.alphaFrame:GetAlpha() - CASTING_BAR_ALPHA_STEP
270 if (alpha > 0) then
271 CastProgressProgressFrame:SetAlpha(alpha)
272 CastProgressTitleFrame:SetAlpha(alpha)
273 CastProgressBarFrame:SetAlpha(alpha)
274 else
275 CastProgress.fadeOut = nil
276 CastProgressProgressFrame:Hide()
277 CastProgressProgressFrame:SetAlpha(CPVar[CastProgress.player].opacity)
278 CastProgressTitleFrame:Hide()
279 CastProgressTitleFrame:SetAlpha(CPVar[CastProgress.player].opacity)
280 CastProgressBarFrame:Hide()
281 CastProgressBarFrame:SetAlpha(CPVar[CastProgress.player].opacity)
282 CastProgressProgressText:SetText("")
283 CastProgressTitleText:SetText("")
284 end
285 end
286 end
287  
288 function CastProgress:Increment()
289 if (CastProgress.castTime >= 8000) then
290 return 1
291 elseif (CastProgress.castTime >= 5000) then
292 return 2
293 elseif (CastProgress.castTime >= 3000) then
294 return 3
295 elseif (CastProgress.castTime >= 2000) then
296 return 4
297 end
298 return 5
299 end
300  
301 function CastProgress:UpdateProgress()
302 local x
303  
304 if CPVar[CastProgress.player].showBar then
305 CastProgressBar:SetValue(CastProgress.elapsedTime/CastProgress.castTime)
306 CastProgressBarSpark:SetPoint("CENTER", CastProgressBar, "LEFT", 190*CastProgress.elapsedTime/CastProgress.castTime, 0);
307 end
308  
309 if CPVar[CastProgress.player].castTime then
310 x = (CastProgress.castTime - CastProgress.elapsedTime) / 1000
311 if (x < 0) then
312 x = 0
313 end
314  
315 if (x ~= CastProgress.progress) then
316 CastProgressProgressText:SetText(string.format("%.1f", x))
317 if(x == 0) then
318 CastProgressProgressText:SetTextColor(0, 1, 0)
319 end
320 end
321 else
322 x = floor(100*(CastProgress.elapsedTime/CastProgress.castTime))
323 x = x - mod(x, CastProgress:Increment())
324 if (x > 100) then
325 x = 100
326 end
327  
328 if (x ~= CastProgress.progress) then
329 CastProgressProgressText:SetText(string.format("%d%%", x))
330 if (x == 100) then
331 CastProgressProgressText:SetTextColor(0, 1, 0)
332 end
333 end
334 end
335 CastProgress.progress = x
336 end
337  
338 function CastProgress:DoScale()
339 if CPVar[CastProgress.player].uiscale then
340 local scale = 1.0
341 CastProgressProgress:SetScale(scale)
342 CastProgressProgressFrame:SetWidth(125)
343 CastProgressProgressFrame:SetHeight(20)
344  
345 CastProgressTitle:SetScale(scale)
346 CastProgressTitleFrame:SetWidth(200)
347 CastProgressTitleFrame:SetHeight(20)
348  
349 if CPVar[CastProgress.player].showBar then
350 CastProgressBar:SetScale(scale)
351 CastProgressBarFrame:SetWidth(195)
352 CastProgressBarFrame:SetHeight(13)
353 end
354 else
355  
356 CastProgressTitle:SetScale(CPVar[CastProgress.player].titleScale)
357 CastProgressTitleFrame:SetWidth(200 * CPVar[CastProgress.player].titleScale)
358 CastProgressTitleFrame:SetHeight(20 * CPVar[CastProgress.player].titleScale)
359  
360 CastProgressProgress:SetScale(CPVar[CastProgress.player].progressScale)
361 CastProgressProgressFrame:SetWidth(125 * CPVar[CastProgress.player].progressScale)
362 CastProgressProgressFrame:SetHeight(20 * CPVar[CastProgress.player].progressScale)
363  
364 if CPVar[CastProgress.player].showBar then
365 CastProgressBar:SetScale(CPVar[CastProgress.player].barScale)
366 CastProgressBarFrame:SetWidth(195 * CPVar[CastProgress.player].barScale)
367 CastProgressBarFrame:SetHeight(13 * CPVar[CastProgress.player].barScale)
368 end
369 end
370 end
371  
372 function CastProgress:DoAnchors()
373 if CPVar[CastProgress.player]["CastProgressTitleFrame"] then
374 local titleFrame = getglobal("CastProgressTitleFrame")
375 titleFrame.sticky = CPVar[CastProgress.player]["CastProgressTitleFrame"]
376 CastProgress:Anchor(titleFrame)
377 end
378 if CPVar[CastProgress.player]["CastProgressProgressFrame"] then
379 local progressFrame = getglobal("CastProgressProgressFrame")
380 progressFrame.sticky = CPVar[CastProgress.player]["CastProgressProgressFrame"]
381 CastProgress:Anchor(progressFrame)
382 end
383 CastProgressTitleText:SetJustifyH(CPVar[CastProgress.player].titleJustify or "CENTER")
384 CastProgressProgressText:SetJustifyH(CPVar[CastProgress.player].progressJustify or "CENTER")
385 end
386  
387 function CastProgress:DoUIScale()
388 if CPVar[CastProgress.player].uiscale then
389 CPVar[CastProgress.player].titleScale = nil
390 CPVar[CastProgress.player].progressScale = nil
391 CPVar[CastProgress.player].barScale = nil
392 OptionsFrame_DisableSlider(CastProgressTitleScaleSlider)
393 CastProgressSameScaleCheckButton:Disable()
394 CastProgressSameScaleCheckButtonText:SetTextColor(0.5, 0.5, 0.5)
395 else
396 if not CPVar[CastProgress.player].progressScale then
397 CPVar[CastProgress.player].progressScale = 1.0
398 end
399 if not CPVar[CastProgress.player].titleScale then
400 CPVar[CastProgress.player].titleScale = 1.0
401 end
402 if not CPVar[CastProgress.player].barScale then
403 CPVar[CastProgress.player].barScale = 1.0
404 end
405 OptionsFrame_EnableSlider(CastProgressTitleScaleSlider)
406 CastProgressSameScaleCheckButton:Enable()
407 CastProgressSameScaleCheckButtonText:SetTextColor(1.0, 0.8, 0.0)
408 CastProgressTitleScaleSlider:SetValue(CPVar[CastProgress.player].titleScale)
409 CastProgressProgressScaleSlider:SetValue(CPVar[CastProgress.player].progressScale)
410 CastProgressCastingBarScaleSlider:SetValue(CPVar[CastProgress.player].barScale)
411 end
412  
413 if not CPVar[CastProgress.player].uiscale and not CPVar[CastProgress.player].sameScale then
414 OptionsFrame_EnableSlider(CastProgressProgressScaleSlider)
415 else
416 OptionsFrame_DisableSlider(CastProgressProgressScaleSlider)
417 end
418  
419 if CPVar[CastProgress.player].showBar and not CPVar[CastProgress.player].uiscale and not CPVar[CastProgress.player].sameScale then
420 OptionsFrame_EnableSlider(CastProgressCastingBarScaleSlider)
421 else
422 OptionsFrame_DisableSlider(CastProgressCastingBarScaleSlider)
423 end
424  
425 CastProgress:DoScale()
426 end
427  
428 function CastProgress:UIScale()
429 CPVar[CastProgress.player].uiscale = this:GetChecked()
430 CastProgress:DoUIScale()
431 end
432  
433 function CastProgress:StickyFrames()
434 CPVar[CastProgress.player].stickyFrames = this:GetChecked()
435 end
436  
437 function CastProgress:AddonMenu()
438 CPVar[CastProgress.player].addonmenu = this:GetChecked()
439 if not CPVar[CastProgress.player].addonmenu then
440 DEFAULT_CHAT_FRAME:AddMessage(CastProgress.strings.ADDONMENU_DISABLE)
441 end
442 end
443  
444 function CastProgress:CastTime()
445 CPVar[CastProgress.player].castTime = this:GetChecked()
446 end
447  
448 function CastProgress:SameScale()
449 CPVar[CastProgress.player].sameScale = this:GetChecked()
450 CastProgress:DoUIScale()
451 end
452  
453 function CastProgress:CastingBar()
454 CPVar[CastProgress.player].showBar = this:GetChecked()
455 if CPVar[CastProgress.player].showBar then
456 CastProgressBarFrame:Show()
457 CastProgressBarSpark:SetPoint("CENTER", CastProgressBarFrame, "LEFT", 97, -2)
458 CastProgressBarSpark:Show()
459 CastProgressBarFrame:Show()
460 CastProgressBarFrameDragTab:Show()
461 else
462 CPVar[CastProgress.player].showBar = nil
463 CastProgressBarFrame:Hide()
464 end
465 CastProgress:DoCastingBar()
466 CastProgress:DoUIScale()
467 end
468  
469 function CastProgress:ShowTitle()
470 CPVar[CastProgress.player].hideTitle = this:GetChecked()
471 if CPVar[CastProgress.player].hideTitle then
472 CastProgressTitleFrame:SetBackdropColor(0,0,0,0)
473 CastProgressTitleFrame:Hide()
474 else
475 CastProgressTitleFrame:SetBackdropColor(0,0,0,1)
476 CastProgressTitleFrame:Show()
477 end
478 CastProgress:DoUIScale()
479 end
480  
481 function CastProgress:ShowProgress()
482 CPVar[CastProgress.player].hideProgress = this:GetChecked()
483 if CPVar[CastProgress.player].hideProgress then
484 CastProgressProgressFrame:SetBackdropColor(0,0,0,0)
485 CastProgressProgressFrame:Hide()
486 else
487 CastProgressProgressFrame:SetBackdropColor(0,0,0,1)
488 CastProgressProgressFrame:Show()
489 end
490 CastProgress:DoUIScale()
491 end
492  
493 function CastProgress:InitOptions()
494 if CPVar[CastProgress.player].addonmenu then
495 AddonMenu:AddMenuItem(CastProgress.strings.OPTIONS, CastProgress.ShowOptions, "Satrina Addons")
496 end
497  
498 CastProgressOptionsCloseButton:SetText(CLOSE)
499 CastProgressHomeButton:SetText("Home")
500 CastProgressUIScaleCheckButtonText:SetText(CastProgress.strings.UISCALE)
501 CastProgressAddonMenuCheckButtonText:SetText(CastProgress.strings.ADDONMENU)
502 CastProgressCastTimeCheckButtonText:SetText(CastProgress.strings.CASTTIME)
503 CastProgressProgressCheckButtonText:SetText(CastProgress.strings.PROGRESS)
504 CastProgressTitleCheckButtonText:SetText(CastProgress.strings.TITLE)
505 CastProgressSameScaleCheckButtonText:SetText(CastProgress.strings.SAMESCALE)
506 CastProgressCastingBarCheckButtonText:SetText(CastProgress.strings.CASTBAR)
507 CastProgressTitleDragTabLabel:SetText("Drag")
508 CastProgressProgressDragTabLabel:SetText("Drag")
509 CastProgressBarFrameDragTabLabel:SetText("Drag")
510 CastProgressTitleJustifyDropDownLabel:SetText(CastProgress.strings.JUSTIFY)
511 CastProgressProgressJustifyDropDownLabel:SetText(CastProgress.strings.PJUSTIFY)
512 CastProgressStickyCheckButtonText:SetText(CastProgress.strings.STICKY)
513  
514 CastProgressTitleScaleSliderText:SetText(CastProgress.strings.TITLESCALE)
515 CastProgressTitleScaleSliderLow:SetText("0.5")
516 CastProgressTitleScaleSliderHigh:SetText("2.0")
517 CastProgressTitleScaleSlider:SetMinMaxValues(0.5, 2.0)
518 CastProgressTitleScaleSlider:SetValueStep(0.01)
519  
520 CastProgressProgressScaleSliderText:SetText(CastProgress.strings.PROGRESSSCALE)
521 CastProgressProgressScaleSliderLow:SetText("0.5")
522 CastProgressProgressScaleSliderHigh:SetText("2.0")
523 CastProgressProgressScaleSlider:SetMinMaxValues(0.5, 2.0)
524 CastProgressProgressScaleSlider:SetValueStep(0.01)
525  
526 CastProgressCastingBarScaleSliderText:SetText(CastProgress.strings.BARSCALE)
527 CastProgressCastingBarScaleSliderLow:SetText("0.5")
528 CastProgressCastingBarScaleSliderHigh:SetText("2.0")
529 CastProgressCastingBarScaleSlider:SetMinMaxValues(0.5, 2.0)
530 CastProgressCastingBarScaleSlider:SetValueStep(0.01)
531  
532 CastProgressOpacitySliderText:SetText(CastProgress.strings.OPACITY)
533 CastProgressOpacitySliderLow:SetText("0.1")
534 CastProgressOpacitySliderHigh:SetText("1.0")
535 CastProgressOpacitySlider:SetMinMaxValues(0.1, 1.0)
536 CastProgressOpacitySlider:SetValueStep(0.01)
537 CastProgressOpacitySlider:SetValue(CPVar[CastProgress.player].opacity)
538 OptionsFrame_EnableSlider(CastProgressOpacitySlider)
539  
540 CastProgressOptionsVersionString:SetText(string.format("%s%.2f|r", CastProgress.strings.VERSION, CastProgress.version))
541  
542 CastProgressUIScaleCheckButton:SetChecked(CPVar[CastProgress.player].uiscale)
543 CastProgressAddonMenuCheckButton:SetChecked(CPVar[CastProgress.player].addonmenu)
544 CastProgressSameScaleCheckButton:SetChecked(CPVar[CastProgress.player].samescale)
545 CastProgressCastTimeCheckButton:SetChecked(CPVar[CastProgress.player].castTime)
546 CastProgressCastingBarCheckButton:SetChecked(CPVar[CastProgress.player].showBar)
547 CastProgressProgressCheckButton:SetChecked(CPVar[CastProgress.player].hideProgress)
548 CastProgressTitleCheckButton:SetChecked(CPVar[CastProgress.player].hideTitle)
549 CastProgressStickyCheckButton:SetChecked(CPVar[CastProgress.player].stickyFrames)
550  
551 if not CPVar[CastProgress.player].uiscale then
552 CastProgressProgressScaleSlider:SetValue(CPVar[CastProgress.player].progressScale)
553 CastProgressTitleScaleSlider:SetValue(CPVar[CastProgress.player].titleScale)
554 CastProgressCastingBarScaleSlider:SetValue(CPVar[CastProgress.player].barScale)
555 end
556  
557 CastProgressProgressFrame.tab = CastProgressProgressDragTabLabel
558 CastProgressTitleFrame.tab = CastProgressTitleDragTabLabel
559 UIDropDownMenu_Initialize(CastProgressTitleJustifyDropDown, CastProgress.InitTitleJustifyDropDown)
560 UIDropDownMenu_Initialize(CastProgressProgressJustifyDropDown, CastProgress.InitProgressJustifyDropDown)
561 end
562  
563 function CastProgress:ShowOptions()
564 CastProgressOptions:Show()
565 CastProgressTitleText:SetText(CastProgress.strings.VERSION..string.format("%.2f|r", CastProgress.version).."|r")
566 CastProgressProgressText:SetText("[ | ]")
567 CastProgress.optionsShown = 1
568 CastProgress.optionsElapsed = 0
569 if not CPVar[CastProgress.player].hideProgress then
570 CastProgressProgressFrame:SetBackdropColor(0,0,0,1)
571 CastProgressProgressFrame:Show()
572 end
573 if not CPVar[CastProgress.player].hideTitle then
574 CastProgressTitleFrame:SetBackdropColor(0,0,0,1)
575 CastProgressTitleFrame:Show()
576 end
577 CastProgressBarFrame.fadeOut = nil
578 CastProgressTitleDragTab:Show()
579 CastProgressProgressDragTab:Show()
580 if CPVar[CastProgress.player].showBar then
581 CastProgressBarFrame:SetAlpha(CPVar[CastProgress.player].opacity)
582 if CT_CastBarFrame then
583 CT_LockMovables(1)
584 end
585 CastProgressBarFrame:Show()
586 CastProgressBarSpark:SetPoint("CENTER", CastProgressBarFrame, "LEFT", 97, -2)
587 CastProgressBarSpark:Show()
588 CastProgressBarFrame:Show()
589 CastProgressBarFrameDragTab:Show()
590 end
591 end
592  
593 function CastProgress:CloseOptions()
594 CastProgressOptions:Hide()
595 CastProgressTitleDragTab:Hide()
596 CastProgressProgressDragTab:Hide()
597 CastProgressBarFrameDragTab:Hide()
598 CastProgress.optionsShown = nil
599 CastProgressProgressFrame:SetBackdropColor(0,0,0,0)
600 CastProgressTitleFrame:SetBackdropColor(0,0,0,0)
601 CastProgress.fadeOut = 1
602 CastProgressBarFrame.fadeOut = 1
603 if CT_CastBarFrame then
604 CT_LockMovables(nil)
605 end
606 end
607  
608 function CastProgress:OnOptionsUpdate(elapsed)
609 if (CastProgress.optionsElapsed > 0.25) then
610 CastProgress.optionsElapsed = 0
611  
612 -- Scaling
613 if not CPVar[CastProgress.player].uiscale then
614 if (CPVar[CastProgress.player].titleScale ~= CastProgressTitleScaleSlider:GetValue()) then
615 CPVar[CastProgress.player].titleScale = CastProgressTitleScaleSlider:GetValue()
616 if CPVar[CastProgress.player].sameScale then
617 CPVar[CastProgress.player].progressScale = CastProgressTitleScaleSlider:GetValue()
618 CPVar[CastProgress.player].barScale = CastProgressTitleScaleSlider:GetValue()
619 end
620 CastProgress:DoScale()
621 end
622  
623 if not CPVar[CastProgress.player].sameScale and (CPVar[CastProgress.player].progressScale ~= CastProgressProgressScaleSlider:GetValue()) then
624 CPVar[CastProgress.player].progressScale = CastProgressProgressScaleSlider:GetValue()
625 CastProgress:DoScale()
626 end
627  
628 if not CPVar[CastProgress.player].sameScale and (CPVar[CastProgress.player].barScale ~= CastProgressCastingBarScaleSlider:GetValue()) then
629 CPVar[CastProgress.player].barScale = CastProgressCastingBarScaleSlider:GetValue()
630 CastProgress:DoScale()
631 end
632 end
633  
634 -- Opacity
635 if (CPVar[CastProgress.player].opacity ~= CastProgressOpacitySlider:GetValue()) then
636 CPVar[CastProgress.player].opacity = CastProgressOpacitySlider:GetValue()
637 CastProgressProgress:SetAlpha(CPVar[CastProgress.player].opacity)
638 CastProgressTitleFrame:SetAlpha(CPVar[CastProgress.player].opacity)
639 CastProgressBarFrame:SetAlpha(CPVar[CastProgress.player].opacity)
640 end
641  
642 if CastProgress.moving and CPVar[CastProgress.player].stickyFrames then
643 -- Snap frames together
644 local rc = 1
645 if (CastProgress.moving == CastProgressProgressFrame) and not CPVar[CastProgress.player].hideTitle then
646 rc = CastProgress:CheckCollision(CastProgressProgressFrame, CastProgressTitleFrame)
647 end
648  
649 if rc and (CastProgress.moving == CastProgressProgressFrame) and CPVar[CastProgress.player].showBar then
650 rc = CastProgress:CheckCollision(CastProgressProgressFrame, CastProgressBarFrame)
651 end
652  
653 if rc and (CastProgress.moving == CastProgressTitleFrame) and CPVar[CastProgress.player].showBar then
654 CastProgress:CheckCollision(CastProgressTitleFrame, CastProgressBarFrame)
655 end
656 end
657  
658 else
659 CastProgress.optionsElapsed = CastProgress.optionsElapsed + elapsed
660 end
661 end
662  
663 function CastProgress.InitTitleJustifyDropDown()
664 for i,t in {"LEFT","CENTER","RIGHT"} do
665 info = {}
666 info.text = t
667 info.value = t
668 info.func = CastProgress.TitleJustifyClick
669 if (t == CastProgressTitleText:GetJustifyH()) then
670 info.checked = true
671 CastProgressTitleJustifyDropDownText:SetText(t)
672 end
673 UIDropDownMenu_AddButton(info)
674 end
675 end
676  
677 function CastProgress.TitleJustifyClick()
678 UIDropDownMenu_SetSelectedID(CastProgressTitleJustifyDropDown, this:GetID(), 1)
679 CastProgressTitleText:SetJustifyH(this.value)
680 CPVar[CastProgress.player].titleJustify = this.value
681 end
682  
683 function CastProgress.InitProgressJustifyDropDown()
684 for i,t in {"LEFT","CENTER","RIGHT"} do
685 info = {}
686 info.text = t
687 info.value = t
688 info.func = CastProgress.ProgressJustifyClick
689 if (t == CastProgressProgressText:GetJustifyH()) then
690 info.checked = true
691 CastProgressProgressJustifyDropDownText:SetText(t)
692 end
693 UIDropDownMenu_AddButton(info)
694 end
695 end
696  
697 function CastProgress.ProgressJustifyClick()
698 UIDropDownMenu_SetSelectedID(CastProgressProgressJustifyDropDown, this:GetID(), 1)
699 CastProgressProgressText:SetJustifyH(this.value)
700 CPVar[CastProgress.player].progressJustify = this.value
701 end
702  
703 function CastProgress:CheckSavedVars()
704 -- Clean up any lingering deprecated saved bits
705 if CPVar[CastProgress.player].version then
706 CPVar[CastProgress.player].version = nil
707 end
708 if CPVar[CastProgress.player].scale then
709 CPVar[CastProgress.player].scale = nil
710 end
711 if CPVar[CastProgress.player].locked then
712 CPVar[CastProgress.player].locked = nil
713 end
714 end
715  
716 -- Yeah, this could be done much more elegantly. Sue me.
717 function CastProgress:CheckCollision(f1,f2)
718  
719 if not f1 or not f2 then
720 return
721 end
722  
723 scaleMult = f2:GetEffectiveScale()/f1:GetEffectiveScale()
724 scaleMult = 1
725  
726 f1.bottom = f1:GetBottom() * scaleMult
727 f1.top = f1:GetTop() * scaleMult
728 f1.left = f1:GetLeft() * scaleMult
729 f1.right = f1:GetRight() * scaleMult
730 f1.middle = (f1.left + f1.right ) / 2 * scaleMult
731 f1.vmiddle = (f1.top + f1.bottom) / 2 * scaleMult
732  
733 f2.bottom = f2:GetBottom()
734 f2.top = f2:GetTop()
735 f2.left = f2:GetLeft()
736 f2.right = f2:GetRight()
737 f2.middle = (f2.left + f2.right ) / 2
738 f2.vmiddle = (f2.top + f2.bottom) / 2
739  
740 local stickyRange = 10
741  
742 if (f1.top <= f2.bottom + stickyRange) and (f1.top >= f2.bottom - stickyRange) then
743 if (f1.middle <= f2.middle + stickyRange) and (f1.middle >= f2.middle - stickyRange) then
744 f1.tab:SetTextColor(1,0,0)
745 f1.sticky = {"TOP", f2:GetName(), "BOTTOM"}
746 elseif (f1.left >= f2.left - stickyRange) and (f1.left <= f2.left + stickyRange) then
747 f1.tab:SetTextColor(1,0,0)
748 f1.sticky = {"TOPLEFT", f2:GetName(), "BOTTOMLEFT"}
749 elseif (f1.right >= f2.right - stickyRange) and (f1.right <= f2.right + stickyRange) then
750 f1.tab:SetTextColor(1,0,0)
751 f1.sticky = {"TOPRIGHT", f2:GetName(), "BOTTOMRIGHT"}
752 else
753 f1.tab:SetTextColor(1,1,1)
754 f1.sticky = nil
755 end
756 elseif (f1.bottom <= f2.top + stickyRange) and (f1.bottom >= f2.top - stickyRange) then
757 if (f1.middle <= f2.middle + stickyRange) and (f1.middle >= f2.middle - stickyRange) then
758 f1.tab:SetTextColor(1,0,1)
759 f1.sticky = {"BOTTOM", f2:GetName(), "TOP"}
760 elseif (f1.left >= f2.left - stickyRange) and (f1.left <= f2.left + stickyRange) then
761 f1.tab:SetTextColor(1,0,1)
762 f1.sticky = {"BOTTOMLEFT", f2:GetName(), "TOPLEFT"}
763 elseif (f1.right >= f2.right - stickyRange) and (f1.right <= f2.right + stickyRange) then
764 f1.tab:SetTextColor(1,0,1)
765 f1.sticky = {"BOTTOMRIGHT", f2:GetName(), "TOPRIGHT"}
766 else
767 f1.tab:SetTextColor(1,1,1)
768 f1.sticky = nil
769 end
770 elseif (f1.vmiddle >= f2.vmiddle - (stickyRange/2)) and (f1.vmiddle <= f2.vmiddle + stickyRange) then
771 if (f1.right >= f2.right - stickyRange) and (f1.right <= f2.right + stickyRange) then
772 f1.tab:SetTextColor(0,1,0)
773 f1.sticky = {"RIGHT", f2:GetName(), "RIGHT"}
774 elseif (f1.left >= f2.left - stickyRange) and (f1.left <= f2.left + stickyRange) then
775 f1.tab:SetTextColor(0,1,0)
776 f1.sticky = {"LEFT", f2:GetName(), "LEFT"}
777 elseif (f1.right >= f2.left - stickyRange) and (f1.right <= f2.left + stickyRange) then
778 f1.tab:SetTextColor(0,1,0)
779 f1.sticky = {"RIGHT", f2:GetName(), "LEFT"}
780 elseif (f1.left >= f2.right - stickyRange) and (f1.left <= f2.right + stickyRange) then
781 f1.tab:SetTextColor(0,1,0)
782 f1.sticky = {"LEFT", f2:GetName(), "RIGHT"}
783 elseif (f1.middle <= f2.middle + stickyRange) and (f1.middle >= f2.middle - stickyRange) then
784 f1.tab:SetTextColor(0,1,0)
785 f1.sticky = {"CENTER", f2:GetName(), "CENTER"}
786 else
787 f1.tab:SetTextColor(1,1,1)
788 f1.sticky = nil
789 return 1
790 end
791 else
792 f1.tab:SetTextColor(1,1,1)
793 f1.sticky = nil
794 return 1
795 end
796 end
797  
798 function CastProgress:Anchor(frame)
799 if frame.sticky then
800 -- Figure out if we need any offsets
801 local x = 0
802 local y = 0
803 if (frame.sticky[2] == "CastProgressBarFrame") then
804 x = (string.find(frame.sticky[1], "LEFT") and 4) or (string.find(frame.sticky[1], "RIGHT") and -4) or 0
805 end
806  
807 if (frame.sticky[1] == frame.sticky[3]) then
808 x = (string.find(frame.sticky[1], "LEFT") and 4) or (string.find(frame.sticky[1], "RIGHT") and -4) or 0
809 end
810  
811 frame:ClearAllPoints()
812 frame:SetPoint(frame.sticky[1], frame.sticky[2], frame.sticky[3], x, y)
813 end
814 end
815  
816 function CastProgress:MouseUp()
817 local f = this:GetParent()
818 f:StopMovingOrSizing()
819 CastProgress:Anchor(f)
820 CastProgress.moving = nil
821 local name = f:GetName()
822 if f.sticky then
823 CPVar[CastProgress.player][name] = f.sticky
824 else
825 CPVar[CastProgress.player][name] = nil
826 end
827 end