View Single Post
02-23-14, 10:50 PM   #5
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Phanx View Post
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.



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
Thank You for the help.

I want to be able to adjust each frames font size individually per what the user wants.

I think ill just stick with doing it the long way per frame.

Thanks
Coke

PS this is what im talking about the long way.

My current unitframes addon:
Code:
local B, C, DB = unpack(select(2, ...)) -- Import:  B - function; C - config; DB - Database

if C["unitframes"].enable ~= true then return end


-- Special Thanks to the guys over at Arena Junkies for most of these scripts
-- http://www.arenajunkies.com/topic/222642-default-ui-scripts/

local _G = _G


-- Player Frame
if C["unitframes"].player.enable then

	-- Frame Scale
	_G["PlayerFrame"]:SetScale(C["unitframes"].player.scale);	
	PlayerFrameHealthBarText:SetFont(C["media"].font, C["unitframes"].player.fontSize,"THINOUTLINE");
	PlayerFrameManaBarText:SetFont(C["media"].font, C["unitframes"].player.fontSize, "THINOUTLINE");
	PlayerFrameAlternateManaBarText:SetFont(C["media"].font, C["unitframes"].player.fontSize, "THINOUTLINE");
	PetFrameHealthBarText:SetFont(C["media"].font, C["unitframes"].player.fontSizepet,"THINOUTLINE");
	PetFrameManaBarText:SetFont(C["media"].font, C["unitframes"].player.fontSizepet, "THINOUTLINE");

end

-- Target Frame
if C["unitframes"].target.enable then

	-- Frame Scale
	 _G["TargetFrame"]:SetScale(C["unitframes"].target.scale);
 	TargetFrameTextureFrameHealthBarText:SetFont(C["media"].font, C["unitframes"].target.fontSize, "THINOUTLINE");
	TargetFrameTextureFrameManaBarText:SetFont(C["media"].font, C["unitframes"].target.fontSize, "THINOUTLINE");

end;

-- Focus Frame
if C["unitframes"].focus.enable then

	-- Frame Scale
	 _G["FocusFrame"]:SetScale(C["unitframes"].focus.scale)
	FocusFrameTextureFrameHealthBarText:SetFont(C["media"].font, C["unitframes"].focus.fontSize,"THINOUTLINE")
	FocusFrameTextureFrameManaBarText:SetFont(C["media"].font, C["unitframes"].focus.fontSize,"THINOUTLINE")

end;


-- Party Frames --
if C["unitframes"].party.enable then

	-- Clear all old settings
	PartyMemberFrame1:ClearAllPoints();
	PartyMemberFrame2:ClearAllPoints();
	PartyMemberFrame3:ClearAllPoints();
	PartyMemberFrame4:ClearAllPoints();

	-- Create new locations
	PartyMemberFrame1:SetPoint(C['unitframes'].party.position.relAnchor, UIParent, C['unitframes'].party.position.offSetX, C['unitframes'].party.position.offSetY);
	PartyMemberFrame2:SetPoint("TOPLEFT", PartyMemberFrame1, 0, -75);
	PartyMemberFrame3:SetPoint("TOPLEFT", PartyMemberFrame2, 0, -75);
	PartyMemberFrame4:SetPoint("TOPLEFT", PartyMemberFrame3, 0, -75);

	-- Make the new locations stay
	PartyMemberFrame1.SetPoint = function() end;
	PartyMemberFrame2.SetPoint = function() end;
	PartyMemberFrame3.SetPoint = function() end;
	PartyMemberFrame4.SetPoint = function() end;

	-- Set the scale of all the frames
	PartyMemberFrame1:SetScale(C["unitframes"].party.scale);
	PartyMemberFrame2:SetScale(C["unitframes"].party.scale);
	PartyMemberFrame3:SetScale(C["unitframes"].party.scale);
	PartyMemberFrame4:SetScale(C["unitframes"].party.scale);
	
	-- Set Font Size
	PartyMemberFrame1HealthBarText:SetFont(C["media"].font, C["unitframes"].party.fontSize, "THINOUTLINE")
	PartyMemberFrame1ManaBarText:SetFont(C["media"].font, C["unitframes"].party.fontSize, "THINOUTLINE")
	PartyMemberFrame2HealthBarText:SetFont(C["media"].font, C["unitframes"].party.fontSize, "THINOUTLINE")
	PartyMemberFrame2ManaBarText:SetFont(C["media"].font, C["unitframes"].party.fontSize, "THINOUTLINE")
	PartyMemberFrame3HealthBarText:SetFont(C["media"].font, C["unitframes"].party.fontSize, "THINOUTLINE")
	PartyMemberFrame3ManaBarText:SetFont(C["media"].font, C["unitframes"].party.fontSize, "THINOUTLINE")
	PartyMemberFrame4HealthBarText:SetFont(C["media"].font, C["unitframes"].party.fontSize, "THINOUTLINE")
	PartyMemberFrame4ManaBarText:SetFont(C["media"].font, C["unitframes"].party.fontSize, "THINOUTLINE")
end;

 -- Arena Frames
if C["unitframes"].arena.enable then
	LoadAddOn("Blizzard_ArenaUI"); -- You only need to run this once. You can safely delete any copies of this line.
	 
	ArenaEnemyFrames:SetScale(C["unitframes"].arena.scale);
	
	ArenaEnemyFrame1HealthBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize,"THINOUTLINE");
	ArenaEnemyFrame1ManaBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize, "THINOUTLINE");
	ArenaEnemyFrame2HealthBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize,"THINOUTLINE");
	ArenaEnemyFrame2ManaBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize, "THINOUTLINE");
	ArenaEnemyFrame3HealthBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize,"THINOUTLINE");
	ArenaEnemyFrame3ManaBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize, "THINOUTLINE");
	ArenaEnemyFrame4HealthBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize,"THINOUTLINE");
	ArenaEnemyFrame4ManaBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize, "THINOUTLINE");
	ArenaEnemyFrame5HealthBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize,"THINOUTLINE");
	ArenaEnemyFrame5ManaBarText:SetFont(C["media"].font, C["unitframes"].arena.fontSize, "THINOUTLINE");


	if C["unitframes"].arena.tracker == true then
		trinkets = {};
		local arenaFrame,trinket;
		for i = 1, 5 do
			arenaFrame = "ArenaEnemyFrame"..i;
			trinket = CreateFrame("Cooldown", arenaFrame.."Trinket", ArenaEnemyFrames);
			trinket:SetPoint("TOPRIGHT", arenaFrame, 30, -6);
			trinket:SetSize(24, 24);
			trinket.icon = trinket:CreateTexture(nil, "BACKGROUND");
			trinket.icon:SetAllPoints();
			trinket.icon:SetTexture("Interface\\Icons\\inv_jewelry_trinketpvp_01");
			trinket:Hide();
			trinkets["arena"..i] = trinket;
		end;
		local events = CreateFrame("Frame");
		function events:UNIT_SPELLCAST_SUCCEEDED(unitID, spell, rank, lineID, spellID)
			if not trinkets[unitID] then
				return;
			end ;       
			if spellID == 59752 or spellID == 42292 then
				CooldownFrame_SetTimer(trinkets[unitID], GetTime(), 120, 1);
				SendChatMessage("Trinket used by: "..GetUnitName(unitID, true), "PARTY");
			end;
		end;
		function events:PLAYER_ENTERING_WORLD()
			local _, instanceType = IsInInstance();
			if instanceType == "arena" then
				self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
			elseif self:IsEventRegistered("UNIT_SPELLCAST_SUCCEEDED") then
				self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED"); 
				for _, trinket in pairs(trinkets) do
					trinket:SetCooldown(0, 0);
					trinket:Hide();
				end;        
			end;
		end;
		events:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end);
		events:RegisterEvent("PLAYER_ENTERING_WORLD");
	end;
end;

 -- Boss Frames
if C["unitframes"].boss.enable then
	for i = 1,4 do
		local boss = _G["Boss"..i.."TargetFrame"];
		if boss then
			boss:SetScale(C["unitframes"].boss.scale)
			boss:ClearAllPoints();
			boss:SetPoint(C['unitframes'].boss.position.relAnchor, UIParent, C['unitframes'].boss.position.offSetX, C['unitframes'].boss.position.offSetY);
			boss.ClearAllPoints = function() end;
			boss.SetPoint = function() end;		
		end;
	end;
end;

-- Font Style thanks to Phanx from WoWinterface.
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)

-- Disable healing/damage spam over player/pet frame:
PlayerHitIndicator:SetText(nil)
PlayerHitIndicator.SetText = function() end
PetHitIndicator:SetText(nil)
PetHitIndicator.SetText = function() end
  Reply With Quote