Thread Tools Display Modes
04-29-09, 09:14 AM   #1
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Converting DogTag for use with oUF

So I am in the process of transitioning from PitBull to oUF. One thing I had setup in my PitBull layout was a DogTag that I got from a DogTag thread on the Elitist Jerks UI forums.

Code:
[(if  ((Abbreviate(Name) ~= Name) and (Length(Name) > 10)) then
    Abbreviate(Name):Substring(1, (Length(Abbreviate(Name)) - 1)):Append(". "):Upper:ClassColor
    Name:Replace(" ", "                            "):Substring(-15, -1):Replace(" ", ""):Truncate(10, nil):Upper:ClassColor
else
    Name:Truncate(10, nil):Upper:ClassColor
end)]
This is the explanation of the code that the author posted as well.

Code:
[(if  ((Abbreviate(Name) ~= Name) and (Length(Name) > 10)) then

-- Checks if the name can be abbreviated (at least one space present),
-- and that the total name length is greater than [10]. 10 can be replaced with
-- any number, that would properly fit your unit frame with no issue.
-- I included this because if there's an ultra short multi-word name, such
-- as "The Dog", it will just display the entire thing.

Abbreviate(Name):Substring(1, (Length(Abbreviate(Name)) - 1)):Append(". "):Upper:ClassColor

-- This creates the abbreviation. Abbreviates the name down,
-- uses substring to start at the first character and pulls out every letter
-- except the last one. Achieved by checking length of the abbreviated name,
-- and subtracting 1 (1 because that's the first letter of the last word that will
-- actually be displayed.) Appends a period for clarity.

Name:Replace(" ", "                            "):Substring(-15, -1):Replace(" ", ""):Truncate(10, nil):Upper:ClassColor

-- This pulls the last word out, using some mega-trickery.
-- Takes the full name, bloats single spaces into twenty.
-- Uses substring to start at the last letter, then pulls out
-- the previous 15 characters, which results in "       Name".
-- Then replaces spaces, nulling them out. If the last word is
-- somehow still too long, it truncates it from the last letters.

else
    Name:Truncate(10, nil):Upper:ClassColor

-- If the name can't be abbreviated (one word), but it's still over the display limit,
-- truncates it to 10 characters.

-- Ta-da! Again, there may be better ways to do this, but this
-- achieves what I was wanting to do!
I was wondering if there was a way to get this implemented into my oUF layout. If someone could point me in the right direction on how to convert this over to oUF it would be greatly appreciated. Thanks in advance.
  Reply With Quote
04-29-09, 12:19 PM   #2
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
looked at this file yet?

Code:
oUF/elements/tags.lua
to cut names up reliably you will need to include utf8lib and use the functions provided by it.

names like "Smeę" actually turn out to be "Sme\195\170", so without utf8lib you won't get legible operations on extended utf8 characters.

here is the tag i use for my raid frames, while not as complex as yours it may give you a point to start from :

Code:
oUF.Tags["[raidhp]"] = function(u)
    o = ""
    if not(u == nil) then
        local c, m, n= UnitHealth(u), UnitHealthMax(u), UnitName(u)
        if UnitIsDead(u) then
            o = "DEAD"
        elseif not UnitIsConnected(u) then
            o = "D/C"
        elseif UnitIsAFK(u) then
            o = "AFK"
        elseif UnitIsGhost(u) then
            o = "GHOST"
        elseif(c >= m) then
            o = n:utf8sub(1,4)
        elseif(UnitCanAttack("player", u)) then
            o = math.floor(c/m*100+0.5).."%"
        else
            o = "-"..numberize(m - c)
        end
    end
    return o
end
oUF.TagEvents["[raidhp]"] = "UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED"
here is the function numberize :
Code:
local numberize = function(val)
    if(val >= 1e3) then
        return ("%.1fk"):format(val / 1e3)
    elseif (val >= 1e6) then
        return ("%.1fm"):format(val / 1e6)
    else
        return val
    end
end
This layout file by tekkub will give you an idea on how to implement oUFs tag system :
http://github.com/tekkub/ouf_tek/blo...bea/layout.lua

Last edited by jadakren : 04-29-09 at 12:25 PM.
  Reply With Quote
04-29-09, 12:42 PM   #3
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Bad jadakren, 'o' is a global!
  Reply With Quote
04-29-09, 01:22 PM   #4
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by p3lim View Post
Bad jadakren, 'o' is a global!
You are the last person on the earth to give people tips about what they should and shouldn't do. Sarcastic tone or not.
  Reply With Quote
04-29-09, 01:29 PM   #5
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
...

god damnit I hate the 10 char minimum post, it ruins the effect of only posting "..."
__________________
I have reached enlightment.
Thank you bacon!
  Reply With Quote
04-29-09, 01:37 PM   #6
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by haste View Post
You are the last person on the earth to give people tips about what they should and shouldn't do. Sarcastic tone or not.
Well, 'o' shouldn't be a global variable, as its most likely to interfer with other addons
  Reply With Quote
04-29-09, 01:45 PM   #7
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by p3lim View Post
Well, 'o' shouldn't be a global variable, as its most likely to interfer with other addons
Feel free to explain us how it will interfere with other add-ons. As you should have knowledge about this, since you are enforcing it like a claw.
  Reply With Quote
04-29-09, 01:45 PM   #8
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
o h h . . . .
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
04-29-09, 01:57 PM   #9
Shadowed
...
Premium Member
Featured
Join Date: Feb 2006
Posts: 387
Originally Posted by haste View Post
Feel free to explain us how it will interfere with other add-ons. As you should have knowledge about this, since you are enforcing it like a claw.
What if I stored a layout in a global table called o, after all it is called "Otravi Unit Frames", completely reasonable!
  Reply With Quote
04-29-09, 02:15 PM   #10
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
oUF oUF ouF ouF ouf ouf unf unf unf unf unf
__________________
I have reached enlightment.
Thank you bacon!
  Reply With Quote
04-29-09, 02:42 PM   #11
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Glad the thread was a smash hit =)
  Reply With Quote
04-29-09, 03:28 PM   #12
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
??
Code:
oUF.Tags["[name]"] = function(u)
    o = ""
    if not(u == nil) then
        local n =  UnitName(u)
        if UnitIsDead(u) then
            o = "Dead"
        elseif not UnitIsConnected(u) then
            o = "D/C"
        elseif UnitIsAFK(u) then
            o = "AFK"
        elseif UnitIsGhost(u) then
            o = "Ghost"
        else
            o = n:utf8sub(1,4)
        elseif (Abbreviate(self.Name)~=self.Name) and (Length(self.Name)>10) then
            Abbreviate(self.Name):Substring(1, (Length(Abbreviate(self.Name)) - 1)):Append(".")
            self.Name:Repalce(" ", "                                   ):Substring(-15,-1):Replace(" ", ""):Truncate(10,nil)
        else
            self.Name:Truncate(10,nil)
        end
    end
    return o
end
oUF.TagEvents["[name]"] = "UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED"
  Reply With Quote
04-29-09, 03:51 PM   #13
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
methinks the ***** in this thread (maybe?) is that you should use "local o"
__________________
I have reached enlightment.
Thank you bacon!
  Reply With Quote
04-30-09, 07:36 AM   #14
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Code:
oUF.Tags["[name]"] = function(u)
    Local o = ""
    if not(u == nil) then
        local n =  UnitName(u)
        if UnitIsDead(u) then
            o = "Dead"
        elseif not UnitIsConnected(u) then
            o = "D/C"
        elseif UnitIsAFK(u) then
            o = "AFK"
        elseif UnitIsGhost(u) then
            o = "Ghost"
        elseif (Abbreviate(self.Name)~=self.Name) and (Length(self.Name)>10) then
            Abbreviate(self.Name):Substring(1, (Length(Abbreviate(self.Name)) - 1)):Append(".")
            self.Name:Replace(" ", "                                   "):Substring(-15,-1):Replace(" ", ""):Truncate(10,nil)
        else
            self.Name:Truncate(10,nil)
        end
    end
    return o
end
oUF.TagEvents["[name]"] = "UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED"
After messing around with this a little last night, it appears that Abbreviate isn't something that is recognized by oUF. So the

I thought I could find the abbreviate function from DogTag3.0 Lib and copy it over, but I was unable to find any reference to it. I could only find Abbrev and it was for "shortclassification" "shortclass" and "shortsex" .

There is something that I am overlooking in my search, and I for the life of me I am unable to figure it out.
  Reply With Quote
04-30-09, 07:53 AM   #15
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by Druidicbeast View Post
Code:
oUF.Tags["[name]"] = function(u)
    Local o = ""
    if not(u == nil) then
        local n =  UnitName(u)
        if UnitIsDead(u) then
            o = "Dead"
        elseif not UnitIsConnected(u) then
            o = "D/C"
        elseif UnitIsAFK(u) then
            o = "AFK"
        elseif UnitIsGhost(u) then
            o = "Ghost"
        elseif (Abbreviate(self.Name)~=self.Name) and (Length(self.Name)>10) then
            Abbreviate(self.Name):Substring(1, (Length(Abbreviate(self.Name)) - 1)):Append(".")
            self.Name:Replace(" ", "                                   "):Substring(-15,-1):Replace(" ", ""):Truncate(10,nil)
        else
            self.Name:Truncate(10,nil)
        end
    end
    return o
end
oUF.TagEvents["[name]"] = "UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED"
After messing around with this a little last night, it appears that Abbreviate isn't something that is recognized by oUF. So the

I thought I could find the abbreviate function from DogTag3.0 Lib and copy it over, but I was unable to find any reference to it. I could only find Abbrev and it was for "shortclassification" "shortclass" and "shortsex" .

There is something that I am overlooking in my search, and I for the life of me I am unable to figure it out.
'local' is case sensitive.
Functions must be valid, i guess that 'Abbreviate' and 'Length' etc is made by DogTag and Im not sure what they actually do to the string.

Also, custom tags should have custom names, overriding the '[name]' tag can mess up other layouts.
  Reply With Quote
04-30-09, 08:08 AM   #16
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
try this:
Code:
oUF.TagEvents['[customname]'] = 'UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED'
oUF.Tags['[customname]'] = function(unit)
	if(UnitIsDead(unit)) then
		return 'Dead'
	elseif(not UnitIsConnected(unit)) then
		return 'D/C'
	elseif(UnitIsAFK(unit)) then
		return 'AFK'
	elseif(UnitIsGhost(unit)) then
		return 'Ghost'
	else
		local name = UnitName(unit)
		local abbreviated = name:gsub(' ', ' ')

		if((abbreviated(name) ~= name) and (string.len(name) > 10)) then
			local str = abbreviated:sub(1, string.len(abbreviated) - 1):string.append('. ')
			return oUF.Tags['[raidcolor]'](unit)..str:rep(' ', '                            '):sub(-15, -1):rep(' ', ''):sub(0, 10)
		else
			return oUF.Tags['[raidcolor]'](unit)..name:sub(0, 10)
	end
end
I'm not that good with string.sub so that might be wrong.

Last edited by p3lim : 04-30-09 at 08:12 AM.
  Reply With Quote
04-30-09, 09:02 AM   #17
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Originally Posted by p3lim View Post
try this:
Code:
oUF.TagEvents['[customname]'] = 'UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED'
oUF.Tags['[customname]'] = function(unit)
	if(UnitIsDead(unit)) then
		return 'Dead'
	elseif(not UnitIsConnected(unit)) then
		return 'D/C'
	elseif(UnitIsAFK(unit)) then
		return 'AFK'
	elseif(UnitIsGhost(unit)) then
		return 'Ghost'
	else
		local name = UnitName(unit)
		local abbreviated = name:gsub(' ', ' ')

		if((abbreviated(name) ~= name) and (string.len(name) > 10)) then
			local str = abbreviated:sub(1, string.len(abbreviated) - 1):string.append('. ')
			return oUF.Tags['[raidcolor]'](unit)..str:rep(' ', '                            '):sub(-15, -1):rep(' ', ''):sub(0, 10)
		else
			return oUF.Tags['[raidcolor]'](unit)..name:sub(0, 10)
	end
end
I'm not that good with string.sub so that might be wrong.
Thank you for your reply. I am currently at work, so I am unable to try it out. I will give it a shot when I get home and post an update here.
  Reply With Quote
04-30-09, 10:40 PM   #18
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Ok I finally got a chance to try it out after raid. I am getting this error:

Code:
Interface\AddOns\oUF_Septembark\Septembark_Main.lua:123: function arguments expected near '.'
Line 123 is what I have in bold green below:

Code:
oUF.TagEvents['[customname]'] = 'UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED'
oUF.Tags['[customname]'] = function(unit)
	if(UnitIsDead(unit)) then
		return 'Dead'
	elseif(not UnitIsConnected(unit)) then
		return 'D/C'
	elseif(UnitIsAFK(unit)) then
		return 'AFK'
	elseif(UnitIsGhost(unit)) then
		return 'Ghost'
	else
		local name = UnitName(unit)
		local abbreviated = name:gsub(' ', ' ')

		if((abbreviated(name) ~= name) and (string.len(name) > 10)) then
			local str = abbreviated:sub(1, string.len(abbreviated) - 1):string.append('. ')
			return oUF.Tags['[raidcolor]'](unit)..str:rep(' ', '                            '):sub(-15, -1):rep(' ', ''):sub(0, 10)
		else
			return oUF.Tags['[raidcolor]'](unit)..name:sub(0, 10)
	end
end
  Reply With Quote
04-30-09, 10:44 PM   #19
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
I think you're horribly complicating this... but that's to be expected if you were using DogTags before. Ignoring the conditionals at the start, what do you want your little [customname] tag to look like?
__________________
I have reached enlightment.
Thank you bacon!
  Reply With Quote
05-01-09, 08:21 AM   #20
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Originally Posted by Tekkub View Post
I think you're horribly complicating this... but that's to be expected if you were using DogTags before. Ignoring the conditionals at the start, what do you want your little [customname] tag to look like?
In short....abbreviate a name vs. truncating it. An example would be Lightning Charged Iron Dwarf. Using the DogTag this would read L. C. Iron Dwarf whereas truncating it would just be Lighting Charged.... .

Truncating doesn't help me when there are several mobs with the same beginning of a name. Lots of mobs have a generic beginning and then are identified by Acolyte, Spellweaver, Bloodknight, Centurion, etc.

Sorry if I am making this horribly complicated , I am still learning this whole lua thing. I am coming from PitBull in hopes to "trim the fat" from my unit frames (5.6mb to be exact). In oUF I am given the chance to only take what I want.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Converting DogTag for use with oUF


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