Reply
 
Thread Tools Display Modes
Old 08-16-12, 11:58 PM   #1
Cralus
A Defias Bandit
Join Date: Apr 2012
Posts: 2
Creating Buff Timers

(I managed to resolve the buff timers problem, but didn't want create a separate thread for this question.)
Contrary to the thread title, I actually have a question about my raid fontstring.

How can I truncate the names on my raid frames so they don't spill out over the sides?


Code:
lib.gen_fontstring = function(f, name, size, outline)
	local fs = f:CreateFontString(nil, "OVERLAY")
    fs:SetFont(name, size, outline)
    return fs
end
Code:
lib.raid_fontstrings = function(f)
    local name = lib.gen_fontstring(f.Health, config.font, 8, "OUTLINEMONOCHROME")
    name:SetPoint("CENTER", f.Health, "CENTER", 0, 0)
    name:SetJustifyH("LEFT")
	
	f:Tag(name, "[unitcolor][name]")
end
thanks

Last edited by Cralus : 08-17-12 at 12:23 AM.
Cralus is offline   Reply With Quote
Old 08-17-12, 01:27 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,141
You can do that by using SetPoints. Remove the "center" SetPoint.

Add two SetPoints:
Lua Code:
  1. name:SetPoint("LEFT", f.Health, , 2, 0)
  2. name:SetPoint("RIGHT", f.Health, , -2, 0)
Now your name will stick inside your health plate.

You can even combine health and your name string:
Lua Code:
  1. --name object
  2. name:SetPoint("LEFT", f.Health, "LEFT", 2, 0)
  3. name:SetJustifyH("LEFT")
  4. --health value object
  5. hpval:SetPoint("RIGHT", f.Health, "RIGHT", -2, 0)
  6. name:SetJustifyH("RIGHT")
  7. --connect name and hpvalue (right point of name will be -5px to the left point of hpval)
  8. name:SetPoint("RIGHT", hpval, "LEFT", -5, 0)
__________________
| Simple is beautiful.
| Blog | Roth UI | Roth UI FAQ | GoogleCode | Zork | Guild | zorker.de

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
zork is offline   Reply With Quote
Old 08-17-12, 01:45 PM   #3
Cralus
A Defias Bandit
Join Date: Apr 2012
Posts: 2
Thanks, Zork!

And yeah, I usually have a consolidated fontstring for Name/HP/PP but my raid frames ONLY have Name displayed.
Cralus is offline   Reply With Quote
Old 08-17-12, 02:03 PM   #4
Senit24
A Fallenroot Satyr
AddOn Compiler - Click to view compilations
Join Date: Jul 2012
Posts: 28
I'm trying to accomplish a similar thing, but this gave me a "..." after the name is cut off. Is there any way to remove that?
Senit24 is offline   Reply With Quote
Old 08-22-12, 06:20 AM   #5
semlar
A Cobalt Mageweaver
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 216
To truncate a string to a certain number of characters you can use string.sub. For example name:sub(1,3) would just return the first 3 letters of the name.
semlar is offline   Reply With Quote
Old 08-22-12, 08:57 AM   #6
Torhal
A Molten Giant
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 984
The problem with truncation is variable-width fonts - you can't reliably determine an appropriate cutoff point.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of Revelation, Spamalyzer, TravelAgent, Volumizer, and many other AddOns.
Torhal is offline   Reply With Quote
Old 09-03-12, 08:00 PM   #7
Senit24
A Fallenroot Satyr
AddOn Compiler - Click to view compilations
Join Date: Jul 2012
Posts: 28
Semlar, I tried adding "name:sub(1,3)" as a test, but it returned "sub is a nil value". Know why?
Code:
lib.tar_fontstrings = function(f)
    local name, hpval
    --health/name text strings
    if not f.hidename then
		name = lib.gen_fontstring(f.Health, config.font, 8, "OUTLINEMONOCHROME")
		name:SetPoint("LEFT", f.Health, "LEFT", 19, -16)
		name:SetJustifyH("LEFT")
		name:sub(1,3)
    end
Senit24 is offline   Reply With Quote
Old 09-03-12, 11:30 PM   #8
Torhal
A Molten Giant
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 984
A FontString is not the same as a Lua string object - there is no "sub" method.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of Revelation, Spamalyzer, TravelAgent, Volumizer, and many other AddOns.
Torhal is offline   Reply With Quote
Old 09-04-12, 01:13 AM   #9
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 2,709
If you want to truncate the value, you have to do it every time you set the text value:

Code:
fontstring:SetText(text:sub(1, 3))
On a side note, strsub(text, 1,3) is faster than text:sub(1, 3), especially if you upvalue strsub. If you're using it in code that runs very frequently (eg. in response to UNIT_HEALTH) you may want to switch notation. If you're using it in code that doesn't run very often, or doesn't run in combat (eg. in response to the user changing an option) then it doesn't really matter, so use whichever you think is more aesthetically pleasing.
__________________
Author/maintainer of Grid, PhanxChat, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Old 09-05-12, 08:51 PM   #10
Senit24
A Fallenroot Satyr
AddOn Compiler - Click to view compilations
Join Date: Jul 2012
Posts: 28
Originally Posted by Phanx View Post
If you want to truncate the value, you have to do it every time you set the text value:

Code:
fontstring:SetText(text:sub(1, 3))
On a side note, strsub(text, 1,3) is faster than text:sub(1, 3), especially if you upvalue strsub. If you're using it in code that runs very frequently (eg. in response to UNIT_HEALTH) you may want to switch notation. If you're using it in code that doesn't run very often, or doesn't run in combat (eg. in response to the user changing an option) then it doesn't really matter, so use whichever you think is more aesthetically pleasing.
Love you Phanx, thanks! And I'm using it for Raid Names, so I think either will work.
Senit24 is offline   Reply With Quote
Old 09-06-12, 01:59 AM   #11
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,141
It will not. Raid frames can make use of multibyte characters. (UTF-8)

Someone like Ûlrîc or Ôéâ ... (not to forget asian players) etc. If I remember correctly sub does cut one byte. If the current character looked at has multibyte characters in the name the sub function has to adept or it will be possible to cut multibyte characters in half which will destroy the name.

There are some scripts on this already. Others may have the links, I do not.

I do not understand why the hassle. Just do the "..." thing and you will have no trouble without having to do any computing.
__________________
| Simple is beautiful.
| Blog | Roth UI | Roth UI FAQ | GoogleCode | Zork | Guild | zorker.de

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 09-06-12 at 02:03 AM.
zork is offline   Reply With Quote
Old 09-06-12, 02:22 PM   #12
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 2,709
The simplest method would be to include the small UTF8 library in your addon, and then do:

Lua Code:
  1. -- upvalue at/near the top of your file:
  2. local utf8sub = string.utf8sub
  3.  
  4. -- call utf8sub instead of strsub to trim the text:
  5. fontstring:SetText(utf8sub(text, 1, 3))
__________________
Author/maintainer of Grid, PhanxChat, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Old 09-06-12, 06:54 PM   #13
Senit24
A Fallenroot Satyr
AddOn Compiler - Click to view compilations
Join Date: Jul 2012
Posts: 28
I'll try that

Originally Posted by zork View Post
I do not understand why the hassle. Just do the "..." thing and you will have no trouble without having to do any computing.
Because "..." takes up even more space, leaving us with [ Kh... ] [ Ba... ] [ Tr... ] etc. So ugly!
*The unit frames are going to be pretty small as it is
Senit24 is offline   Reply With Quote
Old 09-09-12, 12:04 AM   #14
Senit24
A Fallenroot Satyr
AddOn Compiler - Click to view compilations
Join Date: Jul 2012
Posts: 28
I've made this work in a slightly different way than you described, creating a new Tag for name:
Code:
oUF.Tags["playername"] = function(u)
		return UnitName(r or u):sub(1, 3)
	end
oUF.TagEvents["playername"] = "UNIT_NAME_UPDATE"
So I've installed the UTF8 directory, but I'm unsure how to implement it. Is there a way to make it fit with my Tag, or an easier method in general? -Thanks

Last edited by Senit24 : 09-09-12 at 12:07 AM.
Senit24 is offline   Reply With Quote
Old 09-09-12, 12:40 AM   #15
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 2,709
Originally Posted by Senit24 View Post
So I've installed the UTF8 directory, but I'm unsure how to implement it. Is there a way to make it fit with my Tag, or an easier method in general? -Thanks
If you're planning to release your layout, you should embed the UTF8 library inside your addon. If you're using SVN, you should add the library to your svn:externals; click on the "Repository" tab on the UTF8 project page I linked earlier to get the SVN URL. If you're not using SVN, just make a new folder inside your layout folder named "Libs", and copy the UTF8 folder inside the Libs folder. Either way, add the appropriate path in your layout's TOC file to load the library as part of the addon:

Code:
## Interface: 50001
## Title: oUF_Senit
## Dependencies: oUF
## OptionalDependencies: UTF8

Libs\UTF8\utf8.lua

oUF_Senit.lua
Once you've done that, or if you're just using the layout for yourself and have UTF8 installed as a standalone addon, just change your tag function to use the UTF8 version of string.sub:

Code:
oUF.Tags["playername"] = function(u)
	return UnitName(r or u):utf8sub(1, 3)
end
oUF.TagEvents["playername"] = "UNIT_NAME_UPDATE"
If you want to make it (very slightly) faster, use this instead:

Code:
local utf8sub = string.utf8sub
oUF.Tags["playername"] = function(u)
	return utf8sub((UnitName(r or u)), 1, 3)
end
oUF.TagEvents["playername"] = "UNIT_NAME_UPDATE"
On a side note, why are you calling UnitName(r or u) instead of UnitName(u)? Where is r coming from, and why are you prioritizing it over the actual unit whose name change event fired?
__________________
Author/maintainer of Grid, PhanxChat, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Old 09-09-12, 02:32 AM   #16
Senit24
A Fallenroot Satyr
AddOn Compiler - Click to view compilations
Join Date: Jul 2012
Posts: 28
I'm replying from the phone so I can't check whether this works, but I'm sure it will. Great detail, thank you.

The (r) arugment was deprecated when I rewrote my reaction function. I saw that and took it out right after posting my last response.
Senit24 is offline   Reply With Quote
Old 09-09-12, 09:08 AM   #17
Senit24
A Fallenroot Satyr
AddOn Compiler - Click to view compilations
Join Date: Jul 2012
Posts: 28
Tested - works great! I was doing the exact same thing, but I was installing the UTF8 directory wrong. I forgot to include it in my TOC! >.<
Senit24 is offline   Reply With Quote
Old 09-09-12, 02:57 PM   #18
Rainrider
A Chromatic Dragonspawn
Join Date: Nov 2008
Posts: 183
That's how haste defines the default name tag.

u = self.unit, r = fontstring.overrideUnit and self.realUnit (self is the parent frame of the fontstring for the tag)

oUF uses realUnit as a frame unit: i.e. when you enter a vehicle unit becomes "vehicle" and realUnit becomes "player" for the player frame (as it then represents the vehicle the player has entered) and for the pet frame unit = "player" and realUnit = "pet". If unit is the same as realUnit then realUnit is set to nil.

So, as long as one does not set self.overrideUnit = true, it is safe to keep the call like that as r is always nil.

Edit: if would be interesting to set overrideUnit = true for the pet frame and enter a vehicle on a character without a pet. Or am I missing something?
Edit2: well, then you get the vehicle name instead of the player's. It seems WoW considers your vehicle to be your pet too.

Last edited by Rainrider : 09-09-12 at 03:40 PM. Reason: overrideUnit has to be set for the fontstring not the frame that holds it.
Rainrider is offline   Reply With Quote
Reply

Go BackWoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Creating Buff Timers

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