Thread Tools Display Modes
08-15-14, 07:57 PM   #1
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Question Minimum Frame Code

OK, I am trying to improve my LUA skills and learn oUF at the same time. I have looked at many oUF layouts including the Wiki. What is the absolute minimum code to create a frame without the tags and such. I get confused on what is "required", but would like to start there and work my way up.

Thanks
  Reply With Quote
08-16-14, 01:21 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
This creates
- a healthbar function
- a template/style function
- registers templates/styles
- spawns units

Lua Code:
  1. --get addon data
  2.     local addonName, addonTable = ...
  3.  
  4.     --create health statusbar func
  5.     local function CreateHealthBar(self)
  6.  
  7.       local texture = self:CreateTexture()
  8.       texture:SetTexture(1,1,1)
  9.  
  10.       local health = CreateFrame("StatusBar", nil, self)      
  11.       health:SetStatusBarTexture(texture)
  12.       health:SetAllPoints()
  13.  
  14.       return health
  15.  
  16.     end
  17.  
  18.     --create basic style func
  19.     local function CreateBasicStyle(self)
  20.      
  21.       self:SetSize(80,30)
  22.  
  23.       self.Health = CreateHealthBar(self)
  24.  
  25.       self.Health.colorTapping = true
  26.       self.Health.colorDisconnected = true
  27.       self.Health.colorClass = true
  28.       self.Health.colorReaction = true
  29.       self.Health.colorHealth = true
  30.  
  31.     end
  32.  
  33.     --register style
  34.     oUF:RegisterStyle(addonName.."BasicStyle", CreateBasicStyle)
  35.    
  36.     --activate style
  37.     oUF:SetActiveStyle(addonName.."BasicStyle")
  38.  
  39.     --spawn player
  40.     local player = oUF:Spawn("player",addonName.."PlayerFrame")
  41.     player:SetPoint("CENTER",-100,0)
  42.  
  43.     --spawn target
  44.     local target = oUF:Spawn("target",addonName.."TargetFrame")
  45.     target:SetPoint("CENTER",100,0)
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 08-16-14 at 01:23 AM.
  Reply With Quote
08-16-14, 06:35 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Just FYI, I'd like to point out that it's completely unnecessary to create a separate function to make the health bar; you can just make the health bar directly in the "CreateBasicStyle" function. The same goes for any other element. The only benefits to splitting them off into their own functions would be to movecode that only applies to one unit (eg. totem bars are only created on the player frame) and code that's very long and/or has a lot of helper functions to go with it (eg. buff icons) off into its own file for organizational purposes.

Also, strictly, speaking, the bare minimum doesn't even require a health bar.

Code:
oUF:RegisterStyle("MyStyle", function(frame, unit, isSingle)
    -- required because frames without dimensions aren't shown:
    frame:SetSize(100, 25)

    -- not strictly required, but without any visible regions/children the frame will be invisible:
    frame:SetBackdrop({ bgFile = "Interface\\BUTTONS\\WHITE8X8" })

    -- add elements here
end)

oUF:SetActiveStyle("MyStyle")

local player = oUF:Spawn("player")
player:SetPoint("CENTER", -100, 0)

local target = oUF:Spawn("target")
target:SetPoint("CENTER", 100, 0)
Once you've got the basics down, you can really just look at the comments at the top of each element file in oUF. Copy the example from the element into the section labeled "add elements here" above, and then modify it to your liking. I'd recommend starting with the more important elements like health bars, and doing one thing at a time, rather than copy/pasting everything at once and then trying to go back and sort it all out.
__________________
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

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Minimum Frame Code


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