WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Casters Classcolor. (https://www.wowinterface.com/forums/showthread.php?t=45198)

nin 11-20-12 02:27 AM

Casters Classcolor.
 
Hey fellow Wowiers!

Im currently tracking buffs and debuffs on my raidframes, i would like to try and have my bufficons border colored by the class it is cast from, if that makes sense.

Currently the part of the code looks like this were i color the border..

Lua Code:
  1. local buffcolor = { r = 1.0, g = 1.0, b = 0 }
  2. local updateBuff = function(icon, texture, count, dtype, duration, expires, buff)
  3. local color = buffcolor
  4. icon.border:SetBackdropBorderColor(color.r, color.g, color.b,1)

Tried a couple things but getting errors and my lua knowledge is very limited..have a feeling i need to get this to work with the color function somehow?

Lua Code:
  1. local _, class = UnitClass(unit)
  2. local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]

Im probably really off here and it makes me feel really dumb :P.. so if anyone could point me in the right direction i'd be thankful!

EDIT: If you need more code to be able to help out let me know! thank you.

zork 11-20-12 04:51 AM

You want sth like this.

Lua Code:
  1. --functions
  2.  
  3.   local postUpdateDebuff = function(element, unit, button, index, offset)
  4.  
  5.     local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, index, "HARMFUL")
  6.     if not name then return end
  7.     local _, class = UnitClass(caster)
  8.     if not class then return end  
  9.     local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  10.     if not color then return end
  11.     --print(color)
  12.     button.border:SetBackdropBorderColor(color.r, color.g, color.b,1)
  13.  
  14.   end
  15.  
  16.   local postUpdateBuff = function(element, unit, button, index, offset)
  17.  
  18.     local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, index, "HELPFUL")
  19.     if not name then return end
  20.     local _, class = UnitClass(caster)
  21.     if not class then return end  
  22.     local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  23.     if not color then return end
  24.     --print(color)
  25.     button.border:SetBackdropBorderColor(color.r, color.g, color.b,1)
  26.  
  27.   end  
  28.  
  29.   local postUpdateAura = function(element, unit, button, index, offset)
  30.  
  31.     local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, index)
  32.     if not name then return end
  33.     local _, class = UnitClass(caster)
  34.     if not class then return end  
  35.     local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  36.     if not color then return end
  37.     --print(color)
  38.     button.border:SetBackdropBorderColor(color.r, color.g, color.b,1)
  39.  
  40.   end  
  41.  
  42.   --post update aura icon
  43.  
  44.   --self.Buffs.PostUpdateIcon = postUpdateBuff
  45.   --self.Debuffs.PostUpdateIcon = postUpdateDebuff
  46.   self.Auras.PostUpdateIcon = postUpdateAura

Which function you need to call depends on how you created your aura icons. If you used self.Buffs you use postUdateBuff ... etc.

Regarding UnitAura check: http://wowprogramming.com/docs/api/UnitAura
For the oUF documentation on auras read: https://github.com/haste/oUF/wiki/element---auras

I'm currently not sure. It may actually be possible to work with CreateAura instead of PostUpdateIcon because you can extract the unit from element:GetParent().unit.

That would look like this for Auras:

Lua Code:
  1. --function
  2.   local createIcon = function(element, index)
  3.  
  4.     local unit = element:GetParent().unit
  5.     if not unit then return end
  6.     local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, index)
  7.     if not name then return end
  8.     local _, class = UnitClass(caster)
  9.     if not class then return end  
  10.     local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  11.     if not color then return end
  12.     --print(color)
  13.     button.border:SetBackdropBorderColor(color.r, color.g, color.b,1)
  14.  
  15.   end  
  16.  
  17.   self.Auras.CreateIcon = createIcon

The benefit is that CreateIcon is only used once. But I'm not sure if it is sufficient (means if it is called each time a new aura is created, even if an aura existed already for the same index)

nin 11-20-12 12:01 PM

Thanks for the elaborate answer Zork, i really appreciate it!

I'll play around with it and see if i can get it working! :)

If it's of any help to easier get this working in my current code, i use oUF_Mlight's way to track auras.. which is based of oUF_Freebgrid.

https://github.com/Paojy/oUF_Mlight/...eds/auras2.lua

Thanks again! :)

Rainrider 11-20-12 12:28 PM

You have to use PostUpdate as CreateIcon won't update the border color.

You could use the same code as proposed by Zork for Buffs/Debuffs/Auras like that:
Code:

local postUpdateAura = function(element, unit, button, index, offset)
 
    local name, _, _, _, _, _, _, caster = UnitAura(unit, index, button.filter)
    if not name then return end
    local _, class = UnitClass(caster)
    if not class then return end 
    local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
    if not color then return end
    --print(color)
    button.border:SetBackdropBorderColor(color.r, color.g, color.b,1)
 
end

The other possibility is to use CustomFilter, because your icon.border is not icon.overlay. CustomFilter gets the results from UnitAura passed as local arguments, so you don't need to call it one more time in PostUpdate.

nin 11-20-12 02:27 PM

Thanks for the info guys!

What confuses me the most is the structure i have i guess...

I can get this to work with my buffs/debuffs that i use for all my UF's but raidframes because i use a different structure there with spellID's and stuff.

Now i have a file called auras (this is debuffs on my raidframes) and a file called auras2 (these are buffs on my raidframes).

I spawn them in my core layout with

Lua Code:
  1. local auras = CreateFrame("Frame", nil, self.Health)
  2. auras:SetSize(22,22)
  3. auras:SetPoint("CENTER", self.Health,0,6)
  4. auras.size = 21
  5. self.freebAuras = auras
  6. self.freebAuras.PostUpdateIcon = postUpdateAura

Most of the confusion is if i add the postupdate function in my core or in my aura files?

I tried both, im not getting any errors, but the frames are just not being colored(white).

Thanks for being awesome.

Rainrider 11-20-12 02:28 PM

I only overflew the code for oUF_Mlight. What you linked in your post is apparently some custom aura element for tank buffs. There is another one for raid debuffs I suppose and the standard oUF auras element in core.lua. I suppose you don't need to change the first two and only want the alter the behavior of the default aura element.

In that case you'll want to change PostUpdateIcon like that:
Code:

local PostUpdateIcon = function(icons, unit, icon, index, offset)
        local name, _, _, _, _, duration, expirationTime, caster, _, _, SpellID = UnitAura(unit, index, icon.filter)

        if icon.isPlayer or UnitIsFriend("player", unit) or not icon.isDebuff or oUF_MlightDB.AuraFilterwhitelist[tostring(SpellID)] then
                icon.icon:SetDesaturated(false)
                if duration and duration > 0 then
                        icon.remaining:Show()
                else
                        icon.remaining:Hide()
                end
                icon.count:Show()
               
                local _, class = UnitClass(caster)
                if class then
                        local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
                        if color then
                                icon.bd:SetBackdropBorderColor(color.r, color.g, color.b,1)
                        end
                end

        else
                icon.icon:SetDesaturated(true) -- grey other's debuff casted on enemy.
                icon.overlay:Hide()
                icon.remaining:Hide()
                icon.count:Hide()
        end

        if duration then
                icon.bd:Show() -- if the aura is not a gap icon show it"s bd
        end

        icon.expires = expirationTime
        icon:SetScript("OnUpdate", CreateAuraTimer)
end

I haven't tested this and I don't know if it plays well with all the conditions for desaturation and hiding the backdrop.

Phanx 11-20-12 03:52 PM

Quote:

Originally Posted by nin (Post 269198)
Most of the confusion is if i add the postupdate function in my core or in my aura files?

I tried both, im not getting any errors, but the frames are just not being colored(white).

It doesn't matter where the actual function is defined, as long as postUpdateAura is a valid reference to the function when this line of code executes:

Code:

self.freebAuras.PostUpdateIcon = postUpdateAura
Based on your description of the problem, it sounds like postUpdateAura is nil when that line runs, so you're not actually setting a PostUpdateIcon member on the element.

nin 11-22-12 12:51 PM

Thanks, im getting somewhere thanks to all your great help! :)

It is kind of working now but i am unfortunately getting errors when trying lfr, haven't had time
to test it more... but i've had a full lfr with no error aswell.

Mostly i can say that when entering Gara'jals spiritrealm i always got errors.

This is how i added it

Lua Code:
  1. local show = CustomFilter(auras, unit, icon, name, rank, texture, count, dtype, duration, expires, caster, spellID)
  2.         if(show) and icon.buff then
  3.         local _, class = UnitClass(caster)
  4.         if class then
  5.             local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  6.             if color then
  7.                 icon.border:SetBackdropBorderColor(color.r, color.g, color.b,1)
  8.             end
  9.         end

The error is pointing at

Lua Code:
  1. local _, class = UnitClass(caster)

and also this part in oUF\events.lua

Lua Code:
  1. eventFrame:SetScript('OnEvent', function(_, event, arg1, ...)
  2.         local listeners = registry[event]
  3.         if arg1 and not sharedUnitEvents[event] then
  4.             local frames = framesForUnit[arg1]
  5.             if frames then
  6.                 for frame in next, frames do
  7.                     if listeners[frame] and frame:IsVisible() then
  8.                         frame[event](frame, event, arg1, ...)
  9.                     end
  10.                 end
  11.             end
  12.         else
  13.             for frame in next, listeners do
  14.                 if frame:IsVisible() then
  15.                     frame[event](frame, event, arg1, ...)
  16.                 end
  17.             end
  18.         end
  19.     end)

Any hints on what the cause might be, because that error doesn't tell me that much im afraid :(

Phanx 11-22-12 07:22 PM

What is the actual error message?

nin 11-23-12 01:18 AM

oh, how how can i forget to mention that im sorry :o

Lua Code:
  1. Locals: Message: Interface\AddOns\oUF_NIN\elements\auras2.lua:155: Usage: UnitClass("unit")
  2. Time: 11/22/12 09:43:14
  3. Count: 4
  4. Stack: [C]: ?
  5. [C]: in function `UnitClass'
  6. Interface\AddOns\oUF_NIN\elements\auras2.lua:155: in function `func'
  7. Interface\AddOns\oUF\events.lua:113: in function `?'
  8. Interface\AddOns\oUF\events.lua:69: in function <Interface\AddOns\oUF\events.lua:62>

Phanx 11-23-12 08:55 PM

caster can be nil if the aura wasn't applied by a unit, or if the unit that applied it does not currently have a valid unit token. Just add a check to make sure caster is non-nil before proceeding with the class lookup.


All times are GMT -6. The time now is 11:14 AM.

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