WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Anticipation tracking on oUF frame (https://www.wowinterface.com/forums/showthread.php?t=49625)

eiszeit 08-11-14 12:02 PM

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. :(

sticklord 08-11-14 12:18 PM

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

eiszeit 08-11-14 12:26 PM

But these are both in the same file. The layout itself doesn't use the variables. Hmmm.

p3lim 08-11-14 12:43 PM

Afaik, oUF's event handler is unit-aware, so if you spawn this on the target frame, only the target unit will work.

eiszeit 08-11-14 12:47 PM

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.

p3lim 08-11-14 12:53 PM

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.

eiszeit 08-11-14 12:56 PM

Quote:

Originally Posted by p3lim (Post 295204)
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.

Phanx 08-11-14 12:56 PM

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.)

eiszeit 08-11-14 01:04 PM

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.

Phanx 08-11-14 01:17 PM

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)

eiszeit 08-11-14 01:19 PM

Shame on me, thank you! :)

I'll try out using the CPoints function as base.

eiszeit 08-12-14 10:53 AM

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. :)


All times are GMT -6. The time now is 07:09 AM.

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