vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 DL_VARIABLES_LOADED = nil;
2 DL_ENTERING_WORLD = nil;
3  
4 DL_INIT_FUNCTIONS = {};
5 DL_FRAME_FUNCTIONS = {};
6  
7 DL_Old_UseAction = UseAction;
8  
9 DL_Old_PickupAction = PickupAction;
10 DL_Old_PlaceAction = PlaceAction;
11  
12 function DL_PickupAction(action)
13 DL_Old_PickupAction(action);
14 DL_Update_ActionList();
15 end
16  
17 function DL_PlaceAction(action)
18 DL_Old_PlaceAction(action);
19 DL_Update_ActionList();
20 end
21  
22 PickupAction = DL_PickupAction;
23 PlaceAction = DL_PlaceAction;
24  
25 function DiscordLib_Main_OnEvent(event)
26 if (event == "CHAT_MSG_COMBAT_SELF_MISSES" or event == "CHAT_MSG_SPELL_SELF_DAMAGE") then
27 if (string.find(arg1, DL_TEXT.Dodge)) then
28 DL_TARGET_DODGED = 6;
29 elseif (string.find(arg1, DL_TEXT.Parry)) then
30 DL_TARGET_PARRIED = 6;
31 elseif (string.find(arg1, DL_TEXT.Block)) then
32 DL_TARGET_BLOCKED = 6;
33 end
34 elseif (event == "PARTY_MEMBERS_CHANGED") then
35 for i=1,4 do
36 DL_Update_Auras("party"..i);
37 end
38 elseif (event == "PET_ATTACK_START") then
39 DL_PETATTACKING = true;
40 elseif (event == "PET_ATTACK_STOP") then
41 DL_PETATTACKING = nil;
42 elseif (event == "PLAYER_AURAS_CHANGED") then
43 DL_Update_Auras("player");
44 elseif (event == "PLAYER_ENTER_COMBAT") then
45 DL_ATTACKING = true;
46 DL_INCOMBAT = true;
47 elseif (event == "PLAYER_ENTERING_WORLD") then
48 DL_ENTERING_WORLD = true;
49 DL_ATTACKING = nil;
50 DL_INCOMBAT = nil;
51 DL_REGEN = true;
52 if ( DL_VARIABLES_LOADED ) then
53 DL_START_CHECKING_FRAME = true;
54 end
55 elseif (event == "PLAYER_LEAVE_COMBAT") then
56 DL_ATTACKING = nil;
57 if (DL_REGEN) then
58 DL_INCOMBAT = nil;
59 end
60 elseif (event == "PLAYER_REGEN_DISABLED") then
61 DL_REGEN = nil;
62 DL_INCOMBAT = true;
63 elseif (event == "PLAYER_REGEN_ENABLED") then
64 DL_REGEN = true;
65 if (not DL_ATTACKING) then
66 DL_INCOMBAT = nil;
67 end
68 elseif (event == "PLAYER_TARGET_CHANGED") then
69 DL_Update_Auras("target");
70 elseif (event == "RAID_ROSTER_UPDATE") then
71 for i=1,40 do
72 DL_Update_Auras("raid"..i);
73 end
74 elseif (event == "UNIT_AURA") then
75 if (arg1 ~= "mouseover" and arg1 ~= "player") then
76 DL_Update_Auras(arg1);
77 end
78 elseif (event == "UNIT_PET") then
79 DL_Update_Auras("pet");
80 for i=1,4 do
81 DL_Update_Auras("partypet"..i);
82 end
83 elseif (event == "UPDATE_SHAPESHIFT_FORMS") then
84 DL_Update_Forms();
85 elseif (event == "VARIABLES_LOADED") then
86 DL_VARIABLES_LOADED = true;
87 if ( DL_ENTERING_WORLD ) then
88 DL_START_CHECKING_FRAME = true;
89 end
90 end
91 end
92  
93 function DiscordLib_Main_OnLoad()
94 this:RegisterEvent("CHAT_MSG_COMBAT_SELF_MISSES");
95 this:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE");
96 this:RegisterEvent("PARTY_MEMBERS_CHANGED");
97 this:RegisterEvent("PET_ATTACK_START");
98 this:RegisterEvent("PET_ATTACK_STOP");
99 this:RegisterEvent("PLAYER_AURAS_CHANGED");
100 this:RegisterEvent("PLAYER_ENTER_COMBAT");
101 this:RegisterEvent("PLAYER_ENTERING_WORLD");
102 this:RegisterEvent("PLAYER_LEAVE_COMBAT");
103 this:RegisterEvent("PLAYER_REGEN_DISABLED");
104 this:RegisterEvent("PLAYER_REGEN_ENABLED");
105 this:RegisterEvent("PLAYER_TARGET_CHANGED");
106 this:RegisterEvent("RAID_ROSTER_UPDATE");
107 this:RegisterEvent("UNIT_AURA");
108 this:RegisterEvent("UNIT_PET");
109 this:RegisterEvent("UPDATE_SHAPESHIFT_FORMS");
110 this:RegisterEvent("VARIABLES_LOADED");
111  
112 SlashCmdList["DISCLIB"] = DL_Slash_Handler;
113 SLASH_DISCLIB1 = "/disclib";
114 end
115  
116 function DL_Slash_Handler(msg)
117 if (msg == "nobuffchecking") then
118 if (DiscordLibrary_Settings.disableBuffChecking) then
119 DiscordLibrary_Settings.disableBuffChecking = nil;
120 DL_Feedback("Discord Library's buff/debuff checking has been turned on.");
121 DiscordLib_MainFrame:RegisterEvent("UNIT_AURA");
122 DiscordLib_MainFrame:RegisterEvent("PLAYER_AURAS_CHANGED");
123 DL_Update_Auras("player");
124 DL_Update_Auras("pet");
125 DL_Update_Auras("target");
126 for i=1,4 do
127 DL_Update_Auras("party"..i);
128 DL_Update_Auras("partypet"..i);
129 end
130 for i=1,40 do
131 DL_Update_Auras("raid"..i);
132 end
133 else
134 DiscordLibrary_Settings.disableBuffChecking = 1;
135 DL_Feedback("Discord Library's buff/debuff checking has been turned off.");
136 DL_BUFFS = {};
137 DL_DEBUFFS = {};
138 DL_STATUS = {};
139 DiscordLib_MainFrame:UnregisterEvent("UNIT_AURA");
140 DiscordLib_MainFrame:UnregisterEvent("PLAYER_AURAS_CHANGED");
141 end
142 end
143 end
144  
145 function DiscordLib_Main_OnUpdate(elapsed)
146 if (DL_TARGET_DODGED) then
147 DL_TARGET_DODGED = DL_TARGET_DODGED - elapsed;
148 if (DL_TARGET_DODGED < 0) then DL_TARGET_DODGED = nil; end
149 end
150 if (DL_TARGET_BLOCKED) then
151 DL_TARGET_BLOCKED = DL_TARGET_BLOCKED - elapsed;
152 if (DL_TARGET_BLOCKED < 0) then DL_TARGET_BLOCKED = nil; end
153 end
154 if (DL_TARGET_PARRIED) then
155 DL_TARGET_PARRIED = DL_TARGET_PARRIED - elapsed;
156 if (DL_TARGET_PARRIED < 0) then DL_TARGET_PARRIED = nil; end
157 end
158 if (this.inittimer) then
159 this.inittimer = this.inittimer - elapsed;
160 if (this.inittimer < 0) then
161 this.inittimer = nil;
162 DiscordLib_Initialize();
163 end
164 else
165 if (DL_START_CHECKING_FRAME and (not DISCORDLIB_INITIALIZED)) then
166 if (ZoneTextFrame:GetCenter()) then
167 this.inittimer = 1;
168 end
169 end
170 end
171 end
172  
173 function DL_UnitName(unit)
174 local name = UnitName(unit);
175 if (name == UNKNOWNOBJECT or name == UKNOWNBEING) then
176 return nil;
177 else
178 return name;
179 end
180 end
181  
182 DL_Old_MoneyFrame_Update = MoneyFrame_Update
183 function MoneyFrame_Update(frameName, money)
184 if (not money) then return end
185 DL_Old_MoneyFrame_Update(frameName, money)
186 end
187  
188 --[[DL_Old_ChatEdit_OnEnterPressed = ChatEdit_OnEnterPressed
189 function ChatEdit_OnEnterPressed()
190 local f = this:GetName()
191 DL_Debug(f)
192 if (string.find(f, "DAB_")) then
193 return
194 end
195 DL_Old_ChatEdit_OnEnterPressed()
196 end
197  
198 DL_Old_ChatEdit_OnEscapePressed = ChatEdit_OnEscapePressed
199 function ChatEdit_OnEscapePressed(editBox)
200 if (not editBox) then return end
201 if (not editBox.SetText) then return end
202 DL_Old_ChatEdit_OnEscapePressed(editBox)
203 end
204 --]]
205 function DiscordLib_Initialize()
206 if (DISCORDLIB_INITIALIZED) then return; end
207  
208 if (not DiscordLibrary_Settings) then
209 DiscordLibrary_Settings = {}
210 end
211  
212 DL_Old_ColorPickerFrame_OnColorSelect = ColorPickerFrame:GetScript("OnColorSelect");
213 ColorPickerFrame:SetScript("OnColorSelect", function() DL_Old_ColorPickerFrame_OnColorSelect(); DL_ColorBox_UpdateDisplay(); end);
214  
215 for i=2,30 do
216 local left = getglobal("DiscordLib_AuraTooltipTextLeft"..i)
217 for i,v in left do
218 if (type(v) == "function") then
219 left[i] = function() end
220 end
221 end
222 local left = getglobal("DiscordLib_AuraTooltipTextRight"..i)
223 for i,v in left do
224 if (type(v) == "function") then
225 left[i] = function() end
226 end
227 end
228 end
229 for i,v in DiscordLib_AuraTooltipTextLeft1 do
230 if (type(v) == "function" and i ~= "GetText" and i ~= "SetText" and i ~= "Hide" and i ~= "Show") then
231 DiscordLib_AuraTooltipTextLeft1[i] = function() end
232 end
233 end
234 for i,v in DiscordLib_AuraTooltipTextRight1 do
235 if (type(v) == "function" and i ~= "GetText" and i ~= "SetText" and i ~= "Hide" and i ~= "Show") then
236 DiscordLib_AuraTooltipTextRight1[i] = function() end
237 end
238 end
239  
240 DiscordLib_Tooltip:SetOwner(WorldFrame, "ANCHOR_NONE");
241 DiscordLib_AuraTooltip:SetOwner(WorldFrame, "ANCHOR_NONE");
242  
243 DL_Update_ActionList();
244 DL_Init_AnchorFramesList();
245 DL_Init_UnitsList();
246 DL_TEXTURES_LIST = { {text="", value=""} };
247 DL_Init_FontsList();
248 DL_Update_Forms();
249 DL_Update_Auras("player");
250 DL_Update_Auras("pet");
251 for i=1,4 do
252 DL_Update_Auras("party"..i);
253 DL_Update_Auras("partypet"..i);
254 end
255 for i=1,40 do
256 DL_Update_Auras("raid"..i);
257 end
258 for index, initFunction in DL_FRAME_FUNCTIONS do
259 initFunction();
260 end
261 for index, initFunction in DL_INIT_FUNCTIONS do
262 initFunction();
263 end
264  
265 DISCORDLIB_INITIALIZED = true;
266 DL_INIT_FUNCTIONS = nil;
267 end
268  
269 function DiscordLib_RegisterInitFunc(func, delay)
270 DL_INIT_FUNCTIONS_INDEX = DL_INIT_FUNCTIONS_INDEX + 1;
271 DL_INIT_FUNCTIONS[DL_INIT_FUNCTIONS_INDEX] = func;
272 end
273  
274 function DiscordLib_RegisterFrameCreationFunc(func)
275 DL_FRAME_FUNCTIONS_INDEX = DL_FRAME_FUNCTIONS_INDEX + 1
276 DL_FRAME_FUNCTIONS[DL_FRAME_FUNCTIONS_INDEX] = func
277 end
278  
279 function DL_ActionUsable(action)
280 local cd = DL_CooldownLeft(action);
281 if (cd > 0) then return; end
282 local isUsable, notEnoughMana = IsUsableAction(action);
283 if (not isUsable) then return; end
284 if (notEnoughMana) then return; end
285 local range = IsActionInRange(action);
286 if (range ~= 0) then return true; end
287 end
288  
289 function DL_AddToMenu(menu, text, value, desc)
290 if (not text) then return; end
291 if (not value) then value = text; end
292 if (desc == 1) then
293 desc = value;
294 if (desc and string.len(desc) > 25) then
295 desc = string.sub(desc, 1, 25).."\n"..string.sub(desc, 26);
296 end
297 end
298 local found;
299 for _, val in menu do
300 if (val.value == value) then
301 found = 1;
302 break;
303 end
304 end
305 if (not found) then
306 menu[table.getn(menu) + 1] = { text=text, value=value, desc=desc };
307 end
308 end
309  
310 function DL_Alphabetic_Insert(table, value, subindex, start)
311 local insertIndex;
312 for i,v in table do
313 if ( strlower(value[subindex])<strlower(v[subindex]) or strlower(value[subindex])==strlower(v[subindex]) ) then
314 if ((start and i >= start) or (not start)) then
315 insertIndex = i;
316 break;
317 end
318 end
319 end
320 tinsert(table, insertIndex, value);
321 end
322  
323 function DL_AttackTarget()
324 if (UnitHealth("target") and UnitHealth("target") <= 0) then return; end
325 local _, class = UnitClass("player");
326 if (class == "ROGUE" and DL_Get_ShapeshiftForm() == 1) then return; end
327 if (class == "DRUID" and DL_Get_ShapeshiftForm() == 3) then return; end
328 if (UnitCanAttack("player","target")) then
329 if (not DL_ATTACKING) then
330 AttackTarget();
331 end
332 end
333 end
334  
335 function DL_CheckBuff(unit, buff)
336 if (not DL_BUFFS[unit]) then return; end
337 for i=1,16 do
338 if (DL_BUFFS[unit][i]) then
339 if (string.find(DL_BUFFS[unit][i], buff, 1, true)) then
340 return true;
341 end
342 else
343 break;
344 end
345 end
346 end
347  
348 function DL_CheckDebuff(unit, buff)
349 if (not DL_DEBUFFS[unit]) then return; end
350 for i=1,16 do
351 if (DL_DEBUFFS[unit][i]) then
352 if (string.find(DL_DEBUFFS[unit][i], buff, 1, true)) then
353 return i;
354 end
355 else
356 break;
357 end
358 end
359 end
360  
361 function DL_CheckStatus(unit, status)
362 if (not DL_STATUS[unit]) then return 0; end
363 local count = 0;
364 for i=1,16 do
365 if (DL_STATUS[unit][i] == status) then
366 count = count + 1;
367 end
368 end
369 return count;
370 end
371  
372 function DL_CleanUp_TempOptions(menu)
373 if (menu.addedoptions) then
374 for i in menu.addedoptions do
375 getglobal(menu.table)[i] = nil;
376 end
377 end
378 end
379  
380 function DL_ColorBox_UpdateColor()
381 if (not this:GetText() or this:GetText() == "") then return; end
382 local r, g, b = ColorPickerFrame:GetColorRGB();
383 local id = this:GetID();
384 if (id == 1) then
385 r = this:GetNumber();
386 if (not r) then r = 0; end
387 elseif (id == 2) then
388 g = this:GetNumber();
389 if (not g) then g=0; end
390 else
391 b = this:GetNumber();
392 if (not b) then b=0; end
393 end
394 ColorPickerFrame:SetColorRGB(r, g, b);
395 end
396  
397 function DL_ColorBox_UpdateDisplay()
398 if (DL_COLORBOX_FOCUS) then return; end
399 local r, g, b = ColorPickerFrame:GetColorRGB();
400 DL_RedBox:SetNumber(DL_round(r, 4));
401 DL_GreenBox:SetNumber(DL_round(g, 4));
402 DL_BlueBox:SetNumber(DL_round(b, 4));
403 end
404  
405 function DL_Compare(val1, val2, method)
406 if (method == 1) then
407 if (val1 > val2) then return 1; else return; end
408 elseif (method == 2) then
409 if (val1 >= val2) then return 1; else return; end
410 elseif (method == 3) then
411 if (val1 == val2) then return 1; else return; end
412 elseif (method == 4) then
413 if (val1 <= val2) then return 1; else return; end
414 elseif (method == 5) then
415 if (val1 < val2) then return 1; else return; end
416 end
417 end
418  
419 function DL_CooldownLeft(action)
420 local start, duration, enable = GetActionCooldown(action);
421 if (start and duration and enable) then
422 local remaining = duration - (GetTime() - start);
423 if (remaining > 0) then
424 return remaining;
425 else
426 return 0;
427 end
428 else
429 return 0;
430 end
431 end
432  
433 function DL_Copy_Table(src, dest)
434 for index, value in src do
435 if (type(value) == "table") then
436 dest[index] = {};
437 DL_Copy_Table(value, dest[index]);
438 else
439 dest[index] = value;
440 end
441 end
442 end
443  
444 function DL_Debug(msg)
445 DEFAULT_CHAT_FRAME:AddMessage( msg, 1.0, 0.0, 0.0 );
446 end
447  
448 function DL_Error(msg)
449 if (not DL_ScriptErrors:IsVisible()) then
450 DL_ScriptErrors_Message:SetText(msg);
451 DL_ScriptErrors:Show();
452 else
453 DL_ERRORS_QUEUE[table.getn(DL_ERRORS_QUEUE) + 1] = msg;
454 end
455 end
456  
457 function DL_Feedback(msg)
458 DEFAULT_CHAT_FRAME:AddMessage( msg, 1.0, 1.0, 0.0 );
459 end
460  
461 function DL_Get_ActionName(id, ranktoggle)
462 if (not id) then return ""; end
463 if (not HasAction(id)) then return ""; end
464 DiscordLib_Tooltip:SetOwner(WorldFrame, "ANCHOR_NONE", 100, 100);
465 DiscordLib_Tooltip:SetAction(id);
466 local name, rank = "";
467 if (DiscordLib_TooltipTextLeft1:IsShown()) then
468 name = DiscordLib_TooltipTextLeft1:GetText();
469 end
470 if (DiscordLib_TooltipTextRight1:IsShown()) then
471 rank = DiscordLib_TooltipTextRight1:GetText();
472 end
473 if (ranktoggle) then
474 return name, rank;
475 else
476 if (not rank) then
477 return name;
478 else
479 return name.." ("..rank..")";
480 end
481 end
482 end
483  
484 function DL_Get_Backdrop(index)
485 -- returns bgtexture, bordertexture, tile, tileSize, edgeSize, left, right, top, bottom
486 if (index == 1) then
487 return "Interface\\AddOns\\DiscordLibrary\\PlainBackdrop", "Interface\\AddOns\\DiscordLibrary\\PlainBackdrop", true, 8, 1, 1, 1, 1, 1;
488 elseif (index == 2) then
489 return "Interface\\AddOns\\DiscordLibrary\\PlainBackdrop", "Interface\\Tooltips\\UI-Tooltip-Border", true, 16, 16, 5, 5, 5, 5;
490 elseif (index == 3) then
491 return "Interface\\AddOns\\DiscordLibrary\\PlainBackdrop", "Interface\\DialogFrame\\UI-DialogBox-Border", true, 32, 32, 11, 12, 12, 11;
492 elseif (index == 4) then
493 return "Interface\\AddOns\\DiscordLibrary\\PlainBackdrop", "Interface\\Buttons\\UI-SliderBar-Border", true, 8, 8, 3, 3, 6, 6;
494 elseif (index == 5) then
495 return "Interface\\AddOns\\DiscordLibrary\\PlainBackdrop", "Interface\\Glues\\Common\\Glue-Tooltip-Border", true, 16, 16, 10, 5, 4, 9;
496 end
497 end
498  
499 function DL_Get_Health(unit)
500 local health;
501 if (unit == "target" and MobHealth_GetTargetCurHP) then
502 health = MobHealth_GetTargetCurHP();
503 if ((not health) or health == 0) then health = UnitHealth(unit); end
504 elseif (string.find(unit, "target") and MobHealth_PPP) then
505 if (UnitName(unit) and UnitLevel(unit)) then
506 local mhindex = UnitName(unit)..":"..UnitLevel(unit);
507 local ppp = MobHealth_PPP(mhindex);
508 health = math.floor(UnitHealth(unit) * ppp + 0.5);
509 end
510 if (health == 0 or (not health)) then health = UnitHealth(unit); end
511 else
512 health = UnitHealth(unit);
513 end
514 return health;
515 end
516  
517 function DL_Get_HealthMax(unit)
518 local healthmax;
519 if (unit == "target" and MobHealth_GetTargetMaxHP and UnitHealth(unit) > 0) then
520 healthmax = MobHealth_GetTargetMaxHP();
521 if ((not healthmax) or healthmax == 0) then healthmax = UnitHealthMax(unit); end
522 elseif (string.find(unit, "target") and MobHealth_PPP) then
523 if (UnitName(unit) and UnitLevel(unit)) then
524 local mhindex = UnitName(unit)..":"..UnitLevel(unit);
525 local ppp = MobHealth_PPP(mhindex);
526 healthmax = math.floor(100 * ppp + 0.5);
527 end
528 if (healthmax == 0 or (not healthmax)) then healthmax = UnitHealthMax(unit); end
529 else
530 healthmax = UnitHealthMax(unit);
531 end
532 if (not healthmax) then healthmax = 0; end
533 return healthmax;
534 end
535  
536 function DL_Get_HexColor(r, g, b)
537 return "|cFF"..string.format("%02X%02X%02X", r * 255.0, g * 255.0, b * 255.0);
538 end
539  
540 function DL_Get_ItemName(bag, slot)
541 local itemname, itemlink = "";
542 if (slot) then
543 itemlink = GetContainerItemLink(bag,slot);
544 else
545 itemlink = GetInventoryItemLink("player", bag);
546 end
547 if (itemlink) then
548 itemname = string.sub(itemlink, string.find(itemlink, "[", 1, true) + 1, string.find(itemlink, "]", 1, true) - 1);
549 end
550 return itemname;
551 end
552  
553 function DL_Get_MenuText(menu, value)
554 for _, option in menu do
555 if (option.value == value) then
556 return option.text;
557 end
558 end
559 return "";
560 end
561  
562 function DL_Get_LocalKBText(name, prefix, shorten)
563 if (not prefix) then
564 prefix = "KEY_";
565 end
566 local tempName = name;
567 local i = strfind(name, "-");
568 local dashIndex = nil;
569 while ( i ) do
570 if ( not dashIndex ) then
571 dashIndex = i;
572 else
573 dashIndex = dashIndex + i;
574 end
575 tempName = strsub(tempName, i + 1);
576 i = strfind(tempName, "-");
577 end
578  
579 local modKeys = '';
580 if ( not dashIndex ) then
581 dashIndex = 0;
582 else
583 modKeys = strsub(name, 1, dashIndex);
584 end
585  
586 local variablePrefix = prefix;
587 if ( not variablePrefix ) then
588 variablePrefix = "";
589 end
590 local localizedName = nil;
591 if ( IsMacClient() ) then
592 -- see if there is a mac specific name for the key
593 localizedName = getglobal(variablePrefix..tempName.."_MAC");
594 end
595 if ( not localizedName ) then
596 localizedName = getglobal(variablePrefix..tempName);
597 end
598 if ( not localizedName ) then
599 localizedName = tempName;
600 end
601  
602 local kbtext = modKeys..localizedName;
603 if (shorten) then
604 kbtext = string.upper(kbtext);
605 kbtext = string.gsub(kbtext, "SHIFT", "S");
606 kbtext = string.gsub(kbtext, "CTRL", "C");
607 kbtext = string.gsub(kbtext, "ALT", "A");
608 kbtext = string.gsub(kbtext, "MOUSE BUTTON", "MB");
609 kbtext = string.gsub(kbtext, "BUTTON1", "MB1");
610 kbtext = string.gsub(kbtext, "BUTTON2", "MB2");
611 kbtext = string.gsub(kbtext, "BUTTON3", "MB3");
612 kbtext = string.gsub(kbtext, "BUTTON4", "MB4");
613 kbtext = string.gsub(kbtext, "BUTTON5", "MB5");
614 kbtext = string.gsub(kbtext, "MIDDLE MOUSE", "MM");
615 kbtext = string.gsub(kbtext, "NUM PAD", "NP");
616 end
617  
618 return kbtext;
619 end
620  
621 function DL_Get_KeybindingText(name, prefix, shorten)
622 local kbtext, kbtext2 = GetBindingKey(name);
623 if ( not kbtext ) then
624 kbtext = "";
625 else
626 kbtext = DL_Get_LocalKBText(kbtext, prefix, shorten);
627 end
628 if ( not kbtext2 ) then
629 kbtext2 = "";
630 else
631 kbtext2 = DL_Get_LocalKBText(kbtext2, prefix, shorten);
632 end
633 return kbtext, kbtext2;
634 end
635  
636 function DL_Get_Offsets(frame, baseframe, attachpoint, attachto)
637 local x1, y1 = DL_Get_Position(frame, attachpoint);
638 local x2, y2 = DL_Get_Position(baseframe, attachto);
639 local xoffset, yoffset;
640 if (x1 and x2 and y1 and y2) then
641 local es1, es2 = 1, 1;
642 if (baseframe.GetEffectiveScale) then
643 es1 = baseframe:GetEffectiveScale();
644 end
645 if (frame.GetEffectiveScale) then
646 es2 = frame:GetEffectiveScale();
647 end
648 xoffset = DL_round(x1 - x2 * es1 / es2, 2);
649 yoffset = DL_round(y1 - y2 * es1 / es2, 2);
650 end
651 return xoffset, yoffset;
652 end
653  
654 function DL_Get_Position(frame, attach)
655 if (frame.GetCenter and (not frame:GetCenter())) then
656 return;
657 end
658 local x, y;
659 if (attach == "TOPLEFT") then
660 x = frame:GetLeft();
661 y = frame:GetTop();
662 elseif (attach == "TOP") then
663 x = frame:GetCenter();
664 y = frame:GetTop();
665 elseif (attach == "TOPRIGHT") then
666 x = frame:GetRight();
667 y = frame:GetTop();
668 elseif (attach == "LEFT") then
669 x = frame:GetLeft();
670 _, y = frame:GetCenter();
671 elseif (attach == "CENTER") then
672 x, y = frame:GetCenter();
673 elseif (attach == "RIGHT") then
674 x = frame:GetRight();
675 _, y = frame:GetCenter();
676 elseif (attach == "BOTTOMLEFT") then
677 x = frame:GetLeft();
678 y = frame:GetBottom();
679 elseif (attach == "BOTTOM") then
680 x = frame:GetCenter();
681 y = frame:GetBottom();
682 elseif (attach == "BOTTOMRIGHT") then
683 x = frame:GetRight();
684 y = frame:GetBottom();
685 end
686 x = DL_round(x, 2);
687 y = DL_round(y, 2);
688 return x, y;
689 end
690  
691 function DL_Get_ShapeshiftForm()
692 for i=1,GetNumShapeshiftForms() do
693 local _, _, isActive = GetShapeshiftFormInfo(i);
694 if isActive == 1 then return i; end
695 end
696 return 0;
697 end
698  
699 function DL_Hook(func, prefix)
700 setglobal(prefix.."_Old_"..func, getglobal(func));
701 setglobal(func, getglobal(prefix.."_"..func));
702 end
703  
704 function DL_Init_AnchorFramesList()
705 DL_ANCHOR_FRAMES = {};
706 DL_ANCHOR_FRAMES[1] = { text = "UIParent", value="UIParent" };
707 end
708  
709 function DL_Init_CheckBox(frame, setting)
710 if (setting) then
711 frame:SetChecked(1);
712 else
713 frame:SetChecked(0);
714 end
715 end
716  
717 function DL_Init_ColorPicker(frame, color)
718 if (not color) then
719 color = {r=1, g=1, b=1};
720 end
721 frame:SetBackdropColor(color.r, color.g, color.b);
722 end
723  
724 function DL_Init_EditBox(frame, text)
725 if (not text) then
726 text = "";
727 end
728 frame.prevvalue = text;
729 frame:SetText(text);
730 end
731  
732 function DL_Init_FontsList()
733 DL_FONTS_LIST = {};
734 DL_FONTS_LIST[1] = { text="Fonts\\FRIZQT__.TTF", value="Fonts\\FRIZQT__.TTF", desc="Fonts\\FRIZQT__.TTF" };
735 DL_FONTS_LIST[2] = { text="Fonts\\ARIALN.TTF", value="Fonts\\ARIALN.TTF", desc="Fonts\\ARIALN.TTF" };
736 DL_FONTS_LIST[3] = { text="Fonts\\skurri.ttf", value="Fonts\\skurri.ttf", desc="Fonts\\skurri.ttf" };
737 DL_FONTS_LIST[4] = { text="Fonts\\MORPHEUS.ttf", value="Fonts\\MORPHEUS.ttf", desc="Fonts\\MORPHEUS.ttf" };
738 end
739  
740 function DL_Init_MenuControl(frame, setting, override)
741 local text;
742 for _, value in getglobal(frame.table) do
743 if (value.value == setting) then
744 text = value.text;
745 break;
746 end
747 end
748 if ((not text) and frame.addoptions) then
749 for _, value in frame.addoptions do
750 if (value.value == setting) then
751 text = value.text;
752 break;
753 end
754 end
755 end
756 if (not text) then
757 if (override) then
758 text = setting;
759 if (not text) then
760 text = "";
761 end
762 else
763 text = "";
764 end
765 end
766 getglobal(frame:GetName().."_Setting"):SetText(text);
767 end
768  
769 function DL_Init_Slider(frame, setting)
770 if (string.find(frame:GetName(), "DFM") and (not setting)) then
771 getglobal(frame:GetName().."_Display"):SetText("");
772 return;
773 end
774 if (frame.scale) then
775 setting = setting * frame.scale;
776 end
777 local min, max = frame:GetMinMaxValues();
778 getglobal(frame:GetName().."_Display"):SetText(setting);
779 if (setting < min or setting > max) then
780 return;
781 end
782 frame:SetValue(setting);
783 end
784  
785 function DL_Init_TabButton(text, selected, func, checked)
786 getglobal(this:GetName().."_Border"):SetVertexColor(.4, 0, 0);
787 getglobal(this:GetName().."_Text"):SetText(text);
788 this.selected = selected;
789 this.clickFunc = func;
790 if (checked) then
791 getglobal(this:GetName().."_Text"):SetTextColor(1, 0, 0);
792 getglobal(this:GetName().."_Background"):SetVertexColor(1, 1, 0);
793 if (selected) then
794 setglobal(selected, this:GetName());
795 end
796 else
797 getglobal(this:GetName().."_Background"):SetVertexColor(0, 0, 0);
798 end
799 end
800  
801 function DL_Init_UnitsList()
802 DL_UNITS_LIST = {};
803 DL_UNITS_LIST[1] = {text=""};
804 DL_UNITS_LIST[2] = {text="player (you)", value="player"};
805 DL_UNITS_LIST[3] = {text="pet", value="pet"};
806 DL_UNITS_LIST[4] = {text="target", value="target"};
807 for i=1,4 do
808 DL_UNITS_LIST[i + 4] = {text="party"..i, value="party"..i};
809 DL_UNITS_LIST[i + 8] = {text="partypet"..i, value="partypet"..i};
810 end
811 for i=1,40 do
812 DL_UNITS_LIST[i + 12] = {text="raid"..i, value="raid"..i};
813 end
814 end
815  
816 function DL_IsMouseOver(frame)
817 local lowx = frame:GetLeft();
818 local highx = frame:GetRight();
819 local lowy = frame:GetBottom();
820 local highy = frame:GetTop();
821 if (not lowx or not highx or not lowy or not highy) then return; end
822 local x, y = GetCursorPosition();
823 x = x / UIParent:GetScale();
824 y = y / UIParent:GetScale();
825 if (x < lowx or x > highx) then
826 return nil;
827 end
828 if (y < lowy or y > highy) then
829 return nil;
830 end
831 return true;
832 end
833  
834 function DL_Layout_VerticalFrames(base, num, onClick)
835 local button, prev;
836 if (onClick) then
837 getglobal(base..1):SetScript("OnClick", onClick);
838 end
839 for i=2, num do
840 button = getglobal(base..i);
841 prev = getglobal(base..(i - 1));
842 button:ClearAllPoints();
843 button:SetPoint("TOP", prev, "BOTTOM", 0, 0);
844 if (onClick) then
845 button:SetScript("OnClick", onClick);
846 end
847 end
848 end
849  
850 function DL_Layout_Menu(menu, clickFunc)
851 local button, button2;
852 if (clickFunc) then
853 getglobal(menu.."_Option1"):SetScript("OnClick", clickFunc);
854 end
855 for i=2, getglobal(menu).count do
856 button = getglobal(menu.."_Option"..i);
857 button2 = menu.."_Option"..(i - 1);
858 button:ClearAllPoints();
859 button:SetPoint("TOPLEFT", button2, "BOTTOMLEFT", 0, 0);
860 if (clickFunc) then
861 button:SetScript("OnClick", clickFunc);
862 end
863 end
864 end
865  
866 function DL_Layout_ScrollButtons(base, num, onClick)
867 local button, prev;
868 if (onClick) then
869 getglobal(base..1):SetScript("OnClick", onClick);
870 getglobal(base.."1Highlight"):SetVertexColor(1, 0, 1, 1);
871 getglobal(base.."1Checked"):SetVertexColor(.7, .7, 0, 1);
872 end
873 for i=2, num do
874 button = getglobal(base..i);
875 prev = getglobal(base..(i - 1));
876 button:ClearAllPoints();
877 button:SetPoint("TOP", prev, "BOTTOM", 0, 0);
878 if (onClick) then
879 button:SetScript("OnClick", onClick);
880 getglobal(base..i.."Highlight"):SetVertexColor(1, 0, 1, 1);
881 getglobal(base..i.."Checked"):SetVertexColor(.7, .7, 0, 1);
882 end
883 end
884 end
885  
886 function DL_Menu_Timeout(elapsed)
887 if (this.timer) then
888 this.timer = this.timer - elapsed;
889 if (this.timer < 0) then
890 this.timer = nil;
891 this:Hide();
892 end
893 end
894 end
895  
896 function DL_NudgeButton_OnLoad()
897 if (this:GetID() == 0) then
898 this:SetText(0);
899 elseif (this:GetID() == 1) then
900 this:SetText("^");
901 elseif (this:GetID() == 2) then
902 this:SetText("v");
903 elseif (this:GetID() == 3) then
904 this:SetText("<");
905 elseif (this:GetID() == 4) then
906 this:SetText(">");
907 elseif (this:GetID() == 5) then
908 this:SetText("-");
909 elseif (this:GetID() == 6) then
910 this:SetText("+");
911 elseif (this:GetID() == 7) then
912 this:SetText("R");
913 elseif (this:GetID() == 8) then
914 this:SetText("L");
915 end
916 this:RegisterForClicks("LeftButtonUp", "RightButtonUp", "MiddleButtonUp");
917 end
918  
919 function DL_PetAttack()
920 if (DL_PETATTACKING) then return; end
921 if (not UnitName("target")) then return; end
922 if (not UnitCanAttack("pet", "target")) then return; end
923 PetAttack();
924 end
925  
926 function DL_round(number, precision)
927 if (precision > 0) then
928 number = number * 10 ^ precision;
929 end
930 local remainder = number - math.floor(number);
931 if (remainder >= .5) then
932 number = math.floor(number) + 1;
933 else
934 number = math.floor(number);
935 end
936 if (precision > 0) then
937 number = number / 10 ^ precision;
938 end
939 return number;
940 end
941  
942 function DL_ScriptErrors_OK_OnClick()
943 if (DL_ERRORS_QUEUE[1]) then
944 DL_ScriptErrors_Message:SetText(DL_ERRORS_QUEUE[1]);
945 table.remove(DL_ERRORS_QUEUE, 1);
946 else
947 DL_ScriptErrors:Hide();
948 end
949 end
950  
951 function DL_Set_Anchor(subframe, xoffset, yoffset, attachpoint, attachto, center, frame)
952 if (not frame) then
953 frame = this;
954 end
955 if (not attachpoint) then
956 attachpoint = "TOPLEFT";
957 end
958 if (not attachto) then
959 attachto = "BOTTOMLEFT";
960 end
961 xoffset = getglobal(frame:GetName().."_Label"):GetWidth() + xoffset + 5;
962 if (center) then
963 xoffset = xoffset / 2;
964 end
965 frame:ClearAllPoints();
966 frame:SetPoint(attachpoint, frame:GetParent():GetName()..subframe, attachto, xoffset, yoffset);
967 end
968  
969 function DL_Set_Label(text)
970 getglobal(this:GetName().."_Label"):SetText(text);
971 end
972  
973 function DL_Set_OptionsTitle(frame, texture, version)
974 getglobal(frame.."_TitleFrame_Title"):SetTexture("Interface\\AddOns\\"..texture);
975 getglobal(frame.."_TitleFrame_Title"):SetAlpha(1);
976 getglobal(frame.."_TitleFrame_Version"):SetText("v"..version);
977 end
978  
979 function DL_Set_Timer(id, seconds)
980 if (not DL_TIMERS) then DL_TIMERS = {}; end
981 DL_TIMERS[id] = seconds;
982 end
983  
984 function DL_Show_Menu(toggle)
985 if (toggle) then
986 this = this:GetParent();
987 end
988 local menu = getglobal(this.menu);
989 if (menu:IsVisible()) then
990 menu:Hide();
991 DL_CleanUp_TempOptions(menu);
992 return;
993 end
994 if (this.addoptions) then
995 menu.addedoptions = {};
996 for i,v in this.addoptions do
997 tinsert(getglobal(this.table), v);
998 menu.addedoptions[table.getn(getglobal(this.table))] = 1;
999 end
1000 else
1001 menu.addedoptions = nil;
1002 end
1003 if (not menu.scrollMenu) then
1004 local count = 0;
1005 local widest = 0;
1006 for _, value in getglobal(this.table) do
1007 count = count + 1;
1008 getglobal(this.menu.."_Option"..count):Show();
1009 getglobal(this.menu.."_Option"..count.."_Text"):SetText(value.text);
1010 getglobal(this.menu.."_Option"..count).value = value.value;
1011 getglobal(this.menu.."_Option"..count).desc = value.desc;
1012 local width = getglobal(this.menu.."_Option"..count.."_Text"):GetWidth();
1013 if (width > widest) then
1014 widest = width;
1015 end
1016 end
1017 for i=1, menu.count do
1018 if (i <= count) then
1019 getglobal(this.menu.."_Option"..i):SetWidth(widest);
1020 else
1021 getglobal(this.menu.."_Option"..i):Hide();
1022 end
1023 end
1024 menu:SetWidth(widest + 20);
1025 menu:SetHeight(count * 15 + 20);
1026 end
1027 menu:ClearAllPoints();
1028 local frame = this:GetName();
1029 menu:SetPoint("TOPLEFT", frame, "BOTTOMLEFT", 0, 0);
1030 if (menu:GetBottom() < UIParent:GetBottom()) then
1031 local yoffset = UIParent:GetBottom() - menu:GetBottom();
1032 menu:ClearAllPoints();
1033 menu:SetPoint("TOPLEFT", this:GetName().."_Setting", "BOTTOMLEFT", 0, yoffset);
1034 end
1035 menu:Show();
1036 menu.table = this.table;
1037 menu.index = this.index;
1038 menu.subindex = this.subindex;
1039 menu.subindex2 = this.subindex2;
1040 menu.miscindex = this.miscindex;
1041 menu.initFunc = this.initFunc;
1042 menu.settingType = this.settingType;
1043 menu.controlbox = this:GetName().."_Setting";
1044 menu.cboxbase = this:GetName();
1045 if (menu.scrollMenu) then
1046 for i=1, 10 do
1047 getglobal(menu:GetName().."_Button"..i):SetChecked(0);
1048 end
1049 this = getglobal(menu:GetName().."_ScrollFrame");
1050 getglobal(menu:GetName().."_ScrollFrameScrollBar"):SetValue(0);
1051 getglobal(menu:GetName().."_ScrollFrame").offset = 0;
1052 menu.updateFunc();
1053 end
1054 end
1055  
1056 function DL_Sort(origTable)
1057 local function sortf(a, b)
1058 if ( strlower(a)<strlower(b) ) then
1059 return true;
1060 elseif ( strlower(a)==strlower(b) and a<b ) then
1061 return true;
1062 end
1063 end
1064 table.sort(origTable, sortf);
1065 end
1066  
1067 function DL_SortKeys(origTable)
1068 local a = {};
1069 for n in pairs(origTable) do
1070 table.insert(a, n);
1071 end
1072 DL_Sort(a, sortf);
1073 return a;
1074 end
1075  
1076 function DL_TabButton_OnClick()
1077 local selected = getglobal(this.selected);
1078 if (selected) then
1079 getglobal(selected):SetChecked(0);
1080 getglobal(selected.."_Background"):SetVertexColor(0, 0, 0);
1081 getglobal(selected.."_Text"):SetTextColor(1, 1, 0);
1082 end
1083 this:SetChecked(1);
1084 getglobal(this:GetName().."_Background"):SetVertexColor(1, 1, 0);
1085 getglobal(this:GetName().."_Text"):SetTextColor(1, 0, 0);
1086 if (this.selected) then
1087 setglobal(this.selected, this:GetName());
1088 end
1089 if (this.clickFunc) then
1090 this.clickFunc(this:GetID());
1091 end
1092 end
1093  
1094 function DL_Update_Auras(unit)
1095 if (DiscordLibrary_Settings and DiscordLibrary_Settings.disableBuffChecking) then
1096 return;
1097 end
1098 if (not DL_BUFFS[unit]) then
1099 DL_BUFFS[unit] = {};
1100 end
1101 if (not DL_DEBUFFS[unit]) then
1102 DL_DEBUFFS[unit] = {};
1103 end
1104 if (not DL_STATUS[unit]) then
1105 DL_STATUS[unit] = {};
1106 end
1107 if ((not UnitExists(unit)) or (not UnitName(unit))) then return; end
1108 for i=1,16 do
1109 if (UnitBuff(unit, i)) then
1110 DiscordLib_AuraTooltip:SetUnitBuff(unit, i);
1111 if (DiscordLib_AuraTooltipTextLeft1:IsShown()) then
1112 DL_BUFFS[unit][i] = DiscordLib_AuraTooltipTextLeft1:GetText();
1113 else
1114 DL_BUFFS[unit][i] = "";
1115 end
1116 else
1117 DL_BUFFS[unit][i] = "";
1118 end
1119 if (UnitDebuff(unit, i)) then
1120 DiscordLib_AuraTooltip:SetUnitDebuff(unit, i);
1121 if (DiscordLib_AuraTooltipTextLeft1:IsShown()) then
1122 DL_DEBUFFS[unit][i] = DiscordLib_AuraTooltipTextLeft1:GetText();
1123 else
1124 DL_DEBUFFS[unit][i] = "";
1125 end
1126 if (DiscordLib_AuraTooltipTextRight1:IsShown()) then
1127 DL_STATUS[unit][i] = DiscordLib_AuraTooltipTextRight1:GetText();
1128 else
1129 DL_STATUS[unit][i] = "";
1130 end
1131 else
1132 DL_DEBUFFS[unit][i] = "";
1133 DL_STATUS[unit][i] = "";
1134 end
1135 end
1136 end
1137  
1138 function DL_Update_Forms()
1139 DL_FORMS = {};
1140 local _, class = UnitClass("player");
1141 if (class ~= "WARRIOR") then
1142 DL_FORMS[0] = { text=DL_TEXT.Humanoid, value=0 };
1143 end
1144 for i=1,GetNumShapeshiftForms() do
1145 local _, name = GetShapeshiftFormInfo(i);
1146 DL_FORMS[i] = { text=name, value=i };
1147 end
1148 end
1149  
1150 function DL_Update_Timers(elapsed)
1151 if (not DL_TIMERS) then return; end
1152 for k,v in DL_TIMERS do
1153 DL_TIMERS[k] = v - elapsed;
1154 end
1155 end
1156  
1157 function UseAction(action, checkcursor, selfcast)
1158 DL_LAST_ACTION = action;
1159 DL_Old_UseAction(action, checkcursor, selfcast);
1160 end
1161  
1162 function DL_Update_ActionList()
1163 DL_ACTIONS = {};
1164 for i=1, 120 do
1165 DL_ACTIONS[i] = { text="["..i.."] "..DL_Get_ActionName(i), value=i };
1166 end
1167 end