WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Unit Frames (https://www.wowinterface.com/forums/showthread.php?t=49468)

Uitat 07-15-14 08:34 AM

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

jeruku 07-15-14 09:30 AM

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

Uitat 07-15-14 10:15 AM

Quote:

Originally Posted by jeruku (Post 293876)
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

Fizzlemizz 07-15-14 11:22 AM

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.

jeruku 07-15-14 11:56 AM

Ah, sorry about that misunderstanding.

Then I suppose pretty much what Fizzlemizz said.

Phanx 07-15-14 04:47 PM

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.

JDoubleU00 07-16-14 01:44 PM

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?

Uitat 07-16-14 01:47 PM

Quote:

Originally Posted by Phanx (Post 293888)
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

Uitat 07-16-14 02:00 PM

Quote:

Originally Posted by rocnroll (Post 293917)
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?

semlar 07-16-14 02:08 PM

Quote:

Originally Posted by Uitat (Post 293919)
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.

Lombra 07-16-14 02:55 PM

You might have to register right clicks? Not sure.

JDoubleU00 07-16-14 03:56 PM

So, what does this code do?

f:SetAttribute("*type1", "target")
f:SetAttribute("*type2", "togglemenu")

Fizzlemizz 07-16-14 04:29 PM

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.

semlar 07-16-14 05:16 PM

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.

kurapica.igas 07-16-14 07:32 PM

don't forget register
Lua Code:
  1. f:RegisterForClicks("AnyUp")

Phanx 07-16-14 11:52 PM

Quote:

Originally Posted by kurapica.igas (Post 293928)
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.

JDoubleU00 07-17-14 01:25 AM

Beautiful! This works great, now I just have to add attributes, change it from a white box. Fun time now.

Thanks!

Fizzlemizz 07-17-14 01:56 AM

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).

Phanx 07-17-14 02:57 AM

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.

Uitat 07-17-14 04:39 AM

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)


All times are GMT -6. The time now is 05:48 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI