WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Converting DogTag for use with oUF (https://www.wowinterface.com/forums/showthread.php?t=23053)

Druidicbeast 04-29-09 09:14 AM

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.

jadakren 04-29-09 12:19 PM

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

p3lim 04-29-09 12:42 PM

Bad jadakren, 'o' is a global!

haste 04-29-09 01:22 PM

Quote:

Originally Posted by p3lim (Post 132045)
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.

Tekkub 04-29-09 01:29 PM

...

god damnit I hate the 10 char minimum post, it ruins the effect of only posting "..."

p3lim 04-29-09 01:37 PM

Quote:

Originally Posted by haste (Post 132057)
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

haste 04-29-09 01:45 PM

Quote:

Originally Posted by p3lim (Post 132064)
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.

zork 04-29-09 01:45 PM

o h h . . . .

Shadowed 04-29-09 01:57 PM

Quote:

Originally Posted by haste (Post 132066)
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!

Tekkub 04-29-09 02:15 PM

oUF oUF ouF ouF ouf ouf unf unf unf unf unf

Druidicbeast 04-29-09 02:42 PM

Glad the thread was a smash hit =)

Druidicbeast 04-29-09 03:28 PM

??
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"


Tekkub 04-29-09 03:51 PM

methinks the ***** in this thread (maybe?) is that you should use "local o"

Druidicbeast 04-30-09 07:36 AM

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.

p3lim 04-30-09 07:53 AM

Quote:

Originally Posted by Druidicbeast (Post 132287)
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.

p3lim 04-30-09 08:08 AM

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.

Druidicbeast 04-30-09 09:02 AM

Quote:

Originally Posted by p3lim (Post 132295)
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.

Druidicbeast 04-30-09 10:40 PM

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


Tekkub 04-30-09 10:44 PM

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?

Druidicbeast 05-01-09 08:21 AM

Quote:

Originally Posted by Tekkub (Post 132506)
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.


All times are GMT -6. The time now is 01:17 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI