Guest User

Datapanel.lua

a guest
Apr 27th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 99.42 KB | None | 0 0
  1. local MODULE_NAME = "Datapanel"
  2. local ADDON_NAME = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
  3. local MODULE = ADDON_NAME:NewModule(MODULE_NAME, "AceEvent-3.0")
  4. local L = setmetatable({}, { __index = function(t,k)
  5. local v = tostring(k)
  6. rawset(t, k, v)
  7. return v
  8. end })
  9.  
  10. ------------------------------------------------------------------------
  11. -- Module Database
  12. ------------------------------------------------------------------------
  13.  
  14. local BASIC_BACKGROUND = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]]
  15. local BASIC_BORDERPANEL = [[Interface\AddOns\BasicUI\Media\UI-DialogBox-Border.blp]]
  16.  
  17. local db
  18. local defaults = {
  19. profile = {
  20. enable = true,
  21. battleground = true, -- enable 3 stats in battleground only that replace stat1,stat2,stat3.
  22. bag = false, -- True = Open Backpack; False = Open All bags
  23.  
  24. -- nData Media
  25. border = BASIC_BORDERPANEL, -- Border for Datapanel ( Choose either Datapanel or Neav for border choice)
  26. background = BASIC_BACKGROUND, -- Background for Datapanel
  27.  
  28. -- Color Datatext
  29. customcolor = { r = 1, g = 1, b = 1}, -- Color of Text for Datapanel
  30.  
  31. location = "bottom", -- 3 Choices for panel placement = "top", "bottom", or "shortbar". Shortbar is to match nMainbar shortbar.
  32. armor = "P0", -- show your armor value against the level mob you are currently targeting.
  33. avd = "P0", -- show your current avoidance against the level of the mob your targeting
  34. bags = "P9", -- show space used in bags on panel.
  35. haste = "P0", -- show your haste rating on panels.
  36. system = "P0", -- show total memory and others systems info (FPS/MS) on panel.
  37. guild = "P4", -- show number on guildmate connected on panel.
  38. dur = "P8", -- show your equipment durability on panel.
  39. friends = "P6", -- show number of friends connected.
  40. dps_text = "P0", -- show a dps meter on panel.
  41. hps_text = "P0", -- show a heal meter on panel.
  42. spec = "P5", -- show your current spec on panel.
  43. coords = "P0", -- show your current coords on panel.
  44. pro = "P7", -- shows your professions and tradeskills
  45. stat1 = "P1", -- Stat Based on your Role (Avoidance-Tank, AP-Melee, SP/HP-Caster)
  46. stat2 = "P3", -- Stat Based on your Role (Armor-Tank, Crit-Melee, Crit-Caster)
  47. recount = "P2", -- Stat Based on Recount"s DPS
  48. recountraiddps = false, -- Enables tracking or Recounts Raid DPS
  49. calltoarms = "P0", -- Show Current Call to Arms.
  50. }
  51. }
  52.  
  53. ------------------------------------------------------------------------
  54. -- Local Module Functions
  55. ------------------------------------------------------------------------
  56. -- Variables that point to frames or other objects:
  57. local MainPanel, LeftPanel, CenterPanel, RightPanel, BGPanel
  58. local currentFightDPS
  59. local PLAYER_CLASS = UnitClass("player")
  60. local PLAYER_NAME = UnitName("player")
  61. local PLAYER_REALM = GetRealmName()
  62. local SCREEN_WIDTH = tonumber(string.match(({GetScreenResolutions()})[GetCurrentResolution()], "(%d+)x+%d"))
  63. local TOC_VERSION = select(4, GetBuildInfo())
  64. local GAME_LOCALE = GetLocale()
  65. local classColor
  66.  
  67. local function RGBToHex(r, g, b)
  68. if r > 1 then r = 1 elseif r < 0 then r = 0 end
  69. if g > 1 then g = 1 elseif g < 0 then g = 0 end
  70. if b > 1 then b = 1 elseif b < 0 then b = 0 end
  71. return format("|cff%02x%02x%02x", r*255, g*255, b*255)
  72. end
  73.  
  74. local function HexToRGB(hex)
  75. local rhex, ghex, bhex = strsub(hex, 1, 2), strsub(hex, 3, 4), strsub(hex, 5, 6)
  76. return tonumber(rhex, 16), tonumber(ghex, 16), tonumber(bhex, 16)
  77. end
  78.  
  79. local function ShortValue(v)
  80. if v >= 1e6 then
  81. return format("%.1fm", v / 1e6):gsub("%.?0+([km])$", "%1")
  82. elseif v >= 1e3 or v <= -1e3 then
  83. return format("%.1fk", v / 1e3):gsub("%.?0+([km])$", "%1")
  84. else
  85. return v
  86. end
  87. end
  88.  
  89. --Check Player's Role
  90.  
  91. local classRoles = {
  92. PALADIN = {
  93. [1] = "Caster",
  94. [2] = "Tank",
  95. [3] = "Melee",
  96. },
  97. PRIEST = "Caster",
  98. WARLOCK = "Caster",
  99. WARRIOR = {
  100. [1] = "Melee",
  101. [2] = "Melee",
  102. [3] = "Tank",
  103. },
  104. HUNTER = "Melee",
  105. SHAMAN = {
  106. [1] = "Caster",
  107. [2] = "Melee",
  108. [3] = "Caster",
  109. },
  110. ROGUE = "Melee",
  111. MAGE = "Caster",
  112. DEATHKNIGHT = {
  113. [1] = "Tank",
  114. [2] = "Melee",
  115. [3] = "Melee",
  116. },
  117. DRUID = {
  118. [1] = "Caster",
  119. [2] = "Melee",
  120. [3] = "Tank",
  121. [4] = "Caster"
  122. },
  123. MONK = {
  124. [1] = "Tank",
  125. [2] = "Caster",
  126. [3] = "Melee",
  127. },
  128. }
  129.  
  130. local _, playerClass = UnitClass("player")
  131. local Role
  132. local function CheckRole()
  133. local talentTree = GetSpecialization()
  134.  
  135. if(type(classRoles[playerClass]) == "string") then
  136. Role = classRoles[playerClass]
  137. elseif(talentTree) then
  138. Role = classRoles[playerClass][talentTree]
  139. end
  140. end
  141.  
  142. local eventHandler = CreateFrame("Frame")
  143. eventHandler:RegisterEvent("PLAYER_ENTERING_WORLD")
  144. eventHandler:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
  145. eventHandler:RegisterEvent("PLAYER_TALENT_UPDATE")
  146. eventHandler:RegisterEvent("CHARACTER_POINTS_CHANGED")
  147. eventHandler:SetScript("OnEvent", CheckRole)
  148.  
  149.  
  150. ------------------------------------------------------------------------
  151. -- Module Functions
  152. ------------------------------------------------------------------------
  153.  
  154. function MODULE:SetMainPanel()
  155.  
  156. if db.location ~= "top" then
  157. MainPanel:SetPoint("BOTTOM", UIParent, 0, 0)
  158. MainPanel:SetWidth(1200)
  159. MainPanel:SetFrameLevel(1)
  160. MainMenuBar:ClearAllPoints()
  161. MainMenuBar:SetPoint("BOTTOM", MainPanel, "TOP", 0, -3)
  162.  
  163.  
  164. -- Hide Panels When in a Vehicle or Pet Battle
  165. MainPanel:RegisterUnitEvent("UNIT_ENTERING_VEHICLE", "player")
  166. MainPanel:RegisterUnitEvent("UNIT_EXITED_VEHICLE", "player")
  167. MainPanel:RegisterUnitEvent("PET_BATTLE_OPENING_START")
  168. MainPanel:RegisterUnitEvent("PET_BATTLE_CLOSE")
  169. MainPanel:RegisterUnitEvent("PLAYER_ENTERING_WORLD")
  170.  
  171. MainPanel:SetScript("OnEvent", function(self, event, ...)
  172. if event == "UNIT_ENTERING_VEHICLE" or event == "PET_BATTLE_OPENING_START" then
  173. self:Hide()
  174. elseif event == "UNIT_EXITED_VEHICLE" or event == "PET_BATTLE_CLOSE" or event == "PLAYER_ENTERING_WORLD" then
  175. self:Show()
  176. end
  177. end)
  178. else
  179. MainPanel:SetPoint("TOP", UIParent, 0, 0)
  180. MainPanel:SetWidth(SCREEN_WIDTH)
  181. end
  182. end
  183.  
  184. function MODULE:SetPanelLeft()
  185.  
  186. if db.location ~= "top" then
  187. PanelLeft:SetPoint("LEFT", MainPanel, 5, 0)
  188. PanelLeft:SetHeight(35)
  189. PanelLeft:SetWidth(1200 / 3)
  190. PanelLeft:SetFrameStrata("MEDIUM")
  191. PanelLeft:SetFrameLevel(2)
  192. else
  193. PanelLeft:SetPoint("LEFT", MainPanel, 5, 0)
  194. PanelLeft:SetHeight(35)
  195. PanelLeft:SetWidth(SCREEN_WIDTH / 3)
  196. PanelLeft:SetFrameStrata("LOW")
  197. PanelLeft:SetFrameLevel(1)
  198. end
  199. end
  200.  
  201. function MODULE:SetPanelCenter()
  202.  
  203. if db.location ~= "top" then
  204. PanelCenter:SetPoint("CENTER", MainPanel, 0, 0)
  205. PanelCenter:SetHeight(35)
  206. PanelCenter:SetWidth(1200 / 3)
  207. PanelCenter:SetFrameStrata("MEDIUM")
  208. PanelCenter:SetFrameLevel(1)
  209. else
  210. PanelCenter:SetPoint("CENTER", MainPanel, 0, 0)
  211. PanelCenter:SetHeight(35)
  212. PanelCenter:SetWidth(SCREEN_WIDTH / 3)
  213. PanelCenter:SetFrameStrata("LOW")
  214. PanelCenter:SetFrameLevel(1)
  215. end
  216. end
  217.  
  218. function MODULE:SetPanelRight()
  219.  
  220. if db.location ~= "top" then
  221. PanelRight:SetPoint("RIGHT", MainPanel, -5, 0)
  222. PanelRight:SetHeight(35)
  223. PanelRight:SetWidth(1200 / 3)
  224. PanelRight:SetFrameStrata("MEDIUM")
  225. PanelRight:SetFrameLevel(1)
  226. else
  227. PanelRight:SetPoint("RIGHT", MainPanel, -5, 0)
  228. PanelRight:SetHeight(35)
  229. PanelRight:SetWidth(SCREEN_WIDTH / 3)
  230. PanelRight:SetFrameStrata("LOW")
  231. PanelRight:SetFrameLevel(1)
  232. end
  233. end
  234.  
  235. function MODULE:MoveObjects()
  236.  
  237. if db.location ~= "top" then
  238. -- World Status
  239. WorldStateAlwaysUpFrame:ClearAllPoints()
  240. WorldStateAlwaysUpFrame:SetPoint('TOP', -20, -40)
  241.  
  242. -- Move the tooltip above the Actionbar
  243. hooksecurefunc('GameTooltip_SetDefaultAnchor', function(self)
  244. self:SetPoint('BOTTOMRIGHT', UIParent, -95, 135)
  245. end)
  246.  
  247. -- Move the Bags above the Actionbar
  248. CONTAINER_WIDTH = 192;
  249. CONTAINER_SPACING = 5;
  250. VISIBLE_CONTAINER_SPACING = 3;
  251. CONTAINER_OFFSET_Y = 70;
  252. CONTAINER_OFFSET_X = 0;
  253.  
  254.  
  255. function UpdateContainerFrameAnchors()
  256. local _, xOffset, yOffset, _, _, _, _;
  257. local containerScale = 1;
  258. screenHeight = GetScreenHeight() / containerScale;
  259. -- Adjust the start anchor for bags depending on the multibars
  260. xOffset = CONTAINER_OFFSET_X / containerScale;
  261. yOffset = CONTAINER_OFFSET_Y / containerScale + 25;
  262. -- freeScreenHeight determines when to start a new column of bags
  263. freeScreenHeight = screenHeight - yOffset;
  264. column = 0;
  265. for index, frameName in ipairs(ContainerFrame1.bags) do
  266. frame = _G[frameName];
  267. frame:SetScale(containerScale);
  268. if ( index == 1 ) then
  269. -- First bag
  270. frame:SetPoint('BOTTOMRIGHT', frame:GetParent(), 'BOTTOMRIGHT', -xOffset, yOffset );
  271. elseif ( freeScreenHeight < frame:GetHeight() ) then
  272. -- Start a new column
  273. column = column + 1;
  274. freeScreenHeight = screenHeight - yOffset;
  275. frame:SetPoint('BOTTOMRIGHT', frame:GetParent(), 'BOTTOMRIGHT', -(column * CONTAINER_WIDTH) - xOffset, yOffset );
  276. else
  277. -- Anchor to the previous bag
  278. frame:SetPoint('BOTTOMRIGHT', ContainerFrame1.bags[index - 1], 'TOPRIGHT', 0, CONTAINER_SPACING);
  279. end
  280. freeScreenHeight = freeScreenHeight - frame:GetHeight() - VISIBLE_CONTAINER_SPACING;
  281. end
  282. end
  283. else
  284. -- Player Frame
  285. PlayerFrame:ClearAllPoints()
  286. PlayerFrame:SetPoint("TOPLEFT", -19, -20)
  287.  
  288. -- Target Frame
  289. TargetFrame:ClearAllPoints()
  290. TargetFrame:SetPoint("TOPLEFT", 250, -20)
  291.  
  292. -- Minimap Frame
  293. MinimapCluster:ClearAllPoints()
  294. MinimapCluster:SetPoint('TOPRIGHT', 0, -32)
  295.  
  296. -- Buff Frame
  297. BuffFrame:ClearAllPoints()
  298. BuffFrame:SetPoint('TOP', MinimapCluster, -110, -2)
  299.  
  300. -- PvP Frame
  301. WorldStateAlwaysUpFrame:ClearAllPoints()
  302. WorldStateAlwaysUpFrame:SetPoint('TOP', 0, -32)
  303. end
  304. end
  305.  
  306. function MODULE:PlacePlugin(position, plugin)
  307. local left = PanelLeft
  308. local center = PanelCenter
  309. local right = PanelRight
  310.  
  311. -- Left Panel Data
  312. if position == "P1" then
  313. plugin:SetParent(left)
  314. plugin:SetHeight(left:GetHeight())
  315. plugin:SetPoint('LEFT', left, 30, 0)
  316. plugin:SetPoint('TOP', left)
  317. plugin:SetPoint('BOTTOM', left)
  318. elseif position == "P2" then
  319. plugin:SetParent(left)
  320. plugin:SetHeight(left:GetHeight())
  321. plugin:SetPoint('TOP', left)
  322. plugin:SetPoint('BOTTOM', left)
  323. elseif position == "P3" then
  324. plugin:SetParent(left)
  325. plugin:SetHeight(left:GetHeight())
  326. plugin:SetPoint('RIGHT', left, -30, 0)
  327. plugin:SetPoint('TOP', left)
  328. plugin:SetPoint('BOTTOM', left)
  329.  
  330. -- Center Panel Data
  331. elseif position == "P4" then
  332. plugin:SetParent(center)
  333. plugin:SetHeight(center:GetHeight())
  334. plugin:SetPoint('LEFT', center, 30, 0)
  335. plugin:SetPoint('TOP', center)
  336. plugin:SetPoint('BOTTOM', center)
  337. elseif position == "P5" then
  338. plugin:SetParent(center)
  339. plugin:SetHeight(center:GetHeight())
  340. plugin:SetPoint('TOP', center)
  341. plugin:SetPoint('BOTTOM', center)
  342. elseif position == "P6" then
  343. plugin:SetParent(center)
  344. plugin:SetHeight(center:GetHeight())
  345. plugin:SetPoint('RIGHT', center, -30, 0)
  346. plugin:SetPoint('TOP', center)
  347. plugin:SetPoint('BOTTOM', center)
  348.  
  349. -- Right Panel Data
  350. elseif position == "P7" then
  351. plugin:SetParent(right)
  352. plugin:SetHeight(right:GetHeight())
  353. plugin:SetPoint('LEFT', right, 30, 0)
  354. plugin:SetPoint('TOP', right)
  355. plugin:SetPoint('BOTTOM', right)
  356. elseif position == "P8" then
  357. plugin:SetParent(right)
  358. plugin:SetHeight(right:GetHeight())
  359. plugin:SetPoint('TOP', right)
  360. plugin:SetPoint('BOTTOM', right)
  361. elseif position == "P9" then
  362. plugin:SetParent(right)
  363. plugin:SetHeight(right:GetHeight())
  364. plugin:SetPoint('RIGHT', right, -30, 0)
  365. plugin:SetPoint('TOP', right)
  366. plugin:SetPoint('BOTTOM', right)
  367. elseif position == "P0" then
  368. return
  369. end
  370. end
  371.  
  372. function MODULE:CreateStats()
  373.  
  374. local function DataTextTooltipAnchor(self)
  375. local panel = self:GetParent()
  376. local anchor = 'GameTooltip'
  377. local xoff = 1
  378. local yoff = 3
  379.  
  380.  
  381. for _, panel in pairs ({
  382. PanelLeft,
  383. PanelCenter,
  384. PanelRight,
  385. }) do
  386. if db.top == true then
  387. anchor = 'ANCHOR_BOTTOM'
  388. else
  389. anchor = 'ANCHOR_TOP'
  390. end
  391. end
  392. return anchor, panel, xoff, yoff
  393. end
  394.  
  395. if ADDON_NAME.db.profile.media.classcolor ~= true then
  396. local r, g, b = db.customcolor.r, db.customcolor.g, db.customcolor.b
  397. hexa = ("|cff%.2x%.2x%.2x"):format(r * 255, g * 255, b * 255)
  398. hexb = "|r"
  399. else
  400. hexa = ("|cff%.2x%.2x%.2x"):format(classColor.r * 255, classColor.g * 255, classColor.b * 255)
  401. hexb = "|r"
  402. end
  403.  
  404. ----------------
  405. -- Player Armor
  406. ----------------
  407. if db.armor then
  408. local effectiveArmor
  409.  
  410. local Stat = CreateFrame('Frame', nil, MainPanel)
  411. Stat:EnableMouse(true)
  412. Stat:SetFrameStrata('BACKGROUND')
  413. Stat:SetFrameLevel(3)
  414.  
  415. local Text = Stat:CreateFontString(nil, 'OVERLAY')
  416. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  417. self:PlacePlugin(db.armor, Text)
  418.  
  419. local function Update(self)
  420. effectiveArmor = select(2, UnitArmor("player"))
  421. Text:SetText(hexa.."Armor: "..hexb..(effectiveArmor))
  422. --Setup Armor Tooltip
  423. self:SetAllPoints(Text)
  424. end
  425.  
  426. Stat:RegisterEvent("UNIT_INVENTORY_CHANGED")
  427. Stat:RegisterEvent("UNIT_AURA")
  428. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  429. Stat:SetScript("OnMouseDown", function() ToggleCharacter("PaperDollFrame") end)
  430. Stat:SetScript("OnEvent", Update)
  431. Stat:SetScript("OnEnter", function(self)
  432. if not InCombatLockdown() then
  433. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  434. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  435. GameTooltip:ClearLines()
  436. GameTooltip:AddLine("Mitigation By Level: ")
  437. local lv = 83
  438. local mitigation = (effectiveArmor/(effectiveArmor+(467.5*lv-22167.5)))
  439. for i = 1, 4 do
  440. local format = string.format
  441. if mitigation > .75 then
  442. mitigation = .75
  443. end
  444. GameTooltip:AddDoubleLine(lv,format("%.2f", mitigation*100) .. "%",1,1,1)
  445. lv = lv - 1
  446. end
  447. if UnitLevel("target") > 0 and UnitLevel("target") < UnitLevel("player") then
  448. if mitigation > .75 then
  449. mitigation = .75
  450. end
  451. GameTooltip:AddDoubleLine(UnitLevel("target"),format("%.2f", mitigation*100) .. "%",1,1,1)
  452. end
  453. GameTooltip:Show()
  454. end
  455. end)
  456. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  457. end
  458.  
  459. --------------------
  460. -- Player Avoidance
  461. --------------------
  462. if db.avd then
  463. local dodge, parry, block, avoidance, targetlv, playerlv, basemisschance, leveldifference
  464. local Stat = CreateFrame('Frame', nil, MainPanel)
  465. Stat:EnableMouse(true)
  466. Stat:SetFrameStrata('BACKGROUND')
  467. Stat:SetFrameLevel(3)
  468.  
  469. local Text = Stat:CreateFontString(nil, 'OVERLAY')
  470. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  471. self:PlacePlugin(db.avd, Text)
  472.  
  473. local targetlv, playerlv
  474.  
  475. local function Update(self)
  476. local format = string.format
  477. targetlv, playerlv = UnitLevel("target"), UnitLevel("player")
  478. local basemisschance, leveldifference, avoidance
  479.  
  480. if targetlv == -1 then
  481. basemisschance = (5 - (3*.2)) --Boss Value
  482. leveldifference = 3
  483. elseif targetlv > playerlv then
  484. basemisschance = (5 - ((targetlv - playerlv)*.2)) --Mobs above player level
  485. leveldifference = (targetlv - playerlv)
  486. elseif targetlv < playerlv and targetlv > 0 then
  487. basemisschance = (5 + ((playerlv - targetlv)*.2)) --Mobs below player level
  488. leveldifference = (targetlv - playerlv)
  489. else
  490. basemisschance = 5 --Sets miss chance of attacker level if no target exists, lv80=5, 81=4.2, 82=3.4, 83=2.6
  491. leveldifference = 0
  492. end
  493.  
  494. if myrace == "NightElf" then
  495. basemisschance = basemisschance + 2
  496. end
  497.  
  498. if leveldifference >= 0 then
  499. dodge = (GetDodgeChance()-leveldifference*.2)
  500. parry = (GetParryChance()-leveldifference*.2)
  501. block = (GetBlockChance()-leveldifference*.2)
  502. avoidance = (dodge+parry+block)
  503. Text:SetText(hexa.."Avd: "..hexb..format("%.2f", avoidance).."|r")
  504. else
  505. dodge = (GetDodgeChance()+abs(leveldifference*.2))
  506. parry = (GetParryChance()+abs(leveldifference*.2))
  507. block = (GetBlockChance()+abs(leveldifference*.2))
  508. avoidance = (dodge+parry+block)
  509. Text:SetText(hexa.."Avd: "..hexb..format("%.2f", avoidance).."|r")
  510. end
  511.  
  512. --Setup Avoidance Tooltip
  513. self:SetAllPoints(Text)
  514. end
  515.  
  516.  
  517. Stat:RegisterEvent("UNIT_AURA")
  518. Stat:RegisterEvent("UNIT_INVENTORY_CHANGED")
  519. Stat:RegisterEvent("PLAYER_TARGET_CHANGED")
  520. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  521. Stat:SetScript("OnEvent", Update)
  522. Stat:SetScript("OnEnter", function(self)
  523. if not InCombatLockdown() then
  524. local anchor, yoff = DataTextTooltipAnchor(Text)
  525. GameTooltip:SetOwner(self, anchor, 0, yoff)
  526. GameTooltip:ClearAllPoints()
  527. GameTooltip:ClearLines()
  528. if targetlv > 1 then
  529. GameTooltip:AddDoubleLine("Avoidance Breakdown".." (".."lvl".." "..targetlv..")")
  530. elseif targetlv == -1 then
  531. GameTooltip:AddDoubleLine("Avoidance Breakdown".." (".."Boss"..")")
  532. else
  533. GameTooltip:AddDoubleLine("Avoidance Breakdown".." (".."lvl".." "..targetlv..")")
  534. end
  535. GameTooltip:AddDoubleLine("Dodge",format("%.2f",dodge) .. "%",1,1,1, 1,1,1)
  536. GameTooltip:AddDoubleLine("Parry",format("%.2f",parry) .. "%",1,1,1, 1,1,1)
  537. GameTooltip:AddDoubleLine("Block",format("%.2f",block) .. "%",1,1,1, 1,1,1)
  538. GameTooltip:Show()
  539. end
  540. end)
  541. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  542. end
  543.  
  544. --------
  545. -- Bags
  546. --------
  547.  
  548. if db.bags then
  549. local Stat = CreateFrame('Frame', nil, MainPanel)
  550. Stat:EnableMouse(true)
  551. Stat:SetFrameStrata('BACKGROUND')
  552. Stat:SetFrameLevel(3)
  553.  
  554. local Text = Stat:CreateFontString(nil, 'OVERLAY')
  555. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  556. self:PlacePlugin(db.bags, Text)
  557.  
  558. local Profit = 0
  559. local Spent = 0
  560. local OldMoney = 0
  561. local myPlayerRealm = GetRealmName();
  562.  
  563.  
  564. local function formatMoney(c)
  565. local str = ""
  566. if not c or c < 0 then
  567. return str
  568. end
  569.  
  570. if c >= 10000 then
  571. local g = math.floor(c/10000)
  572. c = c - g*10000
  573. str = str..BreakUpLargeNumbers(g).."|cFFFFD800g|r "
  574. end
  575. if c >= 100 then
  576. local s = math.floor(c/100)
  577. c = c - s*100
  578. str = str..s.."|cFFC7C7C7s|r "
  579. end
  580. if c >= 0 then
  581. str = str..c.."|cFFEEA55Fc|r"
  582. end
  583.  
  584. return str
  585. end
  586.  
  587. local function OnEvent(self, event)
  588. local totalSlots, freeSlots = 0, 0
  589. local itemLink, subtype, isBag
  590. for i = 0,NUM_BAG_SLOTS do
  591. isBag = true
  592. if i > 0 then
  593. itemLink = GetInventoryItemLink('player', ContainerIDToInventoryID(i))
  594. if itemLink then
  595. subtype = select(7, GetItemInfo(itemLink))
  596. if (subtype == 'Mining Bag') or (subtype == 'Gem Bag') or (subtype == 'Engineering Bag') or (subtype == 'Enchanting Bag') or (subtype == 'Herb Bag') or (subtype == 'Inscription Bag') or (subtype == 'Leatherworking Bag') or (subtype == 'Fishing Bag')then
  597. isBag = false
  598. end
  599. end
  600. end
  601. if isBag then
  602. totalSlots = totalSlots + GetContainerNumSlots(i)
  603. freeSlots = freeSlots + GetContainerNumFreeSlots(i)
  604. end
  605. Text:SetText(hexa.."Bags: "..hexb.. freeSlots.. '/' ..totalSlots)
  606. if freeSlots < 6 then
  607. Text:SetTextColor(1,0,0)
  608. elseif freeSlots < 10 then
  609. Text:SetTextColor(1,0,0)
  610. elseif freeSlots > 10 then
  611. Text:SetTextColor(1,1,1)
  612. end
  613. self:SetAllPoints(Text)
  614.  
  615. end
  616. if event == "PLAYER_ENTERING_WORLD" then
  617. OldMoney = GetMoney()
  618. end
  619.  
  620. local NewMoney = GetMoney()
  621. local Change = NewMoney-OldMoney -- Positive if we gain money
  622.  
  623. if OldMoney>NewMoney then -- Lost Money
  624. Spent = Spent - Change
  625. else -- Gained Money
  626. Profit = Profit + Change
  627. end
  628.  
  629. self:SetAllPoints(Text)
  630.  
  631. local myPlayerName = UnitName("player")
  632. if not BasicDB then BasicDB = {} end
  633. if not BasicDB.gold then BasicDB.gold = {} end
  634. if not BasicDB.gold[myPlayerRealm] then BasicDB.gold[myPlayerRealm]={} end
  635. BasicDB.gold[myPlayerRealm][myPlayerName] = GetMoney()
  636.  
  637. OldMoney = NewMoney
  638.  
  639. end
  640.  
  641. Stat:RegisterEvent("PLAYER_MONEY")
  642. Stat:RegisterEvent("SEND_MAIL_MONEY_CHANGED")
  643. Stat:RegisterEvent("SEND_MAIL_COD_CHANGED")
  644. Stat:RegisterEvent("PLAYER_TRADE_MONEY")
  645. Stat:RegisterEvent("TRADE_MONEY_CHANGED")
  646. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  647. Stat:RegisterEvent("BAG_UPDATE")
  648.  
  649. Stat:SetScript('OnMouseDown',
  650. function()
  651. if db.bag ~= true then
  652. ToggleAllBags()
  653. else
  654. ToggleBag(0)
  655. end
  656. end
  657. )
  658. Stat:SetScript('OnEvent', OnEvent)
  659. Stat:SetScript("OnEnter", function(self)
  660. if not InCombatLockdown() then
  661. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  662. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  663. GameTooltip:ClearLines()
  664. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Gold")
  665. GameTooltip:AddLine' '
  666. GameTooltip:AddLine("This Session: ")
  667. GameTooltip:AddDoubleLine("Earned:", formatMoney(Profit), 1, 1, 1, 1, 1, 1)
  668. GameTooltip:AddDoubleLine("Spent:", formatMoney(Spent), 1, 1, 1, 1, 1, 1)
  669. if Profit < Spent then
  670. GameTooltip:AddDoubleLine("Deficit:", formatMoney(Profit-Spent), 1, 0, 0, 1, 1, 1)
  671. elseif (Profit-Spent)>0 then
  672. GameTooltip:AddDoubleLine("Profit:", formatMoney(Profit-Spent), 0, 1, 0, 1, 1, 1)
  673. end
  674. GameTooltip:AddDoubleLine("Total:", formatMoney(OldMoney), 1, 1, 1, 1, 1, 1)
  675. GameTooltip:AddLine' '
  676.  
  677. local totalGold = 0
  678. GameTooltip:AddLine("Character's: ")
  679. local thisRealmList = BasicDB.gold[myPlayerRealm];
  680. for k,v in pairs(thisRealmList) do
  681. GameTooltip:AddDoubleLine(k, formatMoney(v), 1, 1, 1, 1, 1, 1)
  682. totalGold=totalGold+v;
  683. end
  684. GameTooltip:AddLine' '
  685. GameTooltip:AddLine("Server:")
  686. GameTooltip:AddDoubleLine("Total: ", formatMoney(totalGold), 1, 1, 1, 1, 1, 1)
  687.  
  688. for i = 1, GetNumWatchedTokens() do
  689. local name, count, extraCurrencyType, icon, itemID = GetBackpackCurrencyInfo(i)
  690. if name and i == 1 then
  691. GameTooltip:AddLine(" ")
  692. GameTooltip:AddLine(CURRENCY..":")
  693. end
  694. local r, g, b = 1,1,1
  695. if itemID then r, g, b = GetItemQualityColor(select(3, GetItemInfo(itemID))) end
  696. if name and count then GameTooltip:AddDoubleLine(name, count, r, g, b, 1, 1, 1) end
  697. end
  698. GameTooltip:AddLine' '
  699. GameTooltip:AddLine("|cffeda55fClick|r to Open Bags")
  700. GameTooltip:Show()
  701. end
  702. end)
  703.  
  704. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  705. -- reset gold data
  706. local function RESETGOLD()
  707. local myPlayerRealm = GetRealmName();
  708. local myPlayerName = UnitName("player");
  709.  
  710. BasicDB.gold = {}
  711. BasicDB.gold[myPlayerRealm]={}
  712. BasicDB.gold[myPlayerRealm][myPlayerName] = GetMoney();
  713. end
  714. SLASH_RESETGOLD1 = "/resetgold"
  715. SlashCmdList["RESETGOLD"] = RESETGOLD
  716.  
  717. end
  718.  
  719. ----------------
  720. -- Battleground
  721. ----------------
  722. if db.battleground == true then
  723.  
  724. --Map IDs
  725. local WSG = 443
  726. local TP = 626
  727. local AV = 401
  728. local SOTA = 512
  729. local IOC = 540
  730. local EOTS = 482
  731. local TBFG = 736
  732. local AB = 461
  733.  
  734. local bgframe = BGPanel
  735. bgframe:SetScript('OnEnter', function(self)
  736. local numScores = GetNumBattlefieldScores()
  737. for i=1, numScores do
  738. local name, killingBlows, honorableKills, deaths, honorGained, faction, race, class, classToken, damageDone, healingDone, bgRating, ratingChange = GetBattlefieldScore(i)
  739. if ( name ) then
  740. if ( name == UnitName('player') ) then
  741. GameTooltip:SetOwner(self, 'ANCHOR_TOPLEFT', 0, 4)
  742. GameTooltip:ClearLines()
  743. GameTooltip:SetPoint('BOTTOM', self, 'TOP', 0, 1)
  744. GameTooltip:ClearLines()
  745. GameTooltip:AddLine("Stats for : "..hexa..name..hexb)
  746. GameTooltip:AddLine' '
  747. GameTooltip:AddDoubleLine("Killing Blows:", killingBlows,1,1,1)
  748. GameTooltip:AddDoubleLine("Honorable Kills:", honorableKills,1,1,1)
  749. GameTooltip:AddDoubleLine("Deaths:", deaths,1,1,1)
  750. GameTooltip:AddDoubleLine("Honor Gained:", format('%d', honorGained),1,1,1)
  751. GameTooltip:AddDoubleLine("Damage Done:", damageDone,1,1,1)
  752. GameTooltip:AddDoubleLine("Healing Done:", healingDone,1,1,1)
  753. --Add extra statistics to watch based on what BG you are in.
  754. if curmapid == WSG or curmapid == TP then
  755. GameTooltip:AddDoubleLine("Flags Captured:",GetBattlefieldStatData(i, 1),1,1,1)
  756. GameTooltip:AddDoubleLine("Flags Returned:",GetBattlefieldStatData(i, 2),1,1,1)
  757. elseif curmapid == EOTS then
  758. GameTooltip:AddDoubleLine("Flags Captured:",GetBattlefieldStatData(i, 1),1,1,1)
  759. elseif curmapid == AV then
  760. GameTooltip:AddDoubleLine("Graveyards Assaulted:",GetBattlefieldStatData(i, 1),1,1,1)
  761. GameTooltip:AddDoubleLine("Graveyards Defended:",GetBattlefieldStatData(i, 2),1,1,1)
  762. GameTooltip:AddDoubleLine("Towers Assaulted:",GetBattlefieldStatData(i, 3),1,1,1)
  763. GameTooltip:AddDoubleLine("Towers Defended:",GetBattlefieldStatData(i, 4),1,1,1)
  764. elseif curmapid == SOTA then
  765. GameTooltip:AddDoubleLine("Demolishers Destroyed:",GetBattlefieldStatData(i, 1),1,1,1)
  766. GameTooltip:AddDoubleLine("Gates Destroyed:",GetBattlefieldStatData(i, 2),1,1,1)
  767. elseif curmapid == IOC or curmapid == TBFG or curmapid == AB then
  768. GameTooltip:AddDoubleLine("Bases Assaulted:",GetBattlefieldStatData(i, 1),1,1,1)
  769. GameTooltip:AddDoubleLine("Bases Defended:",GetBattlefieldStatData(i, 2),1,1,1)
  770. end
  771. GameTooltip:Show()
  772. end
  773. end
  774. end
  775. end)
  776. bgframe:SetScript('OnLeave', function(self) GameTooltip:Hide() end)
  777.  
  778. local Stat = CreateFrame('Frame', nil, MainPanel)
  779. Stat:EnableMouse(true)
  780.  
  781. local Text1 = BGPanel:CreateFontString(nil, 'OVERLAY')
  782. Text1:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  783. Text1:SetPoint('LEFT', BGPanel, 30, 0)
  784. Text1:SetHeight(MainPanel:GetHeight())
  785.  
  786. local Text2 = BGPanel:CreateFontString(nil, 'OVERLAY')
  787. Text2:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  788. Text2:SetPoint('CENTER', BGPanel, 0, 0)
  789. Text2:SetHeight(MainPanel:GetHeight())
  790.  
  791. local Text3 = BGPanel:CreateFontString(nil, 'OVERLAY')
  792. Text3:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  793. Text3:SetPoint('RIGHT', BGPanel, -30, 0)
  794. Text3:SetHeight(MainPanel:GetHeight())
  795.  
  796. local int = 2
  797. local function Update(self, t)
  798. int = int - t
  799. if int < 0 then
  800. local dmgtxt
  801. RequestBattlefieldScoreData()
  802. local numScores = GetNumBattlefieldScores()
  803. for i=1, numScores do
  804. local name, killingBlows, honorableKills, deaths, honorGained, faction, race, class, classToken, damageDone, healingDone, bgRating, ratingChange = GetBattlefieldScore(i)
  805. if healingDone > damageDone then
  806. dmgtxt = ("Healing : "..hexa..healingDone..hexb)
  807. else
  808. dmgtxt = ("Damage : "..hexa..damageDone..hexb)
  809. end
  810. if ( name ) then
  811. if ( name == PLAYER_NAME ) then
  812. Text2:SetText("Honor : "..hexa..format('%d', honorGained)..hexb)
  813. Text1:SetText(dmgtxt)
  814. Text3:SetText("Killing Blows : "..hexa..killingBlows..hexb)
  815. end
  816. end
  817. end
  818. int = 0
  819. end
  820. end
  821.  
  822. --hide text when not in an bg
  823. local function OnEvent(self, event)
  824. if event == 'PLAYER_ENTERING_WORLD' then
  825. local inInstance, instanceType = IsInInstance()
  826. if inInstance and (instanceType == 'pvp') then
  827. bgframe:Show()
  828. PanelLeft:Hide()
  829. else
  830. Text1:SetText('')
  831. Text2:SetText('')
  832. Text3:SetText('')
  833. bgframe:Hide()
  834. PanelLeft:Show()
  835. end
  836. end
  837. end
  838.  
  839. Stat:RegisterEvent('PLAYER_ENTERING_WORLD')
  840. Stat:SetScript('OnEvent', OnEvent)
  841. Stat:SetScript('OnUpdate', Update)
  842. Update(Stat, 10)
  843. end
  844.  
  845. ----------------
  846. -- Call To Arms
  847. ----------------
  848. if db.calltoarms then
  849. local Stat = CreateFrame('Frame', nil, MainPanel)
  850. Stat:EnableMouse(true)
  851. Stat:SetFrameStrata("MEDIUM")
  852. Stat:SetFrameLevel(3)
  853.  
  854. local Text = Stat:CreateFontString(nil, "OVERLAY")
  855. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  856. self:PlacePlugin(db.calltoarms, Text)
  857.  
  858. local function MakeIconString(tank, healer, damage)
  859. local str = ""
  860. if tank then
  861. str = str..'T'
  862. end
  863. if healer then
  864. str = str..', H'
  865. end
  866. if damage then
  867. str = str..', D'
  868. end
  869.  
  870. return str
  871. end
  872.  
  873. local function MakeString(tank, healer, damage)
  874. local str = ""
  875. if tank then
  876. str = str..'Tank'
  877. end
  878. if healer then
  879. str = str..', Healer'
  880. end
  881. if damage then
  882. str = str..', DPS'
  883. end
  884.  
  885. return str
  886. end
  887.  
  888. local function OnEvent(self, event, ...)
  889. local tankReward = false
  890. local healerReward = false
  891. local dpsReward = false
  892. local unavailable = true
  893. for i=1, GetNumRandomDungeons() do
  894. local id, name = GetLFGRandomDungeonInfo(i)
  895. for x = 1,LFG_ROLE_NUM_SHORTAGE_TYPES do
  896. local eligible, forTank, forHealer, forDamage, itemCount = GetLFGRoleShortageRewards(id, x)
  897. if eligible then unavailable = false end
  898. if eligible and forTank and itemCount > 0 then tankReward = true end
  899. if eligible and forHealer and itemCount > 0 then healerReward = true end
  900. if eligible and forDamage and itemCount > 0 then dpsReward = true end
  901. end
  902. end
  903.  
  904. if unavailable then
  905. Text:SetText(QUEUE_TIME_UNAVAILABLE)
  906. else
  907. Text:SetText(hexa..'C to A'..hexb.." : "..MakeIconString(tankReward, healerReward, dpsReward).." ")
  908. end
  909.  
  910. self:SetAllPoints(Text)
  911. end
  912.  
  913. local function OnEnter(self)
  914. if InCombatLockdown() then return end
  915.  
  916. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  917. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  918. GameTooltip:ClearLines()
  919. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Call to Arms")
  920. GameTooltip:AddLine(' ')
  921.  
  922. local allUnavailable = true
  923. local numCTA = 0
  924. for i=1, GetNumRandomDungeons() do
  925. local id, name = GetLFGRandomDungeonInfo(i)
  926. local tankReward = false
  927. local healerReward = false
  928. local dpsReward = false
  929. local unavailable = true
  930. for x=1, LFG_ROLE_NUM_SHORTAGE_TYPES do
  931. local eligible, forTank, forHealer, forDamage, itemCount = GetLFGRoleShortageRewards(id, x)
  932. if eligible then unavailable = false end
  933. if eligible and forTank and itemCount > 0 then tankReward = true end
  934. if eligible and forHealer and itemCount > 0 then healerReward = true end
  935. if eligible and forDamage and itemCount > 0 then dpsReward = true end
  936. end
  937. if not unavailable then
  938. allUnavailable = false
  939. local rolesString = MakeString(tankReward, healerReward, dpsReward)
  940. if rolesString ~= "" then
  941. GameTooltip:AddDoubleLine(name.." : ", rolesString..' ', 1, 1, 1)
  942. end
  943. if tankReward or healerReward or dpsReward then numCTA = numCTA + 1 end
  944. end
  945. end
  946.  
  947. if allUnavailable then
  948. GameTooltip:AddLine("Could not get Call To Arms information.")
  949. elseif numCTA == 0 then
  950. GameTooltip:AddLine("Could not get Call To Arms information.")
  951. end
  952. GameTooltip:AddLine' '
  953. GameTooltip:AddLine("|cffeda55fLeft Click|r to Open Dungeon Finder")
  954. GameTooltip:AddLine("|cffeda55fRight Click|r to Open PvP Finder")
  955. GameTooltip:Show()
  956. end
  957.  
  958. Stat:RegisterEvent("LFG_UPDATE_RANDOM_INFO")
  959. Stat:RegisterEvent("PLAYER_LOGIN")
  960. Stat:SetScript("OnEvent", OnEvent)
  961. Stat:SetScript("OnMouseDown", function(self, btn)
  962. if btn == "LeftButton" then
  963. ToggleLFDParentFrame(1)
  964. elseif btn == "RightButton" then
  965. TogglePVPUI(1)
  966. end
  967. end)
  968. Stat:SetScript("OnEnter", OnEnter)
  969. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  970. end
  971.  
  972. ---------------
  973. -- Coordinates
  974. ---------------
  975. if db.coords then
  976. local Stat = CreateFrame('Frame', nil, MainPanel)
  977. Stat:EnableMouse(true)
  978. Stat:SetFrameStrata('BACKGROUND')
  979. Stat:SetFrameLevel(3)
  980.  
  981. local Text = Stat:CreateFontString(nil, "OVERLAY")
  982. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  983. self:PlacePlugin(db.coords, Text)
  984.  
  985. local function Update(self)
  986. local px,py=GetPlayerMapPosition("player")
  987. Text:SetText(format(hexa.."Loc: "..hexb.."%i , %i",px*100,py*100))
  988. end
  989.  
  990. Stat:SetScript("OnUpdate", Update)
  991. Update(Stat, 10)
  992. end
  993.  
  994. ---------------------
  995. -- Damage Per Second
  996. ---------------------
  997. if db.dps_text then
  998. local events = {SWING_DAMAGE = true, RANGE_DAMAGE = true, SPELL_DAMAGE = true, SPELL_PERIODIC_DAMAGE = true, DAMAGE_SHIELD = true, DAMAGE_SPLIT = true, SPELL_EXTRA_ATTACKS = true}
  999. local DPS_FEED = CreateFrame('Frame', nil, MainPanel)
  1000. local player_id = UnitGUID('player')
  1001. local dmg_total, last_dmg_amount = 0, 0
  1002. local cmbt_time = 0
  1003.  
  1004. local pet_id = UnitGUID('pet')
  1005.  
  1006. local dText = DPS_FEED:CreateFontString(nil, 'OVERLAY')
  1007. dText:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  1008. dText:SetText("DPS: ", '0')
  1009.  
  1010. self:PlacePlugin(db.dps_text, dText)
  1011.  
  1012. DPS_FEED:EnableMouse(true)
  1013. DPS_FEED:SetFrameStrata('BACKGROUND')
  1014. DPS_FEED:SetFrameLevel(3)
  1015. DPS_FEED:SetHeight(20)
  1016. DPS_FEED:SetWidth(100)
  1017. DPS_FEED:SetAllPoints(dText)
  1018.  
  1019. DPS_FEED:SetScript('OnEvent', function(self, event, ...) self[event](self, ...) end)
  1020. DPS_FEED:RegisterEvent('PLAYER_LOGIN')
  1021.  
  1022. DPS_FEED:SetScript('OnUpdate', function(self, elap)
  1023. if UnitAffectingCombat('player') then
  1024. cmbt_time = cmbt_time + elap
  1025. end
  1026.  
  1027. dText:SetText(getDPS())
  1028. end)
  1029.  
  1030. function DPS_FEED:PLAYER_LOGIN()
  1031. DPS_FEED:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
  1032. DPS_FEED:RegisterEvent('PLAYER_REGEN_ENABLED')
  1033. DPS_FEED:RegisterEvent('PLAYER_REGEN_DISABLED')
  1034. DPS_FEED:RegisterEvent('UNIT_PET')
  1035. player_id = UnitGUID('player')
  1036. DPS_FEED:UnregisterEvent('PLAYER_LOGIN')
  1037. end
  1038.  
  1039. function DPS_FEED:UNIT_PET(unit)
  1040. if unit == 'player' then
  1041. pet_id = UnitGUID('pet')
  1042. end
  1043. end
  1044.  
  1045. -- handler for the combat log. used http://www.wowwiki.com/API_COMBAT_LOG_EVENT for api
  1046. function DPS_FEED:COMBAT_LOG_EVENT_UNFILTERED(...)
  1047. -- filter for events we only care about. i.e heals
  1048. if not events[select(2, ...)] then return end
  1049.  
  1050. -- only use events from the player
  1051. local id = select(4, ...)
  1052.  
  1053. if id == player_id or id == pet_id then
  1054. if select(2, ...) == "SWING_DAMAGE" then
  1055. if TOC_VERSION < 40200 then
  1056. last_dmg_amount = select(10, ...)
  1057. else
  1058. last_dmg_amount = select(12, ...)
  1059. end
  1060. else
  1061. if TOC_VERSION < 40200 then
  1062. last_dmg_amount = select(13, ...)
  1063. else
  1064. last_dmg_amount = select(15, ...)
  1065. end
  1066. end
  1067. dmg_total = dmg_total + last_dmg_amount
  1068. end
  1069. end
  1070.  
  1071. function getDPS()
  1072. if (dmg_total == 0) then
  1073. return (hexa.."DPS"..hexb..' 0')
  1074. else
  1075. return string.format(hexa.."DPS: "..hexb..'%.1f ', (dmg_total or 0) / (cmbt_time or 1))
  1076. end
  1077. end
  1078.  
  1079. function DPS_FEED:PLAYER_REGEN_ENABLED()
  1080. dText:SetText(getDPS())
  1081. end
  1082.  
  1083. function DPS_FEED:PLAYER_REGEN_DISABLED()
  1084. cmbt_time = 0
  1085. dmg_total = 0
  1086. last_dmg_amount = 0
  1087. end
  1088.  
  1089. DPS_FEED:SetScript('OnMouseDown', function (self, button, down)
  1090. cmbt_time = 0
  1091. dmg_total = 0
  1092. last_dmg_amount = 0
  1093. end)
  1094. end
  1095.  
  1096. --------------
  1097. -- Durability
  1098. --------------
  1099. if db.dur then
  1100.  
  1101. Slots = {
  1102. [1] = {1, "Head", 1000},
  1103. [2] = {3, "Shoulder", 1000},
  1104. [3] = {5, "Chest", 1000},
  1105. [4] = {6, "Waist", 1000},
  1106. [5] = {9, "Wrist", 1000},
  1107. [6] = {10, "Hands", 1000},
  1108. [7] = {7, "Legs", 1000},
  1109. [8] = {8, "Feet", 1000},
  1110. [9] = {16, "Main Hand", 1000},
  1111. [10] = {17, "Off Hand", 1000},
  1112. [11] = {18, "Ranged", 1000}
  1113. }
  1114.  
  1115.  
  1116. local Stat = CreateFrame('Frame', nil, MainPanel)
  1117. Stat:EnableMouse(true)
  1118. Stat:SetFrameStrata("MEDIUM")
  1119. Stat:SetFrameLevel(3)
  1120.  
  1121. local Text = Stat:CreateFontString(nil, "OVERLAY")
  1122. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  1123. self:PlacePlugin(db.dur, Text)
  1124.  
  1125. local function OnEvent(self)
  1126. local Total = 0
  1127. local current, max
  1128.  
  1129. for i = 1, 11 do
  1130. if GetInventoryItemLink("player", Slots[i][1]) ~= nil then
  1131. current, max = GetInventoryItemDurability(Slots[i][1])
  1132. if current then
  1133. Slots[i][3] = current/max
  1134. Total = Total + 1
  1135. end
  1136. end
  1137. end
  1138. table.sort(Slots, function(a, b) return a[3] < b[3] end)
  1139.  
  1140. if Total > 0 then
  1141. Text:SetText(hexa.."Armor: "..hexb..floor(Slots[1][3]*100).."% |r")
  1142. else
  1143. Text:SetText(hexa.."Armor: "..hexb.."100% |r")
  1144. end
  1145. -- Setup Durability Tooltip
  1146. self:SetAllPoints(Text)
  1147. Total = 0
  1148. end
  1149.  
  1150. Stat:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
  1151. Stat:RegisterEvent("MERCHANT_SHOW")
  1152. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  1153. Stat:SetScript("OnMouseDown", function() ToggleCharacter("PaperDollFrame") end)
  1154. Stat:SetScript("OnEvent", OnEvent)
  1155. Stat:SetScript("OnEnter", function(self)
  1156. if not InCombatLockdown() then
  1157. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  1158. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  1159. GameTooltip:ClearLines()
  1160. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Durability")
  1161. GameTooltip:AddLine' '
  1162. for i = 1, 11 do
  1163. if Slots[i][3] ~= 1000 then
  1164. local green, red
  1165. green = Slots[i][3]*2
  1166. red = 1 - green
  1167. GameTooltip:AddDoubleLine(Slots[i][2], floor(Slots[i][3]*100).."%",1 ,1 , 1, red + 1, green, 0)
  1168. end
  1169. end
  1170. GameTooltip:AddLine(" ")
  1171. GameTooltip:AddLine("|cffeda55fClick|r to Show Character Panel")
  1172. GameTooltip:Show()
  1173. end
  1174. end)
  1175. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  1176.  
  1177. end
  1178.  
  1179. -----------
  1180. -- FRIEND
  1181. -----------
  1182.  
  1183. if db.friends then
  1184.  
  1185.  
  1186. local _, _, _, broadcastText = BNGetInfo();
  1187.  
  1188. StaticPopupDialogs["SET_BN_BROADCAST"] = {
  1189. preferredIndex = STATICPOPUP_NUMDIALOGS,
  1190. text = BN_BROADCAST_TOOLTIP,
  1191. button1 = ACCEPT,
  1192. button2 = CANCEL,
  1193. hasEditBox = 1,
  1194. editBoxWidth = 350,
  1195. maxLetters = 127,
  1196. OnAccept = function(self)
  1197. BNSetCustomMessage(self.editBox:GetText())
  1198. end,
  1199. OnShow = function(self)
  1200. self.editBox:SetText(broadcastText)
  1201. self.editBox:SetFocus()
  1202. end,
  1203. OnHide = ChatEdit_FocusActiveWindow,
  1204. EditBoxOnEnterPressed = function(self)
  1205. BNSetCustomMessage(self:GetText())
  1206. self:GetParent():Hide()
  1207. end,
  1208. EditBoxOnEscapePressed = function(self)
  1209. self:GetParent():Hide()
  1210. end,
  1211. timeout = 0,
  1212. exclusive = 1,
  1213. whileDead = 1,
  1214. hideOnEscape = 1
  1215. }
  1216.  
  1217. local Stat = CreateFrame('Frame', nil, MainPanel)
  1218. Stat:EnableMouse(true)
  1219. Stat:SetFrameStrata("MEDIUM")
  1220. Stat:SetFrameLevel(3)
  1221.  
  1222. local Text = Stat:CreateFontString(nil, "OVERLAY")
  1223. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  1224. self:PlacePlugin(db.friends, Text)
  1225.  
  1226. local menuFrame = CreateFrame("Frame", "FriendRightClickMenu", UIParent, "UIDropDownMenuTemplate")
  1227. local menuList = {
  1228. { text = OPTIONS_MENU, isTitle = true,notCheckable=true},
  1229. { text = INVITE, hasArrow = true,notCheckable=true, },
  1230. { text = CHAT_MSG_WHISPER_INFORM, hasArrow = true,notCheckable=true, },
  1231. { text = PLAYER_STATUS, hasArrow = true, notCheckable=true,
  1232. menuList = {
  1233. { text = "|cff2BC226"..AVAILABLE.."|r", notCheckable=true, func = function() if IsChatAFK() then SendChatMessage("", "AFK") elseif IsChatDND() then SendChatMessage("", "DND") end end },
  1234. { text = "|cffE7E716"..DND.."|r", notCheckable=true, func = function() if not IsChatDND() then SendChatMessage("", "DND") end end },
  1235. { text = "|cffFF0000"..AFK.."|r", notCheckable=true, func = function() if not IsChatAFK() then SendChatMessage("", "AFK") end end },
  1236. },
  1237. },
  1238. { text = BN_BROADCAST_TOOLTIP, notCheckable=true, func = function() StaticPopup_Show("SET_BN_BROADCAST") end },
  1239. }
  1240.  
  1241. local function GetTableIndex(table, fieldIndex, value)
  1242. for k,v in ipairs(table) do
  1243. if v[fieldIndex] == value then return k end
  1244. end
  1245. return -1
  1246. end
  1247.  
  1248. local function inviteClick(self, arg1, arg2, checked)
  1249. menuFrame:Hide()
  1250. if type(arg1) ~= 'number' then
  1251. InviteUnit(arg1)
  1252. else
  1253. BNInviteFriend(arg1);
  1254. end
  1255. end
  1256.  
  1257. local function whisperClick(self,name,bnet)
  1258. menuFrame:Hide()
  1259. if bnet then
  1260. ChatFrame_SendSmartTell(name)
  1261. else
  1262. SetItemRef( "player:"..name, ("|Hplayer:%1$s|h[%1$s]|h"):format(name), "LeftButton" )
  1263. end
  1264. end
  1265.  
  1266.  
  1267. local levelNameString = "|cff%02x%02x%02x%d|r |cff%02x%02x%02x%s|r"
  1268. local clientLevelNameString = "%s (|cff%02x%02x%02x%d|r |cff%02x%02x%02x%s|r%s) |cff%02x%02x%02x%s|r"
  1269. local levelNameClassString = "|cff%02x%02x%02x%d|r %s%s%s"
  1270. local worldOfWarcraftString = "World of Warcraft"
  1271. local battleNetString = "Battle.NET"
  1272. local wowString = "WoW"
  1273. local totalOnlineString = "Online: " .. "%s/%s"
  1274. local tthead, ttsubh, ttoff = {r=0.4, g=0.78, b=1}, {r=0.75, g=0.9, b=1}, {r=.3,g=1,b=.3}
  1275. local activezone, inactivezone = {r=0.3, g=1.0, b=0.3}, {r=0.65, g=0.65, b=0.65}
  1276. local displayString = string.join("", hexa.."%s "..hexb, "|cffffffff", "%d|r")
  1277. local statusTable = { "|cffff0000[AFK]|r", "|cffff0000[DND]|r", "" }
  1278. local groupedTable = { "|cffaaaaaa*|r", "" }
  1279. local friendTable, BNTable = {}, {}
  1280. local totalOnline, BNTotalOnline = 0, 0
  1281.  
  1282. local function BuildFriendTable(total)
  1283. totalOnline = 0
  1284. wipe(friendTable)
  1285. local name, level, class, area, connected, status, note
  1286. for i = 1, total do
  1287. name, level, class, area, connected, status, note = GetFriendInfo(i)
  1288. for k,v in pairs(LOCALIZED_CLASS_NAMES_MALE) do if class == v then class = k end end
  1289.  
  1290. if status == "<"..AFK..">" then
  1291. status = "|cffff0000[AFK]|r"
  1292. elseif status == "<"..DND..">" then
  1293. status = "|cffff0000[DND]|r"
  1294. end
  1295.  
  1296. friendTable[i] = { name, level, class, area, connected, status, note }
  1297. if connected then totalOnline = totalOnline + 1 end
  1298. end
  1299. end
  1300.  
  1301. local function UpdateFriendTable(total)
  1302. totalOnline = 0
  1303. local name, level, class, area, connected, status, note
  1304. for i = 1, #friendTable do
  1305. name, level, class, area, connected, status, note = GetFriendInfo(i)
  1306. for k,v in pairs(LOCALIZED_CLASS_NAMES_MALE) do if class == v then class = k end end
  1307.  
  1308. -- get the correct index in our table
  1309. local index = GetTableIndex(friendTable, 1, name)
  1310. -- we cannot find a friend in our table, so rebuild it
  1311. if index == -1 then
  1312. BuildFriendTable(total)
  1313. break
  1314. end
  1315. -- update on-line status for all members
  1316. friendTable[index][5] = connected
  1317. -- update information only for on-line members
  1318. if connected then
  1319. friendTable[index][2] = level
  1320. friendTable[index][3] = class
  1321. friendTable[index][4] = area
  1322. friendTable[index][6] = status
  1323. friendTable[index][7] = note
  1324. totalOnline = totalOnline + 1
  1325. end
  1326. end
  1327. end
  1328.  
  1329. local function BuildBNTable(total)
  1330. BNTotalOnline = 0
  1331. wipe(BNTable)
  1332.  
  1333. for i = 1, total do
  1334. local presenceID, presenceName, battleTag, isBattleTagPresence, toonName, toonID, client, isOnline, lastOnline, isAFK, isDND, messageText, noteText, isRIDFriend, messageTime, canSoR = BNGetFriendInfo(i)
  1335. local hasFocus, _, _, realmName, realmID, faction, race, class, guild, zoneName, level, gameText = BNGetToonInfo(presenceID)
  1336.  
  1337. for k,v in pairs(LOCALIZED_CLASS_NAMES_MALE) do if class == v then class = k end end
  1338.  
  1339. BNTable[i] = { presenceID, presenceName, battleTag, toonName, toonID, client, isOnline, isAFK, isDND, noteText, realmName, faction, race, class, zoneName, level }
  1340. if isOnline then BNTotalOnline = BNTotalOnline + 1 end
  1341. end
  1342. end
  1343.  
  1344. local function UpdateBNTable(total)
  1345. BNTotalOnline = 0
  1346. for i = 1, #BNTable do
  1347. -- get guild roster information
  1348. local presenceID, presenceName, battleTag, isBattleTagPresence, toonName, toonID, client, isOnline, lastOnline, isAFK, isDND, messageText, noteText, isRIDFriend, messageTime, canSoR = BNGetFriendInfo(i)
  1349. local hasFocus, _, _, realmName, realmID, faction, race, class, guild, zoneName, level, gameText = BNGetToonInfo(presenceID)
  1350.  
  1351. for k,v in pairs(LOCALIZED_CLASS_NAMES_MALE) do if class == v then class = k end end
  1352.  
  1353. -- get the correct index in our table
  1354. local index = GetTableIndex(BNTable, 1, presenceID)
  1355. -- we cannot find a BN member in our table, so rebuild it
  1356. if index == -1 then
  1357. BuildBNTable(total)
  1358. return
  1359. end
  1360. -- update on-line status for all members
  1361. BNTable[index][7] = isOnline
  1362. -- update information only for on-line members
  1363. if isOnline then
  1364. BNTable[index][2] = presenceName
  1365. BNTable[index][3] = battleTag
  1366. BNTable[index][4] = toonName
  1367. BNTable[index][5] = toonID
  1368. BNTable[index][6] = client
  1369. BNTable[index][8] = isAFK
  1370. BNTable[index][9] = isDND
  1371. BNTable[index][10] = noteText
  1372. BNTable[index][11] = realmName
  1373. BNTable[index][12] = faction
  1374. BNTable[index][13] = race
  1375. BNTable[index][14] = class
  1376. BNTable[index][15] = zoneName
  1377. BNTable[index][16] = level
  1378.  
  1379. BNTotalOnline = BNTotalOnline + 1
  1380. end
  1381. end
  1382. end
  1383.  
  1384. Stat:SetScript("OnMouseUp", function(self, btn)
  1385. if btn ~= "RightButton" then return end
  1386.  
  1387. GameTooltip:Hide()
  1388.  
  1389. local menuCountWhispers = 0
  1390. local menuCountInvites = 0
  1391. local classc, levelc
  1392.  
  1393. menuList[2].menuList = {}
  1394. menuList[3].menuList = {}
  1395.  
  1396. if totalOnline > 0 then
  1397. for i = 1, #friendTable do
  1398. if (friendTable[i][5]) then
  1399. menuCountInvites = menuCountInvites + 1
  1400. menuCountWhispers = menuCountWhispers + 1
  1401.  
  1402. classc, levelc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[friendTable[i][3]], GetQuestDifficultyColor(friendTable[i][2])
  1403. if classc == nil then classc = GetQuestDifficultyColor(friendTable[i][2]) end
  1404.  
  1405. menuList[2].menuList[menuCountInvites] = {text = format(levelNameString,levelc.r*255,levelc.g*255,levelc.b*255,friendTable[i][2],classc.r*255,classc.g*255,classc.b*255,friendTable[i][1]), arg1 = friendTable[i][1],notCheckable=true, func = inviteClick}
  1406. menuList[3].menuList[menuCountWhispers] = {text = format(levelNameString,levelc.r*255,levelc.g*255,levelc.b*255,friendTable[i][2],classc.r*255,classc.g*255,classc.b*255,friendTable[i][1]), arg1 = friendTable[i][1],notCheckable=true, func = whisperClick}
  1407. end
  1408. end
  1409. end
  1410.  
  1411. if BNTotalOnline > 0 then
  1412. local realID, grouped
  1413. for i = 1, #BNTable do
  1414. if (BNTable[i][7]) then
  1415. realID = BNTable[i][2]
  1416. menuCountWhispers = menuCountWhispers + 1
  1417. menuList[3].menuList[menuCountWhispers] = {text = realID, arg1 = realID, arg2 = true, notCheckable=true, func = whisperClick}
  1418.  
  1419. if BNTable[i][6] == wowString and UnitFactionGroup("player") == BNTable[i][12] then
  1420. classc, levelc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[BNTable[i][14]], GetQuestDifficultyColor(90)
  1421. if classc == nil then classc = GetQuestDifficultyColor(90) end
  1422.  
  1423. if UnitInParty(BNTable[i][4]) or UnitInRaid(BNTable[i][4]) then grouped = 1 else grouped = 2 end
  1424. menuCountInvites = menuCountInvites + 1
  1425. menuList[2].menuList[menuCountInvites] = {text = format(levelNameString,levelc.r*255,levelc.g*255,levelc.b*255,BNTable[i][16],classc.r*255,classc.g*255,classc.b*255,BNTable[i][4]), arg1 = BNTable[i][5],notCheckable=true, func = inviteClick}
  1426. end
  1427. end
  1428. end
  1429. end
  1430.  
  1431. EasyMenu(menuList, menuFrame, "cursor", 0, 0, "MENU", 2)
  1432. end)
  1433.  
  1434. local function Update(self, event)
  1435. if event == "BN_FRIEND_INFO_CHANGED" or "BN_FRIEND_ACCOUNT_ONLINE" or "BN_FRIEND_ACCOUNT_OFFLINE" or "BN_TOON_NAME_UPDATED"
  1436. or "BN_FRIEND_TOON_ONLINE" or "BN_FRIEND_TOON_OFFLINE" or "PLAYER_ENTERING_WORLD" then
  1437. local BNTotal = BNGetNumFriends()
  1438. if BNTotal == #BNTable then
  1439. UpdateBNTable(BNTotal)
  1440. else
  1441. BuildBNTable(BNTotal)
  1442. end
  1443. end
  1444.  
  1445. if event == "FRIENDLIST_UPDATE" or "PLAYER_ENTERING_WORLD" then
  1446. local total = GetNumFriends()
  1447. if total == #friendTable then
  1448. UpdateFriendTable(total)
  1449. else
  1450. BuildFriendTable(total)
  1451. end
  1452. end
  1453.  
  1454. Text:SetFormattedText(displayString, "Friends:", totalOnline + BNTotalOnline)
  1455. self:SetAllPoints(Text)
  1456. end
  1457.  
  1458. Stat:SetScript("OnMouseDown", function(self, btn) if btn == "LeftButton" then ToggleFriendsFrame() end end)
  1459. Stat:SetScript("OnEnter", function(self)
  1460. if InCombatLockdown() then return end
  1461.  
  1462. local totalonline = totalOnline + BNTotalOnline
  1463. local totalfriends = #friendTable + #BNTable
  1464. local zonec, classc, levelc, realmc, grouped
  1465. if totalonline > 0 then
  1466. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  1467. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  1468. GameTooltip:ClearLines()
  1469. GameTooltip:AddDoubleLine(hexa..PLAYER_NAME.."'s"..hexb.." Friends", format(totalOnlineString, totalonline, totalfriends))
  1470. if totalOnline > 0 then
  1471. GameTooltip:AddLine(' ')
  1472. GameTooltip:AddLine(worldOfWarcraftString)
  1473. for i = 1, #friendTable do
  1474. if friendTable[i][5] then
  1475. if GetRealZoneText() == friendTable[i][4] then zonec = activezone else zonec = inactivezone end
  1476. classc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[friendTable[i][3]]
  1477. if classc == nil then classc = GetQuestDifficultyColor(friendTable[i][2]) end
  1478.  
  1479. if friendTable[i][2] ~= '' then
  1480. levelc = GetQuestDifficultyColor(friendTable[i][2])
  1481. else
  1482. levelc = RAID_CLASS_COLORS["PRIEST"]
  1483. classc = RAID_CLASS_COLORS["PRIEST"]
  1484. end
  1485.  
  1486. if UnitInParty(friendTable[i][1]) or UnitInRaid(friendTable[i][1]) then grouped = 1 else grouped = 2 end
  1487. GameTooltip:AddDoubleLine(format(levelNameClassString,levelc.r*255,levelc.g*255,levelc.b*255,friendTable[i][2],friendTable[i][1],groupedTable[grouped]," "..friendTable[i][6]),friendTable[i][4],classc.r,classc.g,classc.b,zonec.r,zonec.g,zonec.b)
  1488. end
  1489. end
  1490. end
  1491. if BNTotalOnline > 0 then
  1492. GameTooltip:AddLine(' ')
  1493. GameTooltip:AddLine(battleNetString)
  1494.  
  1495. local status = 0
  1496. for i = 1, #BNTable do
  1497. if BNTable[i][7] then
  1498. if BNTable[i][6] == wowString then
  1499. if (BNTable[i][8] == true) then status = 1 elseif (BNTable[i][9] == true) then status = 2 else status = 3 end
  1500.  
  1501. classc, levelc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[BNTable[i][14]], GetQuestDifficultyColor(90)
  1502. if classc == nil then classc = GetQuestDifficultyColor(90) end
  1503.  
  1504. if UnitInParty(BNTable[i][4]) or UnitInRaid(BNTable[i][4]) then grouped = 1 else grouped = 2 end
  1505. GameTooltip:AddDoubleLine(format(clientLevelNameString, BNTable[i][6],levelc.r*255,levelc.g*255,levelc.b*255,BNTable[i][16],classc.r*255,classc.g*255,classc.b*255,BNTable[i][4],groupedTable[grouped], 255, 0, 0, statusTable[status]),BNTable[i][2],238,238,238,238,238,238)
  1506. if IsShiftKeyDown() then
  1507. if GetRealZoneText() == BNTable[i][15] then zonec = activezone else zonec = inactivezone end
  1508. if GetRealmName() == BNTable[i][11] then realmc = activezone else realmc = inactivezone end
  1509. GameTooltip:AddDoubleLine(" "..BNTable[i][15], BNTable[i][11], zonec.r, zonec.g, zonec.b, realmc.r, realmc.g, realmc.b)
  1510. end
  1511. else
  1512. GameTooltip:AddDoubleLine("|cffeeeeee"..BNTable[i][6].." ("..BNTable[i][4]..")|r", "|cffeeeeee"..BNTable[i][2].."|r")
  1513. end
  1514. end
  1515. end
  1516. end
  1517. GameTooltip:Show()
  1518. else
  1519. GameTooltip:Hide()
  1520. end
  1521. end)
  1522.  
  1523. Stat:RegisterEvent("BN_FRIEND_ACCOUNT_ONLINE")
  1524. Stat:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE")
  1525. Stat:RegisterEvent("BN_FRIEND_INFO_CHANGED")
  1526. Stat:RegisterEvent("BN_FRIEND_TOON_ONLINE")
  1527. Stat:RegisterEvent("BN_FRIEND_TOON_OFFLINE")
  1528. Stat:RegisterEvent("BN_TOON_NAME_UPDATED")
  1529. Stat:RegisterEvent("FRIENDLIST_UPDATE")
  1530. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  1531.  
  1532. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  1533. Stat:SetScript("OnEvent", Update)
  1534. end
  1535.  
  1536.  
  1537. ---------
  1538. -- Guild
  1539. ---------
  1540. if db.guild then
  1541.  
  1542. local Stat = CreateFrame('Frame', nil, MainPanel)
  1543. Stat:EnableMouse(true)
  1544. Stat:SetFrameStrata("MEDIUM")
  1545. Stat:SetFrameLevel(3)
  1546.  
  1547. local Text = Stat:CreateFontString(nil, "OVERLAY")
  1548. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  1549. self:PlacePlugin(db.guild, Text)
  1550.  
  1551. local tthead, ttsubh, ttoff = {r=0.4, g=0.78, b=1}, {r=0.75, g=0.9, b=1}, {r=.3,g=1,b=.3}
  1552. local activezone, inactivezone = {r=0.3, g=1.0, b=0.3}, {r=0.65, g=0.65, b=0.65}
  1553. local displayString = string.join("", hexa.."%s: "..hexb, "|cffffffff", "%d|r")
  1554. local guildInfoString0 = "%s"
  1555. local guildInfoString1 = "%s [%d]"
  1556. local guildInfoString2 = "%s: %d/%d"
  1557. local guildMotDString = "%s |cffaaaaaa- |cffffffff%s"
  1558. local levelNameString = "|cff%02x%02x%02x%d|r |cff%02x%02x%02x%s|r %s"
  1559. local levelNameStatusString = "|cff%02x%02x%02x%d|r %s %s"
  1560. local nameRankString = "%s |cff999999-|cffffffff %s"
  1561. local noteString = " '%s'"
  1562. local officerNoteString = " o: '%s'"
  1563.  
  1564. local guildTable, guildXP, guildMotD = {}, {}, ""
  1565. local totalOnline = 0
  1566.  
  1567.  
  1568. local function BuildGuildTable()
  1569. totalOnline = 0
  1570. wipe(guildTable)
  1571. local _, name, rank, level, zone, note, officernote, connected, status, class, isMobile
  1572. for i = 1, GetNumGuildMembers() do
  1573. name, rank, _, level, _, zone, note, officernote, connected, status, class, _, _, isMobile = GetGuildRosterInfo(i)
  1574.  
  1575. if status == 1 then
  1576. status = "|cffff0000["..AFK.."]|r"
  1577. elseif status == 2 then
  1578. status = "|cffff0000["..DND.."]|r"
  1579. else
  1580. status = ""
  1581. end
  1582.  
  1583. guildTable[i] = { name, rank, level, zone, note, officernote, connected, status, class, isMobile }
  1584. if connected then totalOnline = totalOnline + 1 end
  1585. end
  1586. table.sort(guildTable, function(a, b)
  1587. if a and b then
  1588. return a[1] < b[1]
  1589. end
  1590. end)
  1591. end
  1592.  
  1593. local function UpdateGuildXP()
  1594. local currentXP, remainingXP = UnitGetGuildXP("player")
  1595. local nextLevelXP = currentXP + remainingXP
  1596.  
  1597. -- prevent 4.3 division / 0
  1598. if nextLevelXP == 0 or maxDailyXP == 0 then return end
  1599.  
  1600. local percentTotal = tostring(math.ceil((currentXP / nextLevelXP) * 100))
  1601.  
  1602. guildXP[0] = { currentXP, nextLevelXP, percentTotal }
  1603. end
  1604.  
  1605. local function UpdateGuildMessage()
  1606. guildMotD = GetGuildRosterMOTD()
  1607. end
  1608.  
  1609. local function Update(self, event, ...)
  1610. if event == "PLAYER_ENTERING_WORLD" then
  1611. self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  1612. if IsInGuild() and not GuildFrame then LoadAddOn("Blizzard_GuildUI") end
  1613. end
  1614.  
  1615. if IsInGuild() then
  1616. totalOnline = 0
  1617. local name, rank, level, zone, note, officernote, connected, status, class
  1618. for i = 1, GetNumGuildMembers() do
  1619. local connected = select(9, GetGuildRosterInfo(i))
  1620. if connected then totalOnline = totalOnline + 1 end
  1621. end
  1622. Text:SetFormattedText(displayString, "Guild", totalOnline)
  1623. else
  1624. Text:SetText("No Guild")
  1625. end
  1626.  
  1627. self:SetAllPoints(Text)
  1628. end
  1629.  
  1630. local menuFrame = CreateFrame("Frame", "GuildRightClickMenu", UIParent, "UIDropDownMenuTemplate")
  1631. local menuList = {
  1632. { text = OPTIONS_MENU, isTitle = true,notCheckable=true},
  1633. { text = INVITE, hasArrow = true,notCheckable=true,},
  1634. { text = CHAT_MSG_WHISPER_INFORM, hasArrow = true,notCheckable=true,}
  1635. }
  1636.  
  1637. local function inviteClick(self, arg1, arg2, checked)
  1638. menuFrame:Hide()
  1639. InviteUnit(arg1)
  1640. end
  1641.  
  1642. local function whisperClick(self,arg1,arg2,checked)
  1643. menuFrame:Hide()
  1644. SetItemRef( "player:"..arg1, ("|Hplayer:%1$s|h[%1$s]|h"):format(arg1), "LeftButton" )
  1645. end
  1646.  
  1647. local function ToggleGuildFrame()
  1648. if IsInGuild() then
  1649. if not GuildFrame then LoadAddOn("Blizzard_GuildUI") end
  1650. GuildFrame_Toggle()
  1651. GuildFrame_TabClicked(GuildFrameTab2)
  1652. else
  1653. if not LookingForGuildFrame then LoadAddOn("Blizzard_LookingForGuildUI") end
  1654. LookingForGuildFrame_Toggle()
  1655. end
  1656. end
  1657.  
  1658. Stat:SetScript("OnMouseUp", function(self, btn)
  1659. if btn ~= "RightButton" or not IsInGuild() then return end
  1660.  
  1661. GameTooltip:Hide()
  1662.  
  1663. local classc, levelc, grouped
  1664. local menuCountWhispers = 0
  1665. local menuCountInvites = 0
  1666.  
  1667. menuList[2].menuList = {}
  1668. menuList[3].menuList = {}
  1669.  
  1670. for i = 1, #guildTable do
  1671. if (guildTable[i][7] and guildTable[i][1] ~= nDatamyname) then
  1672. local classc, levelc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[guildTable[i][9]], GetQuestDifficultyColor(guildTable[i][3])
  1673.  
  1674. if UnitInParty(guildTable[i][1]) or UnitInRaid(guildTable[i][1]) then
  1675. grouped = "|cffaaaaaa*|r"
  1676. else
  1677. grouped = ""
  1678. if not guildTable[i][10] then
  1679. menuCountInvites = menuCountInvites + 1
  1680. menuList[2].menuList[menuCountInvites] = {text = string.format(levelNameString, levelc.r*255,levelc.g*255,levelc.b*255, guildTable[i][3], classc.r*255,classc.g*255,classc.b*255, guildTable[i][1], ""), arg1 = guildTable[i][1],notCheckable=true, func = inviteClick}
  1681. end
  1682. end
  1683. menuCountWhispers = menuCountWhispers + 1
  1684. menuList[3].menuList[menuCountWhispers] = {text = string.format(levelNameString, levelc.r*255,levelc.g*255,levelc.b*255, guildTable[i][3], classc.r*255,classc.g*255,classc.b*255, guildTable[i][1], grouped), arg1 = guildTable[i][1],notCheckable=true, func = whisperClick}
  1685. end
  1686. end
  1687.  
  1688. EasyMenu(menuList, menuFrame, "cursor", 0, 0, "MENU", 2)
  1689. end)
  1690.  
  1691. Stat:SetScript("OnEnter", function(self)
  1692. if InCombatLockdown() or not IsInGuild() then return end
  1693.  
  1694. GuildRoster()
  1695. UpdateGuildMessage()
  1696. BuildGuildTable()
  1697.  
  1698. local name, rank, level, zone, note, officernote, connected, status, class, isMobile
  1699. local zonec, classc, levelc
  1700. local online = totalOnline
  1701. local guildName, guildRankName, guildRankIndex = GetGuildInfo("player");
  1702. local GuildInfo = GetGuildInfo('player')
  1703. local GuildLevel = GetGuildLevel()
  1704.  
  1705. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  1706. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  1707. GameTooltip:ClearLines()
  1708. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Guild")
  1709. if GuildInfo then
  1710. GameTooltip:AddDoubleLine(string.format(guildInfoString0, GuildInfo), string.format(guildInfoString1, "Guild Level:", GuildLevel),tthead.r,tthead.g,tthead.b,tthead.r,tthead.g,tthead.b)
  1711. end
  1712. GameTooltip:AddLine' '
  1713. if GuildLevel then
  1714. GameTooltip:AddLine( string.format(guildInfoString2, "Member's Online", online, #guildTable),tthead.r,tthead.g,tthead.b)
  1715. end
  1716.  
  1717. if guildMotD ~= "" then GameTooltip:AddLine(' ')
  1718. GameTooltip:AddLine(string.format(guildMotDString, GUILD_MOTD, guildMotD), ttsubh.r, ttsubh.g, ttsubh.b, 1)
  1719. end
  1720.  
  1721. local col = RGBToHex(ttsubh.r, ttsubh.g, ttsubh.b)
  1722. GameTooltip:AddLine' '
  1723. if GuildLevel and GuildLevel ~= 25 then
  1724.  
  1725. if guildXP[0] then
  1726. local currentXP, nextLevelXP, percentTotal = unpack(guildXP[0])
  1727.  
  1728. GameTooltip:AddLine(string.format(col..GUILD_EXPERIENCE_CURRENT, "|r |cFFFFFFFF"..ShortValue(currentXP), ShortValue(nextLevelXP), percentTotal))
  1729. end
  1730. end
  1731.  
  1732. local _, _, standingID, barMin, barMax, barValue = GetGuildFactionInfo()
  1733. if standingID ~= 8 then -- Not Max Rep
  1734. barMax = barMax - barMin
  1735. barValue = barValue - barMin
  1736. barMin = 0
  1737. GameTooltip:AddLine(string.format("%s:|r |cFFFFFFFF%s/%s (%s%%)",col..COMBAT_FACTION_CHANGE, ShortValue(barValue), ShortValue(barMax), math.ceil((barValue / barMax) * 100)))
  1738. end
  1739.  
  1740. if online > 1 then
  1741. GameTooltip:AddLine(' ')
  1742. for i = 1, #guildTable do
  1743. if online <= 1 then
  1744. if online > 1 then GameTooltip:AddLine(format("+ %d More...", online - modules.Guild.maxguild),ttsubh.r,ttsubh.g,ttsubh.b) end
  1745. break
  1746. end
  1747.  
  1748. name, rank, level, zone, note, officernote, connected, status, class, isMobile = unpack(guildTable[i])
  1749. if connected and name ~= nDatamyname then
  1750. if GetRealZoneText() == zone then zonec = activezone else zonec = inactivezone end
  1751. classc, levelc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class], GetQuestDifficultyColor(level)
  1752.  
  1753. if isMobile then zone = "" end
  1754.  
  1755. if IsShiftKeyDown() then
  1756. GameTooltip:AddDoubleLine(string.format(nameRankString, name, rank), zone, classc.r, classc.g, classc.b, zonec.r, zonec.g, zonec.b)
  1757. if note ~= "" then GameTooltip:AddLine(string.format(noteString, note), ttsubh.r, ttsubh.g, ttsubh.b, 1) end
  1758. if officernote ~= "" then GameTooltip:AddLine(string.format(officerNoteString, officernote), ttoff.r, ttoff.g, ttoff.b ,1) end
  1759. else
  1760. GameTooltip:AddDoubleLine(string.format(levelNameStatusString, levelc.r*255, levelc.g*255, levelc.b*255, level, name, status), zone, classc.r,classc.g,classc.b, zonec.r,zonec.g,zonec.b)
  1761. end
  1762. end
  1763. end
  1764. end
  1765. GameTooltip:AddLine' '
  1766. GameTooltip:AddLine("|cffeda55fLeft Click|r to Open Guild Roster")
  1767. GameTooltip:AddLine("|cffeda55fHold Shift & Mouseover|r to See Guild and Officer Note's")
  1768. GameTooltip:AddLine("|cffeda55fRight Click|r to open Options Menu")
  1769. GameTooltip:Show()
  1770. end)
  1771.  
  1772. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  1773. Stat:SetScript("OnMouseDown", function(self, btn)
  1774. if btn ~= "LeftButton" then return end
  1775. ToggleGuildFrame()
  1776. end)
  1777.  
  1778. Stat:RegisterEvent("GUILD_ROSTER_SHOW")
  1779. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  1780. Stat:RegisterEvent("GUILD_ROSTER_UPDATE")
  1781. Stat:RegisterEvent("PLAYER_GUILD_UPDATE")
  1782. Stat:SetScript("OnEvent", Update)
  1783. end
  1784.  
  1785. ----------------
  1786. -- Player Haste
  1787. ----------------
  1788. if db.haste then
  1789. local Stat = CreateFrame('Frame', nil, MainPanel)
  1790. Stat:EnableMouse(true)
  1791. Stat:SetFrameStrata('BACKGROUND')
  1792. Stat:SetFrameLevel(3)
  1793.  
  1794. local Text = Stat:CreateFontString(nil, 'OVERLAY')
  1795. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  1796. self:PlacePlugin(db.haste, Text)
  1797.  
  1798. local int = 1
  1799.  
  1800. local function Update(self, t)
  1801. local spellhaste = GetCombatRating(CR_HASTE_SPELL)
  1802. local rangedhaste = GetCombatRating(CR_HASTE_RANGED)
  1803. local attackhaste = GetCombatRating(CR_HASTE_MELEE)
  1804.  
  1805. if attackhaste > spellhaste and select(2, UnitClass("Player")) ~= "HUNTER" then
  1806. haste = attackhaste
  1807. elseif select(2, UnitClass("Player")) == "HUNTER" then
  1808. haste = rangedhaste
  1809. else
  1810. haste = spellhaste
  1811. end
  1812.  
  1813. int = int - t
  1814. if int < 0 then
  1815. Text:SetText(hexa.."Haste: "..hexb..haste)
  1816. int = 1
  1817. end
  1818. end
  1819.  
  1820. Stat:SetScript("OnUpdate", Update)
  1821. Update(Stat, 10)
  1822. end
  1823.  
  1824. ---------------
  1825. -- Professions
  1826. ---------------
  1827. if db.pro then
  1828.  
  1829. local Stat = CreateFrame('Button', nil, MainPanel)
  1830. Stat:RegisterEvent('PLAYER_ENTERING_WORLD')
  1831. Stat:SetFrameStrata('BACKGROUND')
  1832. Stat:SetFrameLevel(3)
  1833. Stat:EnableMouse(true)
  1834. Stat.tooltip = false
  1835.  
  1836. local Text = Stat:CreateFontString(nil, 'OVERLAY')
  1837. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  1838. self:PlacePlugin(db.pro, Text)
  1839.  
  1840. local function Update(self)
  1841. for i = 1, select("#", GetProfessions()) do
  1842. local v = select(i, GetProfessions());
  1843. if v ~= nil then
  1844. local name, texture, rank, maxRank = GetProfessionInfo(v)
  1845. Text:SetFormattedText(hexa.."Professions"..hexb)
  1846. end
  1847. end
  1848. self:SetAllPoints(Text)
  1849. end
  1850.  
  1851. Stat:SetScript('OnEnter', function()
  1852. if InCombatLockdown() then return end
  1853. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  1854. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  1855. GameTooltip:ClearLines()
  1856. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Professions")
  1857. GameTooltip:AddLine' '
  1858. for i = 1, select("#", GetProfessions()) do
  1859. local v = select(i, GetProfessions());
  1860. if v ~= nil then
  1861. local name, texture, rank, maxRank = GetProfessionInfo(v)
  1862. GameTooltip:AddDoubleLine(name, rank..' / '..maxRank,.75,.9,1,.3,1,.3)
  1863. end
  1864. end
  1865. GameTooltip:AddLine' '
  1866. GameTooltip:AddLine("|cffeda55fLeft Click|r to Open Profession #1")
  1867. GameTooltip:AddLine("|cffeda55fMiddle Click|r to Open Spell Book")
  1868. GameTooltip:AddLine("|cffeda55fRight Click|r to Open Profession #2")
  1869.  
  1870. GameTooltip:Show()
  1871. end)
  1872.  
  1873.  
  1874. Stat:SetScript("OnClick",function(self,btn)
  1875. local prof1, prof2 = GetProfessions()
  1876. if btn == "LeftButton" then
  1877. if prof1 then
  1878. if (GetProfessionInfo(prof1) == ('Herbalism')) then
  1879. print('|cff00B4FFBasic|rUI: |cffFF0000Herbalism has no options!|r')
  1880. elseif(GetProfessionInfo(prof1) == ('Skinning')) then
  1881. print('|cff00B4FFBasic|rUI: |cffFF0000Skinning has no options!|r')
  1882. elseif(GetProfessionInfo(prof1) == ('Mining')) then
  1883. CastSpellByName("Smelting")
  1884. else
  1885. CastSpellByName((GetProfessionInfo(prof1)))
  1886. end
  1887. else
  1888. print('|cff00B4FFBasic|rUI: |cffFF0000No Profession Found!|r')
  1889. end
  1890. elseif btn == 'MiddleButton' then
  1891. ToggleSpellBook(BOOKTYPE_PROFESSION);
  1892. elseif btn == "RightButton" then
  1893. if prof2 then
  1894. if (GetProfessionInfo(prof2) == ('Herbalism')) then
  1895. print('|cff00B4FFBasic|rUI: |cffFF0000Herbalism has no options!|r')
  1896. elseif(GetProfessionInfo(prof2) == ('Skinning')) then
  1897. print('|cff00B4FFBasic|rUI: |cffFF0000Skinning has no options!|r')
  1898. elseif(GetProfessionInfo(prof2) == ('Mining')) then
  1899. CastSpellByName("Smelting")
  1900. else
  1901. CastSpellByName((GetProfessionInfo(prof2)))
  1902. end
  1903. else
  1904. print('|cff00B4FFBasic|rUI: |cffFF0000No Profession Found!|r')
  1905. end
  1906. end
  1907. end)
  1908.  
  1909.  
  1910. Stat:RegisterForClicks("AnyUp")
  1911. Stat:SetScript('OnUpdate', Update)
  1912. Stat:SetScript('OnLeave', function() GameTooltip:Hide() end)
  1913. end
  1914.  
  1915.  
  1916. -----------
  1917. -- Recount
  1918. -----------
  1919. if db.recount then
  1920.  
  1921. local RecountDPS = CreateFrame('Frame', nil, MainPanel)
  1922. RecountDPS:EnableMouse(true)
  1923. RecountDPS:SetFrameStrata("MEDIUM")
  1924. RecountDPS:SetFrameLevel(3)
  1925.  
  1926. local Text = RecountDPS:CreateFontString(nil, "OVERLAY")
  1927. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  1928. self:PlacePlugin(db.recount, Text)
  1929. RecountDPS:SetAllPoints(Text)
  1930.  
  1931. function OnEvent(self, event, ...)
  1932. if event == "PLAYER_LOGIN" then
  1933. if IsAddOnLoaded("Recount") then
  1934. RecountDPS:RegisterEvent("PLAYER_REGEN_ENABLED")
  1935. RecountDPS:RegisterEvent("PLAYER_REGEN_DISABLED")
  1936. PLAYER_NAME = UnitName("player")
  1937. currentFightDPS = 0
  1938. else
  1939. return
  1940. end
  1941. RecountDPS:UnregisterEvent("PLAYER_LOGIN")
  1942. elseif event == "PLAYER_ENTERING_WORLD" then
  1943. self.updateDPS()
  1944. RecountDPS:UnregisterEvent("PLAYER_ENTERING_WORLD")
  1945. end
  1946. end
  1947.  
  1948. function RecountDPS:RecountHook_UpdateText()
  1949. self:updateDPS()
  1950. end
  1951.  
  1952. function RecountDPS:updateDPS()
  1953. Text:SetText(hexa.."DPS: "..hexb.. RecountDPS.getDPS() .. "|r")
  1954. end
  1955.  
  1956. function RecountDPS:getDPS()
  1957. if not IsAddOnLoaded("Recount") then return "N/A" end
  1958. if db.recountraiddps == true then
  1959. -- show raid dps
  1960. _, dps = RecountDPS:getRaidValuePerSecond(Recount.db.profile.CurDataSet)
  1961. return dps
  1962. else
  1963. return RecountDPS.getValuePerSecond()
  1964. end
  1965. end
  1966.  
  1967. -- quick dps calculation from recount's data
  1968. function RecountDPS:getValuePerSecond()
  1969. local _, dps = Recount:MergedPetDamageDPS(Recount.db2.combatants[PLAYER_NAME], Recount.db.profile.CurDataSet)
  1970. return math.floor(10 * dps + 0.5) / 10
  1971. end
  1972.  
  1973. function RecountDPS:getRaidValuePerSecond(tablename)
  1974. local dps, curdps, data, damage, temp = 0, 0, nil, 0, 0
  1975. for _,data in pairs(Recount.db2.combatants) do
  1976. if data.Fights and data.Fights[tablename] and (data.type=="Self" or data.type=="Grouped" or data.type=="Pet" or data.type=="Ungrouped") then
  1977. temp, curdps = Recount:MergedPetDamageDPS(data,tablename)
  1978. if data.type ~= "Pet" or (not Recount.db.profile.MergePets and data.Owner and (Recount.db2.combatants[data.Owner].type=="Self" or Recount.db2.combatants[data.Owner].type=="Grouped" or Recount.db2.combatants[data.Owner].type=="Ungrouped")) or (not Recount.db.profile.MergePets and data.Name and data.GUID and self:matchUnitGUID(data.Name, data.GUID)) then
  1979. dps = dps + 10 * curdps
  1980. damage = damage + temp
  1981. end
  1982. end
  1983. end
  1984. return math.floor(damage + 0.5) / 10, math.floor(dps + 0.5)/10
  1985. end
  1986.  
  1987. -- tracked events
  1988. RecountDPS:RegisterEvent("PLAYER_LOGIN")
  1989. RecountDPS:RegisterEvent("PLAYER_ENTERING_WORLD")
  1990.  
  1991. -- scripts
  1992. RecountDPS:SetScript("OnEnter", function(self)
  1993. if InCombatLockdown() then return end
  1994.  
  1995. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  1996. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  1997. GameTooltip:ClearLines()
  1998. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Damage")
  1999. GameTooltip:AddLine' '
  2000. if IsAddOnLoaded("Recount") then
  2001. local damage, dps = Recount:MergedPetDamageDPS(Recount.db2.combatants[PLAYER_NAME], Recount.db.profile.CurDataSet)
  2002. local raid_damage, raid_dps = RecountDPS:getRaidValuePerSecond(Recount.db.profile.CurDataSet)
  2003. -- format the number
  2004. dps = math.floor(10 * dps + 0.5) / 10
  2005. GameTooltip:AddLine("Recount")
  2006. GameTooltip:AddDoubleLine("Personal Damage:", damage, 1, 1, 1, 0.8, 0.8, 0.8)
  2007. GameTooltip:AddDoubleLine("Personal DPS:", dps, 1, 1, 1, 0.8, 0.8, 0.8)
  2008. GameTooltip:AddLine(" ")
  2009. GameTooltip:AddDoubleLine("Raid Damage:", raid_damage, 1, 1, 1, 0.8, 0.8, 0.8)
  2010. GameTooltip:AddDoubleLine("Raid DPS:", raid_dps, 1, 1, 1, 0.8, 0.8, 0.8)
  2011. GameTooltip:AddLine(" ")
  2012. GameTooltip:AddLine("|cffeda55fLeft Click|r to toggle Recount")
  2013. GameTooltip:AddLine("|cffeda55fRight Click|r to reset data")
  2014. GameTooltip:AddLine("|cffeda55fShift + Right Click|r to open config")
  2015. else
  2016. GameTooltip:AddLine("Recount is not loaded.", 255, 0, 0)
  2017. GameTooltip:AddLine("Enable Recount and reload your UI.")
  2018. end
  2019. GameTooltip:Show()
  2020. end)
  2021. RecountDPS:SetScript("OnMouseUp", function(self, button)
  2022. if button == "RightButton" then
  2023. if not IsShiftKeyDown() then
  2024. Recount:ShowReset()
  2025. else
  2026. Recount:ShowConfig()
  2027. end
  2028. elseif button == "LeftButton" then
  2029. if Recount.MainWindow:IsShown() then
  2030. Recount.MainWindow:Hide()
  2031. else
  2032. Recount.MainWindow:Show()
  2033. Recount:RefreshMainWindow()
  2034. end
  2035. end
  2036. end)
  2037. RecountDPS:SetScript("OnEvent", OnEvent)
  2038. RecountDPS:SetScript("OnLeave", function() GameTooltip:Hide() end)
  2039. RecountDPS:SetScript("OnUpdate", function(self, t)
  2040. local int = -1
  2041. int = int - t
  2042. if int < 0 then
  2043. self.updateDPS()
  2044. int = 1
  2045. end
  2046. end)
  2047. end
  2048.  
  2049. --------------------
  2050. -- Talent Spec Swap
  2051. --------------------
  2052. if db.spec then
  2053.  
  2054. local Stat = CreateFrame('Frame', nil, MainPanel)
  2055. Stat:EnableMouse(true)
  2056. Stat:SetFrameStrata('BACKGROUND')
  2057. Stat:SetFrameLevel(3)
  2058.  
  2059. local Text = Stat:CreateFontString(nil, 'OVERLAY')
  2060. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  2061. self:PlacePlugin(db.spec, Text)
  2062.  
  2063. local talent = {}
  2064. local active
  2065. local talentString = string.join('', '|cffFFFFFF%s|r ')
  2066. local activeString = string.join('', '|cff00FF00' , ACTIVE_PETS, '|r')
  2067. local inactiveString = string.join('', '|cffFF0000', FACTION_INACTIVE, '|r')
  2068.  
  2069.  
  2070.  
  2071. local function LoadTalentTrees()
  2072. for i = 1, GetNumSpecGroups(false, false) do
  2073. talent[i] = {} -- init talent group table
  2074. for j = 1, GetNumSpecializations(false, false) do
  2075. talent[i][j] = select(5, GetSpecializationInfo(j, false, false, i))
  2076. end
  2077. end
  2078. end
  2079.  
  2080. local int = 1
  2081. local function Update(self, t)
  2082. int = int - t
  2083. if int > 0 or not GetSpecialization() then return end
  2084.  
  2085. active = GetActiveSpecGroup(false, false)
  2086. Text:SetFormattedText(talentString, hexa..select(2, GetSpecializationInfo(GetSpecialization(false, false, active)))..hexb)
  2087. int = 1
  2088.  
  2089. -- disable script
  2090. self:SetScript('OnUpdate', nil)
  2091. end
  2092.  
  2093.  
  2094. Stat:SetScript('OnEnter', function(self)
  2095. if InCombatLockdown() then return end
  2096.  
  2097. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  2098. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  2099.  
  2100. GameTooltip:ClearLines()
  2101. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Spec")
  2102. GameTooltip:AddLine' '
  2103. for i = 1, GetNumSpecGroups() do
  2104. if GetSpecialization(false, false, i) then
  2105. GameTooltip:AddLine(string.join('- ', string.format(talentString, select(2, GetSpecializationInfo(GetSpecialization(false, false, i)))), (i == active and activeString or inactiveString)),1,1,1)
  2106. end
  2107. end
  2108.  
  2109. GameTooltip:AddLine' '
  2110. GameTooltip:AddLine("|cffeda55fLeft Click|r to Switch Spec's")
  2111. GameTooltip:AddLine("|cffeda55fRight Click|r to Open Talent Tree")
  2112. GameTooltip:Show()
  2113. end)
  2114.  
  2115. Stat:SetScript('OnLeave', function() GameTooltip:Hide() end)
  2116.  
  2117. local function OnEvent(self, event, ...)
  2118. if event == 'PLAYER_ENTERING_WORLD' then
  2119. self:UnregisterEvent('PLAYER_ENTERING_WORLD')
  2120. end
  2121.  
  2122. -- load talent information
  2123. LoadTalentTrees()
  2124.  
  2125. -- Setup Talents Tooltip
  2126. self:SetAllPoints(Text)
  2127.  
  2128. -- update datatext
  2129. if event ~= 'PLAYER_ENTERING_WORLD' then
  2130. self:SetScript('OnUpdate', Update)
  2131. end
  2132. end
  2133.  
  2134.  
  2135.  
  2136. Stat:RegisterEvent('PLAYER_ENTERING_WORLD');
  2137. Stat:RegisterEvent('CHARACTER_POINTS_CHANGED');
  2138. Stat:RegisterEvent('PLAYER_TALENT_UPDATE');
  2139. Stat:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')
  2140. Stat:RegisterEvent("EQUIPMENT_SETS_CHANGED")
  2141. Stat:SetScript('OnEvent', OnEvent)
  2142. Stat:SetScript('OnUpdate', Update)
  2143.  
  2144. Stat:SetScript("OnMouseDown", function(self, button)
  2145. if button == "LeftButton" then
  2146. SetActiveSpecGroup (active == 1 and 2 or 1)
  2147. elseif button == "RightButton" then
  2148. ToggleTalentFrame()
  2149. end
  2150. end)
  2151. end
  2152.  
  2153. -----------------
  2154. -- Statistics #1
  2155. -----------------
  2156. if db.stat1 then
  2157.  
  2158. local Stat = CreateFrame('Frame', nil, MainPanel)
  2159. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  2160. Stat:SetFrameStrata("BACKGROUND")
  2161. Stat:SetFrameLevel(3)
  2162. Stat:EnableMouse(true)
  2163.  
  2164. local Text = Stat:CreateFontString(nil, "OVERLAY")
  2165. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  2166. self:PlacePlugin(db.stat1, Text)
  2167.  
  2168. local format = string.format
  2169. local targetlv, playerlv = UnitLevel("target"), UnitLevel("player")
  2170. local basemisschance, leveldifference, dodge, parry, block
  2171. local chanceString = "%.2f%%"
  2172. local modifierString = string.join("", "%d (+", chanceString, ")")
  2173. local manaRegenString = "%d / %d"
  2174. local displayNumberString = string.join("", "%s", "%d|r")
  2175. local displayFloatString = string.join("", "%s", "%.2f%%|r")
  2176. local spellpwr, avoidance, pwr
  2177. local haste, hasteBonus
  2178. local level = UnitLevel("player")
  2179.  
  2180. local function ShowTooltip(self)
  2181. if InCombatLockdown() then return end
  2182.  
  2183. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  2184. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  2185. GameTooltip:ClearLines()
  2186. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Statistics")
  2187. GameTooltip:AddLine' '
  2188.  
  2189. if Role == "Tank" then
  2190. if targetlv > 1 then
  2191. GameTooltip:AddDoubleLine("Avoidance Breakdown", string.join("", " (", "lvl", " ", targetlv, ")"))
  2192. elseif targetlv == -1 then
  2193. GameTooltip:AddDoubleLine("Avoidance Breakdown", string.join("", " (", "Boss", ")"))
  2194. else
  2195. GameTooltip:AddDoubleLine("Avoidance Breakdown", string.join("", " (", "lvl", " ", playerlv, ")"))
  2196. end
  2197. GameTooltip:AddLine' '
  2198. GameTooltip:AddDoubleLine(DODGE_CHANCE, format(chanceString, dodge),1,1,1)
  2199. GameTooltip:AddDoubleLine(PARRY_CHANCE, format(chanceString, parry),1,1,1)
  2200. GameTooltip:AddDoubleLine(BLOCK_CHANCE, format(chanceString, block),1,1,1)
  2201. GameTooltip:AddDoubleLine(MISS_CHANCE, format(chanceString, basemisschance),1,1,1)
  2202. elseif Role == "Caster" then
  2203. GameTooltip:AddDoubleLine(STAT_HIT_CHANCE, format(modifierString, GetCombatRating(CR_HIT_SPELL), GetCombatRatingBonus(CR_HIT_SPELL)), 1, 1, 1)
  2204. GameTooltip:AddDoubleLine(STAT_HASTE, format(modifierString, GetCombatRating(CR_HASTE_SPELL), GetCombatRatingBonus(CR_HASTE_SPELL)), 1, 1, 1)
  2205. local base, combat = GetManaRegen()
  2206. GameTooltip:AddDoubleLine(MANA_REGEN, format(manaRegenString, base * 5, combat * 5), 1, 1, 1)
  2207. elseif Role == "Melee" then
  2208. local hit = UNIT_CLASS == "HUNTER" and GetCombatRating(CR_HIT_RANGED) or GetCombatRating(CR_HIT_MELEE)
  2209. local hitBonus = UNIT_CLASS == "HUNTER" and GetCombatRatingBonus(CR_HIT_RANGED) or GetCombatRatingBonus(CR_HIT_MELEE)
  2210.  
  2211. GameTooltip:AddDoubleLine(STAT_HIT_CHANCE, format(modifierString, hit, hitBonus), 1, 1, 1)
  2212.  
  2213. local haste = UNIT_CLASS == "HUNTER" and GetCombatRating(CR_HASTE_RANGED) or GetCombatRating(CR_HASTE_MELEE)
  2214. local hasteBonus = UNIT_CLASS == "HUNTER" and GetCombatRatingBonus(CR_HASTE_RANGED) or GetCombatRatingBonus(CR_HASTE_MELEE)
  2215.  
  2216. GameTooltip:AddDoubleLine(STAT_HASTE, format(modifierString, haste, hasteBonus), 1, 1, 1)
  2217. end
  2218.  
  2219. local masteryspell
  2220. if GetCombatRating(CR_MASTERY) ~= 0 and GetSpecialization() then
  2221. if UNIT_CLASS == "DRUID" then
  2222. if Role == "Melee" then
  2223. masteryspell = select(2, GetSpecializationMasterySpells(GetSpecialization()))
  2224. elseif Role == "Tank" then
  2225. masteryspell = select(1, GetSpecializationMasterySpells(GetSpecialization()))
  2226. else
  2227. masteryspell = GetSpecializationMasterySpells(GetSpecialization())
  2228. end
  2229. else
  2230. masteryspell = GetSpecializationMasterySpells(GetSpecialization())
  2231. end
  2232.  
  2233.  
  2234.  
  2235. local masteryName, _, _, _, _, _, _, _, _ = GetSpellInfo(masteryspell)
  2236. if masteryName then
  2237. GameTooltip:AddLine' '
  2238. GameTooltip:AddDoubleLine(masteryName, format(modifierString, GetCombatRating(CR_MASTERY), GetCombatRatingBonus(CR_MASTERY)), 1, 1, 1)
  2239. end
  2240. end
  2241.  
  2242. GameTooltip:Show()
  2243. end
  2244.  
  2245. local function UpdateTank(self)
  2246.  
  2247. -- the 5 is for base miss chance
  2248. if targetlv == -1 then
  2249. basemisschance = (5 - (3*.2))
  2250. leveldifference = 3
  2251. elseif targetlv > playerlv then
  2252. basemisschance = (5 - ((targetlv - playerlv)*.2))
  2253. leveldifference = (targetlv - playerlv)
  2254. elseif targetlv < playerlv and targetlv > 0 then
  2255. basemisschance = (5 + ((playerlv - targetlv)*.2))
  2256. leveldifference = (targetlv - playerlv)
  2257. else
  2258. basemisschance = 5
  2259. leveldifference = 0
  2260. end
  2261.  
  2262. if select(2, UnitRace("player")) == "NightElf" then basemisschance = basemisschance + 2 end
  2263.  
  2264. if leveldifference >= 0 then
  2265. dodge = (GetDodgeChance()-leveldifference*.2)
  2266. parry = (GetParryChance()-leveldifference*.2)
  2267. block = (GetBlockChance()-leveldifference*.2)
  2268. else
  2269. dodge = (GetDodgeChance()+abs(leveldifference*.2))
  2270. parry = (GetParryChance()+abs(leveldifference*.2))
  2271. block = (GetBlockChance()+abs(leveldifference*.2))
  2272. end
  2273.  
  2274. if dodge <= 0 then dodge = 0 end
  2275. if parry <= 0 then parry = 0 end
  2276. if block <= 0 then block = 0 end
  2277.  
  2278. if UNIT_CLASS == "DRUID" then
  2279. parry = 0
  2280. block = 0
  2281. elseif UNIT_CLASS == "DEATHKNIGHT" then
  2282. block = 0
  2283. end
  2284. avoidance = (dodge+parry+block+basemisschance)
  2285.  
  2286. Text:SetFormattedText(displayFloatString, hexa.."AVD: "..hexb, avoidance)
  2287. --Setup Tooltip
  2288. self:SetAllPoints(Text)
  2289. end
  2290.  
  2291. local function UpdateCaster(self)
  2292. if GetSpellBonusHealing() > GetSpellBonusDamage(7) then
  2293. spellpwr = GetSpellBonusHealing()
  2294. else
  2295. spellpwr = GetSpellBonusDamage(7)
  2296. end
  2297.  
  2298. Text:SetFormattedText(displayNumberString, hexa.."SP: "..hexb, spellpwr)
  2299. --Setup Tooltip
  2300. self:SetAllPoints(Text)
  2301. end
  2302.  
  2303. local function UpdateMelee(self)
  2304. local base, posBuff, negBuff = UnitAttackPower("player");
  2305. local effective = base + posBuff + negBuff;
  2306. local Rbase, RposBuff, RnegBuff = UnitRangedAttackPower("player");
  2307. local Reffective = Rbase + RposBuff + RnegBuff;
  2308.  
  2309. if UNIT_CLASS == "HUNTER" then
  2310. pwr = Reffective
  2311. else
  2312. pwr = effective
  2313. end
  2314.  
  2315. Text:SetFormattedText(displayNumberString, hexa.."AP: "..hexb, pwr)
  2316. --Setup Tooltip
  2317. self:SetAllPoints(Text)
  2318. end
  2319.  
  2320. -- initial delay for update (let the ui load)
  2321. local int = 5
  2322. local function Update(self, t)
  2323. int = int - t
  2324. if int > 0 then return end
  2325. if Role == "Tank" then
  2326. UpdateTank(self)
  2327. elseif Role == "Caster" then
  2328. UpdateCaster(self)
  2329. elseif Role == "Melee" then
  2330. UpdateMelee(self)
  2331. end
  2332. int = 2
  2333. end
  2334.  
  2335. Stat:SetScript("OnEnter", function() ShowTooltip(Stat) end)
  2336. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  2337. Stat:SetScript("OnUpdate", Update)
  2338. Update(Stat, 10)
  2339. end
  2340.  
  2341. -----------------
  2342. -- Statistics #2
  2343. -----------------
  2344. if db.stat2 then
  2345.  
  2346. local Stat = CreateFrame('Frame', nil, MainPanel)
  2347. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  2348. Stat:SetFrameStrata("BACKGROUND")
  2349. Stat:SetFrameLevel(3)
  2350. Stat:EnableMouse(true)
  2351.  
  2352. local Text = Stat:CreateFontString(nil, "OVERLAY")
  2353. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  2354. self:PlacePlugin(db.stat2, Text)
  2355.  
  2356. local _G = getfenv(0)
  2357. local format = string.format
  2358. local chanceString = "%.2f%%"
  2359. local armorString = hexa..ARMOR..hexb..": "
  2360. local modifierString = string.join("", "%d (+", chanceString, ")")
  2361. local baseArmor, effectiveArmor, armor, posBuff, negBuff
  2362. local displayNumberString = string.join("", "%s", "%d|r")
  2363. local displayFloatString = string.join("", "%s", "%.2f%%|r")
  2364. local level = UnitLevel("player")
  2365.  
  2366.  
  2367. local function CalculateMitigation(level, effective)
  2368. local mitigation
  2369.  
  2370. if not effective then
  2371. _, effective, _, _, _ = UnitArmor("player")
  2372. end
  2373.  
  2374. if level < 60 then
  2375. mitigation = (effective/(effective + 400 + (85 * level)));
  2376. else
  2377. mitigation = (effective/(effective + (467.5 * level - 22167.5)));
  2378. end
  2379. if mitigation > .75 then
  2380. mitigation = .75
  2381. end
  2382. return mitigation
  2383. end
  2384.  
  2385. local function AddTooltipHeader(description)
  2386. GameTooltip:AddLine(description)
  2387. GameTooltip:AddLine(' ')
  2388. end
  2389.  
  2390. local function ShowTooltip(self)
  2391. if InCombatLockdown() then return end
  2392.  
  2393. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  2394. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  2395. GameTooltip:ClearLines()
  2396. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Statistics")
  2397. GameTooltip:AddLine' '
  2398.  
  2399. if Role == "Tank" then
  2400. AddTooltipHeader("Mitigation By Level: ")
  2401. local lv = level +3
  2402. for i = 1, 4 do
  2403. GameTooltip:AddDoubleLine(lv,format(chanceString, CalculateMitigation(lv, effectiveArmor) * 100),1,1,1)
  2404. lv = lv - 1
  2405. end
  2406. lv = UnitLevel("target")
  2407. if lv and lv > 0 and (lv > level + 3 or lv < level) then
  2408. GameTooltip:AddDoubleLine(lv, format(chanceString, CalculateMitigation(lv, effectiveArmor) * 100),1,1,1)
  2409. end
  2410. elseif Role == "Caster" or Role == "Melee" then
  2411. AddTooltipHeader(MAGIC_RESISTANCES_COLON)
  2412.  
  2413. local base, total, bonus, minus
  2414. for i = 2, 6 do
  2415. base, total, bonus, minus = UnitResistance("player", i)
  2416. GameTooltip:AddDoubleLine(_G["DAMAGE_SCHOOL"..(i+1)], format(chanceString, (total / (total + (500 + level + 2.5))) * 100),1,1,1)
  2417. end
  2418.  
  2419. local spellpen = GetSpellPenetration()
  2420. if (UNIT_CLASS == "SHAMAN" or Role == "Caster") and spellpen > 0 then
  2421. GameTooltip:AddLine' '
  2422. GameTooltip:AddDoubleLine(ITEM_MOD_SPELL_PENETRATION_SHORT, spellpen,1,1,1)
  2423. end
  2424. end
  2425. GameTooltip:Show()
  2426. end
  2427.  
  2428. local function UpdateTank(self)
  2429. baseArmor, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player");
  2430.  
  2431. Text:SetFormattedText(displayNumberString, armorString, effectiveArmor)
  2432. --Setup Tooltip
  2433. self:SetAllPoints(Text)
  2434. end
  2435.  
  2436. local function UpdateCaster(self)
  2437. local spellcrit = GetSpellCritChance(1)
  2438.  
  2439. Text:SetFormattedText(displayFloatString, hexa.."Crit: "..hexb, spellcrit)
  2440. --Setup Tooltip
  2441. self:SetAllPoints(Text)
  2442. end
  2443.  
  2444. local function UpdateMelee(self)
  2445. local meleecrit = GetCritChance()
  2446. local rangedcrit = GetRangedCritChance()
  2447. local critChance
  2448.  
  2449. if UNIT_CLASS == "HUNTER" then
  2450. critChance = rangedcrit
  2451. else
  2452. critChance = meleecrit
  2453. end
  2454.  
  2455. Text:SetFormattedText(displayFloatString, hexa.."Crit: "..hexb, critChance)
  2456. --Setup Tooltip
  2457. self:SetAllPoints(Text)
  2458. end
  2459.  
  2460. -- initial delay for update (let the ui load)
  2461. local int = 5
  2462. local function Update(self, t)
  2463. int = int - t
  2464. if int > 0 then return end
  2465.  
  2466. if Role == "Tank" then
  2467. UpdateTank(self)
  2468. elseif Role == "Caster" then
  2469. UpdateCaster(self)
  2470. elseif Role == "Melee" then
  2471. UpdateMelee(self)
  2472. end
  2473. int = 2
  2474. end
  2475.  
  2476. Stat:SetScript("OnEnter", function() ShowTooltip(Stat) end)
  2477. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  2478. Stat:SetScript("OnUpdate", Update)
  2479. Update(Stat, 10)
  2480. end
  2481.  
  2482. -------------------
  2483. -- System Settings
  2484. -------------------
  2485. if db.system then
  2486.  
  2487. local Stat = CreateFrame('Frame', nil, MainPanel)
  2488. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  2489. Stat:SetFrameStrata("BACKGROUND")
  2490. Stat:SetFrameLevel(3)
  2491. Stat:EnableMouse(true)
  2492. Stat.tooltip = false
  2493.  
  2494. local Text = Stat:CreateFontString(nil, "OVERLAY")
  2495. Text:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize,'THINOUTLINE')
  2496. self:PlacePlugin(db.system, Text)
  2497.  
  2498. local bandwidthString = "%.2f Mbps"
  2499. local percentageString = "%.2f%%"
  2500. local homeLatencyString = "%d ms"
  2501. local worldLatencyString = "%d ms"
  2502. local kiloByteString = "%d kb"
  2503. local megaByteString = "%.2f mb"
  2504.  
  2505. local function formatMem(memory)
  2506. local mult = 10^1
  2507. if memory > 999 then
  2508. local mem = ((memory/1024) * mult) / mult
  2509. return string.format(megaByteString, mem)
  2510. else
  2511. local mem = (memory * mult) / mult
  2512. return string.format(kiloByteString, mem)
  2513. end
  2514. end
  2515.  
  2516. local memoryTable = {}
  2517.  
  2518. local function RebuildAddonList(self)
  2519. local addOnCount = GetNumAddOns()
  2520. if (addOnCount == #memoryTable) or self.tooltip == true then return end
  2521.  
  2522. -- Number of loaded addons changed, create new memoryTable for all addons
  2523. memoryTable = {}
  2524. for i = 1, addOnCount do
  2525. memoryTable[i] = { i, select(2, GetAddOnInfo(i)), 0, IsAddOnLoaded(i) }
  2526. end
  2527. self:SetAllPoints(Text)
  2528. end
  2529.  
  2530. local function UpdateMemory()
  2531. -- Update the memory usages of the addons
  2532. UpdateAddOnMemoryUsage()
  2533. -- Load memory usage in table
  2534. local addOnMem = 0
  2535. local totalMemory = 0
  2536. for i = 1, #memoryTable do
  2537. addOnMem = GetAddOnMemoryUsage(memoryTable[i][1])
  2538. memoryTable[i][3] = addOnMem
  2539. totalMemory = totalMemory + addOnMem
  2540. end
  2541. -- Sort the table to put the largest addon on top
  2542. table.sort(memoryTable, function(a, b)
  2543. if a and b then
  2544. return a[3] > b[3]
  2545. end
  2546. end)
  2547.  
  2548. return totalMemory
  2549. end
  2550.  
  2551. -- initial delay for update (let the ui load)
  2552. local int, int2 = 6, 5
  2553. local statusColors = {
  2554. "|cff0CD809",
  2555. "|cffE8DA0F",
  2556. "|cffFF9000",
  2557. "|cffD80909"
  2558. }
  2559.  
  2560. local function Update(self, t)
  2561. int = int - t
  2562. int2 = int2 - t
  2563.  
  2564. if int < 0 then
  2565. RebuildAddonList(self)
  2566. int = 10
  2567. end
  2568. if int2 < 0 then
  2569. local framerate = floor(GetFramerate())
  2570. local fpscolor = 4
  2571. local latency = select(4, GetNetStats())
  2572. local latencycolor = 4
  2573.  
  2574. if latency < 150 then
  2575. latencycolor = 1
  2576. elseif latency >= 150 and latency < 300 then
  2577. latencycolor = 2
  2578. elseif latency >= 300 and latency < 500 then
  2579. latencycolor = 3
  2580. end
  2581. if framerate >= 30 then
  2582. fpscolor = 1
  2583. elseif framerate >= 20 and framerate < 30 then
  2584. fpscolor = 2
  2585. elseif framerate >= 10 and framerate < 20 then
  2586. fpscolor = 3
  2587. end
  2588. local displayFormat = string.join("", hexa.."FPS: "..hexb, statusColors[fpscolor], "%d|r", hexa.." MS: "..hexb, statusColors[latencycolor], "%d|r")
  2589. Text:SetFormattedText(displayFormat, framerate, latency)
  2590. int2 = 1
  2591. end
  2592. end
  2593. Stat:SetScript("OnMouseDown", function () collectgarbage("collect") Update(Stat, 20) end)
  2594. Stat:SetScript("OnEnter", function(self)
  2595. if InCombatLockdown() then return end
  2596. local bandwidth = GetAvailableBandwidth()
  2597. local _, _, latencyHome, latencyWorld = GetNetStats()
  2598. local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  2599. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  2600. GameTooltip:ClearLines()
  2601. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Latency")
  2602. GameTooltip:AddLine' '
  2603. GameTooltip:AddDoubleLine("Home Latency: ", string.format(homeLatencyString, latencyHome), 0.80, 0.31, 0.31,0.84, 0.75, 0.65)
  2604. GameTooltip:AddDoubleLine("World Latency: ", string.format(worldLatencyString, latencyWorld), 0.80, 0.31, 0.31,0.84, 0.75, 0.65)
  2605.  
  2606. if bandwidth ~= 0 then
  2607. GameTooltip:AddDoubleLine(L.datatext_bandwidth , string.format(bandwidthString, bandwidth),0.69, 0.31, 0.31,0.84, 0.75, 0.65)
  2608. GameTooltip:AddDoubleLine("Download: " , string.format(percentageString, GetDownloadedPercentage() *100),0.69, 0.31, 0.31, 0.84, 0.75, 0.65)
  2609. GameTooltip:AddLine(" ")
  2610. end
  2611. local totalMemory = UpdateMemory()
  2612. GameTooltip:AddDoubleLine("Total Memory Usage:", formatMem(totalMemory), 0.69, 0.31, 0.31,0.84, 0.75, 0.65)
  2613. GameTooltip:AddLine(" ")
  2614. for i = 1, #memoryTable do
  2615. if (memoryTable[i][4]) then
  2616. local red = memoryTable[i][3] / totalMemory
  2617. local green = 1 - red
  2618. GameTooltip:AddDoubleLine(memoryTable[i][2], formatMem(memoryTable[i][3]), 1, 1, 1, red, green + .5, 0)
  2619. end
  2620. end
  2621. GameTooltip:Show()
  2622. end)
  2623. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  2624. Stat:SetScript("OnUpdate", Update)
  2625. Update(Stat, 10)
  2626. end
  2627. end
  2628.  
  2629. function MODULE:OnInitialize()
  2630. self.db = ADDON_NAME.db:RegisterNamespace(MODULE_NAME, defaults)
  2631. db = self.db.profile
  2632.  
  2633. local _, class = UnitClass("player")
  2634. classColor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  2635.  
  2636. self:SetEnabledState(ADDON_NAME:GetModuleEnabled(MODULE_NAME))
  2637. end
  2638.  
  2639.  
  2640. function MODULE:OnEnable()
  2641. -- This line should not be needed if you're using modules correctly:
  2642. if not db.enable then return end
  2643.  
  2644. if db.enable then -- How is this different than "enable" ? If the panel is not enabled, what's the point of doing anything else?
  2645. self:CreatePanel() -- factor this giant blob out into its own function to keep things clean
  2646. self:Refresh()
  2647. end
  2648. end
  2649.  
  2650. function MODULE:Refresh()
  2651. if InCombatLockdown() then
  2652. return self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEnable")
  2653. end
  2654. self:UnregisterEvent("PLAYER_REGEN_ENABLED")
  2655.  
  2656. self:CreateStats()
  2657. end
  2658.  
  2659. function MODULE:SetFontString(parent, file, size, flags)
  2660. local fs = parent:CreateFontString(nil, "OVERLAY")
  2661. fs:SetFont(file, size, flags)
  2662. fs:SetJustifyH("LEFT")
  2663. fs:SetShadowColor(0, 0, 0)
  2664. fs:SetShadowOffset(1.25, -1.25)
  2665. return fs
  2666. end
  2667.  
  2668. function MODULE:CreatePanel()
  2669.  
  2670. if MainPanel then return end -- already done
  2671.  
  2672. -- These are not "local" here because they're already "local" at the top of the file.
  2673. MainPanel = CreateFrame("Frame", "Datapanel", UIParent)
  2674. PanelLeft = CreateFrame("Frame", nil, MainPanel)
  2675. PanelCenter = CreateFrame("Frame", nil, MainPanel)
  2676. PanelRight = CreateFrame("Frame", nil, MainPanel)
  2677. BGPanel = CreateFrame("Frame", nil, MainPanel)
  2678.  
  2679.  
  2680. -- These are common to all panel styles, so don't duplicate code.
  2681. MainPanel:SetHeight(35)
  2682. MainPanel:SetFrameStrata("LOW")
  2683. MainPanel:SetBackdrop({ bgFile = db.background, edgeFile = db.border, edgeSize = 25, insets = { left = 5, right = 5, top = 5, bottom = 5 } })
  2684. MainPanel:SetBackdropColor(0, 0, 0, 1)
  2685.  
  2686. -- Setup the Panels
  2687. self:SetMainPanel()
  2688. self:SetPanelLeft()
  2689. self:SetPanelCenter()
  2690. self:SetPanelRight()
  2691.  
  2692. -- No Need for function it always sets it self on the PanelLeft
  2693. BGPanel:SetAllPoints(PanelLeft)
  2694. BGPanel:SetFrameStrata("LOW")
  2695. BGPanel:SetFrameLevel(1)
  2696.  
  2697. -- Move some Objects for the Datapanel
  2698. self:MoveObjects()
  2699.  
  2700. end
  2701.  
  2702.  
  2703. ------------------------------------------------------------------------
  2704. -- Module Options
  2705. ------------------------------------------------------------------------
  2706.  
  2707. local options
  2708. function MODULE:GetOptions()
  2709. if options then
  2710. return options
  2711. end
  2712.  
  2713. local function isModuleDisabled()
  2714. return not ADDON_NAME:GetModuleEnabled(MODULE_NAME)
  2715. end
  2716.  
  2717. local statposition = {
  2718. ["P0"] = L["Not Shown"],
  2719. ["P1"] = L["Position #1"],
  2720. ["P2"] = L["Position #2"],
  2721. ["P3"] = L["Position #3"],
  2722. ["P4"] = L["Position #4"],
  2723. ["P5"] = L["Position #5"],
  2724. ["P6"] = L["Position #6"],
  2725. ["P7"] = L["Position #7"],
  2726. ["P8"] = L["Position #8"],
  2727. ["P9"] = L["Position #9"],
  2728. }
  2729.  
  2730. local locate = {
  2731. ['top'] = L['Top'],
  2732. ['bottom'] = L['Bottom'],
  2733. }
  2734.  
  2735. options = {
  2736. type = "group",
  2737. name = L[MODULE_NAME],
  2738. childGroups = "tree",
  2739. get = function(info) return db[ info[#info] ] end,
  2740. set = function(info, value) db[ info[#info] ] = value; end,
  2741. disabled = isModuleDisabled(),
  2742. args = {
  2743. ---------------------------
  2744. --Option Type Seperators
  2745. sep1 = {
  2746. type = "description",
  2747. order = 2,
  2748. name = " ",
  2749. },
  2750. sep2 = {
  2751. type = "description",
  2752. order = 3,
  2753. name = " ",
  2754. },
  2755. sep3 = {
  2756. type = "description",
  2757. order = 4,
  2758. name = " ",
  2759. },
  2760. sep4 = {
  2761. type = "description",
  2762. order = 5,
  2763. name = " ",
  2764. },
  2765. ---------------------------
  2766. reloadUI = {
  2767. type = "execute",
  2768. name = "Reload UI",
  2769. desc = " ",
  2770. order = 0,
  2771. func = function()
  2772. ReloadUI()
  2773. end,
  2774. },
  2775. Text = {
  2776. type = "description",
  2777. order = 0,
  2778. name = "When changes are made a reload of the UI is needed.",
  2779. width = "full",
  2780. },
  2781. Text1 = {
  2782. type = "description",
  2783. order = 1,
  2784. name = " ",
  2785. width = "full",
  2786. },
  2787. enable = {
  2788. type = "toggle",
  2789. order = 1,
  2790. name = L["Enable Datapanel Module"],
  2791. width = "full"
  2792. },
  2793. location = {
  2794. order = 3,
  2795. name = L["Location"],
  2796. desc = L["Choose the location of the datapanel."],
  2797. disabled = function() return isModuleDisabled() or not db.enable end,
  2798. type = "select",
  2799. values = locate;
  2800. },
  2801. time24 = {
  2802. type = "toggle",
  2803. order = 2,
  2804. name = L["24-Hour Time"],
  2805. desc = L["Display time datapanel on a 24 hour time scale"],
  2806. disabled = function() return isModuleDisabled() or not db.enable end,
  2807. },
  2808. bag = {
  2809. type = "toggle",
  2810. order = 2,
  2811. name = L["Bag Open"],
  2812. desc = L["Checked opens Backpack only, Unchecked opens all bags."],
  2813. disabled = function() return isModuleDisabled() or not db.enable end,
  2814. },
  2815. battleground = {
  2816. type = "toggle",
  2817. order = 2,
  2818. name = L["Battleground Text"],
  2819. desc = L["Display special datapanels when inside a battleground"],
  2820. disabled = function() return isModuleDisabled() or not db.enable end,
  2821. },
  2822. recountraiddps = {
  2823. type = "toggle",
  2824. order = 2,
  2825. name = L["Recount Raid DPS"],
  2826. desc = L["Display Recount's Raid DPS (RECOUNT MUST BE INSTALLED)"],
  2827. disabled = function() return isModuleDisabled() or not db.enable end,
  2828. },
  2829. DataGroup = {
  2830. type = "group",
  2831. order = 6,
  2832. name = L["Text Positions"],
  2833. guiInline = true,
  2834. disabled = function() return isModuleDisabled() or not db.enable end,
  2835. args = {
  2836. ---------------------------
  2837. --Option Type Seperators
  2838. sep1 = {
  2839. type = "description",
  2840. order = 2,
  2841. name = " ",
  2842. },
  2843. sep2 = {
  2844. type = "description",
  2845. order = 3,
  2846. name = " ",
  2847. },
  2848. sep3 = {
  2849. type = "description",
  2850. order = 4,
  2851. name = " ",
  2852. },
  2853. sep4 = {
  2854. type = "description",
  2855. order = 5,
  2856. name = " ",
  2857. },
  2858. ---------------------------
  2859. bags = {
  2860. type = "select",
  2861. order = 5,
  2862. name = L["Bags"],
  2863. desc = L["Display amount of bag space"],
  2864. values = statposition;
  2865. disabled = function() return isModuleDisabled() or not db.enable end,
  2866. },
  2867. calltoarms = {
  2868. type = "select",
  2869. order = 5,
  2870. name = L["Call to Arms"],
  2871. desc = L["Display the active roles that will recieve a reward for completing a random dungeon"],
  2872. values = statposition;
  2873. disabled = function() return isModuleDisabled() or not db.enable end,
  2874. },
  2875. coords = {
  2876. type = "select",
  2877. order = 5,
  2878. name = L["Coordinates"],
  2879. desc = L["Display Player's Coordinates"],
  2880. values = statposition;
  2881. disabled = function() return isModuleDisabled() or not db.enable end,
  2882. },
  2883. dps_text = {
  2884. type = "select",
  2885. order = 5,
  2886. name = L["DPS"],
  2887. desc = L["Display amount of DPS"],
  2888. values = statposition;
  2889. disabled = function() return isModuleDisabled() or not db.enable end,
  2890. },
  2891. dur = {
  2892. type = "select",
  2893. order = 5,
  2894. name = L["Durability"],
  2895. desc = L["Display your current durability"],
  2896. values = statposition;
  2897. disabled = function() return isModuleDisabled() or not db.enable end,
  2898. },
  2899. friends = {
  2900. type = "select",
  2901. order = 5,
  2902. name = L["Friends"],
  2903. desc = L["Display current online friends"],
  2904. values = statposition;
  2905. disabled = function() return isModuleDisabled() or not db.enable end,
  2906. },
  2907. guild = {
  2908. type = "select",
  2909. order = 5,
  2910. name = L["Guild"],
  2911. desc = L["Display current online people in guild"],
  2912. values = statposition;
  2913. disabled = function() return isModuleDisabled() or not db.enable end,
  2914. },
  2915. hps_text = {
  2916. type = "select",
  2917. order = 5,
  2918. name = L["HPS"],
  2919. desc = L["Display amount of HPS"],
  2920. values = statposition;
  2921. disabled = function() return isModuleDisabled() or not db.enable end,
  2922. },
  2923. pro = {
  2924. type = "select",
  2925. order = 5,
  2926. name = L["Professions"],
  2927. desc = L["Display Professions"],
  2928. values = statposition;
  2929. disabled = function() return isModuleDisabled() or not db.enable end,
  2930. },
  2931. recount = {
  2932. type = "select",
  2933. order = 5,
  2934. name = L["Recount"],
  2935. desc = L["Display Recount's DPS (RECOUNT MUST BE INSTALLED)"],
  2936. values = statposition;
  2937. disabled = function() return isModuleDisabled() or not db.enable end,
  2938. },
  2939. spec = {
  2940. type = "select",
  2941. order = 5,
  2942. name = L["Talent Spec"],
  2943. desc = L["Display current spec"],
  2944. values = statposition;
  2945. disabled = function() return isModuleDisabled() or not db.enable end,
  2946. },
  2947. stat1 = {
  2948. type = "select",
  2949. order = 5,
  2950. name = L["Stat #1"],
  2951. desc = L["Display stat based on your role (Avoidance-Tank, AP-Melee, SP/HP-Caster)"],
  2952. values = statposition;
  2953. disabled = function() return isModuleDisabled() or not db.enable end,
  2954. },
  2955. stat2 = {
  2956. type = "select",
  2957. order = 5,
  2958. name = L["Stat #2"],
  2959. desc = L["Display stat based on your role (Armor-Tank, Crit-Melee, Crit-Caster)"],
  2960. values = statposition;
  2961. disabled = function() return isModuleDisabled() or not db.enable end,
  2962. },
  2963. system = {
  2964. type = "select",
  2965. order = 5,
  2966. name = L["System"],
  2967. desc = L["Display FPS and Latency"],
  2968. values = statposition;
  2969. disabled = function() return isModuleDisabled() or not db.enable end,
  2970. },
  2971. },
  2972. },
  2973. },
  2974. }
  2975. return options
  2976. end
Add Comment
Please, Sign In to add comment