07-07-14, 02:22 PM | #1 |
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:
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:
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:
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 |
|
07-09-14, 07:09 AM | #2 |
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 Code:
local Health = CreateFrame("FRAME", nil, self) Code:
Health:SetPoint("TOP", 0, -8) Health:SetPoint("LEFT", 8, 0) Health:SetPoint('RIGHT', -90, 0) ---------- 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.
__________________
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. |
|
07-09-14, 09:46 AM | #3 |
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:
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)" 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 |
|
07-10-14, 01:44 AM | #4 |
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.
|
|
07-10-14, 08:57 AM | #5 |
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:
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 |
|
07-10-14, 10:48 AM | #6 |
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:
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:
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:
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 |
|
07-10-14, 11:19 AM | #7 | |
Rainrider already explained most of it, but:
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.
__________________
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. |
||
07-10-14, 04:22 PM | #8 |
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:
Last edited by Kygo : 07-11-14 at 06:58 AM. |
|
07-12-14, 05:52 AM | #9 |
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:
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. |
|
07-12-14, 08:03 AM | #10 |
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) 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) =============================================================== 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.
__________________
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. |
|
07-12-14, 08:39 AM | #11 | ||
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 -------------
------------ 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. |
|||
07-13-14, 12:22 AM | #12 | |
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 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.
__________________
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. |
||
07-13-14, 06:01 AM | #13 | |
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. |
||
07-13-14, 07:25 AM | #14 |
oUF doesn't handle tooltips, but it's simple to add them:
Code:
frame:SetScript("OnEnter", UnitFrame_OnEnter) frame:SetScript("OnLeave", UnitFrame_OnLeave) Code:
frame:RegisterForClicks("AnyUp")
__________________
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. |
|
07-13-14, 08:16 AM | #15 | ||
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 |
|||
07-14-14, 02:27 AM | #16 | ||
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
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
__________________
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. |
|||
07-14-14, 06:07 AM | #17 | |
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 |
||
07-14-14, 06:40 AM | #18 | |
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
__________________
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. |
||
07-14-14, 06:44 AM | #19 | |
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. |
||
07-14-14, 08:56 AM | #20 |
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
__________________
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. |
|
WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » oUF_Kygo, a few tips wanted |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|