Thread Tools Display Modes
07-15-14, 08:34 AM   #1
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Unit Frames

ok i have searched like crazy and even tried to write my own code: but i can get nothing at all to work.

can someone point out a tutorial or something that will help me learn how to make individual Player/party/raid frames that actually function?

PS i really dont want to use XML
__________________

Last edited by Uitat : 07-15-14 at 08:38 AM. Reason: PS
  Reply With Quote
07-15-14, 09:30 AM   #2
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
You could try oUF. It eases the creation of unit-frames significantly so long as you understand its basic functions.

A good example, at least it was for me, is oUF Ascii as it is as basic as possible without having all the extra code for the bells and whistles. Then simply move on to adding bars like in the example layout oUF: Lily.

Further documentation can be found at the oUF Wiki on GitHub
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote
07-15-14, 10:15 AM   #3
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by jeruku View Post
You could try oUF. It eases the creation of unit-frames significantly so long as you understand its basic functions.

A good example, at least it was for me, is oUF Ascii as it is as basic as possible without having all the extra code for the bells and whistles. Then simply move on to adding bars like in the example layout oUF: Lily.

Further documentation can be found at the oUF Wiki on GitHub
well im actually trying to write my own code, just cant figure out how to do this without XML
__________________
  Reply With Quote
07-15-14, 11:22 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,878
You have to use (inherit in your CreateFrame call) the SecureUnitButtonTemplate which is xml but other than that the usual rules should apply to actualy create the unit elements.

Use a function to create your base widgets much like you would use xml to create element templates, other functions on top of that to add the bits to make status bars etc. and build up from there.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-15-14 at 12:52 PM.
  Reply With Quote
07-15-14, 11:56 AM   #5
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
Ah, sorry about that misunderstanding.

Then I suppose pretty much what Fizzlemizz said.
  Reply With Quote
07-15-14, 04:47 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Create the frame:
Code:
local f = CreateFrame("Button", "MyPlayerFrame", UIParent, "SecureUnitButtonTemplate")
Tell it which unit to represent:
Code:
f:SetAttribute("unit", "player")
RegisterUnitWatch(f)
Tell it to show the unit's vehicle when the unit is in one:
Code:
f:SetAttribute("toggleForVehicle", true)
Give it the standard click actions:
Code:
f:RegisterForClicks("AnyUp")
f:SetAttribute("*type1", "target")
f:SetAttribute("*type2", "togglemenu")
Make it visible for testing purposes:
Code:
f:SetPoint("CENTER")
f:SetSize(100, 100)
f:SetBackdrop({ bgFile = "Interface\\BUTTONS\\WHITE8X8" })
Then add other objects (such as font strings and status bars), register events (such as UNIT_HEALTH), and add scripts to update the objects in response to the events.
__________________
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.

Last edited by Phanx : 07-16-14 at 11:47 PM.
  Reply With Quote
07-16-14, 01:44 PM   #7
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
I tried this myself and everything worked except the right click for the menu. I have no Lua errors. I have done some Googling, but cannot see what I am doing wrong.

Thoughts?
  Reply With Quote
07-16-14, 01:47 PM   #8
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by Phanx View Post
Then add other objects (such as font strings and status bars), register events (such as UNIT_HEALTH), and add scripts to update the objects in response to the events.
ive said it before ill say it again, Phanx, your a god

you give the best lessons in the world..... i just wish i had money to pay you for all your advice
__________________
  Reply With Quote
07-16-14, 02:00 PM   #9
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by rocnroll View Post
I tried this myself and everything worked except the right click for the menu. I have no Lua errors. I have done some Googling, but cannot see what I am doing wrong.

Thoughts?
there is no on click on right click handler, you shouldn't be able to right click
...
am i correct in this Phanx?
__________________
  Reply With Quote
07-16-14, 02:08 PM   #10
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Uitat View Post
there is no on click on right click handler, you shouldn't be able to right click
The OnClick event provides which button was pressed as the second argument ("LeftButton", "RightButton", "MiddleButton", etc.)

If you need to do things in the restricted environment in response to a right click then the SecureHandler page on wowpedia has an example snippet.

Last edited by semlar : 07-16-14 at 02:19 PM.
  Reply With Quote
07-16-14, 02:55 PM   #11
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
You might have to register right clicks? Not sure.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
07-16-14, 03:56 PM   #12
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
So, what does this code do?

f:SetAttribute("*type1", "target")
f:SetAttribute("*type2", "togglemenu")
  Reply With Quote
07-16-14, 04:29 PM   #13
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,878
Code:
f:SetAttribute("*type1", "target") --target the unit on left click
Code:
f:SetAttribute("*type2", "togglemenu") --toggle the unit specific menu (leave party, target icons etc.) on right click.
Edit: for completion sake you might also want too:
Code:
f:SetAttribute("*type3", "assist") -- on middle click, target the target of the clicked unit.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-16-14 at 08:27 PM.
  Reply With Quote
07-16-14, 05:16 PM   #14
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Specifically, "*type1" means any kind of left click (modified or not) and "*type2" is any right click.

The second argument is the action to take in response to the type of click.
  Reply With Quote
07-16-14, 07:32 PM   #15
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
don't forget register
Lua Code:
  1. f:RegisterForClicks("AnyUp")
  Reply With Quote
07-16-14, 11:52 PM   #16
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by kurapica.igas View Post
don't forget register
Lua Code:
  1. f:RegisterForClicks("AnyUp")
Yep, sorry, forgot that in my original example. By default, button objects are only registered for left-clicks. There is a function in Blizzard's code that appears to have been intended as an OnLoad script for the SecureUnitButtonTemplate, that registers for all clicks and sets the target/togglemenu attributes, but it's not actually used, so you have to do that stuff yourself. I amended my original example to fix this.
__________________
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
07-17-14, 01:25 AM   #17
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Beautiful! This works great, now I just have to add attributes, change it from a white box. Fun time now.

Thanks!
  Reply With Quote
07-17-14, 01:56 AM   #18
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,878
Depending on what you want to achieve you have:

player, pet, target, party[1-4], partypet [1-4], boss [1-5], focus and target of target units at least (not talking raid frames).

each can have:
health bar
mana bar
buffs, debuffs (with aura timers?)
portrait (static 2d or 3d playermodel with/without animations)
icons (status, leader , loot, pvp, role, race...)
target bars (health, mana)
cast bar
texts (name, level, class, target, elite, dead/offline, health/mana (as %) ...)
stuff I've probably forgotten.

The target unit has combo and anticipation points (supposedly changing to the player in WoD).

The player unit has class bars/frames (Rune, Harmony, Eclipse, Druid Mana etc.), XP (bar + text + rested), Temp. Enchants (they still exist).

The upside is, pets no longer get grumpy and bugger off when not fed so you no longer have to track their happiness . There's also one other (icon I think) we lost last expansion (or maybe the one before).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-17-14 at 04:01 AM.
  Reply With Quote
07-17-14, 02:57 AM   #19
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Even though you don't want to use the oUF framework, its highly modular nature means it's a good place to look to see which events and functions are related to what:

https://github.com/haste/oUF/tree/master/elements

For example, if you want to see which events you should listen to, and which functions you should call, to display and update the unit's health, just look in the health module:

https://github.com/haste/oUF/blob/ma...nts/health.lua

I'd recommend this over the default UI code, since while the default UI obviously works, it's generally not a good example of well-written Lua code, and any complex systems (unit frames, for example) are extremely disorganized, with one part over here in this file, one part over there in that file, three parts up here, one part down there, etc.

API references are also your friend, but won't give you as much of a sense of what you need for a specific task.
__________________
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
07-17-14, 04:39 AM   #20
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
thank you both this information will be invaluable

just a side note... what i have so far! will get into events and widgets next

Lua Code:
  1. local resolHeight = GetScreenHeight()
  2. local resolWidth = GetScreenWidth()
  3. local aspectRatio = (resolWidth/resolHeight)
  4.  
  5. local backdrop = {
  6.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  7.     edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
  8.     tile = true,
  9.     tileSize = 32,
  10.     edgeSize = 20,
  11.     insets = {
  12.         left = 4,
  13.         right = 4,
  14.         top = 4,
  15.         bottom = 4,
  16.     }
  17. }
  18.  
  19. local partyWidth = resolWidth*.28
  20. local frame = CreateFrame("frame", "Unit1", UIParent)
  21. Unit1:SetWidth(resolWidth*.335)
  22. Unit1:SetHeight(resolHeight*.133)
  23. Unit1:SetPoint("BOTTOM", LeftChatBaseFrame,"TOP", 4, 15)
  24. Unit1:SetFrameStrata("BACKGROUND")
  25. Unit1:SetFrameLevel(1)
  26. Unit1:SetAlpha(1)
  27. Unit1:SetBackdrop(backdrop)
  28.  
  29. local f = CreateFrame("Button", "MyPlayerFrame", Unit1, "SecureUnitButtonTemplate")
  30. f:SetAttribute("unit", "player")
  31. RegisterUnitWatch(f)
  32. f:SetAttribute("toggleForVehicle", true)
  33. f:RegisterForClicks("AnyUp")
  34. f:SetAttribute("*type1", "target")
  35. f:SetAttribute("*type2", "togglemenu")
  36. f:SetPoint("TOPLEFT", Unit1, "TOPLEFT", 7, -7)
  37. f:SetSize(resolWidth*.325, resolHeight*.10)
  38. f:SetBackdrop({ bgFile = "Interface\\AddOns\\_Deranjata\\Media\\Aluminium.tga" })
  39. f:SetBackdropColor(0, .5, 0)
__________________

Last edited by Uitat : 07-17-14 at 04:44 AM. Reason: code
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Unit Frames


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