Thread Tools Display Modes
03-12-14, 06:16 PM   #21
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Add the part highlighted in teal:
Code:
			else
				if value < valueMax then
					for j = 1, #shorts do
						local v = shorts[j]
						if valueMax >= v[1] then
							return fontString:SetFormattedText(t[3] .. "/" .. v[3], value / t[2], valueMax / v[2])
						end
					end
				end
				return fontString:SetFormattedText(t[3], value / t[2])
			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-13-14, 04:35 PM   #22
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
Add the part highlighted in teal:
Code:
			else
				if value < valueMax then
					for j = 1, #shorts do
						local v = shorts[j]
						if valueMax >= v[1] then
							return fontString:SetFormattedText(t[3] .. "/" .. v[3], value / t[2], valueMax / v[2])
						end
					end
				end
				return fontString:SetFormattedText(t[3], value / t[2])
			end
Thank You for this code it works perfectly.

Last question then I think I'm done with font's.

My tooltip addon I use is based primarily off of nTooltip and for his pets he uses a color like:

Code:
r = 157/255
g = 197/255
b = 255/255

How would I get the highlighted yellow code to be this color:

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 UnitIsDead(unit) or 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)
I know its a minor thing but I would like when I tooltip over a unit for the color in the tooltip to match the color of the font on the unit.

I know I couldjust change the tooltip font to:

Code:
r = 1
g = 1
b = 1
and this would give me a white on the tooltip. But I kinda like the other color.

Thanks again for all your guys help with my font questions.

Coke
  Reply With Quote
03-13-14, 04:36 PM   #23
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Code:
local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }

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 = PET_COLOR
        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-13-14, 04:44 PM   #24
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
Code:
local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }

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 = PET_COLOR
        end
So simple yet I couldn't figure it out.

Now for a personal question do you do programming for a living or is this just a hobby like me?

Either way you are great at it and thank you for all you do for us less then program savvy people.

Coke
  Reply With Quote
03-31-14, 11:05 AM   #25
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Yet another font string question...

Is there a way to hide a party members realm, I've search the forums and only found this function for the chat not for the unit frames.

I would really like to change "-REALNAME" to (*) if possible.

Coke
  Reply With Quote
03-31-14, 11:16 AM   #26
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Lua Code:
  1. -- originalName is defined is this fashion as an example; in practice
  2. -- you will want to pass whatever variable contains the NAME-REALM key
  3. -- into strsplit().
  4. local originalName = "Clamsoda-BleedingHollow"
  5. local unitName, unitRealm = strsplit("-", originalName)
  6.  
  7. print(unitRealm and unitName.."(*)" or unitName)

What is happening here is that strsplit will pass everything before and after the defined delimiter to as many variables as we allow it to. NAME-REALM keys are always delimited by a "-", and I am almost positive that no REALM keys contain a "-", thus we can safely split the name from the realm in this way. If unitRealm becomes defined, we print unitName with "(*)" concatenated; else we print just the name.

This should be quite adaptable, let me know if you need any further assistance.

Last edited by Clamsoda : 03-31-14 at 11:23 AM.
  Reply With Quote
03-31-14, 11:47 AM   #27
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Clamsoda View Post
Lua Code:
  1. -- originalName is defined is this fashion as an example; in practice
  2. -- you will want to pass whatever variable contains the NAME-REALM key
  3. -- into strsplit().
  4. local originalName = "Clamsoda-BleedingHollow"
  5. local unitName, unitRealm = strsplit("-", originalName)
  6.  
  7. print(unitRealm and unitName.."(*)" or unitName)

What is happening here is that strsplit will pass everything before and after the defined delimiter to as many variables as we allow it to. NAME-REALM keys are always delimited by a "-", and I am almost positive that no REALM keys contain a "-", thus we can safely split the name from the realm in this way. If unitRealm becomes defined, we print unitName with "(*)" concatenated; else we print just the name.

This should be quite adaptable, let me know if you need any further assistance.
Will this just work on Party member names or all name game wide?

Coke
  Reply With Quote
03-31-14, 12:05 PM   #28
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
I mean....it doesn't necessarily pertain to anything in particular, it is just applied API. Technically, you could pass any name token through it as long as there aren't any "-" outside of the delimitation. If there is no realm name, you just get a name; if there is a realm name, you get the "(*)".

The one issue I see is the inconsistency in how name-realm tokens are passed through certain functions and events at the moment. "(*)" has typically been used for units on other realms, but some events -- CLEU for example -- are passing names with realms attached regardless of if they are on your realm or not.

Tl;dr: You may get "(*)" for units that are on your realm as well, giving the false impression that they are cross-realm.

Of course, you could cache your realm and match it against what got split and go from there.
  Reply With Quote
03-31-14, 12:42 PM   #29
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Clamsoda View Post
I mean....it doesn't necessarily pertain to anything in particular, it is just applied API. Technically, you could pass any name token through it as long as there aren't any "-" outside of the delimitation. If there is no realm name, you just get a name; if there is a realm name, you get the "(*)".

The one issue I see is the inconsistency in how name-realm tokens are passed through certain functions and events at the moment. "(*)" has typically been used for units on other realms, but some events -- CLEU for example -- are passing names with realms attached regardless of if they are on your realm or not.

Tl;dr: You may get "(*)" for units that are on your realm as well, giving the false impression that they are cross-realm.

Of course, you could cache your realm and match it against what got split and go from there.
Ok so something like:
Lua Code:
  1. if db.unitframes.party.enable then
  2.         for i = 1, MAX_PARTY_MEMBERS do
  3.             local partyFrame = "PartyMemberFrame"..i
  4.             local originalName = _G[partyFrame].name
  5.             local unitName, unitRealm = strsplit("-", originalName)
  6.             _G[partyFrame].name:SetText(unitRealm and unitName.."(*)" or unitName)         
  7.             _G[partyFrame]:SetScale(db.unitframes.party.scale);
  8.             _G[partyFrame.."HealthBarText"]:SetFont(db.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
  9.             _G[partyFrame.."ManaBarText"]:SetFont(db.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
  10.     end

Should set the name of my party members to just there name?
  Reply With Quote
03-31-14, 01:03 PM   #30
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
That looks functional to me, log into WoW and try it =~].
  Reply With Quote
03-31-14, 01:47 PM   #31
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
when I log in I get this error with all addons enabled:
Code:
3x BasicUI-5.4.7\Modules\Unitframes.lua:50: bad argument #2 to "strsplit" (string expected, got table)
<in C code>
BasicUI-5.4.7\Modules\Unitframes.lua:50: in function <BasicUI\Modules\Unitframes.lua:7>
(tail call): ?
<in C code>
<string>:"safecall Dispatcher[1]":9: in function <string>:"safecall Dispatcher[1]":5
(tail call): ?
AuctionLite-v1.8.12\Libs\AceAddon-3.0\AceAddon-3.0-12.lua:558: in function "EnableAddon"
AuctionLite-v1.8.12\Libs\AceAddon-3.0\AceAddon-3.0-12.lua:571: in function "EnableAddon"
AuctionLite-v1.8.12\Libs\AceAddon-3.0\AceAddon-3.0-12.lua:651: in function <AuctionLite\Libs\AceAddon-3.0\AceAddon-3.0.lua:636>
<in C code>
FrameXML\UIParent.lua:306: in function "UIParentLoadAddOn"
FrameXML\UIParent.lua:329: in function "CombatLog_LoadUI"
FrameXML\UIParent.lua:742: in function <FrameXML\UIParent.lua:705>

Locals:
nil
and this one with just BasicUI enabled:
Code:
Message: Interface\AddOns\BasicUI\Modules\Unitframes.lua:50: bad argument #2 to 'strsplit' (string expected, got table)
Time: 03/31/14 12:45:00
Count: 1
Stack: [C]: in function `strsplit'
Interface\AddOns\BasicUI\Modules\Unitframes.lua:50: in function <Interface\AddOns\BasicUI\Modules\Unitframes.lua:7>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[1]"]:9: in function <[string "safecall Dispatcher[1]"]:5>
(tail call): ?
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:543: in function `EnableAddon'
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:556: in function `EnableAddon'
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:636: in function <...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:621>
[C]: in function `LoadAddOn'
Interface\FrameXML\UIParent.lua:306: in function `UIParentLoadAddOn'
Interface\FrameXML\UIParent.lua:329: in function `CombatLog_LoadUI'
Interface\FrameXML\UIParent.lua:742: in function <Interface\FrameXML\UIParent.lua:705>

Locals: <none>
  Reply With Quote
03-31-14, 01:51 PM   #32
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
It's a table value. The fontstring widget itself.
Use:
_G[partyFrame].name:GetText()

Last edited by Duugu : 03-31-14 at 01:56 PM.
  Reply With Quote
03-31-14, 01:52 PM   #33
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Lua Code:
  1. local originalName = _G[partyFrame].name

needs to be

Lua Code:
  1. local originalName = _G[partyFrame].name:GetText()
  Reply With Quote
03-31-14, 02:52 PM   #34
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Clamsoda View Post
Lua Code:
  1. local originalName = _G[partyFrame].name

needs to be

Lua Code:
  1. local originalName = _G[partyFrame].name:GetText()
Ok this is not working for me.

Below I have attached my Unitframes.lua, Phanx helped me with a code to change my Unit Text color and I think it is conflicting with this script.

I get this error:
Code:
Message: Interface\AddOns\BasicUI\Modules\Unitframes.lua:52: bad argument #2 to 'strsplit' (string expected, got table)
Time: 03/31/14 13:48:33
Count: 1
Stack: [C]: in function `strsplit'
Interface\AddOns\BasicUI\Modules\Unitframes.lua:52: in function <Interface\AddOns\BasicUI\Modules\Unitframes.lua:7>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[1]"]:9: in function <[string "safecall Dispatcher[1]"]:5>
(tail call): ?
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:543: in function `EnableAddon'
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:556: in function `EnableAddon'
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:636: in function <...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:621>
[C]: in function `LoadAddOn'
Interface\FrameXML\UIParent.lua:306: in function `UIParentLoadAddOn'
Interface\FrameXML\UIParent.lua:329: in function `CombatLog_LoadUI'
Interface\FrameXML\UIParent.lua:742: in function <Interface\FrameXML\UIParent.lua:705>

Locals: <none>
Thanks for helping with this.
Coke

Last edited by cokedrivers : 03-31-14 at 02:56 PM.
  Reply With Quote
03-31-14, 04:43 PM   #35
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
I suspect the issue is that you are iterating over every possible party unitframe, even when no unit has been assigned to it. If there is no unit, there is no name token to pass into strsplit.

What I suspect you need to do is listen to GROUP_ROSTER_UPDATE and iterate over the party frames that actually have assigned units.

That is the only thing I can think of looking over your code.

Hopefully someone else will take a look and offer some insight.
  Reply With Quote
03-31-14, 05:01 PM   #36
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
It would be simpler to just ignore the original text and get the name again:
Code:
_G[partyFrame].name:SetText(GetUnitName("party"..i))
If you wanted to show the realm name again in the future, add a second argument true to GetUnitName:
Code:
_G[partyFrame].name:SetText(GetUnitName("party"..i, true))
However, the error you posted indicates that either:

(a) you did not, in fact, make the change Clamsoda suggested, as your originalName variable is still referring to the fontstring, rather than its text contents, or

(b) the unit in question doesn't exist. Using GetUnitName instead of manipulating the existing text will avoid this problem, but you should really not bother doing anything with frames that aren't shown. I see you're checking GetNumGroupMembers() >= 1 on each loop iteration; this is wasteful and won't achieve the desired result anyway, because having 1 party member doesn't mean you have 4 party members. Instead, just check that the frame being processed is shown:

Code:
		for i = 1, MAX_PARTY_MEMBERS do	
			local partyFrame = "PartyMemberFrame"..i
			if partyFrame:IsShown() then
				local originalName = _G[partyFrame].name:GetText()
				local unitName, unitRealm = strsplit("-", originalName)
				_G[partyFrame].name:SetText(unitRealm and unitName.."(*)" or unitName)
			end
However, upon looking at your file, this entire block of code is pointless, because you only run it once when you log in, at which time information about party members may not even be available, and certainly won't update when your group changes. Instead, you should add this code to your UnitFrame_Update hook and remove it from your OnEnable function:

Code:
	hooksecurefunc("UnitFrame_Update", function(self, isParty)
		if not self.name or not self:IsShown() then return end
		
		-- other code here is fine, just omitted from this post for brevity
	 
		self.name:SetTextColor(color.r, color.g, color.b)
		if isParty then
			self.name:SetText(GetUnitName(self.overrideName or unit))
		end
	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.

Last edited by Phanx : 03-31-14 at 05:11 PM.
  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