Thread Tools Display Modes
09-24-13, 08:17 PM   #21
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by asett View Post
You can inherit more than just one template.
You can already inherit more than one template using CreateFrame. Also, I doubt you'll find many arguments for using XML when a pure LUA solution is available, so you are preaching to the choir on that.
  Reply With Quote
09-24-13, 10:46 PM   #22
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by asett View Post
Lua Code:
  1. if tContains({...}, "MyMovingBarTemplate") then
On a side note, creating a bunch of single-use tables and using tContains -- which, by the way, is not a real Lua or WoW API function, but is just a wrapper around a loop written in Blizzard's Lua code for the default UI -- is pretty inefficient and will generate a lot of garbage, especially if you're making a lot of frames.

You should either create just one table from the arguments, at the beginning of the function, and refer to it for each check:

Code:
local templateList = { ... }
for i = 1, #templateList do
   -- this enables us to do tbl["k"] instead of having
   -- to loop over the table every time we want to see
   -- if it contains something
   templateList[templateList[i]] = true
end

if templateList["MyMovingBarTemplate"] then
   -- add moving stuff
end
Also, if you end up adding more templates, you could split them out into their own functions to avoid having your BuildFrame function be 500 lines of if blocks:

Code:
-- outside of BuildFrame:
local templates = {
    MyMovingBarTemplate = function(frame)
        -- add moving stuff to frame
        return frame
    end
}

-- inside of BuildFrame, after creating the frame:
local templateList = { ... }
for i = 1, #templateList do
    frame = templates[templateList[i]](frame)
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.
  Reply With Quote
09-25-13, 09:59 PM   #23
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Well, it's possible to make all template(include all secure frames, only need basic blizzard's secure templates) by using lua.

In the addon IGAS_UI and it's lib IGAS, there are no xml templates, all created by pure lua code.

Factory is a simple way, but hard for creating a whole inheritance system.

I choose a hard way to get this, first bring in an oop system, then make many classes instead of templates.

It cost many time, luckily, the oop system is pure lua, so I can use it in my real-life programs, unluckily, it looks like other languages, so no many addon authors would want to learn it.
  Reply With Quote
09-26-13, 02:51 AM   #24
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Originally Posted by kurapica.igas View Post
It cost many time, luckily, the oop system is pure lua, so I can use it in my real-life programs, unluckily, it looks like other languages, so no many addon authors would want to learn it.
Holy cow. That is alot of work.

I tried to understand your actionbar code. I failed.

I like that part of the nameplate code. But not sure if scanning over the WorldFrame children is better than scanning _G for NamePlate once you have the index.
Lua Code:
  1. if GetCVarBool("nameplateShowEnemies") == 1 or GetCVarBool("nameplateShowFriends") == 1 then
  2.   if _MaxNamePlate == 0 then
  3.     return CheckWorldFrame()
  4.   else
  5.     return CheckG()
  6.   end
  7. end
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 09-26-13 at 02:55 AM.
  Reply With Quote
09-26-13, 03:32 AM   #25
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Originally Posted by zork View Post
Holy cow. That is alot of work.

I tried to understand your actionbar code. I failed.

I like that part of the nameplate code. But not sure if scanning over the WorldFrame children is better than scanning _G for NamePlate once you have the index.
Lua Code:
  1. if GetCVarBool("nameplateShowEnemies") == 1 or GetCVarBool("nameplateShowFriends") == 1 then
  2.   if _MaxNamePlate == 0 then
  3.     return CheckWorldFrame()
  4.   else
  5.     return CheckG()
  6.   end
  7. end
Since the nameplates's has global names like "NamePlate%d+", I'm true checking _G is a quick way to scan new nameplates. Only a simple table index.

Well, the actionbar in IGAS_UI is more complex than else like raidpanels, just because I want create a free pop action bar system, too many settings for the secure part.

If only want to create action buttons, it's just like :

Lua Code:
  1. btn = System.Widget.Action.ActionButton("MyActionButton_1")
  2. btn:SetSize(30, 30)
  3. btn:SetPoint("CENTER")
  4.  
  5. btn.Action = 1

If you look at the actionbar.definition.lua, you should find class "IActionButton" inherit "ActionButton".

Just a big collection of widget factories. The oop system make the big project possible, but also make things too more to learn.

Last edited by kurapica.igas : 09-26-13 at 05:54 AM.
  Reply With Quote
09-27-13, 01:11 AM   #26
Digital_Utopia
A Flamescale Wyrmkin
 
Digital_Utopia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 110
Originally Posted by fRodzet View Post
True that is!

Creating Templates in XML is easy anyways, but for longer codes i think XML gets really messy and adding comments (<!-- xxx -->) in XML doesn't seem to make it more readable to me.
You really shouldn't need comments - that's what the "name" attribute in the root node is for. If you strive for a kinda quasi-OOP method, where each object will have its own lua file, and an accompanying xml file, things stay very neat and orderly, making maintaining and changing things a lot easier.

While I'm not going to argue that hammering out an entire UI in lua isn't easier in the short term, it's generally considered extremely lazy to mix visual elements and code in any language/api that has a layout system.
__________________
  Reply With Quote
09-27-13, 02:21 AM   #27
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Digital_Utopia View Post
You really shouldn't need comments - that's what the "name" attribute in the root node is for. If you strive for a kinda quasi-OOP method, where each object will have its own lua file, and an accompanying xml file, things stay very neat and orderly, making maintaining and changing things a lot easier.

While I'm not going to argue that hammering out an entire UI in lua isn't easier in the short term, it's generally considered extremely lazy to mix visual elements and code in any language/api that has a layout system.
I rather use xml for addon options then lua. If blizzard uses it too then why shoudn't we?
  Reply With Quote
09-27-13, 02:02 PM   #28
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by Resike View Post
I rather use xml for addon options then lua. If blizzard uses it too then why shoudn't we?
Because it requires 10 times the amount of "code", annoying formatting standards and is not flexible. It might seem like a natural thing that Blizzard UI code follows conventions perfectly and is super efficient, but that's far from true in many cases.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
09-27-13, 02:35 PM   #29
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Lombra View Post
Because it requires 10 times the amount of "code", annoying formatting standards and is not flexible. It might seem like a natural thing that Blizzard UI code follows conventions perfectly and is super efficient, but that's far from true in many cases.
If you use templates then i don't think it takes up more space then pure lua. Annoying formatting? Use a text editor with xml support/auto close. Not flexible? I don't get it you pretty much just need to edit numbers to change something.
  Reply With Quote
09-27-13, 03:17 PM   #30
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by Resike View Post
I rather use xml for addon options then lua. If blizzard uses it too then why shoudn't we?
Blizzard's code is full of horrible implementation so citing it as a basis for doing something isn't really the way to go.

Some negatives of using XML:
1. Global variables must be used either for object names or inherited functions.
2. Directly coding a script handler in an XML template will result in separate copies of each function rather than one copy shared between the all objects.
3. Most code I've seen ends up with wasted functions for script handlers, a function that does nothing but call another function. This is a waste of memory and processing time, no matter how small a waste it is.

Some positive of using Lua:
1. A Lua factory function can be garbage-collected, an XML template cannot.
2. No need for an OnLoad script.
3. You can pass arguments to really customize the creation process.
  Reply With Quote
09-27-13, 07:43 PM   #31
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Some positive of using Lua:
4. Local variables and frame references
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-27-13, 08:34 PM   #32
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Originally Posted by Resike View Post
I rather use xml for addon options then lua. If blizzard uses it too then why shoudn't we?
  1. Blizzard leaked _ as a global.
  2. The ressurection popup shows after reloading the UI, when you are alive.
  3. Multiple AddOns querying inspection data has serious negative effects on the UI.
  4. There is a bug that mysteriously forces windows to a lower strata, preventing their interaction.
  5. Blizzard's taint system is horrendous and prevents normal use of the UI under some circumstances.
  6. Bugs with InterfaceOptionsFrame_OpenToCategory.

Just because Blizzard does something, doesn't make it worth doing.
  Reply With Quote
09-28-13, 02:03 AM   #33
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Clamsoda View Post
  1. Blizzard leaked _ as a global.
  2. The ressurection popup shows after reloading the UI, when you are alive.
  3. Multiple AddOns querying inspection data has serious negative effects on the UI.
  4. There is a bug that mysteriously forces windows to a lower strata, preventing their interaction.
  5. Blizzard's taint system is horrendous and prevents normal use of the UI under some circumstances.
  6. Bugs with InterfaceOptionsFrame_OpenToCategory.

Just because Blizzard does something, doesn't make it worth doing.
Yes, but i'm not blizzard i code taint free. I don't think this problems comes with xml, but more like the blizzard api is like the windows registry. Full of useless ****, but noone dares to delete anything, and just keep adding stuff. Of course taints are gonna happen.
  Reply With Quote
09-28-13, 02:11 AM   #34
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Vrul View Post
Blizzard's code is full of horrible implementation so citing it as a basis for doing something isn't really the way to go.

Some negatives of using XML:
1. Global variables must be used either for object names or inherited functions.
2. Directly coding a script handler in an XML template will result in separate copies of each function rather than one copy shared between the all objects.
3. Most code I've seen ends up with wasted functions for script handlers, a function that does nothing but call another function. This is a waste of memory and processing time, no matter how small a waste it is.

Some positive of using Lua:
1. A Lua factory function can be garbage-collected, an XML template cannot.
2. No need for an OnLoad script.
3. You can pass arguments to really customize the creation process.
Well i don't code everyting in xml, just the shell of the GUI, the interacting functions are in lua.
  Reply With Quote
09-28-13, 09:04 AM   #35
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by Resike View Post
i code taint free.
No you don't. Taint happens more often than you think, but it's not always a problem.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-28-13, 09:42 AM   #36
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Seerah View Post
No you don't. Taint happens more often than you think, but it's not always a problem.
Well of course, but its not 1980, the operation system should auto solve a lot of collisions like that.

But at least i don't leak _ in every 6 months.
  Reply With Quote
09-28-13, 08:44 PM   #37
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Originally Posted by Resike View Post
Well of course, but its not 1980, the operation system should auto solve a lot of collisions like that.
The operating system has nothing to do with taint in wow.
  Reply With Quote
09-29-13, 04:28 AM   #38
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Rainrider View Post
The operating system has nothing to do with taint in wow.
Of course it has, if its a programming language which using memory and cpu time then what do you think who will decide on which memory part the program will run, and who will handle the thread priority.

Last edited by Resike : 09-29-13 at 04:33 AM.
  Reply With Quote
09-29-13, 05:04 AM   #39
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Originally Posted by Resike View Post
Of course it has, if its a programming language which using memory and cpu time then what do you think who will decide on which memory part the program will run, and who will handle the thread priority.
I suggest you read this introduction before making another reply
Because this one frankly makes no sense.
  Reply With Quote
09-29-13, 06:57 AM   #40
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Dridzt View Post
I suggest you read this introduction before making another reply
Because this one frankly makes no sense.
I tought Seerah meant for not just the Blizzard taint system.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to create a Template using lua?

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