View Single Post
05-31-17, 11:41 AM   #3
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
oUF Nameplates Guide

Basics

You need to modify your style function for it to handle nameplates.

Here's an example style function:
Lua Code:
  1. oUF:RegisterStyle("YourStyle", function(frame, unit)
  2.     if unit == "player" then
  3.         -- your player-specific code here
  4.     elseif unit == "boss1" then
  5.         -- your boss1-specific code here
  6.     elseif unit:match("nameplate") then
  7.         -- health bar
  8.         local health = CreateFrame("StatusBar", nil, frame)
  9.         health:SetAllPoints()
  10.         health:SetStatusBarTexture("Interface\\BUTTONS\\WHITE8X8")
  11.         health.colorHealth = true
  12.         health.colorTapping = true
  13.         health.colorDisconnected = true
  14.         frame.Health = health
  15.  
  16.         -- frame background
  17.         local bg = frame:CreateTexture(nil, "BACKGROUND")
  18.         bg:SetAllPoints()
  19.         bg:SetColorTexture(0.2, 0.2, 0.2)
  20.  
  21.         -- set size and points
  22.         frame:SetSize(128, 16)
  23.         frame:SetPoint("CENTER", 0, 0)
  24.     end
  25. end)

One important thing to note here is that these nameplates will be parented to the Blizzard nameplate points on WorldFrame.
You can adjust the anchor however you'd like, but you'll have to do it in the style function as seen above.

Spawning nameplates is done like this:
Lua Code:
  1. oUF:SpawnNamePlates()
This function behaves much like oUF:SpawnHeader(), in the way that you only need to call it once to spawn all the nameplates.

oUF:SpawnNamePlates() takes three (optional) arguements:
  1. Name prefix
    • The default name is "oUF_YourStyleNameplate1", this argument will replace the "oUF_YourStyle" part of it.
  2. Callback function
    • This function will be called after a nameplate unit or the player's target has changed.
  3. List of nameplate-related CVars.

If you use oUF:Factory() or use multiple styles, you may want to call oUF:SetActiveStyle("YourStyle") first.

For more info, see code and documentation.

Important: Scaling

These nameplates are anchored to the default Blizzard nameplates, which in turn are anchored to WorldFrame.
This means that all nameplates are not affected by the global UI scale.
To change the scale, use frame:SetScale(scale) in the style function.

One thing to note is that the scaling is influenced by CVars, and we recommend "resetting" these, like so:

Lua Code:
  1. local cvars = {
  2.     -- important, strongly recommend to set these to 1
  3.     nameplateGlobalScale = 1,
  4.     NamePlateHorizontalScale = 1,
  5.     NamePlateVerticalScale = 1,
  6.     -- optional, you may use any values
  7.     nameplateLargerScale = 1,
  8.     nameplateMaxScale = 1,
  9.     nameplateMinScale = 1,
  10.     nameplateSelectedScale = 1,
  11.     nameplateSelfScale = 1,
  12. }
  13.  
  14. oUF:SpawnNamePlates(nil, nil, cvars)

Important: Protected Nameplates

oUF does not interact with forbidden nameplates (friendly nameplates in instances), which means you don't need to worry about avoiding these in your layout.
__________________

Last edited by lightspark : 06-01-17 at 09:56 AM. Reason: Reviewed by p3lim