Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 

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