Thread Tools Display Modes
08-11-14, 12:02 PM   #1
eiszeit
A Chromatic Dragonspawn
 
eiszeit's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 154
Anticipation tracking on oUF frame

Hello there!

I am trying to track my Anticipation stacks (Rogue Lvl 90 Talent where you can store up additional 5 combo points) on my oUF layout.

This is the code inside my function library

Lua Code:
  1. local anticipation = {}
  2.  
  3. lib.createAnticipation = function()
  4.     local frame =  CreateFrame("Frame", nil, oUF_LynPlayer)
  5.     frame:SetFrameLevel(oUF_LynPlayer:GetFrameLevel()+1)
  6.     frame:SetSize(((cfg.power.width + 2) * 5) + 5, cfg.power.height)
  7.     frame:SetPoint('CENTER', UIParent, 0, 0)
  8.    
  9.     for i = 1, 5 do
  10.         anticipation[i] = CreateFrame("StatusBar", nil, frame)
  11.         anticipation[i]:SetStatusBarTexture(cfg.barGw)
  12.         anticipation[i]:SetStatusBarColor(1, 0.3, 0)
  13.         anticipation[i]:SetHeight(cfg.power.height)
  14.         anticipation[i]:SetWidth(cfg.power.width)
  15.         anticipation[i]:SetPoint('LEFT', anticipation[i-1], 'RIGHT', 2, 0)
  16.        
  17.         anticipation[i].bg = CreateFrame("Frame", nil, anticipation[i])
  18.         anticipation[i].bg:SetFrameLevel(anticipation[i]:GetFrameLevel()-1)
  19.         anticipation[i].bg:SetPoint("TOPLEFT", -1, 1)
  20.         anticipation[i].bg:SetPoint("BOTTOMRIGHT", 1, -1)
  21.         anticipation[i].bg:SetBackdrop({
  22.                     bgFile = cfg.background,
  23.                     tile = false,
  24.                     tileSize = 16,
  25.                     edgeSize = 0,
  26.                     insets = {
  27.                       left = 0,
  28.                       right = 0,
  29.                       top = 0,
  30.                       bottom = 0,
  31.                     },
  32.                   })
  33.         anticipation[i].bg:SetBackdropColor(0,0,0,1)
  34.        
  35.         anticipation[i]:Hide()
  36.     end
  37.    
  38. end
  39.  
  40. lib.updateAnticipation = function(self, event)
  41.     if self.unit ~= "player" then return end
  42.    
  43.     for i = 1, 5 do anticipation[i]:Hide() end
  44.     local stacks = select(4, UnitBuff('player', GetSpellInfo(115189))) -- Anticipation stacks
  45.     if stacks then
  46.         for i = 1, stacks do
  47.             anticipation[i]:Show()
  48.         end
  49.     end
  50.  
  51.        
  52. end

... and these are called on my oUF player frame:

Lua Code:
  1. self:RegisterEvent('PLAYER_LOGIN', lib.createAnticipation)
  2. self:RegisterEvent('UNIT_AURA', lib.updateAnticipation)

My problem is now, it doesn't throw errors, the event call works (chat prints out correct Anticipation stacks when I get one/loose one) - but it doesn't show my frames.
__________________
Lyn • I'm a mess of unfinished thoughts
  Reply With Quote
08-11-14, 12:18 PM   #2
sticklord
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 57
I'm not a proffessional but i think because "anticipation" is a local variable the layout can't access it.
Try:
Lua Code:
  1. lib.createAnticipation = function(self)
  2.  
  3.     -- your code
  4.  
  5.     self.anticipation = anticipation  
  6. end
  7.  
  8. lib.updateAnticipation = function(self, event)
  9.     if self.unit ~= "player" then return end
  10.     anticipation = self.anticipation
  11.    
  12.     -- your code
  13.        
  14. end
  Reply With Quote
08-11-14, 12:26 PM   #3
eiszeit
A Chromatic Dragonspawn
 
eiszeit's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 154
But these are both in the same file. The layout itself doesn't use the variables. Hmmm.
__________________
Lyn • I'm a mess of unfinished thoughts
  Reply With Quote
08-11-14, 12:43 PM   #4
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Afaik, oUF's event handler is unit-aware, so if you spawn this on the target frame, only the target unit will work.
  Reply With Quote
08-11-14, 12:47 PM   #5
eiszeit
A Chromatic Dragonspawn
 
eiszeit's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 154
I am spawning it on the player frame, because I don't need the target ("anymore") for CPs in WoD.

As I said, the events fire, the only issue is, the frame I created doesn't show .. the text itself outputs normally, as it should, in my chat.
__________________
Lyn • I'm a mess of unfinished thoughts
  Reply With Quote
08-11-14, 12:53 PM   #6
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Code:
anticipation[i]:SetPoint('LEFT', anticipation[i-1], 'RIGHT', 2, 0)
anticipation[0] does not exist, so the first one does not have a valid point.
  Reply With Quote
08-11-14, 12:56 PM   #7
eiszeit
A Chromatic Dragonspawn
 
eiszeit's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 154
Originally Posted by p3lim View Post
Code:
anticipation[i]:SetPoint('LEFT', anticipation[i-1], 'RIGHT', 2, 0)
anticipation[0] does not exist, so the first one does not have a valid point.
Oh! That must be it, I'll try it out when server is on again.
__________________
Lyn • I'm a mess of unfinished thoughts
  Reply With Quote
08-11-14, 12:56 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
What you're doing seems like a really strange way to go about adding a custom element to your frame. Why aren't you just creating the objects right away, as I assume you're already creating your health bar etc. right away? Even if you pick an event your frame will receive, and register it correctly, there's just no reason to delay creating an element -- just create it. I'd also recommend making a proper element, rather than just registering some events directly on your frame. The CPoints element can easily be adapted to handle Anticipation instead -- make a copy, rename, and edit.

Oh, and there's no reason to waste memory creating a separate frame for the backdrop; since you're only using a backdrop texture, with no border, you should just use a texture:

Code:
local bg = bar:CreateTexture(nil, "BACKGROUND")
bg:SetPoint("TOPLEFT", -1, 1)
bg:SetPoint("BOTTOMRIGHT", 1, -1)
bg:SetTexture(0, 0, 0)
bar.bg = bg
(No point in even setting a texture file if you're just going to make it black.)
__________________
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
08-11-14, 01:04 PM   #9
eiszeit
A Chromatic Dragonspawn
 
eiszeit's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 154
Phanx, I deleted the chat messages, because after I saw that the events are working I removed the unneccessary code. So, it's the actual code w/o print messages. Also, I only wanted to post the relevant code.

First, thanks for the tip with the background texture.. haven't thought of that.

I haven't tried it with a modified CPoints method, because instead of a variable/function/whatever it is on the target, I track my buffs, because Anticipation is just a buff with stacks on my buff bar. (I am not thaaaat good with Lua, tho' )

Guess I'll try that out.
__________________
Lyn • I'm a mess of unfinished thoughts
  Reply With Quote
08-11-14, 01:17 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yeah, so just replace the part that queries combo points with a UnitBuff query, and the part that registers combo point events with a UNIT_AURA registration, in addition to renaming the element itself.

Also, please stop wasting resources looking up the buff name with GetSpellInfo every time UNIT_AURA fires -- look it up once and store it in a variable:

Code:
local ANTICIPATION = GetSpellInfo(115189)

local function Update(...)
   -- use the ANTICIPATION variable in here
end
and also stop wasting CPU time on calling select -- just ignore the first three returns:

Code:
local _, _, _, stacks = UnitBuff("player", ANTICIPATION)
__________________
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
08-11-14, 01:19 PM   #11
eiszeit
A Chromatic Dragonspawn
 
eiszeit's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 154
Shame on me, thank you!

I'll try out using the CPoints function as base.
__________________
Lyn • I'm a mess of unfinished thoughts
  Reply With Quote
08-12-14, 10:53 AM   #12
eiszeit
A Chromatic Dragonspawn
 
eiszeit's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 154
So, after I got from work .. I tried it again how Phanx it suggested. It works. I am quite happy with the result, thanks for the help!



Just working on styling it a bit now.
__________________
Lyn • I'm a mess of unfinished thoughts
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Anticipation tracking on oUF frame

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