Reply
Thread Tools Display Modes
Unread 07-07-14, 02:22 PM   #1
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
oUF_Kygo, a few tips wanted

Heya!
Just a bit of a FYI, this might be long post, I'm really new when it comes to LUA.
After a little absence from WoW I'm back , and I got the idea to create my own layout for my AddOn comp which is currently using oUF_Phanx. (http://www.wowinterface.com/download...-oUFPhanx.html)

Been trying to put something really simple togheter first, but so far no luck at all. Or the lack of skills might be the correct word.
All I've managed to get working is this:
Lua Code:
  1. local _, ns = ...
  2. local _, playerClass = UnitClass("player")
  3. local colors = oUF.colors
  4. local config
  5.  
  6. ns.frames, ns.headers, ns.objects, ns.fontstrings, ns.statusbars = {}, {}, {}, {}, {}
  7.  
  8. -- Frames
  9. local function Spawn(frame, unit, isSingle)
  10.     frame:SetPoint("CENTER", UIParent)
  11.     frame:SetSize(100, 25)
  12.  
  13.     local bg = frame:CreateTexture(nil, "BACKGROUND")
  14.     bg:SetAllPoints(true)
  15.     bg:SetTexture(0, 0, 0, 0.5)
  16.     frame.bg = bg
  17.    
  18.     local name = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  19.     name:SetPoint("BOTTOM", frame, "TOP")
  20.     self:Tag(name, "[name]")
  21.     frame.Name = name
  22. end

It does not do a whole lot more than a small black box in the middle of the screen (Thats what it's supposed to do).
And it throws a LUA error which has caused me to scratch my head a whole lot. Line 27 is "self:Tag(name, "[name]").
Lua Code:
  1. Message: Interface\AddOns\oUF_Kygo\Frames.lua:27: attempt to index global 'self' (a nil value)
  2. Time: 07/07/14 22:15:18
  3. Count: 1
  4. Stack: Interface\AddOns\oUF_Kygo\Frames.lua:27: in function `styleFunc'
  5. Interface\AddOns\oUF\ouf.lua:262: in function <Interface\AddOns\oUF\ouf.lua:192>
  6. (tail call): ?
  7. Interface\AddOns\oUF\ouf.lua:552: in function `Spawn'
  8. Interface\AddOns\oUF_Kygo\Frames.lua:63: in main chunk
  9.  
  10. Locals: frame = oUF_KygoPlayer {
  11.  0 = <userdata>
  12.  bg = <unnamed> {
  13.  }
  14.  style = "Kygo"
  15.  UNIT_EXITED_VEHICLE = <function> defined @Interface\AddOns\oUF\ouf.lua:38
  16.  UNIT_ENTERED_VEHICLE = <function> defined @Interface\AddOns\oUF\ouf.lua:38
  17.  PLAYER_ENTERING_WORLD = <function> defined @Interface\AddOns\oUF\ouf.lua:149
  18.  __elements = <table> {
  19.  }
  20.  unit = "player"
  21. }
  22. unit = "player"
  23. isSingle = true
  24. bg = <unnamed> {
  25.  0 = <userdata>
  26. }
  27. name = <unnamed> {
  28.  0 = <userdata>
  29. }
  30. (*temporary) = nil
  31. (*temporary) = nil
  32. (*temporary) = "BOTTOM"
  33. (*temporary) = oUF_KygoPlayer {
  34.  0 = <userdata>
  35.  bg = <unnamed> {
  36.  }
  37.  style = "Kygo"
  38.  UNIT_EXITED_VEHICLE = <function> defined @Interface\AddOns\oUF\ouf.lua:38
  39.  UNIT_ENTERED_VEHICLE = <function> defined @Interface\AddOns\oUF\ouf.lua:38
  40.  PLAYER_ENTERING_WORLD = <function> defined @Interface\AddOns\oUF\ouf.lua:149
  41.  __elements = <table> {
  42.  }
  43.  unit = "player"
  44. }
  45. (*temporary) = "TOP"
  46. (*temporary) = "attempt to index global 'self' (a nil value)"



Been trying to use diffrent variants of Healthbar and powerbar code snippets (Everything from Zork's oUF_Simple to oUF_Phanx) but when I start WoW back up with the new code in place , it's only showing the standard Blizzard UnitFrames.
The code I've been trying to make it work is this:
Lua Code:
  1. -- Health bar
  2.     local Health = CreateFrame("FRAME", nil, self)
  3.     Health:SetHeight(14)
  4. --  Health:SetStatusBarTexture(_TEXTURE)
  5.  
  6.     Health:SetPoint("TOP", 0, -8)
  7.     Health:SetPoint("LEFT", 8, 0)
  8.     Health:SetPoint('RIGHT', -90, 0)
  9.  
  10.     Health.frequentUpdates = true
  11.     Health.colorDisconnected = true
  12.     Health.colorTapping = true
  13.     Health.colorSmooth = true
  14.  
  15.     Health.PostUpdate = PostUpdateHealth
  16.  
  17.     self.Health = health
  18.  
  19.     local HealthPoints = Health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  20.     HealthPoints:SetPoint("LEFT", Health, "RIGHT", 2, -1)
  21.     HealthPoints:SetPoint("RIGHT", self, -6, -1)
  22.     HealthPoints:SetJustifyH"CENTER"
  23.     HealthPoints:SetFont(GameFontNormal:GetFont(), 10)
  24.     HealthPoints:SetTextColor(1, 1, 1)
  25.  
  26.     self:Tag(HealthPoints, '[dead][offline][classic:health]')
  27.  
  28.     Health.value = HealthPoints

If this code is out of date or just plain wrong, no need to sugar coat it!

Last edited by Kygo : 07-08-14 at 12:48 PM. Reason: Noticed error with link
Kygo is offline   Reply With Quote
Unread 07-09-14, 07:09 AM   #2
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,738
In your first snippet (the one giving you an error):

Code:
local _, ns = ...
local _, playerClass = UnitClass("player")
local colors = oUF.colors
local config
-- ^ Your code doesn't use any of these variables, so you can remove them,
-- though if you plan to extend your code across multiple files in the future
-- then you might want to keep the first one. In particular, the "config" variable
-- is specific to the inner workings of oUF_Phanx, so it's unlikely your layout
-- will use it.

ns.frames, ns.headers, ns.objects, ns.fontstrings, ns.statusbars = {}, {}, {}, {}, {}
-- ^ Your code doesn't use any of these tables, which are specific to the internal
-- workings of oUF_Phanx. You can just remove this whole line.

-- Frames

local function Spawn(frame, unit, isSingle)
    frame:SetPoint("CENTER", UIParent)
    frame:SetSize(100, 25)
 
    local bg = frame:CreateTexture(nil, "BACKGROUND")
    bg:SetAllPoints(true)
    bg:SetTexture(0, 0, 0, 0.5)
    frame.bg = bg
    
    local name = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    name:SetPoint("BOTTOM", frame, "TOP")
    self:Tag(name, "[name]")
    -- ^ This line triggers the error because you are using a variable "self"
    -- which you didn't define anywhere. You probably meant "frame" to
    -- refer to the unit frame you are currently working with.
    frame.Name = name
end
I don't see anything wrong in your second block, but there are a few "bad habits" you should try to avoid when writing your own code (and should also correct when copying from other people's sloppy code, for consistency):

Code:
    local Health = CreateFrame("FRAME", nil, self)
Frame types are not written in all-caps. The API will auto-correct the capitalization for values that you pass in, but you should use correct capitalization anyway, both because it's correct, and because Lua itself is case sensitive, so if you're ever comparing values to the values returned by API functions like frame:GetFrameType(), your "FRAME" will not match the returned "Frame".

Code:
    Health:SetPoint("TOP", 0, -8)
    Health:SetPoint("LEFT", 8, 0)
    Health:SetPoint('RIGHT', -90, 0)
Pick one style of string quoting and stick with it. Don't randomly use "double quotes" on one line, and 'single quotes' the next. I'd suggest using "double quotes" since it's more likely you'll want to use an apostrophe inside a string than a quotation mark, and that way you won't have to escape things as often.

----------

Overall I'd say you're on the right track with your first snippet -- start with the most basic thing (the base frame) and add one thing at a time, making sure you understand each piece rather than copying and pasting a bunch of stuff at once and trying to figure it out afterward. You'll be a lot less frustrated along the way, and end up knowing a lot more.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Unread 07-09-14, 09:46 AM   #3
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
Thank you so much Phanx for the explination of my errors and corrected me!
I will learn to use the correct capitalization in my code!

The code snippets I found inside oUF_Phanx , I thought those were requiered for the code to run, for instance that the "local _, ns = ..." told oUF the code to oUF so it knew what to run?

Great! Got the name working, did play around with the settings for size, alpha and color!

Now I've been trying to make the healthbar appear and work, did as you said, swapped out ' for " on a few places, and did swap out "self" for "Frame" due to because I have not defined "self" anywhere.
How the health code looks right now:
(Did add "local function Spawn(Frame, unit, isSingle) because without it threw a error, can post it aswell if needed/wanted)
Lua Code:
  1. -- Health bar
  2. local function Spawn(Frame, unit, isSingle)
  3.     Frame:SetPoint("CENTER", UIParent)
  4.     Frame:SetSize(100, 25)
  5.    
  6.     local Health = CreateFrame("Frame", nil, self)
  7.     Health:SetHeight(25)
  8. --  Health:SetStatusBarTexture(_TEXTURE)
  9.  
  10.     Health:SetPoint("TOP", 0, -8)
  11.     Health:SetPoint("LEFT", 8, 0)
  12.     Health:SetPoint("RIGHT", -90, 0)
  13.    
  14.  
  15.     Health.frequentUpdates = true
  16.     Health.colorDisconnected = true
  17.     Health.colorTapping = true
  18.     Health.colorSmooth = true
  19.  
  20.     Health.PostUpdate = PostUpdateHealth
  21.  
  22.     Frame.Health = Health
  23.    
  24.     local HealthPoints = Health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  25.     HealthPoints:SetPoint("LEFT", Health, "RIGHT", 2, -1)
  26.     HealthPoints:SetPoint("RIGHT", self, -6, -1)
  27.     --HealthPoints:SetJustify("CENTER")
  28.     HealthPoints:SetFont(GameFontNormal:GetFont(), 10)
  29.     HealthPoints:SetTextColor(1, 1, 1)
  30.  
  31.     Frame:Tag(HealthPoints,"[dead][offline]")
  32.    
  33.  
  34.     Health.value = HealthPoints
  35. end

But now is that code throwing a diffrent error. The LUA error that code throws:
Got a LUA error saying that [classic:Health] is invalid so i did just remove that part for now.
And my black box with my name on top of it did disappear :S But I did not get a standard Blizzard Unitframe for the player!

Code:
Message: Interface\AddOns\oUF\elements\health.lua:99: attempt to call method 'SetMinMaxValues' (a nil value)
Time: 07/09/14 17:33:36
Count: 1
Stack: Interface\AddOns\oUF\elements\health.lua:99: in function <Interface\AddOns\oUF\elements\health.lua:91>
(tail call): ?
Interface\AddOns\oUF\ouf.lua:158: in function <Interface\AddOns\oUF\ouf.lua:149>
(tail call): ?

Locals: self = oUF_KygoPlayer {
 0 = <userdata>
 __tags = <table> {
 }
 PLAYER_ENTERING_WORLD = <function> defined @Interface\AddOns\oUF\ouf.lua:149
 UNIT_FACTION = <function> defined @Interface\AddOns\oUF\elements\health.lua:147
 unit = "player"
 UNIT_CONNECTION = <function> defined @Interface\AddOns\oUF\elements\health.lua:147
 UNIT_EXITED_VEHICLE = <function> defined @Interface\AddOns\oUF\ouf.lua:38
 style = "Kygo"
 Health = <unnamed> {
 }
 UNIT_HEALTH_FREQUENT = <function> defined @Interface\AddOns\oUF\elements\health.lua:147
 UNIT_MAXHEALTH = <function> defined @Interface\AddOns\oUF\elements\health.lua:147
 __elements = <table> {
 }
 UNIT_ENTERED_VEHICLE = <function> defined @Interface\AddOns\oUF\ouf.lua:38
}
event = "PLAYER_ENTERING_WORLD"
unit = "player"
health = <unnamed> {
 __owner = oUF_KygoPlayer {
 }
 colorSmooth = true
 colorTapping = true
 ForceUpdate = <function> defined @Interface\AddOns\oUF\elements\health.lua:151
 value = <unnamed> {
 }
 0 = <userdata>
 frequentUpdates = true
 colorDisconnected = true
}
min = 154
max = 154
disconnected = false
(*temporary) = nil
(*temporary) = <unnamed> {
 __owner = oUF_KygoPlayer {
 }
 colorSmooth = true
 colorTapping = true
 ForceUpdate = <function> defined @Interface\AddOns\oUF\elements\health.lua:151
 value = <unnamed> {
 }
 0 = <userdata>
 frequentUpdates = true
 colorDisconnected = true
}
(*temporary) = 0
(*temporary) = 154
(*temporary) = "attempt to call method 'SetMinMaxValues' (a nil value)"
Did look through the health.lua inside \oUF\elements to see if I could find arguments or what to call them that looks like those I already have inside the code, but could not find any. (Could have missed them, will look through the code again)


http://pastebin.com/u/Kygo , the full code and errors.

Last edited by Kygo : 07-09-14 at 09:56 AM. Reason: Added pastebin link
Kygo is offline   Reply With Quote
Unread 07-10-14, 01:44 AM   #4
Rainrider
A Rage Talon Dragon Guard
Join Date: Nov 2008
Posts: 318
There are different types of frames and the elements in oUF require a specific one in order to use their internal update process. Depending on the type of the widget it has certain methods available. A good overview of the widget hierarchy could be found on wowprogramming.com. Usually there is some documentation in the top part of the element file that states the required widget. So, the health element requires you to define a key entry Health (i.e. Frame.Health) of the UI widget type "StatusBar". At Line 6 in your posted code snippet you define it as a simple "Frame", to which the SetMinMaxValues method, called in the elements internal update method, is not available.
Rainrider is offline   Reply With Quote
Unread 07-10-14, 08:57 AM   #5
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
Made a few changes to the code. Got textures for 3 units ( only player, target and pet spawned).
Name is visible aswell, but now the HealthPoints tag wont work. Been trying to fix it on my own with various names and variables changed.

@Rainrider, I did fiddle around with the examples inside "oUF\\elements\\health.lua" , did not make it any better. Only made me more confused and annoyed when it threw a bunch of errors at me.
Right now, I don't get any errors with
Lua Code:
  1. --SB:Tag(HealthPoints, "[dead][curhp]")
  2.     --SB.value = HealthPoints
commented out. But then again, no current HP tag is visible either.

And also, why does the "target" texture show even tho I don't have a target?
Been trying to make a statusbar that "moves" or what to call it when the HP decrease and/or increase, without any progress.

The full code that I'm using right now is here -> http://pastebin.com/VKyVvR5c . It's messy right now with a bunch commented out, but it's only for testing purposes.

Here are a few screenshots with the frames.

http://imgur.com/a/063Rs
Kygo is offline   Reply With Quote
Unread 07-10-14, 10:48 AM   #6
Rainrider
A Rage Talon Dragon Guard
Join Date: Nov 2008
Posts: 318
It seems to me you are a bit confused about the structure of your layout and that you are copying stuff from somewhere else without fully understanding it. Let's try it step by step.

Widgets in World of Warcraft are just tables to Lua. So you just attach oUF elements to the table you create for a certain unit.

The function you use to describe the look of your frames (the one you called Spawn at line 10 in your pastebin) is your style function and it is run by oUF for every unit you spawn through oUF:Spawn.

The style function receives 3 arguments:
  1. the unit button - that is what you called Frame at line 10. Technically this is a frame of type "Button" (so that mouse interaction is possible for it), that's why it is called a unit button. Remember, to Lua this is still just a table.
  2. unit - a string identifying the unit corresponding to the unit button. In your case it will be either "player", "target" or "pet".
  3. isSingle - a boolean telling you whether you get a header or a single unit. You are currently only creating single units, so just leave this be for the moment.

So let's start empty and try to style the player frame (the unit button for the player unit), add a health bar and a health value to it.

lua Code:
  1. local function Style(frame, unit, isSingle)
  2.     frame:SetSize(100, 25)
  3.  
  4.     -- create a background for the frame
  5.     local frameBG = frame:CreateTexture(nil, "BACKGROUND")
  6.     frameBG:SetAllPoints()
  7.     frameBG:SetTexture(0, 0, 0, 0.5)
  8.  
  9.     -- define the health element
  10.     local health = CreateFrame("StatusBar", nil, frame)
  11.     health:SetSize(100, 15)
  12.     health:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0)
  13.     -- let oUF handle coloring
  14.     -- the key names matter!
  15.     health.colorReaction = true
  16.     health.colorClass = true
  17.  
  18.     -- create a background for the health bar
  19.     local healthBG = health:CreateTexture(nil, "BACKGROUND")
  20.     healthBG:SetAllPoints()
  21.     healthBG:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")
  22.     -- make the background inherit the color of the status bar and be darker
  23.     healthBG.multiplier = 0.3
  24.     -- attach the background to the health bar table
  25.     -- the table key has to be named bg
  26.     health.bg = healthBG
  27.  
  28.     -- register it with oUF
  29.     -- this means you create a table key named Health
  30.     frame.Health = health
  31.  
  32.     -- create the health text
  33.     -- the health bar is the parent of the fontstring
  34.     -- because we want it to appear on the health bar
  35.     local healthText = health:CreateFontString(nil, "OVERLAY", GameFontNormal)
  36.     healthText:SetPoint("RIGHT", health, "RIGHT")
  37.     frame:Tag(healthText, "[dead][curhp]")
  38. end

Beware the order in that we define things. The unit button is passed as an argument to the Style function, that is the reason I can use it right away. You generally can't use stuff that hasn't been defined yet. So if you want to create a background for your health bar, you have to create the health bar first.

So what did I do and why:
I created a background for the unit button so that you can have a visual representation for it and can better see how it is used to hold the other stuff we apply to the frame.

Then I created the health bar and a background texture for it, so that you can see how the health bar sits on top of the frame and how it looks when it depletes.

Then I created a tag to hold the current health value and display "Dead" before it, if the unit is dead.

Beware that I didn't position the frame. In your code you used a single statement for positioning regardless of what frame your Style function is being called for. Thus all your spawned frames appear on top of each other and you have to move them with oUF_MovableFrames. Let's position them properly:

lua Code:
  1. oUF:RegisterStyle("Kygo", Style)
  2. oUF:SetActiveStyle("Kygo")
  3. local player = oUF:Spawn("player")
  4. player:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  5.  
  6. local target = oUF:Spawn("target")
  7. target:SetPoint("LEFT", player, "RIGHT", 20, 0)
  8.  
  9. local pet = oUF:Spawn("pet")
  10. pet:SetPoint("BOTTOMLEFT", player, "TOPLEFT", 0, 20)

The above goes at the end of you file. Beware that we now call our style function Style. I changed the name so that you differentiate it from Spawn, which is a function oUF provides. Now the target frame is positioned 20px right to the player frame, and the pet frame is 20px above the player. Those settings will be overridden by oUF_MovableFrames with the values you set previously by moving your frames around.

I hope you now see how oUF looks for certain table keys attached to your frames and does it's magic based on their existence. Please note that the code provided is dry coded and might not function
Rainrider is offline   Reply With Quote
Unread 07-10-14, 11:19 AM   #7
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,738
Rainrider already explained most of it, but:

Originally Posted by Kygo View Post
The code snippets I found inside oUF_Phanx , I thought those were requiered for the code to run, for instance that the "local _, ns = ..." told oUF the code to oUF so it knew what to run?
Well, those lines are required for oUF_Phanx to run, because other code inside oUF_Phanx expects those variables to exist, and uses them to pass information around between various functions across multiple files. They are not required for oUF, or for addons in general. oUF "knows" what to run because you tell it what to run, eg. oUF:Spawn("player").

You will see a line like "local _, ns = ..." in a lot of addons, but it has nothing to do with oUF. See this post for an explanation of what this line does.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Unread 07-10-14, 04:22 PM   #8
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
Wow, thank you Rainrider! Some how it made a little more sense to me!
I have to admit that the layout in the code I used was quite confusing.
I did find code snippets inside a few oUF layouts , more those were more to see how other people did and what functions etc they did use to make things work.

Really well written explination aswell, made me as a complete beginner understand a bit more!
Thanks!


@Phanx
I see! Learning something new everyday!
That you and Rainrider is helping me out (and possibly others reading this thread?) and having the patience and for that I'm grateful!

Cheers for the link to that post!


Update:
Added powerbar with text and portrait to player unit.
But now for some reason , using powerText:SetSize only affects the width , but not the height?
Might be the wrong syntax for the task or is it because I've set it to parent with the powerbar itself?

Solved the problem above by adding powerText:SetFont("Interface\\AddOns\\oUF_Kygo\\Media\\ExpresswayRg.ttf", 10)
Thought that SetFont made sense afterall :P So did try it out and it worked!

Updated code is here -> http://pastebin.com/U5JH0ten

How would you add a border to your frames?
I did it this way:
If I wouldnt use the ", -2" in the borderf:SetPoint syntax it would missing 2 or 3 px at the bottom.
And without the "borderf:SetSize(116,32)" it does not fill out the frame :S Most likley doing it wrong!
Lua Code:
  1. --border
  2.     local borderf = health:CreateTexture(nil, "BACKGROUND", health)
  3.     borderf:SetPoint("CENTER", frame, "CENTER", 0, -2)
  4.     borderf:SetSize(116, 32)
  5.     borderf:SetTexture("Interface\\ChatFrame\\ChatFrameBorder")
  6.    
  7.     health.borderf = borderf

Last edited by Kygo : 07-11-14 at 06:58 AM.
Kygo is offline   Reply With Quote
Unread 07-12-14, 05:52 AM   #9
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
Hey again! Thought I'd update this thread today!
Did add a border with a small amount of backdrop to my frames using this:
Lua Code:
  1. --border
  2.     local borderf = CreateFrame("Frame", nil, health)
  3.     borderf:SetPoint("RIGHT", 5, -2.6)
  4.     borderf:SetSize(159, 34.5)
  5.    
  6.     borderf:SetBackdrop({
  7.         bgFile = "Interface\\AddOns\\oUF_Kygo\\Media\\backdrop", tile = false,
  8.         edgeFile = "Interface\\AddOns\\oUF_Kygo\\Media\\backdrop_edge", edgeSize = 5,
  9.         insets = { left = 1, right = 1 , top = 1, bottom = 1 }
  10.     })
  11.     borderf:SetBackdropColor(0, 0, 0, .1)
  12.     borderf:SetBackdropBorderColor(0, 0, 0, 1)
  13.    
  14.     health.borderf = borderf
It looks alright, still some tweaking for a bit more depth on the backdrop!

Got a few questions that I hope someone could answer!

If I want to make the healthbars in custom colors , how do I do that? Did try to disable ".colorClass" and add ":SetStatusbarColor" and "SetStatusbarTexture" (not at the same time tho) with (0, 0, 0, .5) (that color just to test!) but it came back saying that both of the syntaxes is returning a nil value.


If I want to add another file that contains referencses / links to the textures and fonts etc or even define custom colors so that the Frames.lua file can use those variables like to replace this >
"Interface\\AddOns\\oUF_Kygo\\Media\\neuropol.ttf" with this > config.healthTextFont or something similar (not completly sure on the syntax that needs to be used)

Like a small push just to get started would be really nice!

Updated code (updated today) > http://pastebin.com/U5JH0ten if you wanna look at it!

Last edited by Kygo : 07-12-14 at 05:56 AM.
Kygo is offline   Reply With Quote
Unread 07-12-14, 08:03 AM   #10
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,738
If you just want a simple solid line border, you can just set the backdrop on the frame itself:

Code:
    frame:SetBackdrop({
        bgFile = "Interface\\AddOns\\oUF_Kygo\\Media\\backdrop", tile = false,
        edgeFile = "Interface\\AddOns\\oUF_Kygo\\Media\\backdrop_edge", edgeSize = 5,
        insets = { left = 1, right = 1 , top = 1, bottom = 1 }
    })
    frame:SetBackdropColor(0, 0, 0, .1)
    frame:SetBackdropBorderColor(0, 0, 0, 1)
However, if you want to use a separate object, then:

1) Attach it to the unit frame, not to the health bar or some other child frame, since it's a backdrop for the whole frame, not a backdrop just for the health bar (which already has a backdrop in the code Rainrider posted).

2) Rather than setting a width and height, just set multiple points so it will automatically cover the whole frame:

Code:
local frameBG = frame:CreateTexture(nil, "BACKGROUND")
frameBG:SetPoint("BOTTOMLEFT", -5, -5)
frameBG:SetPoint("TOPRIGHT", 5, 5)
frameBG:SetTexture(0, 0, 0, 1)
This will create a texture that extends 5px outside of the frame on all sides, and no matter how you resize the frame, the texture will be resized automatically so it still extends 5px outside the frame.

===============================================================

How exactly do you want to customize the health bar color? Depending on your answer, oUF may be able to do it for you automatically, or you might have to do it yourself. Either way, you don't need to use SetStatusBarTexture to change the color. That just tells the bar which texture file to use. To change the color, you only need to use SetStatusBarColor (note the capital B in StatusBar, which is not the same as the Statusbar you wrote, since Lua is case-sensitive).

Also, neither of those functions returns a value -- they're "do stuff" functions, not "get information" functions. What information are you trying to get, and what do you want to do with it?

===============================================================

Honestly I'd strongly recommend against trying to add any configuration at this point, since it just makes your code more complex. Right now you're learning how to bake a cake. Trying to make this your first time in the kitchen isn't really advisable.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Unread 07-12-14, 08:39 AM   #11
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
How exactly do you want to customize the health bar color? Depending on your answer, oUF may be able to do it for you automatically, or you might have to do it yourself. Either way, you don't need to use SetStatusBarTexture to change the color. That just tells the bar which texture file to use. To change the color, you only need to use SetStatusBarColor (note the capital B in StatusBar, which is not the same as the Statusbar you wrote, since Lua is case-sensitive).

Also, neither of those functions returns a value -- they're "do stuff" functions, not "get information" functions. What information are you trying to get, and what do you want to do with it?
I would like to have a dark grey foreground of the healthbar (like the gray in the write box here on WoWI) and the background to be dark red ish.
Something oUF can do automagiclly or do I have to do it on my own?

Screenshot on how the unitframes looks atm: > http://i.imgur.com/67rtldi.jpg
-------------

Honestly I'd strongly recommend against trying to add any configuration at this point, since it just makes your code more complex. Right now you're learning how to bake a cake. Trying to make this your first time in the kitchen isn't really advisable.
I thought so too

------------
Something I forgot to add in the last post, the right-click dropdown menu on frames,
how do I enable that?

Last edited by Kygo : 07-12-14 at 08:43 AM.
Kygo is offline   Reply With Quote
Unread 07-13-14, 12:22 AM   #12
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,738
Originally Posted by Kygo View Post
I would like to have a dark grey foreground of the healthbar (like the gray in the write box here on WoWI) and the background to be dark red ish.
First, remove any color instructions from the bar (eg. "colorClass" or "colorTapped"). Then, just set colors on the bar right after you set the texture. Pastebin is AFK at the moment so this is based on Rainrider's code from a few posts back:

Code:
    -- define the health element
    local health = CreateFrame("StatusBar", nil, frame)
    health:SetSize(100, 15)
    health:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0)

    -- remove this whole section, you don't want oUF doing color stuff:
    -- let oUF handle coloring
    -- the key names matter!
    -- health.colorReaction = true
    -- health.colorClass = true

    -- create a background for the health bar
    local healthBG = health:CreateTexture(nil, "BACKGROUND")
    healthBG:SetAllPoints()
    healthBG:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")

    -- don't need this either:
    -- make the background inherit the color of the status bar and be darker
    -- healthBG.multiplier = 0.3

    -- attach the background to the health bar table
    -- the table key has to be named bg
    health.bg = healthBG

    -- add this:
    -- set the texture yourself, even if you want to use the default one
    -- that oUF will set, because setting a texture after setting a color
    -- resets the color to white:
    health:SetStatusBarTexture("Interface\\TargetingFrame\UI-StatusBar")
    health:SetStatusBarColor(0.25, 0.25, 0.25) -- foreground
    health.bg:SetVertexColor(0.75, 0, 0) -- background

    -- register it with oUF
    -- this means you create a table key named Health
    frame.Health = health
You may also want to use the same texture for the health bar background, that you use for the health bar itself, instead of using the chat frame background texture, which is a semi-transparent flat color instead of a bar-like texture.

Originally Posted by Kygo View Post
Something I forgot to add in the last post, the right-click dropdown menu on frames,
how do I enable that?
Menus should already be enabled by default on all single frames (eg. not group headers). If you have any lines in your code that are doing <frame>:SetAttribute("type2", <something here>) remove them.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Unread 07-13-14, 06:01 AM   #13
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
Originally Posted by Phanx View Post
Menus should already be enabled by default on all single frames (eg. not group headers). If you have any lines in your code that are doing <frame>:SetAttribute("type2", <something here>) remove them.

I could not find any code that matches "<frame>:SetAttribute" at all
Did notice last night aswell that the tooltip when mouseover target or tot frame does not exists either.
Kygo is offline   Reply With Quote
Unread 07-13-14, 07:25 AM   #14
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,738
oUF doesn't handle tooltips, but it's simple to add them:

Code:
frame:SetScript("OnEnter", UnitFrame_OnEnter)
frame:SetScript("OnLeave", UnitFrame_OnLeave)
For menus, I can't recall offhand, but I think unit buttons might not be registered for right-clicks by default... try adding this:

Code:
frame:RegisterForClicks("AnyUp")
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Unread 07-13-14, 08:16 AM   #15
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
Originally Posted by Phanx View Post
oUF doesn't handle tooltips, but it's simple to add them:

Code:
frame:SetScript("OnEnter", UnitFrame_OnEnter)
frame:SetScript("OnLeave", UnitFrame_OnLeave)
Ah thanks!



Originally Posted by Phanx View Post
For menus, I can't recall offhand, but I think unit buttons might not be registered for right-clicks by default... try adding this:

Code:
frame:RegisterForClicks("AnyUp")
Thanks again! Worked as a charm

Btw, is there a health Tag that shortens the health numbers? For instance 7100 becomes 7.1k ? Did try the Tags I knew off and did even check SUF for the tags. (Did remember that SUF did use [curhp] so I thought I'd check that addon for it)
Would be really neat to have that Tag for target frames, esp on boss fights



Edit:
Thought I'd add combo points to the target frame using the example in cpoints.lua (just to try it out). Did alter it tho from self to and from health to frame. I don't get any errors, but it dosent show anything either.
Probably missing out on some small detail :S
And I'm not completly sure on what "index" does either. Maybe something I should'nt be using?

The full code can be found here > http://pastebin.com/U5JH0ten , did update it now when I made this edit

I won't be using the combo points myself, will be using Droodfocus to handle that, but thought it would be nice to add that and just comment it out incase a user want to use them.
Code:
 	if unit == "target" then
	local CPoints = {}
	for index = 1, MAX_COMBO_POINTS do
      local CPoint = health:CreateTexture(nil, 'BACKGROUND', health)
   
      -- Position and size of the combo point.
      CPoint:SetSize(12, 16)
      CPoint:SetPoint("LEFT", health, "LEFT", index * CPoint:GetWidth(), 10)
   
      CPoints[index] = CPoint
	end
   
   -- Register with oUF
   health.CPoints = CPoints
   end

Last edited by Kygo : 07-13-14 at 10:26 AM. Reason: Lua rookie need some more assistance
Kygo is offline   Reply With Quote
Unread 07-14-14, 02:27 AM   #16
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,738
Originally Posted by Kygo View Post
Btw, is there a health Tag that shortens the health numbers? For instance 7100 becomes 7.1k ? Did try the Tags I knew off and did even check SUF for the tags. (Did remember that SUF did use [curhp] so I thought I'd check that addon for it)
oUF uses its own tag system, unrelated to the tag systems used by SUF or other addons. It doesn't provide any "short value" tags by default, but it's easy to add your own. Put this somewhere in your file, outside of your spawn/style function, but before you call oUF:Spawn to create any frames:

Code:
oUF.Tags.Events["shorthp"] = "UNIT_HEALTH"
oUF.Tags.Methods["shorthp"] = function(unit)
	if not UnitIsDeadOrGhost(unit)
		local hp = UnitHealth(unit)
		return AbbreviateLargeNumbers(hp)
	end
end
You can easily add similar tags for mana or any other long values you want to abbreviate.

Originally Posted by Kygo View Post
Thought I'd add combo points to the target frame using the example in cpoints.lua (just to try it out). Did alter it tho from self to and from health to frame. I don't get any errors, but it dosent show anything either. ...... And I'm not completly sure on what "index" does either. Maybe something I should'nt be using? ...... The full code can be found here > http://pastebin.com/U5JH0ten , did update it now when I made this edit
Your code formatting leaves a lot to be desired. Pick either tabs or a specific number of spaces to use for indentation, and use it consistently. I'd recommend tabs, unless you have an editor that helps you manage using spaces for indentation. Either way, it'll be a lot easier to read your code if it's consistently indented.

I cleaned it up for you, and fixed the combo points (you were attaching the CPoints key to the health bar, instead of the frame, so oUF didn't see it as an element at all) and fixed all your hardcoded sizes and position offsets. There are some comments in the code to explain some of the changes.

http://pastebin.com/Z6mbsVpc
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Unread 07-14-14, 06:07 AM   #17
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
Originally Posted by Phanx View Post
oUF uses its own tag system, unrelated to the tag systems used by SUF or other addons. It doesn't provide any "short value" tags by default, but it's easy to add your own. Put this somewhere in your file, outside of your spawn/style function, but before you call oUF:Spawn to create any frames:

Code:
oUF.Tags.Events["shorthp"] = "UNIT_HEALTH"
oUF.Tags.Methods["shorthp"] = function(unit)
	if not UnitIsDeadOrGhost(unit)
		local hp = UnitHealth(unit)
		return AbbreviateLargeNumbers(hp)
	end
end
You can easily add similar tags for mana or any other long values you want to abbreviate.



Your code formatting leaves a lot to be desired. Pick either tabs or a specific number of spaces to use for indentation, and use it consistently. I'd recommend tabs, unless you have an editor that helps you manage using spaces for indentation. Either way, it'll be a lot easier to read your code if it's consistently indented.

I cleaned it up for you, and fixed the combo points (you were attaching the CPoints key to the health bar, instead of the frame, so oUF didn't see it as an element at all) and fixed all your hardcoded sizes and position offsets. There are some comments in the code to explain some of the changes.

http://pastebin.com/Z6mbsVpc
Neat! I did not know that !
CPoints is working now! Did swap out "BACKGROUND" for "OVERLAY" otherwise the CPoints was behind everything ^^

-----

Did add the short tag code for health and for power

-----
The reason why I have split the portrait code up into two blocks, is because "player" and "target" have diffrent anchors
Kygo is offline   Reply With Quote
Unread 07-14-14, 06:40 AM   #18
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,738
Originally Posted by Kygo View Post
The reason why I have split the portrait code up into two blocks, is because "player" and "target" have diffrent anchors
You don't need to duplicate the whole section; just add another check around the parts that change:

Code:
if unit == "player" or unit == "target" then
	-- shared code here
	if unit == "player" then
		-- player specific code here
	else
		-- target specific stuff here
	end
end
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Unread 07-14-14, 06:44 AM   #19
Kygo
An Aku'mai Servant
 
Kygo's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 36
Originally Posted by Phanx View Post
You don't need to duplicate the whole section; just add another check around the parts that change:

Code:
if unit == "player" or unit == "target" then
	-- shared code here
	if unit == "player" then
		-- player specific code here
	else
		-- target specific stuff here
	end
end
I did not know that you could do that!
I still have a humongous amount to learn

New texture and color changes + Cpoint texture and size

Last edited by Kygo : 07-14-14 at 06:57 AM.
Kygo is offline   Reply With Quote
Unread 07-14-14, 08:56 AM   #20
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,738
Actually, looking at your screenshot, you should use relative positioning for your portraits, too:

Code:
	-----------
	-- Portrait
	-----------
	if unit == "player" or unit == "target" then 
		local portrait = CreateFrame("PlayerModel", nil, frame)
		portrait:SetWidth(50)
		portrait:SetAlpha(0.8)
 
		if unit == "player" then
			portrait:SetPoint("TOPRIGHT", frame, "TOPLEFT")
			portrait:SetPoint("BOTTOMRIGHT", frame, "BOTTOMLEFT")
		else
			portrait:SetPoint("TOPLEFT", frame, "TOPRIGHT")
			portrait:SetPoint("BOTTOMLEFT", frame, "BOTTOMRIGHT")
		end

		portrait.PostUpdate = Portrait_PostUpdate
		frame.Portrait = portrait
	end
Your previous method of attaching the left corners of the portrait to the middle of the top and bottom of the frame, and then shifting it to the left by a hardcoded amount that depended on the combined width of the frame and portrait -- either of which you might want to change in the future, or even make user-configurable -- wasn't very logical, when the result you really want is to attach the right corners of the portrait to the left corners of the frame. By just doing what you actually want to do, you avoid needing to hardcode the offsets, and you avoid having values here that depend on unrelated values in other parts of your code.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Reply

Go BackWoWInterface » Featured Projects » oUF (Otravi Unit Frames) » oUF_Kygo, a few tips wanted

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