Thread Tools Display Modes
12-02-10, 10:47 AM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Change font size half way through string.

Okay so i have this function that follows, i want it to change the font size of the guild name when it shows guild names but leave the player font the same size. Is it possible? or do i have to make to separate font strings?
lua Code:
  1. targetNameGuildFrame:SetScript("OnEvent", function(self)
  2.     local targetName = UnitName("target")
  3.     local targetGuildName = GetGuildInfo("target")
  4.     local unitexists = UnitExists("target")
  5.     local targclass = UnitClass("target")
  6.  
  7.     if targetName then
  8.         if targetGuildName then
  9.             local namegstr = ("%s - %s"):format(getTargetNoU('target'), targetGuildName)
  10.             targetNameText:SetText(namegstr)
  11.         else
  12.             local namegstr = ("%s"):format(getTargetNoU('target'))
  13.             targetNameText:SetText(namegstr)
  14.         end
  15.     end
  16. end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
12-02-10, 11:01 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Separate.

*blah ... to at least 10 chars
  Reply With Quote
12-02-10, 04:46 PM   #3
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
FontInstance:SetFont("path", height[,"flags"])
fontName, fontHeight, fontFlags = FontInstance:GetFont()
Code:
if GuildName then
  local fontName = targetNameText:GetFont()
  targetNameText:SetFont(fontName, GUILD_FONT_HEIGHT)
else
  local fontName = targetNameText:GetFont()
  targetNameText:SetFont(fontName, TARGET_FONT_HEIGHT)
end
GUILD _FH and TARGET_FH are w/e heights you want

I included the :GetFont() just incase you didnt know the name of your font file,
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
12-02-10, 05:04 PM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Yea but that would still make that whole line height x or height y.

He's having a string of "ToonName of GuildName" when the target is guilded.

He was asking if he can have it be "ToonName of GuildName" without using 2 fontstrings.
  Reply With Quote
12-03-10, 12:33 AM   #5
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
oh i see,

well if you dont need to change a middle one like

<little Fontstring><Big Fontstring><little Fontstring>

then it should be easy to just make a string for the guild and slap it on the end there.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
12-03-10, 03:13 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
yea making another string is what i did, why it would have been nice to maintain one string was for positioning reasons. It was a pain in the butt to make the two font strings align proper according to name length and then have it change according to if a guild name is present or not then make it calculate the name and the guild name lengths and position accordingly each time... I found though for gettextwidth and set points that the textwidth is about 3x that of the scaling for setpoint so if you divide the textwidths and use that number for the setpoints it'll align right, or rather always be centered. Or at lest real close to it. this was the end result
edit/note - adding some more math to this and feasibly you could change from small to big to small or any combination or extension of that idea.
lua Code:
  1. targetNameGuildFrame:SetScript("OnEvent", function(self)
  2.     local targetName = UnitName("target")
  3.     local targetGuildName = GetGuildInfo("target")
  4.     local unitexists = UnitExists("target")
  5.     local targclass = UnitClass("target")
  6.  
  7.     if targetName then
  8.         if targetGuildName then
  9.             local namegstr = ("%s"):format(getTargetNoU('target'))
  10.             targetNameText:SetText(namegstr)
  11.             local guildstr = ("- %s"):format(targetGuildName)
  12.             targetGuildText:SetText(guildstr)
  13.            
  14.             local Ntex = targetNameText:GetStringWidth()
  15.             local Gtex = targetGuildText:GetStringWidth()
  16.             local mathdone = ((Gtex / 3) - (Ntex / 3))
  17.            
  18.             targetNameText:SetJustifyH("RIGHT")
  19.             targetNameText:SetPoint("RIGHT", targetNameGuildFrame, "CENTER", -mathdone, 0)
  20.             targetNameText:SetPoint("LEFT", targetNameGuildFrame, "LEFT", -mathdone, 0)
  21.             targetGuildText:SetPoint("LEFT", targetNameText, "RIGHT", 0, 0)
  22.             targetGuildText:SetJustifyH("LEFT")
  23.         else
  24.             local namegstr = ("%s"):format(getTargetNoU('target'))
  25.             targetNameText:SetText(namegstr)
  26.             targetGuildText:SetText("")
  27.             targetNameText:SetJustifyH("CENTER")
  28.             targetNameText:SetPoint("RIGHT", targetNameGuildFrame, "RIGHT", 0, 0)
  29.             targetNameText:SetPoint("LEFT", targetNameGuildFrame, "LEFT", 0, 0)
  30.         end
  31.     end
  32. end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 12-03-10 at 03:15 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Change font size half way through string.


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