View Single Post
02-23-14, 08:16 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I vaguely remember posting that... not sure if it was in my original version, or from your edits, but here's a slightly more efficient version:
Code:
local shorts = {
	{ 1e10, 1e9, "%.0fb" }, --  10b+ as  12b
	{  1e9, 1e9, "%.1fb" }, --   1b+ as 8.3b
	{  1e7, 1e6, "%.0fm" }, --  10m+ as  14m
	{  1e6, 1e6, "%.1fm" }, --   1m+ as 7.4m
	{  1e5, 1e3, "%.0fk" }, -- 100k+ as 840k
	{  1e3, 1e3, "%.1fk" }, --   1k+ as 2.5k
	{    0,   1,    "%d" }, -- < 1k  as  974
}
for i = 1, #shorts do
	shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
end

hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
	local style = GetCVar("statusTextDisplay")
	if style == "PERCENT" then
		return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
	end
	for i = 1, #shorts do
		local t = shorts[i]
		if value >= t[1] then
			if style == "BOTH" then
				return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
			else
				return fontString:SetFormattedText(t[3], value / t[2])				
			end
		end
	end
end)
There's no point in checking the style twice for every threshold; just check it once after you find the applicable threshold.

Originally Posted by cokedrivers View Post
Now just to search and figure out how to adjust the size of Healthbar/Manabar fonts for each unitframe.
Generally, if you just want to change the size of a fontstring, while preserving the other properties:

Code:
local font, _, flags = fontstring:GetFont()
fontstring:SetFont(font, 18, flags) -- 18 being your new size
However, since the text on health and mana bars inherits from the TextStatusBarText font object, if you want them all to be the same size, it's easier just to change the font object; your changes will propigate to all fontstrings using it, and you only need to do it once, instead of once for each frame:

Code:
local font, _, flags = TextStatusBarText:GetFont()
TextStatusBarText:SetFont(font, 18, flags) -- 18 being your new size
__________________
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.
  Reply With Quote