Thread Tools Display Modes
02-22-14, 07:57 PM   #1
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Help with some Font settings

EDIT:

Disreguard this post..

Was able to work most of the issues out with the "search" function.

for those that might want to see the code im currently using.

This code was posted by Phanx and editied to my likeing.
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 style == "NUMERIC" then
			if value >= t[1] then
					return fontString:SetFormattedText(t[3], value / t[2])				
			end
		end
		if style == "BOTH" then		
			if value >= t[1] then
					return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)				
			end
		end	
	end
end)
Now just to search and figure out how to adjust the size of Healthbar/Manabar fonts for each unitframe.

Coke

Last edited by cokedrivers : 02-23-14 at 10:31 AM.
  Reply With Quote
02-22-14, 08:09 PM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Öhm.

What is C["unitframes"].fontStyle and where does it come from?
  Reply With Quote
02-23-14, 11:56 AM   #3
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
I've been able to do the following for the player but how would I do this for Arean and boss frames?

Code:
	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");
  Reply With Quote
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
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
03-02-14, 01:57 PM   #6
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
One more question concerning font.

How can I make the following font classcolor to match the person:
  • Me
  • Pet
  • Target
  • Target of Target
  • Party Members

Thanks for any help with this.
  Reply With Quote
03-02-14, 07:47 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The simplest solution is probably going to be to hook the function that sets the text:

Code:
hooksecurefunc("UnitFrame_Update", function(self)
	if not self.name then return end

	if UnitIsPlayer(self.unit) then
		-- Color by class:
		local _, class = UnitClass(self.unit)
		local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
		self.name:SetTextColor(color.r, color.g, color.b)
	else
		-- Not a player. Return to default color:
		self.name:SetTextColor(1, 0.82, 0)
	end
end)
Feel free to color non-players by reaction instead of using the default color.

If you wanted to color pets by their owner's class, the simplest solution would probably be to look at the pet's creature type and just make an assumption -- eg. beast = hunter, demon = warlock, etc.
__________________
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
03-04-14, 03:18 PM   #8
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
The simplest solution is probably going to be to hook the function that sets the text:

Code:
hooksecurefunc("UnitFrame_Update", function(self)
	if not self.name then return end

	if UnitIsPlayer(self.unit) then
		-- Color by class:
		local _, class = UnitClass(self.unit)
		local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
		self.name:SetTextColor(color.r, color.g, color.b)
	else
		-- Not a player. Return to default color:
		self.name:SetTextColor(1, 0.82, 0)
	end
end)
Feel free to color non-players by reaction instead of using the default color.

If you wanted to color pets by their owner's class, the simplest solution would probably be to look at the pet's creature type and just make an assumption -- eg. beast = hunter, demon = warlock, etc.

Thank you for this it works great.

Im confused on trying to do the "reaction" part.

I've tried:
Code:
		self.name:SetTextColor(FACTION_BAR_COLORS[reaction].r, FACTION_BAR_COLORS[reaction].g, FACTION_BAR_COLORS[reaction].b)
but I keep getting errors.

Even tried:
Code:
		FACTION_BAR_COLORS = {
			[1] = {r = 0.8, g = 0.3, b = 0.22},
			[2] = {r = 0.8, g = 0.3, b = 0.22},
			[3] = {r = 0.75, g = 0.27, b = 0},
			[4] = {r = 0.9, g = 0.7, b = 0},
			[5] = {r = 0, g = 0.6, b = 0.1},
			[6] = {r = 0, g = 0.6, b = 0.1},
			[7] = {r = 0, g = 0.6, b = 0.1},
			[8] = {r = 0, g = 0.6, b = 0.1},
		};		
		local reaction = UnitReaction(self.unit, "player");
		self.name:SetTextColor(FACTION_BAR_COLORS[reaction].r, FACTION_BAR_COLORS[reaction].g, FACTION_BAR_COLORS[reaction].b)
so any help would be great.

and thanks again for all your help.

Coke

P.S.
Error I keep getting:
Code:
Message: ...ace\AddOns\BasicUI\Modules\Unitframes\Unitframes.lua:199: attempt to index field '?' (a nil value)
Time: 03/04/14 13:18:37
Count: 5
Stack: ...ace\AddOns\BasicUI\Modules\Unitframes\Unitframes.lua:199: in function <...ace\AddOns\BasicUI\Modules\Unitframes\Unitframes.lua:188>
[C]: in function `UnitFrame_Update'
...terface\AddOns\Blizzard_ArenaUI\Blizzard_ArenaUI.lua:275: in function `ArenaEnemyFrame_UpdatePet'
...terface\AddOns\Blizzard_ArenaUI\Blizzard_ArenaUI.lua:47: in function <...terface\AddOns\Blizzard_ArenaUI\Blizzard_ArenaUI.lua:25>

Locals: self = ArenaEnemyFrame5PetFrame {
 0 = <userdata>
 menu = <function> defined @Interface\AddOns\Blizzard_ArenaUI\Blizzard_ArenaUI.lua:295
 name = ArenaEnemyFrame5PetFrameName {
 }
 DropDown = ArenaEnemyFrame5PetFrameDropDown {
 }
 manabar = ArenaEnemyFrame5PetFrameManaBar {
 }
 portrait = ArenaEnemyFrame5PetFramePortrait {
 }
 healthbar = ArenaEnemyFrame5PetFrameHealthBar {
 }
 unit = "arenapet5"
}
reaction = nil
(*temporary) = <function> defined =[C]:-1
(*temporary) = ArenaEnemyFrame5PetFrameName {
 0 = <userdata>
}
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index field '?' (a nil value)"

Last edited by cokedrivers : 03-04-14 at 03:23 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help with some Font settings


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off