Thread Tools Display Modes
02-15-11, 10:40 PM   #1
tecu
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Apr 2006
Posts: 30
Raid Icon as a Tag

update 2:
Added RAID_TARGET_UPDATE to unitless events (I didn't notice this was an issue because I used .frequentUpdates).

update 1:
Simplified code so you don't need tex coords.

Hey.

I wanted to stick a raid icon in a FontString right next to the unit name. So that it would show up something like this:

Icon present:
[+ Name........]

No icon:
[Name..........]

In other words, the name would shift over to make room for the icon, and shift back when the icon was not present. Since it wasn't super straightforward (you can't just use {rtX}) I figured I'd share my solution:

EDIT:
Turns out it was pretty straightforward after all:
Code:
	local ristring = '|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_%d:0:0:0:-1|t '
	oUF.Tags['tecu:raidicon'] = function(unit)
		local i = GetRaidTargetIndex(unit)
		if i then
			return ristring:format(i)
		end
	end 
	oUF.TagEvents['tecu:raidicon'] = 'RAID_TARGET_UPDATE'
	oUF.UnitlessTagEvents.RAID_TARGET_UPDATE = true
The ':0:0:0:-1' is ':sizex:sizey:offsetx:offsety'. A zero for the size means 'use the height of the fontstring.'




The rest of the original post:
Saved this because there is some useful info for adding textures to fontstrings.

Code:
	local ritex = {}
	do
		local ristr = [[|TInterface\TargetingFrame\UI-RaidTargetingIcons:0:0:0:-1:256:256:%f:%f:%f:%f|t]]
		setmetatable(ritex, {
			__index = function(t, k)
				-- get coords:
				local x1, y1 = ((k - 1) % 4) * 64, (math.floor((k - 1) / 4)) * 64
				
				-- texture escape string:
				local r = ristr:format(x1, x1 + 64, y1, y1 + 64)
				
				-- cache it
				rawset(t, k, r)
				
				-- 
				return r
			end
		})
	end
	oUF.Tags['tecu:raidicon'] = function(unit)
		local i = GetRaidTargetIndex(unit)
		if i then
			return ritex[i]
		end
	end
	oUF.TagEvents['tecu:raidicon'] = 'RAID_TARGET_UPDATE'
oUF.UnitlessTagEvents.RAID_TARGET_UPDATE = true
And some notes:
  • Interface\TargetingFrame\UI-RaidTargetingIcons is 256x256, with icons 1-4 in the top row, and 2-8 in the second.
  • Each icon takes up a 64x64 square of this texture.
  • The numbers in the escape sequence are explained here.
  • BUT (and this is the real reason I bothered posting this): the texture coords used are not normalized to [0, 1] but instead to the dimensions of the texture file itself.

Maybe someone will find this useful!

Last edited by tecu : 02-18-11 at 05:43 PM. Reason: more corrections
  Reply With Quote
02-16-11, 02:28 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Copycat. Thanks alot.
__________________
| 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
02-16-11, 10:24 AM   #3
nin
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 213
This is awesome, Thanks for sharing it!

I'm having one issue though.. not sure if it's something in my layout that might interfere.

But are the icons updating properly for you guys?

I need too "retarget" a target if i got it selected and set an icon. if that makes sense. so if i keep targeting the same thing and switch icons it wont update until i retarget it. my tot frame updates just fine.

thanks

Last edited by nin : 02-16-11 at 10:26 AM.
  Reply With Quote
02-16-11, 03:33 PM   #4
tecu
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Apr 2006
Posts: 30
Update:

So it was bugging me that there should be something in the default UI to make this easy and well:

GlobalStrings.lua:
Code:
TARGET_ICON_SET = "|Hplayer:%s|h[%s]|h sets |TInterface\\TargetingFrame\\UI-RaidTargetingIcon_%d:0|t on %s.";
So it looks like you don't need all the complicated nonsense I posted before and your tag function can look something like this:

Code:
local ristring = '|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_%d:0|t'
oUF.Tags['tecu:raidicon'] = function(unit)
		local i = GetRaidTargetIndex(unit)
		if i then
			return ristring:format(i)
		end
	end
Haven't tested it, but if it works I'll update the OP.

nin:
It sounds like maybe you don't have RAID_TARGET_UPDATE in your TagEvents.
  Reply With Quote
02-17-11, 10:19 AM   #5
nin
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 213
Latest version works for me,oddly enough im still not getting it too update on target frame.. only on tot :P

and yes i am using RAID_TARGET_UPDATE.

I've tried this tag with 2 different layouts now just too see if it's something in my own that was breaking it and i get the same thing happening.

Any ideas?

thanks.
  Reply With Quote
02-17-11, 01:02 PM   #6
tecu
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Apr 2006
Posts: 30
I made another mistake! RAID_TARGET_UPDATE is a unitless event, so you need to add

oUF.UnitlessTagEvents.RAID_TARGET_UPDATE = true

as well, I think. Not entirely sure if that's the way to do it; I'll test it out later.
  Reply With Quote
02-18-11, 05:44 PM   #7
tecu
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Apr 2006
Posts: 30
Updated the OP with the UnitlessEvents info. This is probably why your thing wasn't updating, nin.
  Reply With Quote
02-18-11, 06:28 PM   #8
hankthetank
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 64
Alright, so this is why my reputation tag failed to update.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Raid Icon as a Tag


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