Thread Tools Display Modes
11-30-14, 10:20 AM   #1
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Spiral CD on Buff Frame Issue

Hi everyone! I'm trying to add spiral cd on buff frame

But doesn't work either if i parent it to the icon or the actual buff frame..

Lua Code:
  1. local CdBuffFrame = CreateFrame("Cooldown", nil, _G[self..index], "CooldownFrameTemplate")
  2.     CdBuffFrame:ClearAllPoints()
  3.     CdBuffFrame:SetReverse()
  4.     CdBuffFrame:SetFrameStrata("MEDIUM")
  5.     CdBuffFrame:SetFrameLevel(4)
  6.     CdBuffFrame:SetPoint('TOPRIGHT', _G[self..index], 'TOPRIGHT', -1, -1)
  7.     CdBuffFrame:SetPoint('BOTTOMLEFT', _G[self..index], 'BOTTOMLEFT', 1, 1)

Lua Code:
  1. hooksecurefunc('AuraButton_Update', function(self, index)
  2.     if (_G[self..index]) then
  3.         _G[self..index]:SetSize(AftermathhUI.buffs.buffbuttonsize, AftermathhUI.buffs.buffbuttonsize)
  4.         _G[self..index]:SetScale(AftermathhUI.buffs.buffbuttonscale)
  5.         CreateBorderLight(_G[self..index], AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 1)
  6.     end
  7.    
  8.     if (_G[self..index..'Icon']) then
  9.         _G[self..index..'Icon']:SetTexCoord(0.03, 0.97, 0.03, 0.97)
  10.         _G[self..index..'Icon']:SetDrawLayer("ARTWORK")
  11.     end
  12.  
  13.     if (_G[self..index..'Duration']) then
  14.         _G[self..index..'Duration']:ClearAllPoints()
  15.         _G[self..index..'Duration']:SetPoint('BOTTOM', _G[self..index], 'BOTTOM', 1, -17)
  16.         _G[self..index..'Duration']:SetDrawLayer('OVERLAY')
  17.         _G[self..index..'Duration']:SetFont(AftermathhUI.media.font, 13, AftermathhUI.media.fontflag)
  18.         if AftermathhUI.media.shadowoffset == true then
  19.             _G[self..index..'Duration']:SetShadowOffset(1, -1)
  20.             _G[self..index..'Duration']:SetShadowColor(0, 0, 0)
  21.         else
  22.             _G[self..index..'Duration']:SetShadowOffset(0, 0)
  23.             _G[self..index..'Duration']:SetShadowColor(0, 0, 0)
  24.         end
  25.     end
  26.    
  27.     if (_G[self..index..'Count']) then
  28.         _G[self..index..'Count']:ClearAllPoints()
  29.         _G[self..index..'Count']:SetPoint('BOTTOMRIGHT', _G[self..index], 1, 1)
  30.         _G[self..index..'Count']:SetDrawLayer('OVERLAY')
  31.         _G[self..index..'Count']:SetFont(AftermathhUI.media.font, 14, AftermathhUI.media.fontflag)
  32.         if AftermathhUI.media.shadowoffset == true then
  33.             _G[self..index..'Count']:SetShadowOffset(1, -1)
  34.             _G[self..index..'Count']:SetShadowColor(0, 0, 0)
  35.         else
  36.             _G[self..index..'Count']:SetShadowOffset(0, 0)
  37.             _G[self..index..'Count']:SetShadowColor(0, 0, 0)
  38.         end
  39.     end
  40.    
  41.     if (_G[self..index..'Border']) then
  42.         local r,g,b = _G[self..index..'Border']:GetVertexColor()
  43.         _G[self..index..'Border']:Hide()
  44.         _G[self..index..'Border'].Show = function() end
  45.         _G[self..index..'Border']:SetTexture(nil)
  46.         ColorBorder(_G[self..index], r, g, b)      
  47.     end
  48. end)
  Reply With Quote
11-30-14, 12:49 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Before I look at anything else, please, for the love of... whatever it is you love, stop doing this:

Code:
    if (_G[self..index..'Duration']) then
        _G[self..index..'Duration']:ClearAllPoints()
        _G[self..index..'Duration']:SetPoint('BOTTOM', _G[self..index], 'BOTTOM', 1, -17)
        _G[self..index..'Duration']:SetDrawLayer('OVERLAY')
        _G[self..index..'Duration']:SetFont(AftermathhUI.media.font, 13, AftermathhUI.media.fontflag)
        if AftermathhUI.media.shadowoffset == true then
            _G[self..index..'Duration']:SetShadowOffset(1, -1)
            _G[self..index..'Duration']:SetShadowColor(0, 0, 0)
        else
            _G[self..index..'Duration']:SetShadowOffset(0, 0)
            _G[self..index..'Duration']:SetShadowColor(0, 0, 0)
        end 
    end
Just in that block alone you're doing 9 string concatenations and 9 global lookups. I strongly suggest you familiarize yourself with how to create and use variables:

Code:
    local duration = _G[self..index..'Duration']
    if duration then
        duration:ClearAllPoints()
        duration:SetPoint('BOTTOM', _G[self..index], 'BOTTOM', 1, -17)
        duration:SetDrawLayer('OVERLAY')
        duration:SetFont(AftermathhUI.media.font, 13, AftermathhUI.media.fontflag)
        if AftermathhUI.media.shadowoffset == true then
            duration:SetShadowOffset(1, -1)
            duration:SetShadowColor(0, 0, 0)
        else
            duration:SetShadowOffset(0, 0)
            duration:SetShadowColor(0, 0, 0)
        end 
    end
Now you only have one concatenation and one global lookup, and 9 much faster local lookups. When you expand the above problem and solution to cover the entire block of code you posted, and considering how often AuraButton_Update runs (hint: it's called in every OnUpdate, so if you're getting 45 FPS, it's running 45 times every second!) you could potentially improve the efficiency of your code by a huge amount.

As for the topic problem, (1) you can't parent anything to a texture, only to a frame, and (b) can you be more specific about "doesn't work"? Do you have an error display running? Did you try adding "print" statements throughout your code to see what's happening in real-time in-game? Does anything appear in-game? If so, how is its appearance or behavior different than what you expected?
__________________
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
11-30-14, 01:08 PM   #3
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by Phanx View Post
Before I look at anything else, please, for the love of... whatever it is you love, stop doing this:

Code:
    if (_G[self..index..'Duration']) then
        _G[self..index..'Duration']:ClearAllPoints()
        _G[self..index..'Duration']:SetPoint('BOTTOM', _G[self..index], 'BOTTOM', 1, -17)
        _G[self..index..'Duration']:SetDrawLayer('OVERLAY')
        _G[self..index..'Duration']:SetFont(AftermathhUI.media.font, 13, AftermathhUI.media.fontflag)
        if AftermathhUI.media.shadowoffset == true then
            _G[self..index..'Duration']:SetShadowOffset(1, -1)
            _G[self..index..'Duration']:SetShadowColor(0, 0, 0)
        else
            _G[self..index..'Duration']:SetShadowOffset(0, 0)
            _G[self..index..'Duration']:SetShadowColor(0, 0, 0)
        end 
    end
Just in that block alone you're doing 9 string concatenations and 9 global lookups. I strongly suggest you familiarize yourself with how to create and use variables:

Code:
    local duration = _G[self..index..'Duration']
    if duration then
        duration:ClearAllPoints()
        duration:SetPoint('BOTTOM', _G[self..index], 'BOTTOM', 1, -17)
        duration:SetDrawLayer('OVERLAY')
        duration:SetFont(AftermathhUI.media.font, 13, AftermathhUI.media.fontflag)
        if AftermathhUI.media.shadowoffset == true then
            duration:SetShadowOffset(1, -1)
            duration:SetShadowColor(0, 0, 0)
        else
            duration:SetShadowOffset(0, 0)
            duration:SetShadowColor(0, 0, 0)
        end 
    end
Now you only have one concatenation and one global lookup, and 9 much faster local lookups. When you expand the above problem and solution to cover the entire block of code you posted, and considering how often AuraButton_Update runs (hint: it's called in every OnUpdate, so if you're getting 45 FPS, it's running 45 times every second!) you could potentially improve the efficiency of your code by a huge amount.

As for the topic problem, (1) you can't parent anything to a texture, only to a frame, and (b) can you be more specific about "doesn't work"? Do you have an error display running? Did you try adding "print" statements throughout your code to see what's happening in real-time in-game? Does anything appear in-game? If so, how is its appearance or behavior different than what you expected?
Wow that was a huge learning. Didn't know that thank you!

Literately nothing happens not even a error.
  Reply With Quote
11-30-14, 02:10 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Don't overlook this part:

Originally Posted by Phanx View Post
Did you try adding "print" statements throughout your code to see what's happening in real-time in-game?
99% of the time this simple debugging method will show you exactly what the problem is. At the beginning of each function, print the name of the function and each of its arguments, eg:

Code:
hooksecurefunc('AuraButton_Update', function(self, index)
   print('AuraButton_Update', self, index)
   -- rest of the function here
end)
(On a side note, I would rename "self" to "buttonName" there, since "self" is traditionally used to name a frame/object reference, but that particular value is a string, which is not the same thing at all.)

Anywhere you have significant "if" checks inside a function -- for example, if you call UnitHealth and then do an "if" check on the result -- add another print statement to show you what's being checked, eg:

Code:
local hp, hpMax = UnitHealth("player"), UnitHealthMax("player")
local hpPercent = hp / hpMax
print("Player health:", hp, hpMax, hpPercent)
if hpPercent < 0.1 then
    UIErrorsFrame:AddMessage("You're about to die!")
end
This way you can see everything that's happening, as it happens. If something doesn't happen when you think it should, the information printed will usually tell you why, or at least tell you exactly where to look.
__________________
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
11-30-14, 03:31 PM   #5
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by Phanx View Post
Don't overlook this part:



99% of the time this simple debugging method will show you exactly what the problem is. At the beginning of each function, print the name of the function and each of its arguments, eg:

Code:
hooksecurefunc('AuraButton_Update', function(self, index)
   print('AuraButton_Update', self, index)
   -- rest of the function here
end)
(On a side note, I would rename "self" to "buttonName" there, since "self" is traditionally used to name a frame/object reference, but that particular value is a string, which is not the same thing at all.)

Anywhere you have significant "if" checks inside a function -- for example, if you call UnitHealth and then do an "if" check on the result -- add another print statement to show you what's being checked, eg:

Code:
local hp, hpMax = UnitHealth("player"), UnitHealthMax("player")
local hpPercent = hp / hpMax
print("Player health:", hp, hpMax, hpPercent)
if hpPercent < 0.1 then
    UIErrorsFrame:AddMessage("You're about to die!")
end
This way you can see everything that's happening, as it happens. If something doesn't happen when you think it should, the information printed will usually tell you why, or at least tell you exactly where to look.
It works, but says nothing about the part about

Lua Code:
  1. local CdBuffFrame = CreateFrame("Cooldown", nil, BuffButton, "CooldownFrameTemplate")
  2.     CdBuffFrame:ClearAllPoints()
  3.     CdBuffFrame:SetReverse()
  4.     CdBuffFrame:SetFrameStrata("MEDIUM")
  5.     CdBuffFrame:SetFrameLevel(4)
  6.     CdBuffFrame:SetPoint('TOPRIGHT', BuffIcon, 'TOPRIGHT', -1, -1)
  7.     CdBuffFrame:SetPoint('BOTTOMLEFT', BuffIcon, 'BOTTOMLEFT', 1, 1)

And prints just "AuraButton_Update BuffButton 123.. AuraButton_Update DebuffButton 123..."
  Reply With Quote
11-30-14, 03:49 PM   #6
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Beat me, but I can't see any code to set up or start the cooldown in your example.

Like http://wowprogramming.com/docs/widge...wn/SetCooldown
  Reply With Quote
11-30-14, 05:22 PM   #7
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by Duugu View Post
Beat me, but I can't see any code to set up or start the cooldown in your example.

Like http://wowprogramming.com/docs/widge...wn/SetCooldown
Well that works better, but it tracks but Holy Shock and it goes over my whole screen


Lua Code:
  1. hooksecurefunc('AuraButton_Update', function(ButtonName, index)
  2.    
  3.     local BuffButton = _G[ButtonName..index]
  4.     local BuffIcon = _G[ButtonName..index..'Icon']
  5.     local BuffDuration = _G[ButtonName..index..'Duration']
  6.     local BuffCount = _G[ButtonName..index..'Count']
  7.     local BuffBorder = _G[ButtonName..index..'Border']
  8.        
  9.     local CdBuffFrame = CreateFrame("Cooldown", nil, BuffButton, "CooldownFrameTemplate")
  10.     CdBuffFrame:SetAllPoints(BuffIcon)
  11.     CdBuffFrame:SetReverse()
  12.     CdBuffFrame:SetFrameStrata("MEDIUM")
  13.     CdBuffFrame:SetFrameLevel(4)
  14.     --CdBuffFrame:SetPoint('TOPRIGHT', BuffIcon, 'TOPRIGHT', -1, -1)
  15.     --CdBuffFrame:SetPoint('BOTTOMLEFT', BuffIcon, 'BOTTOMLEFT', 1, 1)
  16.     CdBuffFrame:SetCooldown(GetTime(), 5)
  17.    
  18.     if BuffButton then
  19.         BuffButton:SetSize(AftermathhUI.buffs.buffbuttonsize, AftermathhUI.buffs.buffbuttonsize)
  20.         BuffButton:SetScale(AftermathhUI.buffs.buffbuttonscale)
  21.         CreateBorderLight(BuffButton, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 1)
  22.     end
  23.    
  24.     if BuffIcon then
  25.        BuffIcon:SetTexCoord(0.03, 0.97, 0.03, 0.97)
  26.        BuffIcon:SetDrawLayer("ARTWORK")
  27.     end
  28.  
  29.     if BuffDuration then
  30.         BuffDuration:ClearAllPoints()
  31.         BuffDuration:SetPoint('BOTTOM', BuffButton, 'BOTTOM', 1, -17)
  32.         BuffDuration:SetDrawLayer('OVERLAY')
  33.         BuffDuration:SetFont(AftermathhUI.media.font, 13, AftermathhUI.media.fontflag)
  34.         if AftermathhUI.media.shadowoffset == true then
  35.             BuffDuration:SetShadowOffset(1, -1)
  36.             BuffDuration:SetShadowColor(0, 0, 0)
  37.         else
  38.             BuffDuration:SetShadowOffset(0, 0)
  39.             BuffDuration:SetShadowColor(0, 0, 0)
  40.         end
  41.     end
  42.    
  43.     if BuffCount then
  44.         BuffCount:ClearAllPoints()
  45.         BuffCount:SetPoint('BOTTOMRIGHT', BuffButton, 1, 1)
  46.         BuffCount:SetDrawLayer('OVERLAY')
  47.         BuffCount:SetFont(AftermathhUI.media.font, 14, AftermathhUI.media.fontflag)
  48.         if AftermathhUI.media.shadowoffset == true then
  49.             BuffCount:SetShadowOffset(1, -1)
  50.             BuffCount:SetShadowColor(0, 0, 0)
  51.         else
  52.             BuffCount:SetShadowOffset(0, 0)
  53.             BuffCount:SetShadowColor(0, 0, 0)
  54.         end
  55.     end
  56.    
  57.     if BuffBorder then
  58.         local r,g,b = BuffBorder:GetVertexColor()
  59.         BuffBorder:Hide()
  60.         BuffBorder.Show = function() end
  61.         BuffBorder:SetTexture(nil)
  62.         ColorBorder(BuffButton, r, g, b)       
  63.     end
  64. end)
  Reply With Quote
12-01-14, 01:56 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
AuraButton_Update runs every time anything about the aura button is updated -- what icon it's showing, what duration to display on the text, etc. That code you just posted is creating a new cooldown object each time, so if you're getting 50 FPS, you're creating 50 cooldown objects per buff icon per second. It's also re-setting all the fonts and making all the other changes that often.

I'd suggest hooking BuffButton_OnLoad instead:

Code:
hooksecurefunc("BuffButton_OnLoad", function(self)
   -- self is the button object, not its name.
   -- Use :GetName() to get the name for building the names of regions.

   -- Put your code here.
   -- Assign "self.cooldown" as a reference to the cooldown object you create.
end)
The other problem with your code is that while you are indeed creating a cooldown object, you're never telling it to display anything. That's what you should be doing in AuraButton_Update:

Code:
hooksecurefunc("AuraButton_Update", function(buttonName, index, filter)
   local button = _G[buttonName..index]
   local _, _, _, _, _, duration, expirationTime = UnitAura(PlayerFrame.unit, index, filter)
   if duration > 0 and expirationTime then
      button.cooldown:SetCooldown(expirationTime - GetTime(), duration)
   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
12-01-14, 04:38 PM   #9
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Okay! Thanks i'll try get around this some way
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Spiral CD on Buff Frame Issue

Thread Tools
Display Modes

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