vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Colour tables now taken from WoW values (Since 1.6.4) - Well, we want to be ready when there's Paladin and Shaman in same raid
2 -- and we can leave the colour choice up to Blizzard and it'll just all work.
3  
4 -- We craeted our string based colour table from Blizzard's raid colour table in
5 local function MashXX(class)
6 local c = RAID_CLASS_COLORS[class]
7 XPerlColourTable[class] = string.format("|c00%02X%02X%02X", 255 * c.r, 255 * c.g, 255 * c.b)
8 end
9 XPerlColourTable = {}
10 MashXX("HUNTER")
11 MashXX("WARLOCK")
12 MashXX("PRIEST")
13 MashXX("PALADIN")
14 MashXX("MAGE")
15 MashXX("ROGUE")
16 MashXX("DRUID")
17 MashXX("SHAMAN")
18 MashXX("WARRIOR")
19  
20 -- XPerl_GetClassColour
21 function XPerl_GetClassColour(class)
22 if (class) then
23 local color = RAID_CLASS_COLORS[class]; -- Now using the WoW class color table
24 if (color) then
25 return color
26 end
27 end
28 return {r = 0.5, g = 0.5, b = 1}
29 end
30  
31 -- OtherClickHandlers
32 local function OtherClickHandlers(button, unitid)
33  
34 if (XPerlConfig.CastPartyRaidOnly == 0 or string.sub(unitid, 1, 4) == "raid") then
35 if (CastParty_OnClickByUnit and CastPartyConfig) then -- Cast Party
36 local function CastParty_BuildActionKey(button)
37 local action_key = ""
38 if IsAltKeyDown() then
39 action_key = action_key .. 'Alt'
40 end
41 if IsControlKeyDown() then
42 action_key = action_key .. 'Ctrl'
43 end
44 if IsShiftKeyDown() then
45 action_key = action_key .. 'Shift'
46 end
47 if action_key == "" then
48 action_key = "None"
49 end
50 return action_key
51 end
52  
53 local action_key = CastParty_BuildActionKey()
54 local action = CastPartyConfig.key_bindings[button][action_key]
55  
56 if (action ~= "CastParty_WoWDefaultClick" and action ~= "CastParty_PartyDropDown" and action ~= CASTPARTY_KEYBINDINGS_NONE) then
57 CastParty_OnClickByUnit(button, unitid)
58 return true
59 end
60  
61 elseif (Genesis_MouseHeal) then -- Genesis Clicks
62 if (Genesis_MouseHeal(unitid, button)) then
63 return true
64 end
65  
66 elseif (JC_CatchKeyBinding) then -- JustClick
67 if (JC_CatchKeyBinding(button, unit)) then
68 return true
69 end
70  
71 elseif (CH_Config and CH_Config.PCUFEnabled and CH_UnitClicked) then -- Click Heal
72 local mb = CH_BuildMouseButton(button)
73 actionType = CH_MouseSpells.Friend[mb]
74 if (actionType ~= "MENU" and actionType ~= "TARGET" and actionType ~= "TOOLTIP") then
75 CH_UnitClicked(unitid, button)
76 return true
77 end
78  
79 elseif (SmartHeal and SmartHeal.DefaultClick and SmartHeal.ClickHeal and SmartHeal.GetClickHealButton and SmartHeal.Loaded and SmartHeal.getConfig and SmartHeal:getConfig("enable") and SmartHeal:getConfig("enable", "clickmode")) then
80 local KeyDownType = SmartHeal:GetClickHealButton() -- Smart Heal
81 if(KeyDownType and KeyDownType ~= "undetermined") then
82 SmartHeal:ClickHeal(KeyDownType..button, unitid)
83 return true
84 end
85 end
86 end
87 end
88  
89 -- XPerl_Frame_FindID
90 -- Compatibility function
91 -- Same function used as Perl_Party_FindID, Perl_Party_Pet_FindID, Perl_Raid_FindID
92 function XPerl_Frame_FindID(object)
93 local _, _, num = strfind(object:GetName(), "(%d+)")
94 return tonumber(num)
95 end
96  
97 -- XPerl_OnClick_Handler
98 function XPerl_OnClick_Handler(button, unitid)
99  
100 -- 1.8.3 - Moved these tests before click handlers for consistancy
101 if (button == "LeftButton") then
102 if (SpellIsTargeting()) then
103 SpellTargetUnit(unitid)
104 return true
105 elseif (CursorHasItem()) then
106 if (UnitIsUnit("player", unitid)) then
107 AutoEquipCursorItem()
108 else
109 DropItemOnUnit(unitid)
110 end
111 return true
112 end
113 elseif (button == "RightButton") then
114 if (SpellIsTargeting()) then
115 SpellStopTargeting()
116 return true
117 end
118 end
119  
120 if (type(Perl_Custom_ClickFunction) == "function") then
121 if (Perl_Custom_ClickFunction(button, unitid)) then
122 -- Perl_Custom_ClickFunction should return true if handled, then we do nothing more.
123 -- no return and we'll continue with default X-Perl behaviour
124 return true
125 end
126 end
127  
128 if (XPerlConfig.CastParty == 1) then
129 local frame = getglobal(this:GetName().."_NameFrame")
130 if (not frame or not MouseIsOver(frame)) then
131 -- Name frame gives default behaviour
132  
133 if (OtherClickHandlers(button, unitid)) then
134 return true
135 end
136 end
137 end
138  
139 if (button == "LeftButton") then
140 TargetUnit(unitid)
141 return true
142 end
143 end
144  
145 ---------------------------------
146 --Loading Function --
147 ---------------------------------
148  
149 -- XPerl_DisallowClear
150 --function XPerl_DisallowClear()
151 -- return AceLibrary and AceLibrary:HasInstance("Jostle-2.0")
152 --end
153  
154 -- XPerl_BlizzFramesDisable
155 function XPerl_BlizzFramesDisable()
156 local XPerl_DummyFrame
157 local XPerl_DummyFunc
158  
159 --if (XPerl_DisallowClear()) then
160 -- XPerlConfig.ClearBlizzardFrames = 0
161 --end
162  
163 if (XPerlConfig.ClearBlizzardFrames == 1) then
164 XPerl_DummyFrame = CreateFrame("Frame")
165 XPerl_DummyFunc = function() end
166 end
167  
168 if (XPerl_Player) then
169 -- Blizz Player Frame Events
170 PlayerFrame:UnregisterAllEvents()
171 PlayerFrameHealthBar:UnregisterAllEvents()
172 PlayerFrameManaBar:UnregisterAllEvents()
173 PlayerFrame:Hide()
174 -- Make it so it won't be visible, even if shown by another mod
175 PlayerFrame:ClearAllPoints()
176 PlayerFrame:SetPoint("BOTTOMLEFT", UIParent, "TOPLEFT", 0, 50)
177  
178 if (XPerlConfig.ClearBlizzardFrames == 1) then
179 PlayerFrame = XPerl_DummyFrame
180  
181 PlayerFrame_OnLoad = nil
182 PlayerFrame_Update = nil
183 PlayerFrame_UpdatePartyLeader = nil
184 PlayerFrame_UpdatePvPStatus = nil
185 PlayerFrame_OnEvent = nil
186 PlayerFrame_OnUpdate = nil
187 PlayerFrame_OnClick = nil
188 PlayerFrame_OnReceiveDrag = nil
189 PlayerFrame_UpdateStatus = nil
190 PlayerFrame_UpdateGroupIndicator = nil
191 PlayerFrameDropDown_OnLoad = nil
192 PlayerFrame_UpdatePlaytime = nil
193 end
194 end
195  
196 if (XPerl_Player_Pet) then
197 -- Blizz Pet Frame Events
198 PetFrame:UnregisterAllEvents()
199 PetFrame:Hide()
200 PetFrame:ClearAllPoints()
201 PetFrame:SetPoint("BOTTOMLEFT", UIParent, "TOPLEFT", 0, 50)
202  
203 if (XPerlConfig.ClearBlizzardFrames == 1) then
204 PetFrame = XPerl_DummyFrame
205  
206 PetFrame_OnLoad = nil
207 PetFrame_Update = nil
208 PetFrame_OnEvent = nil
209 PetFrame_OnUpdate = nil
210 PetFrame_OnClick = nil
211 PetFrame_SetHappiness = nil
212 PetFrameDropDown_OnLoad = nil
213 end
214 end
215  
216 if (XPerl_Target) then
217 -- Blizz Target Frame Events
218 TargetFrame:UnregisterAllEvents()
219 TargetFrameHealthBar:UnregisterAllEvents()
220 TargetFrameManaBar:UnregisterAllEvents()
221 TargetFrame:Hide()
222 TargetofTargetFrame:UnregisterAllEvents()
223 TargetofTargetFrame:Hide()
224 TargetFrame:ClearAllPoints()
225 TargetFrame:SetPoint("BOTTOMLEFT", UIParent, "TOPLEFT", 0, 50)
226 TargetofTargetFrame:ClearAllPoints()
227 TargetofTargetFrame:SetPoint("BOTTOMLEFT", UIParent, "TOPLEFT", 0, 50)
228  
229 if (XPerlConfig.ClearBlizzardFrames == 1) then
230 TargetFrame = XPerl_DummyFrame
231 TargetofTargetFrame = XPerl_DummyFrame
232  
233 TargetFrame_OnLoad = nil
234 TargetFrame_Update = nil
235 TargetFrame_OnEvent = nil
236 TargetFrame_OnShow = nil
237 TargetFrame_OnHide = nil
238 TargetFrame_CheckLevel = nil
239 TargetFrame_CheckFaction = nil
240 TargetFrame_CheckClassification = nil
241 TargetFrame_CheckDead = nil
242 TargetFrame_CheckDishonorableKill = nil
243 TargetFrame_OnClick = nil
244 TargetFrame_OnUpdate = nil
245 TargetDebuffButton_Update = nil
246 TargetFrame_HealthUpdate = nil
247 TargetHealthCheck = nil
248 TargetFrameDropDown_OnLoad = nil
249 TargetFrame_UpdateRaidTargetIcon = nil
250  
251 TargetofTarget_OnUpdate = nil
252 TargetofTarget_Update = nil
253 TargetofTarget_OnClick = nil
254 TargetofTarget_CheckDead = nil
255 TargetofTargetHealthCheck = nil
256 end
257 end
258  
259 if (XPerl_party1) then
260 -- Blizz Party Events
261 ShowPartyFrame = function() end
262 HidePartyFrame = ShowPartyFrame
263 for num = 1, 4 do
264 local f = getglobal("PartyMemberFrame"..num)
265 f:Hide()
266 f:UnregisterAllEvents()
267 getglobal("PartyMemberFrame"..num.."HealthBar"):UnregisterAllEvents()
268 getglobal("PartyMemberFrame"..num.."ManaBar"):UnregisterAllEvents()
269  
270 f:ClearAllPoints()
271 f:SetPoint("BOTTOMLEFT", UIParent, "TOPLEFT", 0, 50)
272 end
273  
274 if (XPerlConfig.ClearBlizzardFrames == 1) then
275 for num = 1, 4 do
276 setglobal("PartyMemberFrame"..num, XPerl_DummyFrame)
277 end
278 PartyMemberFrame_OnLoad = nil
279 PartyMemberFrame_UpdateMember = nil
280 PartyMemberFrame_UpdatePet = XPerl_DummyFunc -- Called when you press OK on interface options
281 PartyMemberFrame_UpdateMemberHealth = nil
282 PartyMemberFrame_UpdateLeader = nil
283 PartyMemberFrame_UpdatePvPStatus = nil
284 PartyMemberFrame_OnEvent = nil
285 PartyMemberFrame_OnUpdate = nil
286 PartyMemberFrame_OnClick = nil
287 PartyMemberPetFrame_OnClick = nil
288 PartyMemberFrame_RefreshPetBuffs = nil
289 PartyMemberBuffTooltip_Update = nil
290 PartyMemberHealthCheck = nil
291 PartyFrameDropDown_OnLoad = nil
292 UpdatePartyMemberBackground = nil
293 PartyMemberBackground_ToggleOpacity = nil
294 PartyMemberBackground_SetOpacity = nil
295 PartyMemberBackground_SaveOpacity = nil
296 end
297 end
298 XPerl_BlizzFramesDisable = nil
299 end
300  
301 ---------------------------------
302 --Smooth Health Bar Color --
303 ---------------------------------
304 function XPerl_SetSmoothBarColor (bar, percentage)
305 if (bar) then
306 --local barmin, barmax = bar:GetMinMaxValues()
307 --if (barmin == barmax) then
308 -- return false
309 --end
310 --local percentage = bar:GetValue()/(barmax-barmin)
311  
312 local r, g, b
313 if (XPerlConfig.ClassicHealthBar == 1) then
314 if (percentage < 0.5) then
315 r = 1
316 g = 2*percentage
317 b = 0
318 else
319 g = 1
320 r = 2*(1 - percentage)
321 b = 0
322 end
323 else
324 r = XPerlConfig.ColourHealthEmpty.r + ((XPerlConfig.ColourHealthFull.r - XPerlConfig.ColourHealthEmpty.r) * percentage)
325 g = XPerlConfig.ColourHealthEmpty.g + ((XPerlConfig.ColourHealthFull.g - XPerlConfig.ColourHealthEmpty.g) * percentage)
326 b = XPerlConfig.ColourHealthEmpty.b + ((XPerlConfig.ColourHealthFull.b - XPerlConfig.ColourHealthEmpty.b) * percentage)
327 end
328  
329 if (r >= 0 and g >= 0 and b >= 0 and r <= 1 and g <= 1 and b <= 1) then
330 bar:SetStatusBarColor(r, g, b)
331  
332 local backBar = getglobal(bar:GetName().."BG")
333 if (backBar) then
334 backBar:SetVertexColor(r, g, b, 0.25)
335 end
336 end
337 end
338 end
339  
340 -- XPerl_SetHealthBar
341 function XPerl_SetHealthBar(bar, hp, max)
342 bar:SetMinMaxValues(0, max)
343 if (XPerlConfig.InverseBars == 1) then
344 bar:SetValue(max - hp)
345 else
346 bar:SetValue(hp)
347 end
348  
349 local percent = hp / max
350 local healthPct = string.format("%3.0f", percent * 100)
351  
352 XPerl_SetSmoothBarColor(bar, percent)
353  
354 local barPct = getglobal(bar:GetName().."Percent")
355 if (barPct) then
356 barPct:SetText(healthPct.."%")
357 end
358  
359 local barText = getglobal(bar:GetName().."Text")
360 if (barText) then
361 if (XPerlConfig.HealerMode == 1) then
362 if (XPerlConfig.HealerModeType == 1) then
363 barText:SetText(string.format("%d/%d", hp - max, max))
364 else
365 barText:SetText(hp - max)
366 end
367 else
368 barText:SetText(hp.."/"..max)
369 end
370 end
371 end
372  
373 ---------------------------------
374 --Class Icon Location Functions--
375 ---------------------------------
376 function XPerl_ClassPos (class)
377 if(class=="WARRIOR") then return 0, 0.25, 0, 0.25; end
378 if(class=="MAGE") then return 0.25, 0.5, 0, 0.25; end
379 if(class=="ROGUE") then return 0.5, 0.75, 0, 0.25; end
380 if(class=="DRUID") then return 0.75, 1, 0, 0.25; end
381 if(class=="HUNTER") then return 0, 0.25, 0.25, 0.5; end
382 if(class=="SHAMAN") then return 0.25, 0.5, 0.25, 0.5; end
383 if(class=="PRIEST") then return 0.5, 0.75, 0.25, 0.5; end
384 if(class=="WARLOCK") then return 0.75, 1, 0.25, 0.5; end
385 if(class=="PALADIN") then return 0, 0.25, 0.5, 0.75; end
386 return 0.25, 0.5, 0.5, 0.75 -- Returns empty next one, so blank
387 end
388  
389 -- XPerl_Toggle
390 function XPerl_Toggle()
391 if (XPerlLocked == 1) then
392 XPerl_UnlockFrames()
393 else
394 XPerl_LockFrames()
395 end
396 end
397  
398 -- XPerl_UnlockFrames
399 function XPerl_UnlockFrames()
400 EnableAddOn("XPerl_Options")
401 if (not IsAddOnLoaded("XPerl_Options")) then
402 UIParentLoadAddOn("XPerl_Options")
403 end
404  
405 XPerlLocked = 0
406 if (XPerl_RaidShowAllTitles) then
407 XPerl_RaidShowAllTitles()
408 end
409  
410 if (XPerl_Options) then
411 XPerl_Options:Show()
412 XPerl_Options:SetAlpha(0)
413 XPerl_Options.Fading = "in"
414 end
415 end
416  
417 -- XPerl_LockFrames
418 function XPerl_LockFrames()
419 XPerlLocked = 1
420 if (XPerl_Options) then
421 XPerl_Options.Fading = "out"
422 end
423  
424 if (XPerl_RaidTitles) then
425 XPerl_RaidTitles()
426 end
427 end
428  
429 -- Minimap Icon
430 function XPerl_MinimapButton_OnClick()
431 XPerl_Toggle()
432 end
433  
434 -- XPerl_MinimapButton_Init
435 function XPerl_MinimapButton_Init()
436 if(XPerlConfig.MinimapButtonShown == 1) then
437 XPerl_MinimapButton_Frame:Show()
438 else
439 XPerl_MinimapButton_Frame:Hide()
440 end
441 end
442  
443 -- XPerl_MinimapButton_UpdatePosition
444 function XPerl_MinimapButton_UpdatePosition()
445 XPerl_MinimapButton_Frame:SetPoint(
446 "TOPLEFT",
447 "Minimap",
448 "TOPLEFT",
449 54 - (78 * cos(XPerlConfig.MinimapButtonPosition)),
450 (78 * sin(XPerlConfig.MinimapButtonPosition)) - 55
451 )
452 XPerl_MinimapButton_Init()
453 end
454  
455 -- XPerl_MinimapButton_Dragging
456 function XPerl_MinimapButton_Dragging()
457 local xpos,ypos = GetCursorPosition()
458 local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()
459  
460 xpos = xmin-xpos/UIParent:GetScale()+70
461 ypos = ypos/UIParent:GetScale()-ymin-70
462  
463 XPerl_MinimapButton_SetPosition(math.deg(math.atan2(ypos,xpos)))
464 end
465  
466 -- XPerl_MinimapButton_SetPosition
467 function XPerl_MinimapButton_SetPosition(v)
468 if (v < 0) then
469 v = v + 360
470 end
471  
472 XPerlConfig.MinimapButtonPosition = v
473 XPerl_MinimapButton_UpdatePosition()
474 end
475  
476 -- XPerl_MinimapButton_OnEnter
477 function XPerl_MinimapButton_OnEnter()
478 GameTooltip:SetOwner(this, "ANCHOR_LEFT")
479 GameTooltip:SetText(XPerl_Version, 1, 1, 1)
480 GameTooltip:AddLine(XPERL_MINIMAP_HELP1)
481 GameTooltip:AddLine(XPERL_MINIMAP_HELP2)
482 GameTooltip:Show()
483 end
484  
485 -- XPerl_SetManaBarType
486 local ManaColours = {"ColourMana", "ColourRage", "ColourFocus", "ColourEnergy"}
487 function XPerl_SetManaBarType(argUnit, argFrame, argFrameBG)
488 local power = UnitPowerType(argUnit)
489 if (power) then
490 local colour = XPerlConfig[ManaColours[power + 1]]
491  
492 argFrame:SetStatusBarColor(colour.r, colour.g, colour.b, 1)
493 argFrameBG:SetVertexColor(colour.r, colour.g, colour.b, 0.25)
494 end
495 end
496  
497 -- XPerl_PlayerTip
498 function XPerl_PlayerTip(unitid)
499  
500 if (SpellIsTargeting()) then
501 if (SpellCanTargetUnit(unitid)) then
502 SetCursor("CAST_CURSOR")
503 else
504 SetCursor("CAST_ERROR_CURSOR")
505 end
506 end
507  
508 GameTooltip_SetDefaultAnchor(GameTooltip, this)
509 GameTooltip:SetUnit(unitid)
510  
511 if (XPerl_RaidTipExtra) then
512 XPerl_RaidTipExtra(unitid)
513 end
514  
515 if (XPerlConfig.XPerlTooltipInfo == 1 and XPerl_GetUsage) then
516 local xpUsage = XPerl_GetUsage(UnitName(unitid))
517 if (xpUsage) then
518 local xp, any = "|cFFD00000X-Perl|r "
519 if (xpUsage.version) then
520 xp = xp..xpUsage.version
521 any = true
522 end
523 if (xpUsage.mods and IsShiftKeyDown()) then
524 local modList = XPerl_DecodeModuleList(xpUsage.mods)
525 if (modList) then
526 xp = xp.." : |c00909090"..modList
527 end
528 end
529 if (any) then
530 GameTooltip:AddLine(xp, 1, 1, 1, 1)
531 GameTooltip:Show()
532 end
533 end
534 end
535 end
536  
537 -- XPerl_PlayerTipHide
538 function XPerl_PlayerTipHide()
539 if (XPerlConfig.FadingTooltip == 1) then
540 GameTooltip:FadeOut()
541 else
542 GameTooltip:Hide()
543 end
544 end
545  
546 -- XPerl_ToolTip_AddBuffDuration
547 function XPerl_ToolTip_AddBuffDuration(partyid, x)
548 if (XPerl_Raid_AddBuffDuration) then
549 XPerl_Raid_AddBuffDuration(partyid, x)
550 end
551 end
552  
553 -- XPerl_ColourFriendlyUnit
554 function XPerl_ColourFriendlyUnit(frame, partyid)
555 local color
556 if (UnitCanAttack("player", partyid) and UnitIsEnemy("player", partyid)) then -- For dueling
557 color = XPerlConfig.ColourReactionEnemy
558 else
559 if (XPerlConfig.ClassColouredNames == 1) then
560 local _, engClass = UnitClass(partyid)
561 color = XPerl_GetClassColour(engClass)
562 else
563 if (UnitIsPVP(partyid)) then
564 color = XPerlConfig.ColourReactionFriend
565 else
566 color = XPerlConfig.ColourReactionNone
567 end
568 end
569 end
570  
571 frame:SetTextColor(color.r, color.g, color.b)
572 end
573  
574 -- XPerl_ReactionColour
575 function XPerl_ReactionColour(argUnit)
576  
577 if (UnitPlayerControlled(argUnit) or not UnitIsVisible(argUnit)) then
578 if (UnitFactionGroup("player") == UnitFactionGroup(argUnit)) then
579 if (UnitIsEnemy("player", argUnit)) then
580 -- Dueling
581 return XPerlConfig.ColourReactionEnemy
582  
583 elseif (UnitIsPVP(argUnit)) then
584 return XPerlConfig.ColourReactionFriend
585 end
586 else
587 if (UnitIsPVP(argUnit)) then
588 if (UnitIsPVP("player")) then
589 return XPerlConfig.ColourReactionEnemy
590 else
591 return XPerlConfig.ColourReactionNeutral
592 end
593 end
594 end
595 else
596 if (UnitIsTapped(argUnit) and not UnitIsTappedByPlayer(argUnit)) then
597 color = XPerlConfig.ColourTapped
598 else
599 local reaction = UnitReaction(argUnit, "player")
600 if (reaction) then
601 if (reaction >= 5) then
602 return XPerlConfig.ColourReactionFriend
603 elseif (reaction <= 2) then
604 return XPerlConfig.ColourReactionEnemy
605 elseif (reaction == 3) then
606 return XPerlConfig.ColourReactionUnfriendly
607 else
608 return XPerlConfig.ColourReactionNeutral
609 end
610 else
611 if (UnitFactionGroup("player") == UnitFactionGroup(argUnit)) then
612 return XPerlConfig.ColourReactionFriend
613 elseif (UnitIsEnemy("player", argUnit)) then
614 return XPerlConfig.ColourReactionEnemy
615 else
616 return XPerlConfig.ColourReactionNeutral
617 end
618 end
619 end
620 end
621  
622 return XPerlConfig.ColourReactionNone
623 end
624  
625 -- XPerl_SetUnitNameColor
626 function XPerl_SetUnitNameColor(argUnit,argFrame)
627  
628 if (UnitPlayerControlled(argUnit) or not UnitIsVisible(argUnit)) then
629 -- 1.8.3 - Changed to override pvp name colours
630 if (XPerlConfig.ClassColouredNames == 1) then
631 local _, class = UnitClass(argUnit)
632 color = XPerl_GetClassColour(class)
633 else
634 color = XPerl_ReactionColour(argUnit)
635 end
636 else
637 if (UnitIsTapped(argUnit) and not UnitIsTappedByPlayer(argUnit)) then
638 color = XPerlConfig.ColourTapped
639 else
640 color = XPerl_ReactionColour(argUnit)
641 end
642 end
643  
644 argFrame:SetTextColor(color.r, color.g, color.b, XPerlConfig.TextTransparency)
645 end
646  
647 local BasicEvents = {"UNIT_RAGE", "UNIT_MAXRAGE", "UNIT_ENERGY", "UNIT_MAXENERGY",
648 "UNIT_MANA", "UNIT_MAXMANA", "UNIT_HEALTH", "UNIT_MAXHEALTH",
649 "UNIT_LEVEL", "UNIT_COMBAT", "UNIT_DISPLAYPOWER", "UNIT_NAME_UPDATE"}
650  
651 -- XPerl_RegisterBasics
652 function XPerl_RegisterBasics(argFrame)
653 if (argFrame == nil) then
654 argFrame = this
655 end
656 for i,event in pairs(BasicEvents) do
657 argFrame:RegisterEvent(event)
658 end
659 end
660  
661 -- XPerl_UnregisterBasics
662 function XPerl_UnregisterBasics(argFrame)
663 if (argFrame == nil) then
664 argFrame = this
665 end
666 for i,event in pairs(BasicEvents) do
667 argFrame:UnregisterEvent(event)
668 end
669 end
670  
671 -- PerlSetPortrait3D
672 function XPerlSetPortrait3D(argFrame, argUnit)
673 --[[ if (argUnit == "player") then
674 -- If it's ourself, we can check if we're going to 'look' different, and update anyway
675 -- Many updates requests are false though, and no real change is made
676  
677 local head, shoulders, chest
678 head = GetInventoryItemTexture("player", 1)
679 shoulders = GetInventoryItemTexture("player", 3)
680 chest = GetInventoryItemTexture("player", 5)
681  
682 if (argFrame.lastHead ~= head or argFrame.lastShoulders ~= shoulders or argFrame.lastChest ~= chest) then
683 argFrame.last3DTime = nil
684 end
685  
686 argFrame.lastHead = head
687 argFrame.lastShoulders = shoulders
688 argFrame.lastChest = chest
689 else
690 -- If someone else, check their name and update if changed
691 local name = UnitName(argUnit)
692 if (argFrame.lastName ~= name) then
693 argFrame.last3DTime = nil
694 end
695 argFrame.lastName = name
696 end
697  
698 if (argFrame.last3DTime) then
699 -- 1.8.5 change
700 -- Don't update the portrait so often, at least 15 seconds must pass before each update now
701 if (argFrame.last3DTime < GetTime() + 15) then
702 argFrame:SetCamera(0)
703 return
704 end
705 end
706 ]]
707 argFrame:ClearModel()
708 argFrame:SetUnit(argUnit)
709 argFrame:SetCamera(0)
710  
711 -- argFrame.last3DTime = GetTime()
712 end
713  
714 -- XPerl_CombatFlashSet
715 function XPerl_CombatFlashSet (elapsed, argFrame, argNew, argGreen)
716 if (XPerlConfig.PerlCombatFlash == 0) then
717 argFrame.PlayerFlash = nil
718 return false
719 end
720  
721 if (argFrame) then
722 if (argNew) then
723 argFrame.PlayerFlash = 1
724 argFrame.PlayerFlashGreen = argGreen
725 else
726 if (argFrame.PlayerFlash and elapsed) then
727 argFrame.PlayerFlash = argFrame.PlayerFlash - elapsed
728  
729 if (argFrame.PlayerFlash <= 0) then
730 argFrame.PlayerFlash = 0
731 argFrame.PlayerFlashTime = nil
732 argFrame.PlayerFlashGreen = nil
733 end
734 else
735 return false
736 end
737 end
738  
739 return true
740 end
741 end
742  
743 -- XPerl_CombatFlashSetFrames
744 function XPerl_CombatFlashSetFrames(argFrame)
745 if (argFrame.PlayerFlash) then
746 local baseColour
747 if (argFrame.forcedColour) then
748 baseColour = argFrame.forcedColour
749 else
750 baseColour = XPerlConfig.BorderColour
751 end
752  
753 local r, g, b, a
754 if (argFrame.PlayerFlash > 0) then
755 local flashOffsetColour = argFrame.PlayerFlash / 2
756 if (argFrame.PlayerFlashGreen) then
757 r = baseColour.r - flashOffsetColour
758 g = baseColour.g + flashOffsetColour
759 b = baseColour.b - flashOffsetColour
760 else
761 r = baseColour.r + flashOffsetColour
762 g = baseColour.g - flashOffsetColour
763 b = baseColour.b - flashOffsetColour
764 end
765  
766 if (r < 0) then r = 0; elseif (r > 1) then r = 1; end
767 if (g < 0) then g = 0; elseif (g > 1) then g = 1; end
768 if (b < 0) then b = 0; elseif (b > 1) then b = 1; end
769 else
770 r, g, b = baseColour.r, baseColour.g, baseColour.b
771 end
772  
773 a = XPerlConfig.BorderColour.a
774 for i, frame in pairs(argFrame.FlashFrames) do
775 frame:SetBackdropBorderColor(r, g, b, a)
776 end
777  
778 if (argFrame.PlayerFlash == 0) then
779 argFrame.PlayerFlash = nil
780 end
781 end
782 end
783  
784 local bgDef = {bgFile = "Interface\\Addons\\XPerl\\Images\\XPerl_FrameBack",
785 edgeFile = "",
786 tile = true, tileSize = 32, edgeSize = 16,
787 insets = { left = 5, right = 5, top = 5, bottom = 5 }
788 }
789  
790 -- XPerl_CheckDebuffs
791 function XPerl_CheckDebuffs(unit, frames)
792  
793 if (XPerlConfig.HighlightDebuffs == 0) then
794 return
795 end
796  
797 local show
798 local Curses = {}
799 local debuffCount = 0
800  
801 for i = 1, MAX_TARGET_DEBUFFS do
802 local debuff, debuffStack, debuffType = UnitDebuff(unit, i)
803  
804 if (not debuff) then
805 break
806 end
807  
808 if (debuffType) then
809 Curses[debuffType] = 1
810 else
811 Curses["none"] = 1
812 end
813 debuffCount = debuffCount + 1
814 end
815  
816 if (debuffCount > 0) then
817 if (Curses.Magic) then
818 show = "Magic"
819 elseif (Curses.Curse) then
820 show = "Curse"
821 elseif (Curses.Disease) then
822 show = "Disease"
823 elseif (Curses.Poison) then
824 show = "Poison"
825 end
826  
827 -- We also re-set the colours here so that we highlight best colour per class
828 local _, class = UnitClass("player")
829 if (class == "MAGE") then
830 if (Curses["Curse"]) then
831 show = "Curse"
832 end
833  
834 elseif (class == "DRUID") then
835 if (Curses["Curse"]) then
836 show = "Curse"
837 elseif (Curses["Poison"]) then
838 show = "Poison"
839 end
840  
841 elseif (class == "PRIEST" or class == "WARLOCK") then
842 if (Curses["Magic"]) then
843 show = "Magic"
844 end
845  
846 elseif (class == "PALADIN") then
847 if (Curses["Magic"]) then
848 show = "Magic"
849 elseif (Curses["Poison"]) then
850 show = "Poison"
851 elseif (Curses["Disease"]) then
852 show = "Disease"
853 end
854  
855 elseif (class == "SHAMAN") then
856 if (Curses["Poison"]) then
857 show = "Poison"
858 elseif (Curses["Disease"]) then
859 show = "Disease"
860 end
861 end
862 end
863  
864 if (frames) then
865 local colour, borderColour
866 if (show) then
867 colour = DebuffTypeColor[show]
868 colour.a = 1
869  
870 if (XPerlConfig.HighlightDebuffsBorder == 1) then
871 borderColour = colour
872 else
873 borderColour = XPerlConfig.BorderColour
874 end
875 else
876 colour = XPerlConfig.BackColour
877 borderColour = XPerlConfig.BorderColour
878 end
879  
880 for i, f in frames do
881 if (f:IsShown()) then
882 if (show and XPerlConfig.HighlightDebuffsBorder == 1) then
883 f:GetParent().forcedColour = borderColour
884 bgDef.edgeFile = "Interface\\Addons\\XPerl\\Images\\XPerl_Curse"
885 f:SetBackdrop(bgDef)
886 else
887 f:GetParent().forcedColour = nil
888 bgDef.edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border"
889 f:SetBackdrop(bgDef)
890 end
891  
892 f:SetBackdropColor(colour.r, colour.g, colour.b, colour.a)
893 f:SetBackdropBorderColor(borderColour.r, borderColour.g, borderColour.b, borderColour.a)
894 end
895 end
896 end
897 end
898  
899 -- XPerl_SavePosition(frame)
900 function XPerl_SavePosition(frame)
901 if (not XPerlConfig.SavedPositions) then
902 XPerlConfig.SavedPositions = {}
903 end
904 XPerlConfig.SavedPositions[frame:GetName()] = {top = frame:GetTop(), left = frame:GetLeft()}
905 end
906  
907 -- XPerl_RestorePosition(frame)
908 function XPerl_RestorePosition(frame)
909 if (XPerlConfig.SavedPositions) then
910 local pos = XPerlConfig.SavedPositions[frame:GetName()]
911 if (pos) then
912 if (pos.left or pos.right) then
913 frame:ClearAllPoints()
914 frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", pos.left, pos.top)
915 end
916 end
917 end
918 end
919  
920 -- XPerl_GetRaidPosition
921 function XPerl_GetRaidPosition(findName)
922 for i = 1,GetNumRaidMembers() do
923 if (UnitName("raid"..i) == findName) then
924 return i
925 end
926 end
927 end
928  
929 -- XPerl_SetBuffSize
930 function XPerl_SetBuffSize(prefix, sizeBuff, sizeDebuff)
931 for i = 1,20 do
932 local buff = getglobal(prefix.."BuffFrame_Buff"..i)
933 if (buff) then
934 buff:SetHeight(sizeBuff)
935 buff:SetWidth(sizeBuff)
936 end
937  
938 local buff = getglobal(prefix.."BuffFrame_DeBuff"..i)
939 if (buff) then
940 buff:SetHeight(sizeDebuff)
941 buff:SetWidth(sizeDebuff)
942 end
943 end
944 end
945  
946 -- true indicates the buff is valid on anyone, otherwise a class string dictates we only count it if the player with the buff matches
947 local BuffExceptions = {
948 --ALL = {Spell_Misc_Food = true}, -- Enable this for food
949 PRIEST = {Spell_Nature_ResistNature = true, Spell_Nature_Rejuvenation = true}, -- Druid regens
950 DRUID = {Spell_Holy_Renew = true}, -- Priest regens
951 WARLOCK = {Spell_Shadow_SoulGem = true}, -- Soulstone Resurrection
952 HUNTER = {Spell_Nature_RavenForm = "HUNTER", Ability_Mount_JungleTiger = "HUNTER", Ability_Mount_WhiteTiger = true, Ability_Mount_PinkTiger = "HUNTER", Ability_Hunter_AspectOfTheMonkey = "HUNTER", Spell_Nature_ProtectionformNature = true, Ability_Rogue_FeignDeath = "HUNTER", Ability_Hunter_RunningShot = "HUNTER", Ability_TrueShot = true, Ability_Hunter_BeastTraining = "WARRIOR"},
953 ROGUE = {Ability_Stealth = "ROGUE", Spell_Shadow_ShadowWard = "ROGUE", Ability_Vanish = "ROGUE", Ability_Rogue_Sprint = "ROGUE"}
954 }
955  
956 local DebuffExceptions = {
957 ALL = {INV_Misc_Bandage_08 = true}, -- Recently Bandaged
958 PRIEST = {Spell_Holy_AshesToAshes = true} -- Weakened Soul
959 }
960  
961 -- BuffException
962 --local showInfo
963 local function BuffException(unit, index, flag, func, exceptions)
964  
965 local buff, count, debuffType
966 if (not flag or flag == 0 or flag == "0") then
967 -- Not filtered, just return it
968 buff, count, debuffType = func(unit, index)
969 return buff, count, debuffType, index
970 end
971  
972 buff, count, debuffType = func(unit, index, 1)
973 if (buff) then
974 -- We need the index of the buff unfiltered later for tooltips
975 for i = 1,20 do
976 local buff1, count1, debuffType1 = func(unit, index)
977 if (buff == buff1 and count == count1) then
978 index = i
979 break
980 end
981 end
982  
983 return buff, count, debuffType, index
984 end
985  
986 -- See how many filtered buffs WoW has returned by default
987 local normalBuffFilterCount = 0
988 for i = 1,20 do
989 buff, count, debuffType = func(unit, i, 1)
990 if (not buff) then
991 normalBuffFilterCount = i - 1
992 break
993 end
994 end
995  
996 -- Nothing found by default, so look for exceptions
997 local _, class = UnitClass("player")
998 local _, unitClass = UnitClass(unit)
999 local foundValid = 0
1000 for i = 1,20 do
1001 buff, count, debuffType = func(unit, i)
1002  
1003 if (not buff) then
1004 break
1005 end
1006  
1007 if (strsub(buff, 1, 16) == "Interface\\Icons\\") then
1008 local test = strsub(buff, 17)
1009 local good
1010  
1011 if (exceptions[class]) then
1012 good = exceptions[class][test]
1013 elseif (exceptions.ALL) then
1014 good = exceptions.ALL[test]
1015 end
1016  
1017 -- Enable this for potions
1018 --if (not good) then
1019 -- if (exceptions == BuffExceptions and strsub(test, 1, 11) == "INV_Potion_") then
1020 -- good = true
1021 -- end
1022 --end
1023  
1024 if (good and type(good) == "string" and good ~= unitClass) then
1025 good = nil
1026 end
1027  
1028 if (good) then
1029 foundValid = foundValid + 1
1030 if (foundValid + normalBuffFilterCount == index) then
1031 --if (showInfo) then
1032 -- ChatFrame7:AddMessage("Found extra: "..buff..", requested index == "..index..", actual buff index == "..i)
1033 --end
1034 return buff, count, debuffType, i
1035 end
1036 end
1037 end
1038 end
1039 end
1040  
1041 -- XPerl_UnitBuff
1042 function XPerl_UnitBuff(unit, index, flag)
1043 return BuffException(unit, index, flag, UnitBuff, BuffExceptions)
1044 end
1045  
1046 -- XPerl_UnitBuff
1047 function XPerl_UnitDebuff(unit, index, flag)
1048 return BuffException(unit, index, flag, UnitDebuff, DebuffExceptions)
1049 end
1050  
1051 -- XPerl_TooltipSetUnitBuff
1052 -- Retreives the index of the actual unfiltered buff, and uses this on unfiltered tooltip call
1053 function XPerl_TooltipSetUnitBuff(tooltip, unit, ind, flag)
1054 --showInfo = true
1055 local buff, count, _, index = BuffException(unit, ind, flag, UnitBuff, BuffExceptions)
1056 --showInfo = nil
1057 tooltip:SetUnitBuff(unit, index)
1058 end
1059  
1060 -- XPerl_TooltipSetUnitDebuff
1061 -- Retreives the index of the actual unfiltered debuff, and uses this on unfiltered tooltip call
1062 function XPerl_TooltipSetUnitDebuff(tooltip, unit, ind, flag)
1063 local buff, count, debuffType, index = BuffException(unit, ind, flag, UnitDebuff, DebuffExceptions)
1064 tooltip:SetUnitDebuff(unit, index)
1065 end