View Single Post
12-20-16, 12:48 PM   #3
briskman3000
A Flamescale Wyrmkin
 
briskman3000's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 108
Originally Posted by Lombra View Post
Should be fairly straightforward. Assuming you want to add the info to the game tooltip, you need to hook for example the OnTooltipSetItem script, parse all tooltip lines and edit the text accordingly.

Something like this:
Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self)
	for i = 1, self:NumLines()
		local line = _G["GameTooltipTextLeft"..i]
		if line then
			local text = line:GetText()
			if textContainsRatingValues() then
				line:SetText("Replace text with this")
			end
		end
	end
end)
So from how I'm reading the code you wrote, the first line is the event that fires when you mouse-over an item and then it runs the function(self) code, which is below that line.

The code then basically does a foreach() on each line of text to see if that line has a combat rating value, and then would add the output that is set in that last line.

What I don't see is how it would determine which combat rating the line of text actually contains in order to put the appropriate converted value in each line.

Would something like this work?

Note: This below assumes that the tooltip text is parsed as actual text, and not as the internal stat variable name for example "Critical Strike" vs ITEM_MOD_CRIT_RATING_SHORT

The p"stat" variables are what should contain the rating number converted to a percentage in the code
Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self)
	for i = 1, self:NumLines()
		local line = _G["GameTooltipTextLeft"..i]
		if line then
			local text = line:GetText()
			if textContainsRatingValues() then
                              if text = "Critical Strike" then
				line:SetText(tostring(pcrit) .. "%") else
                              if text = "Haste" then
                                line:SetText(tostring(phaste) .. "%") else
                              if text = "Mastery" then
                                line:SetText(tostring(pmastery) .. "%") else
                              if text = "Versatility" then
                                line:SetText(tostring(pversin) .. "%/" .. tostring(pversout) .. "%") 
                              end
			end
		end
	end

Last edited by briskman3000 : 12-20-16 at 12:50 PM.
  Reply With Quote