vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- Constants |
2 | TITAN_ARTWORK_PATH = "Interface\\AddOns\\Titan\\Artwork\\"; |
||
3 | TITAN_THRESHOLD_EXCEPTION_COLOR = GRAY_FONT_COLOR; |
||
4 | |||
5 | -- Tables |
||
6 | TITAN_PANEL_NONMOVABLE_PLUGINS = {"Clock", "Volume", "UIScale", "Trans", "AutoHide", "AuxAutoHide"}; |
||
7 | |||
8 | TitanPlugins = {}; |
||
9 | TitanPluginsIndex = {}; |
||
10 | |||
11 | function TitanDebug(debug_message) |
||
12 | -- Default green color |
||
13 | DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00" .. TITAN_DEBUG .. " " .. debug_message); |
||
14 | end |
||
15 | |||
16 | function TitanUtils_GetNextButtonOnBar(bar, id, side) |
||
17 | local index = TitanUtils_GetCurrentIndex(TitanPanelSettings.Buttons, id); |
||
18 | |||
19 | for i, id in TitanPanelSettings.Buttons do |
||
20 | if TitanUtils_GetWhichBar(id) == bar and i > index and TitanPanel_GetPluginSide(id) == side then |
||
21 | return i; |
||
22 | end |
||
23 | end |
||
24 | end |
||
25 | |||
26 | function TitanUtils_GetRealPosition(id) |
||
27 | local i = TitanPanel_GetButtonNumber(id); |
||
28 | if TitanPanelSettings.Location[i] == "Bar" and TitanPanelGetVar("BothBars") then |
||
29 | return TITAN_PANEL_PLACE_TOP; |
||
30 | elseif TitanPanelSettings.Location[i] == "Bar" then |
||
31 | return TitanPanelGetVar("Position"); |
||
32 | else |
||
33 | return TITAN_PANEL_PLACE_BOTTOM; |
||
34 | end |
||
35 | end |
||
36 | |||
37 | function TitanUtils_GetWhichBar(id) |
||
38 | local i = TitanPanel_GetButtonNumber(id); |
||
39 | return TitanPanelSettings.Location[i]; |
||
40 | end |
||
41 | |||
42 | function TitanUtils_GetDoubleBar(bothbars, framePosition) |
||
43 | if framePosition == TITAN_PANEL_PLACE_TOP then |
||
44 | return TitanPanelGetVar("DoubleBar") |
||
45 | elseif framePosition == TITAN_PANEL_PLACE_BOTTOM and bothbars == nil then |
||
46 | return TitanPanelGetVar("DoubleBar") |
||
47 | elseif framePosition == TITAN_PANEL_PLACE_BOTTOM and bothbars == 1 then |
||
48 | return TitanPanelGetVar("AuxDoubleBar") |
||
49 | end |
||
50 | end |
||
51 | |||
52 | function TitanUtils_CheckAutoHideCounting(elapsed) |
||
53 | local frame = TitanPanelBarButtonHider; |
||
54 | local auxframe = TitanPanelAuxBarButtonHider; |
||
55 | |||
56 | if (TitanPanelGetVar("AutoHide")) then |
||
57 | if (not frame.frameTimer or not frame.isCounting) then |
||
58 | -- Do nothing |
||
59 | elseif (frame.frameTimer < 0) then |
||
60 | TitanPanelBarButton_Hide("TitanPanelBarButton", TitanPanelGetVar("Position")); |
||
61 | frame.frameTimer = nil; |
||
62 | frame.isCounting = nil; |
||
63 | else |
||
64 | frame.frameTimer = frame.frameTimer - elapsed; |
||
65 | end |
||
66 | end |
||
67 | if (TitanPanelGetVar("AuxAutoHide")) then |
||
68 | if (not auxframe.frameTimer or not auxframe.isCounting) then |
||
69 | -- Do nothing |
||
70 | elseif (auxframe.frameTimer < 0) then |
||
71 | TitanPanelBarButton_Hide("TitanPanelAuxBarButton", TITAN_PANEL_PLACE_BOTTOM); |
||
72 | auxframe.frameTimer = nil; |
||
73 | auxframe.isCounting = nil; |
||
74 | else |
||
75 | auxframe.frameTimer = auxframe.frameTimer - elapsed; |
||
76 | end |
||
77 | end |
||
78 | end |
||
79 | |||
80 | function TitanUtils_StartAutoHideCounting(frame) |
||
81 | TITAN_PANEL_SELECTED = TitanUtils_GetButtonID(this:GetName()) |
||
82 | -- Toggle menu |
||
83 | |||
84 | if TITAN_PANEL_SELECTED == "MoneyButtonGold" or TITAN_PANEL_SELECTED == "MoneyButtonSilver" or TITAN_PANEL_SELECTED == "MoneyButtonCopper" then |
||
85 | TITAN_PANEL_SELECTED = "Money" |
||
86 | end |
||
87 | |||
88 | if frame ~= nil then |
||
89 | local frname = getglobal(frame); |
||
90 | frname.frameTimer = TITAN_AUTOHIDE_WAIT_TIME; |
||
91 | frname.isCounting = 1; |
||
92 | end |
||
93 | |||
94 | end |
||
95 | |||
96 | function TitanUtils_StopAutoHideCounting(frame) |
||
97 | TITAN_PANEL_SELECTED = TitanUtils_GetButtonID(this:GetName()) |
||
98 | -- Toggle menu |
||
99 | |||
100 | if TITAN_PANEL_SELECTED == "MoneyButtonGold" or TITAN_PANEL_SELECTED == "MoneyButtonSilver" or TITAN_PANEL_SELECTED == "MoneyButtonCopper" then |
||
101 | TITAN_PANEL_SELECTED = "Money" |
||
102 | end |
||
103 | |||
104 | if frame == nil then |
||
105 | frame = "TitanPanel" .. TitanUtils_GetWhichBar(TITAN_PANEL_SELECTED) .. "ButtonHider"; |
||
106 | end |
||
107 | |||
108 | local frname = getglobal(frame) |
||
109 | frname.isCounting = nil; |
||
110 | end |
||
111 | |||
112 | function TitanUtils_CheckFrameCounting(frame, elapsed) |
||
113 | if (frame:IsVisible()) then |
||
114 | if (not frame.frameTimer or not frame.isCounting) then |
||
115 | return; |
||
116 | elseif ( frame.frameTimer < 0 ) then |
||
117 | frame:Hide(); |
||
118 | frame.frameTimer = nil; |
||
119 | frame.isCounting = nil; |
||
120 | else |
||
121 | frame.frameTimer = frame.frameTimer - elapsed; |
||
122 | end |
||
123 | end |
||
124 | end |
||
125 | |||
126 | function TitanUtils_StartFrameCounting(frame, frameShowTime) |
||
127 | frame.frameTimer = frameShowTime; |
||
128 | frame.isCounting = 1; |
||
129 | end |
||
130 | |||
131 | function TitanUtils_StopFrameCounting(frame) |
||
132 | frame.isCounting = nil; |
||
133 | end |
||
134 | |||
135 | function TitanUtils_CloseAllControlFrames() |
||
136 | for index, value in TitanPlugins do |
||
137 | local frame = getglobal("TitanPanel"..index.."ControlFrame"); |
||
138 | if (frame and frame:IsVisible()) then |
||
139 | frame:Hide(); |
||
140 | end |
||
141 | end |
||
142 | end |
||
143 | |||
144 | function TitanUtils_IsAnyControlFrameVisible() |
||
145 | for index, value in TitanPlugins do |
||
146 | local frame = getglobal("TitanPanel"..index.."ControlFrame"); |
||
147 | if (frame:IsVisible()) then |
||
148 | return true; |
||
149 | end |
||
150 | end |
||
151 | return false; |
||
152 | end |
||
153 | |||
154 | function TitanUtils_CloseRightClickMenu() |
||
155 | if (DropDownList1:IsVisible()) then |
||
156 | DropDownList1:Hide(); |
||
157 | end |
||
158 | end |
||
159 | |||
160 | function TitanUtils_Ternary(a, b, c) |
||
161 | if (a) then |
||
162 | return b; |
||
163 | else |
||
164 | return c; |
||
165 | end |
||
166 | end |
||
167 | |||
168 | function TitanUtils_Toggle(value) |
||
169 | if (value == 1) then |
||
170 | return nil; |
||
171 | else |
||
172 | return 1; |
||
173 | end |
||
174 | end |
||
175 | |||
176 | function TitanUtils_Min(a, b) |
||
177 | if (a and b) then |
||
178 | return TitanUtils_Ternary((a < b), a, b); |
||
179 | end |
||
180 | end |
||
181 | |||
182 | function TitanUtils_Max(a, b) |
||
183 | if (a and b) then |
||
184 | return TitanUtils_Ternary((a > b), a, b); |
||
185 | end |
||
186 | end |
||
187 | |||
188 | function TitanUtils_GetEstTimeText(s) |
||
189 | if (s < 0) then |
||
190 | return TITAN_NA; |
||
191 | elseif (s < 60) then |
||
192 | return format("%d "..TITAN_SECONDS, s); |
||
193 | elseif (s < 60*60) then |
||
194 | return format("%.1f "..TITAN_MINUTES, s/60); |
||
195 | elseif (s < 24*60*60) then |
||
196 | return format("%.1f "..TITAN_HOURS, s/60/60); |
||
197 | else |
||
198 | return format("%.1f "..TITAN_DAYS, s/24/60/60); |
||
199 | end |
||
200 | end |
||
201 | |||
202 | function TitanUtils_GetFullTimeText(s) |
||
203 | if (s < 0) then |
||
204 | return TITAN_NA; |
||
205 | end |
||
206 | |||
207 | local days = floor(s/24/60/60); s = mod(s, 24*60*60); |
||
208 | local hours = floor(s/60/60); s = mod(s, 60*60); |
||
209 | local minutes = floor(s/60); s = mod(s, 60); |
||
210 | local seconds = s; |
||
211 | |||
212 | return format("%d"..TITAN_DAYS_ABBR..", %2d"..TITAN_HOURS_ABBR..", %2d"..TITAN_MINUTES_ABBR..", %2d"..TITAN_SECONDS_ABBR, |
||
213 | days, hours, minutes, seconds); |
||
214 | end |
||
215 | |||
216 | function TitanUtils_GetAbbrTimeText(s) |
||
217 | if (s < 0) then |
||
218 | return TITAN_NA; |
||
219 | end |
||
220 | |||
221 | local days = floor(s/24/60/60); s = mod(s, 24*60*60); |
||
222 | local hours = floor(s/60/60); s = mod(s, 60*60); |
||
223 | local minutes = floor(s/60); s = mod(s, 60); |
||
224 | local seconds = s; |
||
225 | |||
226 | local timeText = ""; |
||
227 | if (days ~= 0) then |
||
228 | timeText = timeText..format("%d"..TITAN_DAYS_ABBR.." ", days); |
||
229 | end |
||
230 | if (days ~= 0 or hours ~= 0) then |
||
231 | timeText = timeText..format("%d"..TITAN_HOURS_ABBR.." ", hours); |
||
232 | end |
||
233 | if (days ~= 0 or hours ~= 0 or minutes ~= 0) then |
||
234 | timeText = timeText..format("%d"..TITAN_MINUTES_ABBR.." ", minutes); |
||
235 | end |
||
236 | timeText = timeText..format("%d"..TITAN_SECONDS_ABBR, seconds); |
||
237 | |||
238 | return timeText; |
||
239 | end |
||
240 | |||
241 | function TitanUtils_GetButton(id, returnThis) |
||
242 | if (id) then |
||
243 | return getglobal("TitanPanel"..id.."Button"), id; |
||
244 | elseif (returnThis) then |
||
245 | return this, TitanUtils_GetButtonID(); |
||
246 | end |
||
247 | end |
||
248 | |||
249 | function TitanUtils_GetButtonID(name) |
||
250 | if (name == nil) then |
||
251 | name = this:GetName(); |
||
252 | end |
||
253 | |||
254 | if (name ~= nil) then |
||
255 | local s, e, id = string.find(name, "TitanPanel(.*)Button"); |
||
256 | return id; |
||
257 | else |
||
258 | return "not found"; |
||
259 | end |
||
260 | end |
||
261 | |||
262 | function TitanUtils_GetParentButtonID(name) |
||
263 | local frame = TitanUtils_Ternary(name, getglobal(name), this); |
||
264 | |||
265 | if ( frame and frame:GetParent() ) then |
||
266 | return TitanUtils_GetButtonID(frame:GetParent():GetName()); |
||
267 | end |
||
268 | end |
||
269 | |||
270 | function TitanUtils_GetButtonIDFromMenu() |
||
271 | if ( this:GetParent() ) then |
||
272 | if ( this:GetParent():GetName() == "TitanPanelBarButton" ) then |
||
273 | return "Bar"; |
||
274 | elseif ( this:GetParent():GetName() == "TitanPanelAuxBarButton" ) then |
||
275 | return "Bar"; |
||
276 | elseif ( this:GetParent():GetParent()) then |
||
277 | -- TitanPanelChildButton |
||
278 | return TitanUtils_GetButtonID(this:GetParent():GetParent():GetName()); |
||
279 | else |
||
280 | -- TitanPanelButton |
||
281 | return TitanUtils_GetButtonID(this:GetParent():GetName()); |
||
282 | end |
||
283 | end |
||
284 | end |
||
285 | |||
286 | function TitanUtils_GetControlFrame(id) |
||
287 | if (id == nil) then |
||
288 | id = TitanUtils_GetButtonID(); |
||
289 | end |
||
290 | |||
291 | if (id) then |
||
292 | return getglobal("TitanPanel"..id.."ControlFrame"); |
||
293 | else |
||
294 | return; |
||
295 | end |
||
296 | end |
||
297 | |||
298 | function TitanUtils_GetPlugin(id) |
||
299 | if (id == nil) then |
||
300 | id = TitanUtils_GetButtonID(); |
||
301 | end |
||
302 | |||
303 | if (id) then |
||
304 | return TitanPlugins[id]; |
||
305 | end |
||
306 | end |
||
307 | |||
308 | function TitanUtils_IsPluginRegistered(id) |
||
309 | if (id and TitanPlugins[id]) then |
||
310 | return true; |
||
311 | else |
||
312 | return false; |
||
313 | end |
||
314 | end |
||
315 | |||
316 | function TitanUtils_RegisterPlugin(registry) |
||
317 | if (registry and registry.id) then |
||
318 | local id = registry.id; |
||
319 | if TitanUtils_IsPluginRegistered(id) then |
||
320 | -- We have already registered this plugin we have an issue! |
||
321 | TitanPanel_LoadError("Plugin " .. id .. TITAN_PANEL_ERROR_DUP_PLUGIN); |
||
322 | else |
||
323 | if (not TitanUtils_TableContainsValue(TitanPluginsIndex, id)) then |
||
324 | TitanPlugins[id] = registry; |
||
325 | -- if (not TitanUtils_TableContainsValue(TITAN_PANEL_NONMOVABLE_PLUGINS, id)) then |
||
326 | table.insert(TitanPluginsIndex, registry.id); |
||
327 | table.sort(TitanPluginsIndex, |
||
328 | function(a, b) |
||
329 | return TitanPlugins[a].menuText < TitanPlugins[b].menuText; |
||
330 | end |
||
331 | ); |
||
332 | -- end |
||
333 | end |
||
334 | end |
||
335 | end |
||
336 | end |
||
337 | |||
338 | function TitanUtils_TableContainsValue(table, value) |
||
339 | if (table and value) then |
||
340 | for i, v in table do |
||
341 | if (v == value) then |
||
342 | return i; |
||
343 | end |
||
344 | end |
||
345 | end |
||
346 | end |
||
347 | |||
348 | function TitanUtils_TableContainsIndex(table, index) |
||
349 | if (table and index) then |
||
350 | for i, v in table do |
||
351 | if (i == index) then |
||
352 | return i; |
||
353 | end |
||
354 | end |
||
355 | end |
||
356 | end |
||
357 | |||
358 | function TitanUtils_GetCurrentIndex(table, value) |
||
359 | return TitanUtils_TableContainsValue(table, value); |
||
360 | end |
||
361 | |||
362 | function TitanUtils_GetPreviousButton(table, id, isSameType, ignoreClock) |
||
363 | local index = TitanUtils_GetCurrentIndex(table, id); |
||
364 | local isIcon = TitanPanelButton_IsIcon(id); |
||
365 | local previousButton, isPreviousIcon; |
||
366 | |||
367 | if ( isSameType ) then |
||
368 | -- Get the previous button with the same type |
||
369 | while ( index > 1 ) do |
||
370 | previousButton = TitanUtils_GetButton(table[index - 1]); |
||
371 | isPreviousIcon = TitanPanelButton_IsIcon(table[index - 1]); |
||
372 | |||
373 | if ( ( isIcon and isPreviousIcon ) or ( not isIcon and not isPreviousIcon ) ) then |
||
374 | if ( ( table[index - 1] == TITAN_CLOCK_ID ) and ignoreClock ) then |
||
375 | -- Do nothing, ignore Clock button |
||
376 | else |
||
377 | return previousButton; |
||
378 | end |
||
379 | end |
||
380 | |||
381 | index = index - 1; |
||
382 | end |
||
383 | else |
||
384 | -- Simply get the previous button |
||
385 | if ( index > 1 ) then |
||
386 | return TitanUtils_GetButton(table[index - 1]); |
||
387 | end |
||
388 | end |
||
389 | end |
||
390 | |||
391 | function TitanUtils_GetNextButton(table, id, isSameType, ignoreClock) |
||
392 | local index = TitanUtils_GetCurrentIndex(table, id); |
||
393 | local isIcon = TitanPanelButton_IsIcon(id); |
||
394 | local nextButton, isNextIcon; |
||
395 | |||
396 | if ( isSameType ) then |
||
397 | -- Get the next button with the same type |
||
398 | while ( table[index + 1] ) do |
||
399 | nextButton = TitanUtils_GetButton(table[index + 1]); |
||
400 | isNextIcon = TitanPanelButton_IsIcon(table[index + 1]); |
||
401 | |||
402 | if ( ( isIcon and isNextIcon ) or ( not isIcon and not isNextIcon ) ) then |
||
403 | if ( ( table[index + 1] == TITAN_CLOCK_ID ) and ignoreClock ) then |
||
404 | -- Do nothing, ignore Clock button |
||
405 | else |
||
406 | return nextButton; |
||
407 | end |
||
408 | end |
||
409 | |||
410 | index = index + 1; |
||
411 | end |
||
412 | else |
||
413 | -- Simply get the next button |
||
414 | if ( table[index + 1] ) then |
||
415 | return TitanUtils_GetButton(table[index + 1]); |
||
416 | end |
||
417 | end |
||
418 | end |
||
419 | |||
420 | function TitanUtils_GetFirstButton(array, isSameType, isIcon, ignoreClock) |
||
421 | local firstButton, isFirstIcon; |
||
422 | local size = table.getn(array); |
||
423 | local index = 1; |
||
424 | |||
425 | if ( isSameType ) then |
||
426 | -- Get the first button with the same type |
||
427 | while ( index <= size ) do |
||
428 | firstButton = TitanUtils_GetButton(array[index]); |
||
429 | isFirstIcon = TitanPanelButton_IsIcon(array[index]); |
||
430 | |||
431 | if ( ( isIcon and isFirstIcon ) or ( not isIcon and not isFirstIcon ) ) then |
||
432 | if ( ( array[index] == TITAN_CLOCK_ID ) and ignoreClock ) then |
||
433 | -- Do nothing, ignore Clock button |
||
434 | elseif TitanUtils_GetWhichBar(array[index]) == "AuxBar" then |
||
435 | -- Do nothing wrong bar |
||
436 | else |
||
437 | return firstButton; |
||
438 | end |
||
439 | end |
||
440 | |||
441 | index = index + 1; |
||
442 | end |
||
443 | else |
||
444 | -- Simply get the first button |
||
445 | if ( size > 0 ) then |
||
446 | return TitanUtils_GetButton(array[1]); |
||
447 | end |
||
448 | end |
||
449 | end |
||
450 | |||
451 | function TitanUtils_GetFirstAuxButton(array, isSameType, isIcon, ignoreClock) |
||
452 | local firstButton, isFirstIcon; |
||
453 | local size = table.getn(array); |
||
454 | local index = 1; |
||
455 | |||
456 | if ( isSameType ) then |
||
457 | -- Get the first button with the same type |
||
458 | while ( index <= size ) do |
||
459 | firstButton = TitanUtils_GetButton(array[index]); |
||
460 | isFirstIcon = TitanPanelButton_IsIcon(array[index]); |
||
461 | |||
462 | if ( ( isIcon and isFirstIcon ) or ( not isIcon and not isFirstIcon ) ) then |
||
463 | if ( ( array[index] == TITAN_CLOCK_ID ) and ignoreClock ) then |
||
464 | -- Do nothing, ignore Clock button |
||
465 | elseif TitanUtils_GetWhichBar(array[index]) == "Bar" then |
||
466 | -- Do nothing wrong bar |
||
467 | else |
||
468 | return firstButton; |
||
469 | end |
||
470 | end |
||
471 | |||
472 | index = index + 1; |
||
473 | end |
||
474 | else |
||
475 | -- Simply get the first button |
||
476 | if ( size > 0 ) then |
||
477 | return TitanUtils_GetButton(array[1]); |
||
478 | end |
||
479 | end |
||
480 | end |
||
481 | |||
482 | function TitanUtils_GetLastButton(array, isSameType, isIcon, ignoreClock) |
||
483 | local lastButton, isLastIcon; |
||
484 | local size = table.getn(array); |
||
485 | local index = size; |
||
486 | |||
487 | if ( isSameType ) then |
||
488 | -- Get the last button with the same type |
||
489 | while ( index > 0 ) do |
||
490 | lastButton = TitanUtils_GetButton(array[index]); |
||
491 | isLastIcon = TitanPanelButton_IsIcon(array[index]); |
||
492 | |||
493 | if ( ( isIcon and isLastIcon ) or ( not isIcon and not isLastIcon ) ) then |
||
494 | if ( ( array[index] == TITAN_CLOCK_ID ) and ignoreClock ) then |
||
495 | -- Do nothing, ignore Clock button |
||
496 | else |
||
497 | return lastButton; |
||
498 | end |
||
499 | end |
||
500 | |||
501 | index = index - 1; |
||
502 | end |
||
503 | else |
||
504 | -- Simply get the last button |
||
505 | if ( size > 0 ) then |
||
506 | return TitanUtils_GetButton(array[size]); |
||
507 | end |
||
508 | end |
||
509 | end |
||
510 | |||
511 | function TitanUtils_GetCPNIndexInArray(array, value) |
||
512 | if (not array) then |
||
513 | return; |
||
514 | end |
||
515 | |||
516 | local currentIndex, previousIndex, nextIndex; |
||
517 | for i, v in array do |
||
518 | if (v == value) then |
||
519 | currentIndex = i; |
||
520 | end |
||
521 | end |
||
522 | |||
523 | if (currentIndex > 1) then |
||
524 | previousIndex = currentIndex - 1; |
||
525 | end |
||
526 | |||
527 | if (array[currentIndex + 1]) then |
||
528 | nextIndex = currentIndex + 1; |
||
529 | end |
||
530 | |||
531 | return currentIndex, previousIndex, nextIndex; |
||
532 | end |
||
533 | |||
534 | function TitanUtils_PrintArray(array) |
||
535 | if (not array) then |
||
536 | TitanDebug("array is nil"); |
||
537 | else |
||
538 | TitanDebug("{"); |
||
539 | for i, v in array do |
||
540 | TitanDebug("array[" .. tostring(i) .. "] = " .. tostring(v)); |
||
541 | end |
||
542 | TitanDebug("}"); |
||
543 | end |
||
544 | |||
545 | end |
||
546 | |||
547 | function TitanUtils_GetRedText(text) |
||
548 | if (text) then |
||
549 | return RED_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; |
||
550 | end |
||
551 | end |
||
552 | |||
553 | function TitanUtils_GetGreenText(text) |
||
554 | if (text) then |
||
555 | return GREEN_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; |
||
556 | end |
||
557 | end |
||
558 | |||
559 | function TitanUtils_GetNormalText(text) |
||
560 | if (text) then |
||
561 | return NORMAL_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; |
||
562 | end |
||
563 | end |
||
564 | |||
565 | function TitanUtils_GetHighlightText(text) |
||
566 | if (text) then |
||
567 | return HIGHLIGHT_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; |
||
568 | end |
||
569 | end |
||
570 | |||
571 | function TitanUtils_GetColoredText(text, color) |
||
572 | if (text and color) then |
||
573 | local redColorCode = format("%02x", color.r * 255); |
||
574 | local greenColorCode = format("%02x", color.g * 255); |
||
575 | local blueColorCode = format("%02x", color.b * 255); |
||
576 | local colorCode = "|cff"..redColorCode..greenColorCode..blueColorCode; |
||
577 | return colorCode..text..FONT_COLOR_CODE_CLOSE; |
||
578 | end |
||
579 | end |
||
580 | |||
581 | function TitanUtils_GetThresholdColor(ThresholdTable, value) |
||
582 | if ( not tonumber(value) or type(ThresholdTable) ~= "table" or |
||
583 | ThresholdTable.Values == nil or ThresholdTable.Colors == nil or |
||
584 | table.getn(ThresholdTable.Values) >= table.getn(ThresholdTable.Colors) ) then |
||
585 | return TITAN_THRESHOLD_EXCEPTION_COLOR; |
||
586 | end |
||
587 | |||
588 | local n = table.getn(ThresholdTable.Values) + 1; |
||
589 | for i = 1, n do |
||
590 | local low = TitanUtils_Ternary(i == 1, nil, ThresholdTable.Values[i-1]); |
||
591 | local high = TitanUtils_Ternary(i == n, nil, ThresholdTable.Values[i]); |
||
592 | |||
593 | if ( not low and not high ) then |
||
594 | -- No threshold values |
||
595 | return ThresholdTable.Colors[i]; |
||
596 | |||
597 | elseif ( not low and high ) then |
||
598 | -- Value is smaller than the first threshold |
||
599 | if ( value < high ) then return ThresholdTable.Colors[i] end |
||
600 | |||
601 | elseif ( low and not high ) then |
||
602 | -- Value is larger than the last threshold |
||
603 | if ( low <= value ) then return ThresholdTable.Colors[i] end |
||
604 | |||
605 | else |
||
606 | -- Value is in between 2 adjacent thresholds |
||
607 | if ( low <= value and value < high ) then return ThresholdTable.Colors[i] end |
||
608 | end |
||
609 | end |
||
610 | |||
611 | -- Should never reach here |
||
612 | return TITAN_THRESHOLD_EXCEPTION_COLOR; |
||
613 | end |
||
614 | |||
615 | function TitanUtils_ToString(text) |
||
616 | return TitanUtils_Ternary(text, text, ""); |
||
617 | end |
||
618 | |||
619 | function TitanUtils_GetTotalTime() |
||
620 | return TitanPanelBarButton.totalTime; |
||
621 | end |
||
622 | |||
623 | function TitanUtils_GetLevelTime() |
||
624 | return TitanPanelBarButton.levelTime; |
||
625 | end |
||
626 | |||
627 | function TitanUtils_GetSessionTime() |
||
628 | return TitanPanelBarButton.sessionTime; |
||
629 | end |
||
630 | |||
631 | function TitanUtils_GetOffscreen(frame) |
||
632 | local offscreenX, offscreenY; |
||
633 | |||
634 | if ( frame and frame:GetLeft() and frame:GetLeft() * frame:GetEffectiveScale() < UIParent:GetLeft() * UIParent:GetEffectiveScale() ) then |
||
635 | offscreenX = -1; |
||
636 | elseif ( frame and frame:GetRight() and frame:GetRight() * frame:GetEffectiveScale() > UIParent:GetRight() * UIParent:GetEffectiveScale() ) then |
||
637 | offscreenX = 1; |
||
638 | else |
||
639 | offscreenX = 0; |
||
640 | end |
||
641 | |||
642 | if ( frame and frame:GetTop() and frame:GetTop() * frame:GetEffectiveScale() > UIParent:GetTop() * UIParent:GetEffectiveScale() ) then |
||
643 | offscreenY = -1; |
||
644 | elseif ( frame and frame:GetBottom() and frame:GetBottom() * frame:GetEffectiveScale() < UIParent:GetBottom() * UIParent:GetEffectiveScale() ) then |
||
645 | offscreenY = 1; |
||
646 | else |
||
647 | offscreenY = 0; |
||
648 | end |
||
649 | |||
650 | --[[ |
||
651 | TitanDebug(frame:GetName()); |
||
652 | TitanDebug("frame:GetScale() = "..frame:GetScale()); |
||
653 | TitanDebug("frame:GetLeft() = "..frame:GetLeft()); |
||
654 | TitanDebug("frame:GetRight() = "..frame:GetRight()); |
||
655 | TitanDebug("frame:GetTop() = "..frame:GetTop()); |
||
656 | TitanDebug("frame:GetBottom() = "..frame:GetBottom()); |
||
657 | TitanDebug("UIParent:GetScale() = "..UIParent:GetScale()); |
||
658 | TitanDebug("UIParent:GetLeft() = "..UIParent:GetLeft()); |
||
659 | TitanDebug("UIParent:GetRight() = "..UIParent:GetRight()); |
||
660 | TitanDebug("UIParent:GetTop() = "..UIParent:GetTop()); |
||
661 | TitanDebug("UIParent:GetBottom() = "..UIParent:GetBottom()); |
||
662 | TitanDebug("offscreenX = "..offscreenX.." | offscreenY = "..offscreenY); |
||
663 | ]]-- |
||
664 | return offscreenX, offscreenY; |
||
665 | end |
||
666 | |||
667 | -- There's obvious bug in Blizzard code to handle the drop down menu offscreen cases. |
||
668 | -- I overwrote this function in order to do it right |
||
669 | function ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yOffset) |
||
670 | if ( not level ) then |
||
671 | level = 1; |
||
672 | end |
||
673 | UIDROPDOWNMENU_MENU_LEVEL = level; |
||
674 | UIDROPDOWNMENU_MENU_VALUE = value; |
||
675 | local listFrame = getglobal("DropDownList"..level); |
||
676 | local listFrameName = "DropDownList"..level; |
||
677 | local tempFrame; |
||
678 | local point, relativePoint, relativeTo; |
||
679 | if ( not dropDownFrame ) then |
||
680 | tempFrame = this:GetParent(); |
||
681 | else |
||
682 | tempFrame = dropDownFrame; |
||
683 | end |
||
684 | if ( listFrame:IsVisible() and (UIDROPDOWNMENU_OPEN_MENU == tempFrame:GetName()) ) then |
||
685 | listFrame:Hide(); |
||
686 | else |
||
687 | -- Hide the listframe anyways since it is redrawn OnShow() |
||
688 | listFrame:Hide(); |
||
689 | |||
690 | -- Frame to anchor the dropdown menu to |
||
691 | local anchorFrame; |
||
692 | |||
693 | -- Display stuff |
||
694 | -- Level specific stuff |
||
695 | if ( level == 1 ) then |
||
696 | if ( not dropDownFrame ) then |
||
697 | dropDownFrame = this:GetParent(); |
||
698 | end |
||
699 | UIDROPDOWNMENU_OPEN_MENU = dropDownFrame:GetName(); |
||
700 | listFrame:ClearAllPoints(); |
||
701 | -- If there's no specified anchorName then use left side of the dropdown menu |
||
702 | if ( not anchorName ) then |
||
703 | -- See if the anchor was set manually using setanchor |
||
704 | if ( dropDownFrame.xOffset ) then |
||
705 | xOffset = dropDownFrame.xOffset; |
||
706 | end |
||
707 | if ( dropDownFrame.yOffset ) then |
||
708 | yOffset = dropDownFrame.yOffset; |
||
709 | end |
||
710 | if ( dropDownFrame.point ) then |
||
711 | point = dropDownFrame.point; |
||
712 | end |
||
713 | if ( dropDownFrame.relativeTo ) then |
||
714 | relativeTo = dropDownFrame.relativeTo; |
||
715 | else |
||
716 | relativeTo = UIDROPDOWNMENU_OPEN_MENU.."Left"; |
||
717 | end |
||
718 | if ( dropDownFrame.relativePoint ) then |
||
719 | relativePoint = dropDownFrame.relativePoint; |
||
720 | end |
||
721 | elseif ( anchorName == "cursor" ) then |
||
722 | relativeTo = "UIParent"; |
||
723 | local cursorX, cursorY = GetCursorPosition(); |
||
724 | if ( not xOffset ) then |
||
725 | xOffset = 0; |
||
726 | end |
||
727 | if ( not yOffset ) then |
||
728 | yOffset = 0; |
||
729 | end |
||
730 | xOffset = cursorX + xOffset; |
||
731 | yOffset = cursorY + yOffset; |
||
732 | else |
||
733 | relativeTo = anchorName; |
||
734 | end |
||
735 | if ( not xOffset or not yOffset ) then |
||
736 | xOffset = 8; |
||
737 | yOffset = 22; |
||
738 | end |
||
739 | if ( not point ) then |
||
740 | point = "TOPLEFT"; |
||
741 | end |
||
742 | if ( not relativePoint ) then |
||
743 | relativePoint = "BOTTOMLEFT"; |
||
744 | end |
||
745 | listFrame:SetPoint(point, relativeTo, relativePoint, xOffset, yOffset); |
||
746 | else |
||
747 | if ( not dropDownFrame ) then |
||
748 | dropDownFrame = getglobal(UIDROPDOWNMENU_OPEN_MENU); |
||
749 | end |
||
750 | listFrame:ClearAllPoints(); |
||
751 | -- If this is a dropdown button, not the arrow anchor it to itself |
||
752 | if ( strsub(this:GetParent():GetName(), 0,12) == "DropDownList" and strlen(this:GetParent():GetName()) == 13 ) then |
||
753 | anchorFrame = this:GetName(); |
||
754 | else |
||
755 | anchorFrame = this:GetParent():GetName(); |
||
756 | end |
||
757 | listFrame:SetPoint("TOPLEFT", anchorFrame, "TOPRIGHT", 0, 0); |
||
758 | end |
||
759 | |||
760 | -- Change list box appearance depending on display mode |
||
761 | if ( dropDownFrame and dropDownFrame.displayMode == "MENU" ) then |
||
762 | getglobal(listFrameName.."Backdrop"):Hide(); |
||
763 | getglobal(listFrameName.."MenuBackdrop"):Show(); |
||
764 | else |
||
765 | getglobal(listFrameName.."Backdrop"):Show(); |
||
766 | getglobal(listFrameName.."MenuBackdrop"):Hide(); |
||
767 | end |
||
768 | |||
769 | UIDropDownMenu_Initialize(dropDownFrame, dropDownFrame.initialize, nil, level); |
||
770 | -- If no items in the drop down don't show it |
||
771 | if ( listFrame.numButtons == 0 ) then |
||
772 | return; |
||
773 | end |
||
774 | |||
775 | |||
776 | -- Check to see if the dropdownlist is off the screen, if it is anchor it to the top of the dropdown button |
||
777 | -- I overwrote this part to fix Blizzard's offscreen bug |
||
778 | listFrame:Show(); |
||
779 | local offscreenX, offscreenY = TitanUtils_GetOffscreen(listFrame); |
||
780 | offscreenX = TitanUtils_Ternary(offscreenX == 0, nil, 1); |
||
781 | offscreenY = TitanUtils_Ternary(offscreenY == 0, nil, 1); |
||
782 | |||
783 | --[[ |
||
784 | listFrame:Show(); |
||
785 | -- Hack since GetCenter() is returning coords relative to 1024x768 |
||
786 | local x, y = listFrame:GetCenter(); |
||
787 | -- Hack will fix this in next revision of dropdowns |
||
788 | if ( not x or not y ) then |
||
789 | listFrame:Hide(); |
||
790 | return; |
||
791 | end |
||
792 | -- Determine whether the menu is off the screen or not |
||
793 | local offscreenY, offscreenX; |
||
794 | if ( (y - listFrame:GetHeight()/2) < 0 ) then |
||
795 | offscreenY = 1; |
||
796 | end |
||
797 | if ( x + listFrame:GetWidth()/2 > GetScreenWidth() ) then |
||
798 | offscreenX = 1; |
||
799 | end |
||
800 | ]]-- |
||
801 | |||
802 | |||
803 | -- If level 1 can only go off the bottom of the screen |
||
804 | if ( level == 1 ) then |
||
805 | if ( offscreenY ) then |
||
806 | listFrame:ClearAllPoints(); |
||
807 | if ( anchorName == "cursor" ) then |
||
808 | listFrame:SetPoint("BOTTOMLEFT", relativeTo, "BOTTOMLEFT", xOffset, yOffset); |
||
809 | else |
||
810 | listFrame:SetPoint("BOTTOMLEFT", relativeTo, "TOPLEFT", xOffset, -yOffset); |
||
811 | end |
||
812 | end |
||
813 | |||
814 | else |
||
815 | local anchorPoint, relativePoint, offsetX, offsetY; |
||
816 | if ( offscreenY ) then |
||
817 | if ( offscreenX ) then |
||
818 | anchorPoint = "BOTTOMRIGHT"; |
||
819 | relativePoint = "BOTTOMLEFT"; |
||
820 | offsetX = 0; |
||
821 | offsetY = -14; |
||
822 | else |
||
823 | anchorPoint = "BOTTOMLEFT"; |
||
824 | relativePoint = "BOTTOMRIGHT"; |
||
825 | offsetX = 0; |
||
826 | offsetY = -14; |
||
827 | end |
||
828 | else |
||
829 | if ( offscreenX ) then |
||
830 | anchorPoint = "TOPRIGHT"; |
||
831 | relativePoint = "TOPLEFT"; |
||
832 | offsetX = 0; |
||
833 | offsetY = 14; |
||
834 | else |
||
835 | anchorPoint = "TOPLEFT"; |
||
836 | relativePoint = "TOPRIGHT"; |
||
837 | offsetX = 0; |
||
838 | offsetY = 14; |
||
839 | end |
||
840 | end |
||
841 | listFrame:ClearAllPoints(); |
||
842 | listFrame:SetPoint(anchorPoint, anchorFrame, relativePoint, offsetX, offsetY); |
||
843 | end |
||
844 | end |
||
845 | end |
||
846 |