Thread Tools Display Modes
09-22-14, 10:56 AM   #1
saxitoxin
A Theradrim Guardian
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 60
some help/tutorials

I'm looking for some help, hopefully a tutorial that explains tags, I have created a few frames, and would like to add som text to them, health, name, lvl, power and so on.
Any push in the right direction is appreciated
  Reply With Quote
09-22-14, 12:35 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
To add a tag to your frame:

Code:
local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
text:SetPoint("BOTTOM", frame, "TOP", 0, 2)
frame:Tag(text, "[name] - Level [level] [creature]")
Pretty straightforward. Just create a font string, and call the :Tag method on your frame, passing it the font string object first, and the tag string second. The font string doesn't have to be parented directly to the frame, but the :Tag method is always on the frame even if you parent the font string to eg. your health bar.

All the predefined tags are in oUF\elements\tags.lua if you want to see exactly what they do, or here is a list:

Code:
affix
chi
classification
cpoints
curhp
curmana
curpp
dead
group
holypower
leader
leaderlong
level
maxhp
maxmana
maxpp
missinghp
missingpp
name
offline
pereclipse
perhp
perpp
plus
pvp
rare
resting
sex
shadoworbs
shortclassification
smartlevel
soulshards
status
threat
threatcolor
There are some others defined, but they don't have any events attached, so they will not work properly.

To create your own tag:

Code:
oUF.Tags.Events["mytag"] = "SPACE SEPARATED LIST OF EVENTS"

oUF.Tags.Methods["mytag"] = function(unit)
    -- run some code here to get the text and return it
end
As an example, here is the tag I use for unit coloring in my layout:

Code:
oUF.Tags.Events["unitcolor"] = "UNIT_HEALTH UNIT_CLASSIFICATION_CHANGED UNIT_CONNECTION UNIT_FACTION UNIT_REACTION"
oUF.Tags.Methods["unitcolor"] = function(unit)
	local color
	if UnitIsDeadOrGhost(unit) or not UnitIsConnected(unit) then
		color = oUF.colors.disconnected
	elseif UnitIsPlayer(unit) then
		local _, class = UnitClass(unit)
		color = oUF.colors.class[class]
	elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) and not UnitIsTappedByAllThreatList(unit) then
		color = oUF.colors.tapped
	elseif UnitIsEnemy(unit, "player") then
		color = oUF.colors.reaction[1]
	else
		color = oUF.colors.reaction[UnitReaction(unit, "player") or 5]
	end
	return color and ("|cff%02x%02x%02x"):format(color[1] * 255, color[2] * 255, color[3] * 255) or "|cffffffff"
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-24-14, 11:37 AM   #3
saxitoxin
A Theradrim Guardian
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 60
I'm doing something wrong, I can't even get the name to show
this is the code I use in my units/target file
Lua Code:
  1. local name = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  2.     name:SetPoint("BOTTOM", Portrait, "TOP", 0, 4)
  3.     Portrait:Tag(name, "[name]")

and this is all my code in modules/tags file. copied directly from oUF_SquarePortrait, all I have edited is change the name, and made all core instances into tags
Lua Code:
  1. local addon, ns = ...
  2. local cfg = ns.cfg
  3.  
  4.   --container
  5.   local tags = CreateFrame("Frame")
  6.   ns.tags = tags
  7.  
  8.   ---------------------------------------------
  9.   -- FUNCTIONS
  10.   ---------------------------------------------
  11.  
  12.   function tags:CreateDropShadow(parent,edgeFile,edgeSize,padding)
  13.     if parent.dropShadow then return end
  14.     edgeFile = edgeFile or ""
  15.     edgeSize = edgeSize or 8
  16.     padding = padding or 8
  17.     parent.dropShadow = CreateFrame("Frame", nil, parent)
  18.     parent.dropShadow:SetPoint("TOPLEFT",-padding,padding)
  19.     parent.dropShadow:SetPoint("BOTTOMRIGHT",padding,-padding)
  20.     parent.dropShadow:SetBackdrop({ bgFile = nil, edgeFile = edgeFile, tile = false, tileSize = 16, edgeSize = edgeSize, insets = { left = 0, right = 0, top = 0, bottom = 0, }, })  
  21.     local mt = getmetatable(parent).__index
  22.     mt.SetDropShadowColor = function(self,r,g,b,a) self.dropShadow:SetBackdropBorderColor(r or 1, g or 1, b or 1, a or 1) end
  23.   end
  24.  
  25.   --fontstring func
  26.   function tags:NewFontString(parent,family,size,outline,layer)
  27.     local fs = parent:CreateFontString(nil, layer or "OVERLAY")
  28.     fs:SetFont(family,size,outline)
  29.     fs:SetShadowOffset(0, -2)
  30.     fs:SetShadowColor(0,0,0,1)
  31.     return fs
  32.   end
  33.  
  34.   ---------------------------------------------
  35.   -- TAGS
  36.   ---------------------------------------------
  37.  
  38.   --unit name tag
  39.   oUF.Tags.Events["sxui:name"] = "UNIT_NAME_UPDATE UNIT_CONNECTION"
  40.   oUF.Tags.Methods["sxui:name"] = function(unit)
  41.     local name = oUF.Tags.Methods["name"](unit)
  42.     return "|cffffffff"..name.."|r"
  43.   end
  44.  
  45.  
  46.   --unit health tag
  47.   oUF.Tags.Events["sxui:health"] = "UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH"
  48.   oUF.Tags.Methods["sxui:health"] = function(unit)
  49.     local perhp = oUF.Tags.Methods["perhp"](unit)
  50.     return "|cffffffff"..perhp.."|r"
  51.   end
But I still don't get it to work :/
  Reply With Quote
09-24-14, 04:55 PM   #4
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Your portrait element is not your frame.
  Reply With Quote
09-24-14, 08:47 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yep. This right here is your problem:

Originally Posted by saxitoxin View Post
Code:
    local name = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    name:SetPoint("BOTTOM", Portrait, "TOP", 0, 4)
    Portrait:Tag(name, "[name]")
As mentioned in my previous post:

Originally Posted by Phanx View Post
The font string doesn't have to be parented directly to the frame, but the :Tag method is always on the frame even if you parent the font string to eg. your health bar.
Your Portrait object does not have a :Tag method.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » some help/tutorials


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