Quantcast Minimum Frame Code - WoWInterface
Thread Tools Display Modes
08-15-14, 07:57 PM   #1
A Cobalt Mageweaver
rocnroll's Avatar
Join Date: Mar 2008
Posts: 238
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.

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

Lua Code:
  1. --get addon data
  2.     local addonName, addonTable = ...
  4.     --create health statusbar func
  5.     local function CreateHealthBar(self)
  7.       local texture = self:CreateTexture()
  8.       texture:SetTexture(1,1,1)
  10.       local health = CreateFrame("StatusBar", nil, self)      
  11.       health:SetStatusBarTexture(texture)
  12.       health:SetAllPoints()
  14.       return health
  16.     end
  18.     --create basic style func
  19.     local function CreateBasicStyle(self)
  21.       self:SetSize(80,30)
  23.       self.Health = CreateHealthBar(self)
  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
  31.     end
  33.     --register style
  34.     oUF:RegisterStyle(addonName.."BasicStyle", CreateBasicStyle)
  36.     --activate style
  37.     oUF:SetActiveStyle(addonName.."BasicStyle")
  39.     --spawn player
  40.     local player = oUF:Spawn("player",addonName.."PlayerFrame")
  41.     player:SetPoint("CENTER",-100,0)
  43.     --spawn target
  44.     local target = oUF:Spawn("target",addonName.."TargetFrame")
  45.     target:SetPoint("CENTER",100,0)
| Simple is beautiful.
| WoWI AddOns | GitHub | TDMOG

"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
No Life!
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,415
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.

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


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.
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote

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

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