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
03-04-14, 06:51 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Post your entire code if you want help with it. Your snippet refers to a variable that may or may not be defined correctly or incorrectly or at all somewhere else, but you didn't post that part, so it really tells me nothing.
__________________
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, 08:29 PM   #10
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Entire Code

Sorry about that.

Unitframes.lua:
Lua Code:
  1. local B, C, DB = unpack(select(2, ...)) -- Import:  B - function; C - config; DB - Database
  2.  
  3. if C["unitframes"].enable ~= true then return end
  4.  
  5.  
  6. -- Special Thanks to the guys over at Arena Junkies for most of these scripts
  7. -- [url]http://www.arenajunkies.com/topic/222642-default-ui-scripts/[/url]
  8.  
  9. local _G = _G
  10.  
  11.  
  12. -- Player Frame
  13. if C["unitframes"].player.enable then
  14.  
  15.     -- Frame Scale
  16.     _G["PlayerFrame"]:SetScale(C["unitframes"].player.scale);  
  17.     PlayerFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSize,"THINOUTLINE");
  18.     PlayerFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSize, "THINOUTLINE");
  19.     PlayerFrameAlternateManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSize, "THINOUTLINE");
  20.     PetFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSizepet,"THINOUTLINE");
  21.     PetFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSizepet, "THINOUTLINE");
  22.  
  23. end
  24.  
  25. -- Target Frame
  26. if C["unitframes"].target.enable then
  27.  
  28.     -- Frame Scale
  29.      _G["TargetFrame"]:SetScale(C["unitframes"].target.scale);
  30.     TargetFrameTextureFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].target.fontSize, "THINOUTLINE");
  31.     TargetFrameTextureFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].target.fontSize, "THINOUTLINE");
  32.  
  33. end;
  34.  
  35. -- Focus Frame
  36. if C["unitframes"].focus.enable then
  37.  
  38.     -- Frame Scale
  39.      _G["FocusFrame"]:SetScale(C["unitframes"].focus.scale)
  40.     FocusFrameTextureFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].focus.fontSize,"THINOUTLINE")
  41.     FocusFrameTextureFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].focus.fontSize,"THINOUTLINE")
  42.  
  43. end;
  44.  
  45.  
  46. -- Party Frames --
  47. if C["unitframes"].party.enable then
  48.  
  49.     -- Clear all old settings
  50.     PartyMemberFrame1:ClearAllPoints();
  51.     PartyMemberFrame2:ClearAllPoints();
  52.     PartyMemberFrame3:ClearAllPoints();
  53.     PartyMemberFrame4:ClearAllPoints();
  54.  
  55.     -- Create new locations
  56.     PartyMemberFrame1:SetPoint(C['unitframes'].party.position.relAnchor, UIParent, C['unitframes'].party.position.offSetX, C['unitframes'].party.position.offSetY);
  57.     PartyMemberFrame2:SetPoint("TOPLEFT", PartyMemberFrame1, 0, -75);
  58.     PartyMemberFrame3:SetPoint("TOPLEFT", PartyMemberFrame2, 0, -75);
  59.     PartyMemberFrame4:SetPoint("TOPLEFT", PartyMemberFrame3, 0, -75);
  60.  
  61.     -- Make the new locations stay
  62.     PartyMemberFrame1.SetPoint = function() end;
  63.     PartyMemberFrame2.SetPoint = function() end;
  64.     PartyMemberFrame3.SetPoint = function() end;
  65.     PartyMemberFrame4.SetPoint = function() end;
  66.  
  67.     -- Set the scale of all the frames
  68.     PartyMemberFrame1:SetScale(C["unitframes"].party.scale);
  69.     PartyMemberFrame2:SetScale(C["unitframes"].party.scale);
  70.     PartyMemberFrame3:SetScale(C["unitframes"].party.scale);
  71.     PartyMemberFrame4:SetScale(C["unitframes"].party.scale);
  72.    
  73.     -- Set Font Size
  74.     PartyMemberFrame1HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  75.     PartyMemberFrame1ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  76.     PartyMemberFrame2HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  77.     PartyMemberFrame2ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  78.     PartyMemberFrame3HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  79.     PartyMemberFrame3ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  80.     PartyMemberFrame4HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  81.     PartyMemberFrame4ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  82. end;
  83.  
  84.  -- Arena Frames
  85. if C["unitframes"].arena.enable then
  86.     LoadAddOn("Blizzard_ArenaUI"); -- You only need to run this once. You can safely delete any copies of this line.
  87.      
  88.     ArenaEnemyFrames:SetScale(C["unitframes"].arena.scale);
  89.    
  90.     ArenaEnemyFrame1HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  91.     ArenaEnemyFrame1ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  92.     ArenaEnemyFrame2HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  93.     ArenaEnemyFrame2ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  94.     ArenaEnemyFrame3HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  95.     ArenaEnemyFrame3ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  96.     ArenaEnemyFrame4HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  97.     ArenaEnemyFrame4ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  98.     ArenaEnemyFrame5HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  99.     ArenaEnemyFrame5ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  100.  
  101.  
  102.     if C["unitframes"].arena.tracker == true then
  103.         trinkets = {};
  104.         local arenaFrame,trinket;
  105.         for i = 1, 5 do
  106.             arenaFrame = "ArenaEnemyFrame"..i;
  107.             trinket = CreateFrame("Cooldown", arenaFrame.."Trinket", ArenaEnemyFrames);
  108.             trinket:SetPoint("TOPRIGHT", arenaFrame, 30, -6);
  109.             trinket:SetSize(24, 24);
  110.             trinket.icon = trinket:CreateTexture(nil, "BACKGROUND");
  111.             trinket.icon:SetAllPoints();
  112.             trinket.icon:SetTexture("Interface\\Icons\\inv_jewelry_trinketpvp_01");
  113.             trinket:Hide();
  114.             trinkets["arena"..i] = trinket;
  115.         end;
  116.         local events = CreateFrame("Frame");
  117.         function events:UNIT_SPELLCAST_SUCCEEDED(unitID, spell, rank, lineID, spellID)
  118.             if not trinkets[unitID] then
  119.                 return;
  120.             end ;      
  121.             if spellID == 59752 or spellID == 42292 then
  122.                 CooldownFrame_SetTimer(trinkets[unitID], GetTime(), 120, 1);
  123.                 SendChatMessage("Trinket used by: "..GetUnitName(unitID, true), "PARTY");
  124.             end;
  125.         end;
  126.         function events:PLAYER_ENTERING_WORLD()
  127.             local _, instanceType = IsInInstance();
  128.             if instanceType == "arena" then
  129.                 self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  130.             elseif self:IsEventRegistered("UNIT_SPELLCAST_SUCCEEDED") then
  131.                 self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  132.                 for _, trinket in pairs(trinkets) do
  133.                     trinket:SetCooldown(0, 0);
  134.                     trinket:Hide();
  135.                 end;        
  136.             end;
  137.         end;
  138.         events:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end);
  139.         events:RegisterEvent("PLAYER_ENTERING_WORLD");
  140.     end;
  141. end;
  142.  
  143.  -- Boss Frames
  144. if C["unitframes"].boss.enable then
  145.     for i = 1,4 do
  146.         local boss = _G["Boss"..i.."TargetFrame"];
  147.         if boss then
  148.             boss:SetScale(C["unitframes"].boss.scale)
  149.             boss:ClearAllPoints();
  150.             boss:SetPoint(C['unitframes'].boss.position.relAnchor, UIParent, C['unitframes'].boss.position.offSetX, C['unitframes'].boss.position.offSetY);
  151.             boss.ClearAllPoints = function() end;
  152.             boss.SetPoint = function() end;    
  153.         end;
  154.     end;
  155. end;
  156.  
  157. -- Font Style thanks to Phanx from WoWinterface.
  158. local shorts = {
  159.     { 1e10, 1e9, "%.0fb" }, --  10b+ as  12b
  160.     {  1e9, 1e9, "%.1fb" }, --   1b+ as 8.3b
  161.     {  1e7, 1e6, "%.0fm" }, --  10m+ as  14m
  162.     {  1e6, 1e6, "%.1fm" }, --   1m+ as 7.4m
  163.     {  1e5, 1e3, "%.0fk" }, -- 100k+ as 840k
  164.     {  1e3, 1e3, "%.1fk" }, --   1k+ as 2.5k
  165.     {    0,   1,    "%d" }, -- < 1k  as  974
  166. }
  167. for i = 1, #shorts do
  168.     shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
  169. end
  170.  
  171. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
  172.     local style = GetCVar("statusTextDisplay")
  173.     if style == "PERCENT" then
  174.         return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
  175.     end
  176.     for i = 1, #shorts do
  177.         local t = shorts[i]
  178.         if value >= t[1] then
  179.             if style == "BOTH" then
  180.                 return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  181.             else
  182.                 return fontString:SetFormattedText(t[3], value / t[2])             
  183.             end
  184.         end
  185.     end
  186. end)
  187.  
  188. hooksecurefunc("UnitFrame_Update", function(self)
  189.     if not self.name then return end
  190.  
  191.     if UnitIsPlayer(self.unit) then
  192.         -- Color by class:
  193.         local _, class = UnitClass(self.unit)
  194.         local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  195.         self.name:SetTextColor(color.r, color.g, color.b)
  196.     else
  197.         -- Not a player. Return to default color:
  198.         local reaction = UnitReaction(self.unit, "player");
  199.         self.name:SetTextColor(FACTION_BAR_COLORS[reaction].r, FACTION_BAR_COLORS[reaction].g, FACTION_BAR_COLORS[reaction].b)
  200.     end
  201. end)
  202.  
  203. -- Disable healing/damage spam over player/pet frame:
  204. PlayerHitIndicator:SetText(nil)
  205. PlayerHitIndicator.SetText = function() end
  206. PetHitIndicator:SetText(nil)
  207. PetHitIndicator.SetText = function() end

Defaults.lua:
Lua Code:
  1. local B, C, DB = unpack(select(2, ...)) -- Import:  B - function; C - config; DB - Database
  2.  
  3. -----------------
  4. -- Media Options
  5. -----------------
  6. DB["media"] = {
  7.     ["fontNormal"] = "BasicUI NORMAL",
  8.     ["fontBold"] = "BasicUI BOLD",
  9.     ["fontItalic"] = "BasicUI ITALIC",
  10.     ["fontBoldItalic"] = "BasicUI BOLD ITALIC",
  11.     ["fontNumber"] = "BasicUI NUMBER",
  12.     ["fontSize"] = 15,
  13. }
  14.  
  15. --------------
  16. -- Unitframes
  17. --------------
  18. DB["unitframes"] = {
  19.    
  20.     ["enable"] = true,
  21.     ["player"] = {
  22.         ["enable"] = true,          -- Enable Player Frame Adjustments
  23.         ["scale"] = 1.15,           -- Player Frame Scale
  24.         ["fontSize"] = 13,          -- Stausbar Font Size
  25.         ["fontSizepet"] = 10,           -- Stausbar Font Size
  26.     },
  27.     ["target"] = {
  28.         ["enable"] = true,          -- Enable Target Frame Adjustments
  29.         ["scale"] = 1.15,           -- Target Frame Scale
  30.         ["fontSize"] = 13,          -- Stausbar Font Size
  31.     },
  32.     ["focus"] = {
  33.         ["enable"] = true,          -- Enable Focus Frame Adjustments
  34.         ["scale"] = 1.15,           -- Focus Frame Scale
  35.         ["fontSize"] = 13,          -- Stausbar Font Size
  36.     },
  37.     ["party"] = {
  38.         ["enable"] = true,
  39.         ["scale"] = 1.15,
  40.         ["fontSize"] = 11,          -- Stausbar Font Size
  41.         ["position"] = {
  42.             ["relAnchor"] = "TOPLEFT",
  43.             ["offSetX"] = 10,       -- Controls the X offset. (Left - Right)
  44.             ["offSetY"] = -150,     -- Controls the Y offset. (Up - Down)
  45.         },
  46.     },
  47.     ["arena"] = {
  48.         ["enable"] = true,
  49.         ["scale"] = 1.5,
  50.         ["fontSize"] = 11,          -- Stausbar Font Size
  51.         ["tracker"] = true,
  52.     },
  53.     ["boss"] = {
  54.         ["enable"] = true,
  55.         ["scale"] = 1.15,
  56.         ["fontSize"] = 13,          -- Stausbar Font Size  
  57.         ["position"] = {
  58.             ["relAnchor"] = "TOPRIGHT",
  59.             ["offSetX"] = -50,      -- Controls the X offset. (Left - Right)
  60.             ["offSetY"] = -250,     -- Controls the Y offset. (Up - Down)
  61.         },
  62.     },
  63. }

Engine.lua:
Lua Code:
  1. ----------------------------------
  2. -- Engine to make all files communicate.
  3.  
  4. -- Credit Nightcracker
  5. ----------------------------------
  6.  
  7. -- including system
  8. local addon, engine = ...
  9. engine[1] = {} -- B, functions, constants
  10. engine[2] = {} -- C, config
  11. engine[3] = {} -- DB, database, post config load
  12.  
  13. BasicUI = engine --Allow other addons to use Engine

Config.lua:
Lua Code:
  1. ----------------------------------------------------------------------------
  2. -- This Module loads new user settings if BasicUI_Config is loaded
  3. ----------------------------------------------------------------------------
  4. local B, C, DB = unpack(select(2, ...)) -- Import:  B - function; C - config; DB - Database
  5.  
  6. --Convert default database
  7. for group,options in pairs(DB) do
  8.     if not C[group] then C[group] = {} end
  9.     for option, value in pairs(options) do
  10.         C[group][option] = value
  11.     end
  12. end
  13.  
  14. if IsAddOnLoaded("BasicUI_Config") then
  15.     local BasicUIConfig = LibStub("AceAddon-3.0"):GetAddon("BasicUIConfig")
  16.     BasicUIConfig:Load()
  17.  
  18.     --Load settings from BasicUIConfig database
  19.     for group, options in pairs(BasicUIConfig.db.profile) do
  20.         if C[group] then
  21.             for option, value in pairs(options) do
  22.                 C[group][option] = value
  23.             end
  24.         end
  25.     end
  26.        
  27.     B.SavePath = BasicUIConfig.db.profile
  28. end

Is there any other code that you might need?

Coke

Last edited by cokedrivers : 03-04-14 at 08:34 PM.
  Reply With Quote
03-04-14, 09:23 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
UnitReaction can return nil. Here's a version based on the coloring in my oUF layout that will do class colors for players, or gray for tapped units, or reaction colors for other units, with a fallback in case of invalid class/reaction data:

Lua Code:
  1. hooksecurefunc("UnitFrame_Update", function(self)
  2.     if not self.name then return end
  3.  
  4.     local color
  5.     if UnitIsPlayer(unit) then
  6.         local _, class = UnitClass(unit)
  7.         color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  8.     elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
  9.         color = GRAY_FONT_COLOR
  10.     elseif UnitIsEnemy(unit, "player") then
  11.         color = FACTION_BAR_COLORS[1]
  12.     else
  13.         local reaction = UnitReaction(unit, "player")
  14.         color = reaction and FACTION_BAR_COLORS[reaction] or FACTION_BAR_COLORS[5]
  15.     end
  16.  
  17.     if not color then
  18.         color = NORMAL_FONT_COLOR
  19.     end
  20.  
  21.     self.name:SetTextColor(color.r, color.g, color.b)
  22. end)
__________________
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-11-14, 10:35 AM   #12
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
UnitReaction can return nil. Here's a version based on the coloring in my oUF layout that will do class colors for players, or gray for tapped units, or reaction colors for other units, with a fallback in case of invalid class/reaction data:

Lua Code:
  1. hooksecurefunc("UnitFrame_Update", function(self)
  2.     if not self.name then return end
  3.  
  4.     local color
  5.     if UnitIsPlayer(unit) then
  6.         local _, class = UnitClass(unit)
  7.         color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  8.     elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
  9.         color = GRAY_FONT_COLOR
  10.     elseif UnitIsEnemy(unit, "player") then
  11.         color = FACTION_BAR_COLORS[1]
  12.     else
  13.         local reaction = UnitReaction(unit, "player")
  14.         color = reaction and FACTION_BAR_COLORS[reaction] or FACTION_BAR_COLORS[5]
  15.     end
  16.  
  17.     if not color then
  18.         color = NORMAL_FONT_COLOR
  19.     end
  20.  
  21.     self.name:SetTextColor(color.r, color.g, color.b)
  22. end)
The above code didn't work for me, I think the reasoning is your oUF_Phanx uses tags form oUF which in turn does not work with the default unit frames.

What I was able to use was the name coloring from nTooltip with some modifications.

The only down fall to this coding is that the player's name is not class color matched, but all targets become classcolor, grey for dead or tapped, and normal color for npc's.

Here is the code:
Lua Code:
  1. hooksecurefunc("UnitFrame_Update", function(self)
  2.     if not self.name then return end
  3.    
  4.     function BasicUI_UnitColor(unit)
  5.         local r, g, b
  6.  
  7.         unit = "target"
  8.        
  9.         if (UnitIsDead(unit) or UnitIsGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) then
  10.             r = 0.5
  11.             g = 0.5
  12.             b = 0.5
  13.         elseif (UnitIsPlayer(unit)) then
  14.             if (UnitIsFriend(unit, 'player')) then
  15.                 local _, class = UnitClass(unit)
  16.                 r = RAID_CLASS_COLORS[class].r
  17.                 g = RAID_CLASS_COLORS[class].g
  18.                 b = RAID_CLASS_COLORS[class].b
  19.             elseif (not UnitIsFriend(unit, 'player')) then
  20.                 r = 1
  21.                 g = 0
  22.                 b = 0
  23.             end
  24.         elseif (UnitPlayerControlled(unit)) then
  25.             if (UnitCanAttack(unit, 'player')) then
  26.                 if (not UnitCanAttack('player', unit)) then
  27.                     r = 157/255
  28.                     g = 197/255
  29.                     b = 255/255
  30.                 else
  31.                     r = 1
  32.                     g = 0
  33.                     b = 0
  34.                 end
  35.             elseif (UnitCanAttack('player', unit)) then
  36.                 r = 1
  37.                 g = 1
  38.                 b = 0
  39.             elseif (UnitIsPVP(unit)) then
  40.                 r = 0
  41.                 g = 1
  42.                 b = 0
  43.             else
  44.                 r = 157/255
  45.                 g = 197/255
  46.                 b = 255/255
  47.             end
  48.         else
  49.             local reaction = UnitReaction(unit, 'player')
  50.  
  51.             if (reaction) then
  52.                 r = FACTION_BAR_COLORS[reaction].r
  53.                 g = FACTION_BAR_COLORS[reaction].g
  54.                 b = FACTION_BAR_COLORS[reaction].b
  55.             else
  56.                 r = 157/255
  57.                 g = 197/255
  58.                 b = 255/255
  59.             end
  60.         end
  61.  
  62.         return r, g, b
  63.     end
  64.    
  65.     local r, g, b = BasicUI_UnitColor(unit)
  66.  
  67.     self.name:SetTextColor(r, g, b)
  68. end)

Thanks for the help on this.

One last quest for you Phanx

The numeric code seems to show 0 ("Zero") when a target is dead is there a way to remove these when the target is dead?

Something like:
Lua Code:
  1. if UnitIsDead("target") then
  2.      TextStatusBar_UpdateTextStringWithValues:Hide()
  3. end

Again Thank You for all your help with the coding.
Coke
  Reply With Quote
03-11-14, 04:05 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Your code is creating a new copy of a function every time any unit frame is updated, which is really bad. It's also hardcoding the unit to "target" which is probably not what you want, unless you only want your code to work on the target frame, in which case it's still the wrong way to go about it; if you want to limit it to the target frame, you need to check the actual unit and return out if it's not "target", as the current method will color every unit frame according to the properties of your current target.

The code I posted has nothing to do with oUF or tags, but after looking at it again, I see I forgot to define the "unit" variable. You should really have some kind of error display turned on. It will make things so much easier for you (and anyone else who tries to help you) while you're working with code. If you already have one (I recommend BugSack) then you should really post the error message when you report that something "doesn't work".

Anyway, here is a fixed version:

Code:
hooksecurefunc("UnitFrame_Update", function(self)
	if not self.name then return end
	local unit = self.unit -- THIS WAS MISSING

	local color
	if UnitIsPlayer(unit) then
		local _, class = UnitClass(unit)
		color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
	elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
		color = GRAY_FONT_COLOR
	elseif UnitIsEnemy(unit, "player") then
		color = FACTION_BAR_COLORS[1]
	else
		local reaction = UnitReaction(unit, "player")
		color = reaction and FACTION_BAR_COLORS[reaction] or FACTION_BAR_COLORS[5]
	end

	if not color then
		color = NORMAL_FONT_COLOR
	end

	self.name:SetTextColor(color.r, color.g, color.b)
end)
Edit: And for your "hide text on dead units" just do this:

Code:
hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
	if value == 0 then
		return fontString:SetText("")
	end
	local style = GetCVar("statusTextDisplay")
	if style == "PERCENT" then
__________________
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 : 03-11-14 at 04:08 PM.
  Reply With Quote
03-11-14, 05:56 PM   #14
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
Your code is creating a new copy of a function every time any unit frame is updated, which is really bad. It's also hardcoding the unit to "target" which is probably not what you want, unless you only want your code to work on the target frame, in which case it's still the wrong way to go about it; if you want to limit it to the target frame, you need to check the actual unit and return out if it's not "target", as the current method will color every unit frame according to the properties of your current target.

The code I posted has nothing to do with oUF or tags, but after looking at it again, I see I forgot to define the "unit" variable. You should really have some kind of error display turned on. It will make things so much easier for you (and anyone else who tries to help you) while you're working with code. If you already have one (I recommend BugSack) then you should really post the error message when you report that something "doesn't work".

Anyway, here is a fixed version:

Code:
hooksecurefunc("UnitFrame_Update", function(self)
	if not self.name then return end
	local unit = self.unit -- THIS WAS MISSING

	local color
	if UnitIsPlayer(unit) then
		local _, class = UnitClass(unit)
		color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
	elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
		color = GRAY_FONT_COLOR
	elseif UnitIsEnemy(unit, "player") then
		color = FACTION_BAR_COLORS[1]
	else
		local reaction = UnitReaction(unit, "player")
		color = reaction and FACTION_BAR_COLORS[reaction] or FACTION_BAR_COLORS[5]
	end

	if not color then
		color = NORMAL_FONT_COLOR
	end

	self.name:SetTextColor(color.r, color.g, color.b)
end)
Edit: And for your "hide text on dead units" just do this:

Code:
hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
	if value == 0 then
		return fontString:SetText("")
	end
	local style = GetCVar("statusTextDisplay")
	if style == "PERCENT" then
Thank You for the updates they work perfectly.

Also installed bugsack as suggested. Right now no errors.

Thanks again for all your help.
Coke
  Reply With Quote
03-12-14, 08:09 AM   #15
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Pet Name Color to White

I've been trying all morning to get the pet eg beast, demon, and elemental to have there names white.


At first I tried UnitIsPet(unit) but it seems that the wow api does not have that in it.

Then I went searching and found UnitCreatureType(unit) then I tried:
Lua Code:
  1. if UnitCreatureType("beast") or UnitCreatureType("demon") or UnitCreatureType("elemental") then
  2.     self.name:SetTextColor(1, 1, 1)
  3. else
  4.     self.name:SetTextColor(color.r, color.g, color.b)
  5. end

But the above code turned every name color white.

So I did more searching and found a post that had a function created for UnitIsPet so I copy/pasted the:
Lua Code:
  1. local function UnitIsPet(unit)
  2.     local guidtype = tonumber(strsub(UnitGUID(unit),5,5),16)%8
  3.     if guidtype==4 then return true end
  4.     return false
  5. end
then I changed the code to:
Lua Code:
  1. if UnitIsPet(unit) then
  2.     self.name:SetTextColor(1, 1, 1)
  3. else
  4.     self.name:SetTextColor(color.r, color.g, color.b)
  5. end

and this changes the Pet name color to White but bugsack gives me this error:
Code:
5x BasicUI-5.4.4\Modules\Unitframes\Unitframes.lua:193: bad argument #1 to "strsub" (string expected, got nil)
<in C code>
BasicUI-5.4.4\Modules\Unitframes\Unitframes.lua:193: in function <BasicUI\Modules\Unitframes\Unitframes.lua:192>
BasicUI-5.4.4\Modules\Unitframes\Unitframes.lua:220: in function <BasicUI\Modules\Unitframes\Unitframes.lua:198>
<in C code>
Blizzard_ArenaUI\Blizzard_ArenaUI.lua:275: in function "ArenaEnemyFrame_UpdatePet"
Blizzard_ArenaUI\Blizzard_ArenaUI.lua:47: in function <Blizzard_ArenaUI\Blizzard_ArenaUI.lua:25>

Locals:
unit = "arenapet1"
(*temporary) = <function> defined =[C]:-1
Im trying more and more to get this lua coding figured out.

Hopefully this is enough info for you.

If not below is the complete Unitframes.lua just in case.

Coke


Unitframes.lua:
Lua Code:
  1. local B, C, DB = unpack(select(2, ...)) -- Import:  B - function; C - config; DB - Database
  2.  
  3. if C["unitframes"].enable ~= true then return end
  4.  
  5.  
  6. -- Special Thanks to the guys over at Arena Junkies for most of these scripts
  7. -- [url]http://www.arenajunkies.com/topic/222642-default-ui-scripts/[/url]
  8.  
  9. local _G = _G
  10.  
  11.  
  12. -- Player Frame
  13. if C["unitframes"].player.enable then
  14.  
  15.     -- Frame Scale
  16.     _G["PlayerFrame"]:SetScale(C["unitframes"].player.scale);  
  17.     PlayerFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSize,"THINOUTLINE");
  18.     PlayerFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSize, "THINOUTLINE");
  19.     PlayerFrameAlternateManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSize, "THINOUTLINE");
  20.     PetFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSizepet,"THINOUTLINE");
  21.     PetFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSizepet, "THINOUTLINE");
  22.  
  23. end
  24.  
  25. -- Target Frame
  26. if C["unitframes"].target.enable then
  27.  
  28.     -- Frame Scale
  29.      _G["TargetFrame"]:SetScale(C["unitframes"].target.scale);
  30.     TargetFrameTextureFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].target.fontSize, "THINOUTLINE");
  31.     TargetFrameTextureFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].target.fontSize, "THINOUTLINE");
  32.  
  33. end;
  34.  
  35. -- Focus Frame
  36. if C["unitframes"].focus.enable then
  37.  
  38.     -- Frame Scale
  39.      _G["FocusFrame"]:SetScale(C["unitframes"].focus.scale)
  40.     FocusFrameTextureFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].focus.fontSize,"THINOUTLINE")
  41.     FocusFrameTextureFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].focus.fontSize,"THINOUTLINE")
  42.  
  43. end;
  44.  
  45.  
  46. -- Party Frames --
  47. if C["unitframes"].party.enable then
  48.  
  49.     -- Clear all old settings
  50.     PartyMemberFrame1:ClearAllPoints();
  51.     PartyMemberFrame2:ClearAllPoints();
  52.     PartyMemberFrame3:ClearAllPoints();
  53.     PartyMemberFrame4:ClearAllPoints();
  54.  
  55.     -- Create new locations
  56.     PartyMemberFrame1:SetPoint(C['unitframes'].party.position.relAnchor, UIParent, C['unitframes'].party.position.offSetX, C['unitframes'].party.position.offSetY);
  57.     PartyMemberFrame2:SetPoint("TOPLEFT", PartyMemberFrame1, 0, -75);
  58.     PartyMemberFrame3:SetPoint("TOPLEFT", PartyMemberFrame2, 0, -75);
  59.     PartyMemberFrame4:SetPoint("TOPLEFT", PartyMemberFrame3, 0, -75);
  60.  
  61.     -- Make the new locations stay
  62.     PartyMemberFrame1.SetPoint = function() end;
  63.     PartyMemberFrame2.SetPoint = function() end;
  64.     PartyMemberFrame3.SetPoint = function() end;
  65.     PartyMemberFrame4.SetPoint = function() end;
  66.  
  67.     -- Set the scale of all the frames
  68.     PartyMemberFrame1:SetScale(C["unitframes"].party.scale);
  69.     PartyMemberFrame2:SetScale(C["unitframes"].party.scale);
  70.     PartyMemberFrame3:SetScale(C["unitframes"].party.scale);
  71.     PartyMemberFrame4:SetScale(C["unitframes"].party.scale);
  72.    
  73.     -- Set Font Size
  74.     PartyMemberFrame1HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  75.     PartyMemberFrame1ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  76.     PartyMemberFrame2HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  77.     PartyMemberFrame2ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  78.     PartyMemberFrame3HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  79.     PartyMemberFrame3ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  80.     PartyMemberFrame4HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  81.     PartyMemberFrame4ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  82. end;
  83.  
  84.  -- Arena Frames
  85. if C["unitframes"].arena.enable then
  86.     LoadAddOn("Blizzard_ArenaUI"); -- You only need to run this once. You can safely delete any copies of this line.
  87.      
  88.     ArenaEnemyFrames:SetScale(C["unitframes"].arena.scale);
  89.    
  90.     ArenaEnemyFrame1HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  91.     ArenaEnemyFrame1ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  92.     ArenaEnemyFrame2HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  93.     ArenaEnemyFrame2ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  94.     ArenaEnemyFrame3HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  95.     ArenaEnemyFrame3ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  96.     ArenaEnemyFrame4HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  97.     ArenaEnemyFrame4ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  98.     ArenaEnemyFrame5HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  99.     ArenaEnemyFrame5ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  100.  
  101.  
  102.     if C["unitframes"].arena.tracker == true then
  103.         trinkets = {};
  104.         local arenaFrame,trinket;
  105.         for i = 1, 5 do
  106.             arenaFrame = "ArenaEnemyFrame"..i;
  107.             trinket = CreateFrame("Cooldown", arenaFrame.."Trinket", ArenaEnemyFrames);
  108.             trinket:SetPoint("TOPRIGHT", arenaFrame, 30, -6);
  109.             trinket:SetSize(24, 24);
  110.             trinket.icon = trinket:CreateTexture(nil, "BACKGROUND");
  111.             trinket.icon:SetAllPoints();
  112.             trinket.icon:SetTexture("Interface\\Icons\\inv_jewelry_trinketpvp_01");
  113.             trinket:Hide();
  114.             trinkets["arena"..i] = trinket;
  115.         end;
  116.         local events = CreateFrame("Frame");
  117.         function events:UNIT_SPELLCAST_SUCCEEDED(unitID, spell, rank, lineID, spellID)
  118.             if not trinkets[unitID] then
  119.                 return;
  120.             end ;      
  121.             if spellID == 59752 or spellID == 42292 then
  122.                 CooldownFrame_SetTimer(trinkets[unitID], GetTime(), 120, 1);
  123.                 SendChatMessage("Trinket used by: "..GetUnitName(unitID, true), "PARTY");
  124.             end;
  125.         end;
  126.         function events:PLAYER_ENTERING_WORLD()
  127.             local _, instanceType = IsInInstance();
  128.             if instanceType == "arena" then
  129.                 self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  130.             elseif self:IsEventRegistered("UNIT_SPELLCAST_SUCCEEDED") then
  131.                 self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  132.                 for _, trinket in pairs(trinkets) do
  133.                     trinket:SetCooldown(0, 0);
  134.                     trinket:Hide();
  135.                 end;        
  136.             end;
  137.         end;
  138.         events:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end);
  139.         events:RegisterEvent("PLAYER_ENTERING_WORLD");
  140.     end;
  141. end;
  142.  
  143.  -- Boss Frames
  144. if C["unitframes"].boss.enable then
  145.     for i = 1,4 do
  146.         local boss = _G["Boss"..i.."TargetFrame"];
  147.         if boss then
  148.             boss:SetScale(C["unitframes"].boss.scale)
  149.             boss:ClearAllPoints();
  150.             boss:SetPoint(C['unitframes'].boss.position.relAnchor, UIParent, C['unitframes'].boss.position.offSetX, C['unitframes'].boss.position.offSetY);
  151.             boss.ClearAllPoints = function() end;
  152.             boss.SetPoint = function() end;    
  153.         end;
  154.     end;
  155. end;
  156.  
  157. -- Font Style thanks to Phanx from WoWinterface.
  158. local shorts = {
  159.     { 1e10, 1e9, "%.0fb" }, --  10b+ as  12b
  160.     {  1e9, 1e9, "%.1fb" }, --   1b+ as 8.3b
  161.     {  1e7, 1e6, "%.0fm" }, --  10m+ as  14m
  162.     {  1e6, 1e6, "%.1fm" }, --   1m+ as 7.4m
  163.     {  1e5, 1e3, "%.0fk" }, -- 100k+ as 840k
  164.     {  1e3, 1e3, "%.1fk" }, --   1k+ as 2.5k
  165.     {    0,   1,    "%d" }, -- < 1k  as  974
  166. }
  167. for i = 1, #shorts do
  168.     shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
  169. end
  170.  
  171. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
  172.     if value == 0 then
  173.         return fontString:SetText("")
  174.     end
  175.  
  176.     local style = GetCVar("statusTextDisplay")
  177.     if style == "PERCENT" then
  178.         return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
  179.     end
  180.     for i = 1, #shorts do
  181.         local t = shorts[i]
  182.         if value >= t[1] then
  183.             if style == "BOTH" then
  184.                 return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  185.             else
  186.                 return fontString:SetFormattedText(t[3], value / t[2])             
  187.             end
  188.         end
  189.     end
  190. end)
  191.  
  192. local function UnitIsPet(unit)
  193.     local guidtype = tonumber(strsub(UnitGUID(unit),5,5),16)%8
  194.     if guidtype==4 then return true end
  195.     return false
  196. end
  197.  
  198. hooksecurefunc("UnitFrame_Update", function(self)
  199.     if not self.name then return end
  200.     local unit = self.unit -- THIS WAS MISSING
  201.  
  202.     local color
  203.    
  204.     if UnitIsPlayer(unit) then
  205.         local _, class = UnitClass(unit)
  206.         color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  207.     elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
  208.         color = GRAY_FONT_COLOR
  209.     elseif UnitIsEnemy(unit, "player") then
  210.         color = FACTION_BAR_COLORS[1]      
  211.     else
  212.         local reaction = UnitReaction(unit, "player")
  213.         color = reaction and FACTION_BAR_COLORS[reaction] or FACTION_BAR_COLORS[5]
  214.     end
  215.  
  216.     if not color then
  217.         color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["priest"]
  218.     end
  219.  
  220.     if UnitIsPet(unit) then
  221.         self.name:SetTextColor(1, 1, 1)
  222.     else
  223.         self.name:SetTextColor(color.r, color.g, color.b)
  224.     end
  225.  
  226. end)
  227.  
  228.  
  229. -- Disable healing/damage spam over player/pet frame:
  230. PlayerHitIndicator:SetText(nil)
  231. PlayerHitIndicator.SetText = function() end
  232. PetHitIndicator:SetText(nil)
  233. PetHitIndicator.SetText = function() end
  Reply With Quote
03-12-14, 09:39 AM   #16
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
UnitGUID can return nil so you need to account for that:
Code:
local function UnitIsPet(unit)
    local GUID = UnitGUID(unit)
    return GUID and tonumber(GUID:sub(5, 5), 16) % 8 == 4
end
UnitGUID returns nil when the game first loads so probably best to wait for a PLAYER_ENTERING_WORLD event to use it. If that's not an option you could do something more generic:
Code:
local function UnitIsPet(unit)
    return UnitPlayerControlled(unit) and not UnitIsPlayer(unit)
end
Your code:
Code:
if UnitCreatureType("beast") or UnitCreatureType("demon") or UnitCreatureType("elemental") then
    self.name:SetTextColor(1, 1, 1)
else
    self.name:SetTextColor(color.r, color.g, color.b)
end
doesn't work because UnitCreatureType takes unitIDs like 'target' and returns string like 'Beast' or 'Demon'. It wouldn't work the way you want anyway since it would return 'Beast' for a druid in bear or cat form.
  Reply With Quote
03-12-14, 10:51 AM   #17
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Vrul View Post
UnitGUID can return nil so you need to account for that:
Code:
local function UnitIsPet(unit)
    local GUID = UnitGUID(unit)
    return GUID and tonumber(GUID:sub(5, 5), 16) % 8 == 4
end
UnitGUID returns nil when the game first loads so probably best to wait for a PLAYER_ENTERING_WORLD event to use it. If that's not an option you could do something more generic:
Code:
local function UnitIsPet(unit)
    return UnitPlayerControlled(unit) and not UnitIsPlayer(unit)
end
Your code:
Code:
if UnitCreatureType("beast") or UnitCreatureType("demon") or UnitCreatureType("elemental") then
    self.name:SetTextColor(1, 1, 1)
else
    self.name:SetTextColor(color.r, color.g, color.b)
end
doesn't work because UnitCreatureType takes unitIDs like 'target' and returns string like 'Beast' or 'Demon'. It wouldn't work the way you want anyway since it would return 'Beast' for a druid in bear or cat form.
Thank You for the info.

I have added:
Code:
local function UnitIsPet(unit)
    return UnitPlayerControlled(unit) and not UnitIsPlayer(unit)
end
and bugsack is not giving me any errors and my all player pets have there names with a white color.

Thanks again
Coke
  Reply With Quote
03-12-14, 11:30 AM   #18
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Based on what you are using it for you don't really need a separate UnitIsPet function, also the class name used to index CUSTOM_CLASS_COLORS and RAID_CLASS_COLORS should be in all caps:
Code:
hooksecurefunc("UnitFrame_Update", function(self)
    if not self.name then return end

    local unit, color = self.unit
    if UnitPlayerControlled(unit) then
        if UnitIsPlayer(unit) then
            local _, class = UnitClass(unit)
            color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
        else
            color = HIGHLIGHT_FONT_COLOR
        end
    elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
        color = GRAY_FONT_COLOR
    else
        color = FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
    end
 
    if not color then
        color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
    end
 
    self.name:SetTextColor(color.r, color.g, color.b)
end)
  Reply With Quote
03-12-14, 02:52 PM   #19
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Vrul View Post
Based on what you are using it for you don't really need a separate UnitIsPet function, also the class name used to index CUSTOM_CLASS_COLORS and RAID_CLASS_COLORS should be in all caps:
Code:
hooksecurefunc("UnitFrame_Update", function(self)
    if not self.name then return end

    local unit, color = self.unit
    if UnitPlayerControlled(unit) then
        if UnitIsPlayer(unit) then
            local _, class = UnitClass(unit)
            color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
        else
            color = HIGHLIGHT_FONT_COLOR
        end
    elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
        color = GRAY_FONT_COLOR
    else
        color = FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
    end
 
    if not color then
        color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
    end
 
    self.name:SetTextColor(color.r, color.g, color.b)
end)
Again Thanks it works like a charm.

Coke
  Reply With Quote
03-12-14, 02:57 PM   #20
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Statusbar Text

the following code was supplied by Phanx but I was wondering if there is a way to make it do the following.


Full Health = 345K
Full Mana = 160K
Not Full Health = 160K/345K
Not Full Mana = 80K/160K

Code Supplied by Phanx:
Lua Code:
  1. local shorts = {
  2.     { 1e10, 1e9, "%.0fb" }, --  10b+ as  12b
  3.     {  1e9, 1e9, "%.1fb" }, --   1b+ as 8.3b
  4.     {  1e7, 1e6, "%.0fm" }, --  10m+ as  14m
  5.     {  1e6, 1e6, "%.1fm" }, --   1m+ as 7.4m
  6.     {  1e5, 1e3, "%.0fk" }, -- 100k+ as 840k
  7.     {  1e3, 1e3, "%.1fk" }, --   1k+ as 2.5k
  8.     {    0,   1,    "%d" }, -- < 1k  as  974
  9. }
  10. for i = 1, #shorts do
  11.     shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
  12. end
  13.  
  14. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
  15.     if value == 0 then
  16.         return fontString:SetText("")
  17.     end
  18.  
  19.     local style = GetCVar("statusTextDisplay")
  20.     if style == "PERCENT" then
  21.         return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
  22.     end
  23.     for i = 1, #shorts do
  24.         local t = shorts[i]
  25.         if value >= t[1] then
  26.             if style == "BOTH" then
  27.                 return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  28.             else
  29.                 return fontString:SetFormattedText(t[3], value / t[2])             
  30.             end
  31.         end
  32.     end
  33. end)

Thank in advance for any help.
Coke
  Reply With Quote

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

Thread Tools
Display Modes

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