Guest User

Datapanel

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