WoWInterface - View Single Post - GetSpellInfo changes in WOD beta
View Single Post
10-12-14, 01:05 AM   #10
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The common texts in tooltips (X mana, Y rage, Z energy, etc.) all use strings from GlobalStrings.lua, so you can just pick out the strings (Blizzard uses them with string.format) and convert them for use with string.match.

For example, the "X mana" string is contained in the global variable MANA_COST, and I use the following code to make spell tooltips show the mana costs of spells as a percent of my total mana pool instead of as a raw number; the lines I highlighted in green will be the most relevant for you.

	local MANA_COST_PATTERN = gsub(MANA_COST, "%%d", "([%%d%.,]+)")
	local MANA_COST_TEXT = gsub(MANA_COST, "%%d", "%%d%%%%")

	GameTooltip:HookScript("OnTooltipSetSpell", function()
		for i = 2, 4 do
			local line = _G["GameTooltipTextLeft"..i]
			local text = line:GetText()
			if text then
				local cost = strmatch(text, MANA_COST_PATTERN)
				cost = cost and tonumber((gsub(cost, "%D", "")))
				if cost then
					local pool = UnitPowerMax(UnitInVehicle("player") and "vehicle" or "player")
					if cost > 0 and cost <= pool then
						return line:SetFormattedText(MANA_COST_TEXT, cost / pool * 100 + 0.5)
Edit: You will need to do a little more work to "patternize" strings with singular/plural variations, but you should be able to figure it out pretty easily by looking at the global strings for each locale (link above).
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.

Last edited by Phanx : 10-12-14 at 01:25 AM.