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

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