Thread Tools Display Modes
01-12-15, 01:12 AM   #1
fremion
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 3
Changing target aura icon size based on the target type

Hello

I want to increase the size of target buffs if the target is enemy, and leave them normal if the target is friendly.

I am adding this code into where size for target buffs is defined:
Code:
if UnitIsEnemy("player","target") then b.size = 50 else b.size = 24 end
for example, in ouf skaarj it becomes:

Code:
if cfg.aura.target_buffs then
	local b = CreateFrame('Frame', nil, self)
		-- b.size = 24
		if UnitIsEnemy("player","target") then b.size = 50 else b.size = 24 end
		b.spacing = 4
		b.num = cfg.aura.target_buffs_num
            	b:SetSize(b.size*b.num/2+b.spacing*(b.num/2-1), b.size)
		b:SetPoint('TOPLEFT', self, 'TOPRIGHT', 5, 0)
		b.initialAnchor = 'TOPLEFT' 
		b['growth-y'] = 'DOWN'
            	b.PostCreateIcon = auraIcon
            	b.PostUpdateIcon = PostUpdateIcon
            	self.Buffs = b
end
I also check that the target is properly identified as enemy by testing my if statement in a custom weakauras script. But my aura icons are always small. So far, I have tried modifying ouf_skaarj and ouf_drk_fanupdate using the if statement above but it did not work.

Is this a design limitation or is my code is a wrong one?

Thanks and regards
  Reply With Quote
01-12-15, 02:36 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You're putting your code in the wrong place. Right now you've got it in the part that creates the aura icons when you first log in -- at that point, you'll never have a target, so your (nonexistent) target will never be an enemy, so you'll always be setting the size to 24. Instead, you need to put your code somewhere that will be checked over and over during gameplay to catch target changes.

Fortunately, the Auras/Buffs/Debuffs element supports several callbacks that make this easy. I'd suggest something like this:

Code:
function b:PreSetPosition()
     local size = UnitIsEnemy("player", self.__owner.unit) and 50 or 24
     if size == self.size then return end -- no need to continue
     self.size = size -- set the new size
     self:SetSize(size*b.num/2+b.spacing*(b.num/2-1), size) -- resize the container
     return 1 -- to force oUF to reposition all the icons
end
You can put that where you have your current code, and oUF will automatically call it each time it updates the icons.
__________________
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
01-12-15, 03:15 AM   #3
fremion
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 3
Thanks phanx. Perfect explanation and a very nicely constructed suggestion.

Currently I am working but I will try it (and some variations ofc) as soon as I am at home, my kid goes to sleep and my wife let me play
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Changing target aura icon size based on the target type


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