View Single Post
12-23-13, 05:10 PM   #4
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Lua Code:
  1. local frame = CreateFrame("Frame", "Bob", UIParent)
  2.   frame:SetPoint("CENTER",UIParent,0,0)
  3.   frame:SetSize(100,100)
You can just use self, since a frame to hook into isn't needed, oUF handles all that.

Lua Code:
  1. -- Register it with oUF
  2.   self.Health = Health

The Self.Health is a reference to self.Health from oUF itself, in that part you're telling oUF that the frame you called Health is self.Health from oUF. Otherwise oUF doesn't know what to do with it.

And this should purely work...
Lua Code:
  1. ------------------------------------------------------------------------
  2. -- oUF Layout boiletplate
  3. -- Author : Kelly Crabbé
  4. ------------------------------------------------------------------------
  5. ------------------------------------------------------------------------
  6. -- Namespace
  7. ------------------------------------------------------------------------
  8. local _, ns = ...
  9.  
  10. ------------------------------------------------------------------------
  11. -- Config
  12. ------------------------------------------------------------------------
  13. local NORMALFONT = STANDARD_TEXT_FONT
  14. local TEXTURE = [=[Interface\ChatFrame\ChatFrameBackground]=]
  15. local BACKDROP = {
  16.   bgFile = TEXTURE, insets = {top = -1, bottom = -1, left = -1, right = -1}
  17. }
  18.  
  19. -----------------------------
  20. -- Add custom functions (overrides)
  21.  
  22. ------------------------------------------------------------------------
  23. -- UnitSpecific settings
  24. ------------------------------------------------------------------------
  25. local UnitSpecific = {
  26.   player = function(self)
  27.   -- player specific stuff
  28.   end,
  29.   target = function(self)
  30.   -- target specific stuff
  31.   end,
  32.   party = function(self)
  33.     -- party frames
  34.   end,
  35.   boss = function(self)
  36.     -- boss frames
  37.   end,
  38.   arena = function(self)
  39.     -- arena frames
  40.   end
  41. }
  42. UnitSpecific.raid = UnitSpecific.party  -- raid is equal to party
  43.  
  44. ------------------------------------------------------------------------
  45. -- Shared settings
  46. ------------------------------------------------------------------------
  47. local function Shared(self, unit)
  48.   self:SetScript("OnEnter", UnitFrame_OnEnter)
  49.   self:SetScript("OnLeave", UnitFrame_OnLeave)
  50.  
  51.   self:RegisterForClicks"AnyUp"
  52.  
  53.   -- shared functions
  54.   -----------------------------
  55.   -- Health  
  56.   -- Your Health Statusbar
  57.   local Health = CreateFrame("StatusBar", nil, self)
  58.   Health:SetHeight(50)
  59.   Health:SetStatusBarTexture(TEXTURE)
  60.   Health:SetPoint('TOP')
  61.   Health:SetPoint('LEFT')
  62.   Health:SetPoint('RIGHT')
  63.  
  64.  -- Your health background, not needed but handy to see
  65. local Healthbg = Health:CreateTexture(nil, 'BACKGROUND')
  66.  Healthbg:SetAllPoints(Health)
  67.  Healthbg:SetTexture(TEXTURE)
  68.  Healthbg:SetVertexColor(139/255, 70/255, 70/255)
  69.  Healthbg.multiplier = .75
  70.  
  71.   -- Options
  72.   Health.frequentUpdates = true
  73.   Health.colorTapping = true
  74.   Health.colorDisconnected = true
  75.   Health.colorClass = true
  76.   Health.colorReaction = true
  77.   Health.colorHealth = true
  78.  
  79.   -- Register it with oUF
  80.   self.Health = Health
  81.   self.Health.bg = Healthbg
  82.  
  83.   -----------------------------
  84.   -- Power
  85.   -- Your Power Statusbar
  86.   local Power = CreateFrame("StatusBar", nil, self)
  87.   Power:SetHeight(50)
  88.   Power:SetStatusBarTexture(TEXTURE)
  89.   Power:SetPoint('TOP')
  90.   Power:SetPoint('LEFT')
  91.   Power:SetPoint('RIGHT')
  92.  
  93.  -- Your Power background, not needed but handy to see
  94.  local Powerbg = Power:CreateTexture(nil, 'BACKGROUND')
  95.  Powerbg:SetAllPoints(Power)
  96.  Powerbg:SetTexture(TEXTURE)
  97.  Powerbg:SetVertexColor(139/255, 70/255, 70/255)
  98.  Powerbg.multiplier = .75
  99.  
  100.   -- Options
  101.   Power.frequentUpdates = true
  102.   Power.colorPower = true -- powertype colored bar
  103.   Power.colorClassNPC = true -- color power based on NPC
  104.   Power.colorClassPet = true -- color power based on pet type
  105.  
  106.   -- Register it with oUF
  107.   self.Power = Power
  108.   self.Power.bg = Powerbg
  109.  
  110.   -- leave this in!!
  111.   if(UnitSpecific[unit]) then
  112.     return UnitSpecific[unit](self)
  113.   end
  114. end
  115.  
  116. oUF:RegisterStyle('Bob', Shared)
  117. oUF:Factory(function(self)
  118.   self:SetActiveStyle('Bob')
  119.   self:Spawn('player'):SetPoint('CENTER', -300, -250)
  120.   self:Spawn('target'):SetPoint('CENTER', 300, -250)
  121. end)
  Reply With Quote