PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/Tukui/modules/datatext/expertise.lua

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