/Tukui/modules/datatext/expertise.lua

http://github.com/Asphyxia/Tukui · Lua · 111 lines · 91 code · 14 blank · 6 comment · 18 complexity · 2e10fb4c499c1ce089b343a60c0c0bb5 MD5 · raw file

  1. -----------------------------------------
  2. -- Expertise Rating
  3. -----------------------------------------
  4. local T, C, L = unpack(select(2, ...)) -- Import Functions/Constants, Config, Locales
  5. if not C["datatext"].expertise or C["datatext"].expertise == 0 then return end
  6. local Stat = CreateFrame("Frame")
  7. Stat:SetFrameStrata("MEDIUM")
  8. Stat:EnableMouse(true)
  9. Stat:SetFrameLevel(3)
  10. local Text = TukuiInfoLeft:CreateFontString(nil, "LOW")
  11. Text:SetFont(C["media"].pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  12. Text:SetShadowOffset(T.mult, -T.mult)
  13. T.PP(C["datatext"].expertise, Text)
  14. Stat:SetParent(Text:GetParent())
  15. local _G = getfenv(0)
  16. local format = string.format
  17. local displayModifierString = string.join("", "%s", T.datacolor, "%d|r")
  18. -- initial delay for update (let the ui load)
  19. local int = 5
  20. local function Update(self, t)
  21. int = int - t
  22. if int > 0 then return end
  23. local expertise, offhandExpertise = GetExpertise();
  24. local speed, offhandSpeed = UnitAttackSpeed("player");
  25. local text;
  26. if( offhandSpeed ) then
  27. text = expertise.." / "..offhandExpertise;
  28. else
  29. text = expertise;
  30. end
  31. Text:SetFormattedText(displayModifierString, STAT_EXPERTISE..": ", text)
  32. self:SetAllPoints(Text)
  33. int = 2
  34. end
  35. Stat:SetScript('OnEnter', function(self)
  36. local anchor, panel, xoff, yoff = T.DataTextTooltipAnchor(Text)
  37. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  38. GameTooltip:ClearLines()
  39. local expertise, offhandExpertise = GetExpertise();
  40. local expertisePercent, offhandExpertisePercent = GetExpertisePercent();
  41. expertisePercent = format("%.2f", expertisePercent);
  42. offhandExpertisePercent = format("%.2f", offhandExpertisePercent);
  43. local expertiseDisplay, expertisePercentDisplay;
  44. if (IsDualWielding()) then
  45. expertiseDisplay = expertise.." / "..offhandExpertise;
  46. expertisePercentDisplay = expertisePercent.."% / "..offhandExpertisePercent.."%";
  47. else
  48. expertiseDisplay = expertise;
  49. expertisePercentDisplay = expertisePercent.."%";
  50. end
  51. GameTooltip:SetText(HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, _G["COMBAT_RATING_NAME"..CR_EXPERTISE]).." "..expertiseDisplay..FONT_COLOR_CODE_CLOSE);
  52. GameTooltip:AddLine(format(CR_EXPERTISE_TOOLTIP, expertisePercentDisplay, GetCombatRating(CR_EXPERTISE), GetCombatRatingBonus(CR_EXPERTISE)), NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, true);
  53. GameTooltip:AddLine(" ");
  54. -- Dodge chance
  55. GameTooltip:AddDoubleLine(STAT_TARGET_LEVEL, DODGE_CHANCE, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
  56. local playerLevel = UnitLevel("player");
  57. for i=0, 3 do
  58. local mainhandDodge, offhandDodge = GetEnemyDodgeChance(i);
  59. mainhandDodge = format("%.2f%%", mainhandDodge);
  60. offhandDodge = format("%.2f%%", offhandDodge);
  61. local level = playerLevel + i;
  62. if (i == 3) then
  63. level = level.." / |TInterface\\TargetingFrame\\UI-TargetingFrame-Skull:0|t";
  64. end
  65. local dodgeDisplay;
  66. if (IsDualWielding() and mainhandDodge ~= offhandDodge) then
  67. dodgeDisplay = mainhandDodge.." / "..offhandDodge;
  68. else
  69. dodgeDisplay = mainhandDodge.." ";
  70. end
  71. GameTooltip:AddDoubleLine(" "..level, dodgeDisplay.." ", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
  72. end
  73. -- Parry chance
  74. GameTooltip:AddLine(" ");
  75. GameTooltip:AddDoubleLine(STAT_TARGET_LEVEL, PARRY_CHANCE, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
  76. local playerLevel = UnitLevel("player");
  77. for i=0, 3 do
  78. local mainhandParry, offhandParry = GetEnemyParryChance(i);
  79. mainhandParry = format("%.2f%%", mainhandParry);
  80. offhandParry = format("%.2f%%", offhandParry);
  81. local level = playerLevel + i;
  82. if (i == 3) then
  83. level = level.." / |TInterface\\TargetingFrame\\UI-TargetingFrame-Skull:0|t";
  84. end
  85. local parryDisplay;
  86. if (IsDualWielding() and mainhandParry ~= offhandParry) then
  87. parryDisplay = mainhandParry.." / "..offhandParry;
  88. else
  89. parryDisplay = mainhandParry.." ";
  90. end
  91. GameTooltip:AddDoubleLine(" "..level, parryDisplay.." ", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
  92. end
  93. GameTooltip:Show()
  94. end)
  95. Stat:SetScript('OnLeave', function() GameTooltip:Hide() end)
  96. Stat:SetScript("OnUpdate", Update)
  97. Update(Stat, 6)