Thread Tools Display Modes
10-02-12, 03:24 PM   #1
andaril
A Murloc Raider
 
andaril's Avatar
Join Date: Oct 2012
Posts: 4
Combat icon for target

Hello.
I'm using ouf_drk fan update. http://www.wowinterface.com/download...Fanupdate.html
I need to add combat state icon for my target. How to do it with ouf?

I found in wow functions:
Lua Code:
  1. UnitAffectingCombat("unit")
http://www.wowwiki.com/API_UnitAffectingCombat

And in code
/ouf_drk/lib.lua
Lua Code:
  1. --combat icon
  2.     if f.mystyle=="player" then
  3.         f.Combat = h:CreateTexture(nil, 'OVERLAY')
  4.         f.Combat:SetSize(15,15)
  5.         f.Combat:SetTexture('Interface\\CharacterFrame\\UI-StateIcon')
  6.         f.Combat:SetTexCoord(0.58, 0.90, 0.08, 0.41)
  7.         f.Combat:SetPoint('BOTTOMRIGHT', 7, -7)
  8.     end

So i think all i need is to add some code like:
Lua Code:
  1. --combat icon
  2.     if f.mystyle=="target" and UnitAffectingCombat( %UNIT% ) then
  3.         f.Combat = h:CreateTexture(nil, 'OVERLAY')
  4.         f.Combat:SetSize(15,15)
  5.         f.Combat:SetTexture('Interface\\CharacterFrame\\UI-StateIcon')
  6.         f.Combat:SetTexCoord(0.58, 0.90, 0.08, 0.41)
  7.         f.Combat:SetPoint('BOTTOMRIGHT', 7, -7)
  8.     end
And the question: is what i should put into %UNIT%?
It's new for me and i don't know where ouf/ouf_layout stores "unit" and how to get it.
I tried some variants, but no results. And search didn't give me results too, mb cos of my bad english. ;(

Thanks for help.

Last edited by andaril : 10-02-12 at 03:27 PM.
  Reply With Quote
10-02-12, 04:18 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
No. If you add a UnitAffectingCombat check there, you will never see a Combat icon, because the frame is created before anyone is in combat, so the check will prevent the Combat icon from being created in the first place.

All you need to do is create the icon; oUF will handle hiding it and showing it when needed. Just use the first (original) code block, but change:

Code:
if f.mystyle=="player" then
to:

Code:
if f.mystyle=="player" or f.mystyle=="target" then
__________________
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
10-02-12, 05:09 PM   #3
andaril
A Murloc Raider
 
andaril's Avatar
Join Date: Oct 2012
Posts: 4
Originally Posted by Phanx View Post
All you need to do is create the icon; oUF will handle hiding it and showing it when needed. Just use the first (original) code block, but change
It was my first move when i found that code.

But it isn't working for me at all. Icon for target is displaying always, doesn't matter in combat target or no. ;(

API call ( UnitAffectingCombat ) i found in xperl when looking for their implementation of this. And i thought its right way.

Also in ouf framework
ouf/elements/combat.lua
hardcoded
Code:
UnitAffectingCombat('player')
and all displaying goes only when unit == 'player'

Mb i need to write some plugin or something? If "yes" can u give some guide links or examples?
Thanks for ur time.

Last edited by andaril : 10-02-12 at 05:22 PM.
  Reply With Quote
10-02-12, 07:43 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Actually upon further inspection it appears that oUF simply doesn't support a Combat element for anything other than the player unit, so you'll have to handle it yourself. Take the original code:

Code:
--combat icon
    if f.mystyle=="player" then
        f.Combat = h:CreateTexture(nil, 'OVERLAY')
        f.Combat:SetSize(15,15)
        f.Combat:SetTexture('Interface\\CharacterFrame\\UI-StateIcon')
        f.Combat:SetTexCoord(0.58, 0.90, 0.08, 0.41)
        f.Combat:SetPoint('BOTTOMRIGHT', 7, -7)
    end
And replace the "end" at the end with this:

Code:
    elseif f.mystyle == "target" then
        local combat = CreateFrame("Frame", nil, h)
        combat:SetSize(15, 15)
        combat:SetPoint("BOTTOMRIGHT", 7, -7)
        f.CombatIcon = combat

        local combaticon = combat:CreateTexture(nil, "ARTWORK")
        combaticon:SetAllPoints(true)
        combaticon:SetTexture("Interface\\CharacterFrame\\UI-StateIcon")
        combaticon:SetTexCoord(0.58, 0.9, 0.08, 0.41)
        combat.icon = combaticon

        combat.__owner = f
        combat:SetScript("OnUpdate", function(self)
            local unit = self.__owner.unit
            if unit and UnitAffectingCombat(unit) then
                self.icon:Show()
            else
                self.icon:Hide()
            end
        end)
    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
10-03-12, 03:25 AM   #5
andaril
A Murloc Raider
 
andaril's Avatar
Join Date: Oct 2012
Posts: 4
It works.
Thank you for doing all work for me.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Combat icon for target


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