Guest User

XPerl.lua

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