Thread Tools Display Modes
03-17-09, 09:35 AM   #1
wreck
A Flamescale Wyrmkin
 
wreck's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 114
Smile nUI API

An API would be great. Unfortunately I wonder how many authors would move that way if they already have significant time invested in providing features directly via the WoW API, and would prefer not to invest in adding their features to the nUI environment.

That said, I'd like to learn more about your API to start adding some features of my own. Where would you recommend starting? Is it better to create a new addon (like nUI_Config) or can we add items to the nUI/plugins directory as that option seems to already exist.
 
03-17-09, 10:37 AM   #2
spiel2001
nUI's Author
 
spiel2001's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 7,724
I've moved this into the developer chat thread as this conversation is going to lead down a path that's way outside of the scope of suggestions ~smile~

In any event, the nUI plugins directory is specifically for built-in plugins as there's no way for WoW or nUI to detect mods that are added down the tree unfortunately. What the plugins directory does is allow me to keep my own addons to nUI separate from the core code as well as allowing me to move third party plugins directly into nUI with minimal fuss if I decide to make one or more of them part of the core distribution over time. So you would start with a base mod like any other mod that installs into the [ Interface > AddOns ] directory.

I do expect that most authors would not go down the path of developing directly for nUI, particularly if they already have an established mod. However, I do strongly suspect that other people are going to want to build things specifically for use with nUI and that's what that API is about... and a big part of that puzzle is performance. One of the reasons why nUI performs as it does is the core engine which would allow other authors to take advantage of that without adding extra load to the game engine. It also allows authors to access most combat related data without having to code for the events and so on... both of which are things that in time I hope will compel some authors to take advantage of the nUI API.

Anyway, Now... as far as learning the API... it kind of starts with what it is you're out to do. I have heavily documented my code, so that's really the starting point.

The best file to look at as far as learning how to create an information panel plugin is probably [ Interface > AddOns > nUI > Layouts > Default > InfoPanels > nUI_InfoPanel_CombatLog.lua ] == From there you can look at the nUI_InfoPanel_Minimap plugin which shows the basis of one written as a standalone plugin to nUI.

From there, the second place to look is [ Interface > AddOns > nUI > Units > nUI_UnitCache.lua ] which fairly (not entirely) accurately details the cache data nUI can and does collect on players and mobs.

After that the conversation really starts to diverge and I really need to write a document to explain the API, but thats kinda not at the top of the priority list, so for now we can kind of go back and forth here and I'll answer your questions... in time that will probably form the basis of the document ~lol~

Some other key files to look at probably are [ Interface > AddOns > nUI > Units > nUI_UnitPanels.lua ] which will show you how nUI can read the tables in [ Interface > AddOns > nUI > Layouts > Default > UnitPanels {unit mode} > nUI_UnitPanel_{mode}.lua ] to create the panels and then use the skin files to call [ Interface > AddOns > nUI > Units > nUI_Unit.lua ] to create the individual units for the panel.

The latter module pretty much just creates instances of the various unit modules and that's the core of what makes nUI work. If you look, for example, at [ Interface > AddOns > nUI > Units > nUI_UnitLabel.lua ] which is one of the simpler modules, you'll see a method in there function nUI_Unit:registerLabelCallback( unit_id, callback ) -- if your mod, for example, needed to know that name of the player's current target, you would add a method to your mod and register it with nUI like this...

Code:
local myMod = CreateFrame( "Frame", "myMod", UIParent );

local targetInfo;
local totInfo;

myMod.newUnitInfo = function( unit_id, unit_info )
{
    if UnitIsUnit( unit_id, "target" ) then

        targetInfo = unit_info;

        if not unit_info then print( "you don't have a target anymore" );
        else print( "your target is now "..unit_info.name );
        end

    elseif UnitIsUnit( unit_id, "targettarget" ) then

        totInfo = unit_info;

        if targetInfo then
            if not unit_info then print( "your target doesn't have a target anymore" );
            else print( "your target's target is now "..unit_info.name );
            end
        end
    end
}

nUI_Unit:registerLabelCallback( "target", myMod );
nUI_Unit:registerLabelCallback( "targettarget", myMod );
In this somewhat simple example, the mod doesn't have to worry about events at all. It doesn't need to worry about whether not the player changed targets or any other similar situation. nUI will track the name of the "target" and "targettarget" units and alert your mod when the name changes or when the unit no longer exists (it passes a nil value for "unit_info" when the unit no longer exists).

So, using this API, nUI plugins are entirely free of worrying about the game engine or data monitoring and collection. Just register your mod with the modules that produce the data you care about and nUI deals with all of the rest.

The benefit in this is that there's only one mod that is watching for changes in the units and when a change that a plugin cares about occurs, nUI can then alert them all and pass the data to them pre-collected. This also means that nUI only has to "read" the data once when it changes and then can pass that to any number of waiting UI elements.

The best example is the player unit frame health bar (nUI_UnitHealth.lua) -- There are player unit frame bars in all seven unit frame panels, plus all three HUDs... so there are ten player unit frame bars in nUI, but when there's a player health update, nUI only asks Bliz for the player's health once, then just passes that data to the ten waiting health bars.

Follow?
__________________

What people don't get is that I am, ultimately, an artist at heart.
My brush has two colors, 1 and 0, and my canvas is made of silicon.



Official nUI Web Site: http://www.nUIaddon.com
Official nUI Support Forum: http://forums.nUIaddon.com
My day job: http://www.presidio.com/
 
04-14-09, 03:35 PM   #3
Tegarbah
A Wyrmkin Dreamwalker
 
Tegarbah's Avatar
Join Date: Jun 2008
Posts: 58
Man, what I wouldn't give to be able to code stuff like that. I learned C++ about 5 years ago and I've used what I learned to play around with Visual Basic in Excel. Don't know if I could make the leap to understand this stuff. Do they teach LUA in university classes?
__________________



 
04-14-09, 03:44 PM   #4
spiel2001
nUI's Author
 
spiel2001's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 7,724
Lua is actually very easy to learn... if you can handle C/C++, you can handle Lua. The best way to start is to pick a simple mod and pull it apart. Look at the code and work backwards to figure out what it's doing and how.

Two really good sites...

http://www.lua.org/manual/5.1/
http://www.wowwiki.com/Portal:Interface_customization
__________________

What people don't get is that I am, ultimately, an artist at heart.
My brush has two colors, 1 and 0, and my canvas is made of silicon.



Official nUI Web Site: http://www.nUIaddon.com
Official nUI Support Forum: http://forums.nUIaddon.com
My day job: http://www.presidio.com/
 
04-15-09, 12:30 AM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Knowing how hard it was for me to get that first step up on doing addons I have heavily commented my addons so feel free to look at them.
 
04-15-09, 12:56 AM   #6
Vis
A Pyroguard Emberseer
 
Vis's Avatar
Join Date: Mar 2009
Posts: 1,827
Originally Posted by Xrystal View Post
Knowing how hard it was for me to get that first step up on doing addons I have heavily commented my addons so feel free to look at them.
Yay! Just added your addons to my favorites to peruse later, If they are commented like Spiel's are, it will be another good learning experience

*I know nothing about coding besides some basic understanding through osmosis of Spiel's code and comments, lol
 
04-16-09, 12:09 AM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Coolies. I've tried to comment every function and tried to split up each functionality as a separate function to make things easier to get to grips with. But if you have any questions feel free to ask them and I'll see if I can help out.

I had the C++ background so took a while to stop doing // instead of -- to comment out lines. and use { } to surround statements and functions. All a learning curve.

I'll be slowly working through my more simpler ( I hope ) addons and try and figure them out myself. Less downloading requirements at the next patch or idea change. Also, I've been reading other peoples request and if its a simple enough request I try to do it. That way you know you have at least one third party tester.
 
04-16-09, 04:22 AM   #8
spiel2001
nUI's Author
 
spiel2001's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 7,724
That's awesome... and I appreciate the hand.

I do C/C++/Java/Lua and it's really funny how often I can code for hours before I realize I'm coding in the wrong language... Writing C++ conditionals like "if a > b then" and using braces in the Lua, etc. /rolleyes
__________________

What people don't get is that I am, ultimately, an artist at heart.
My brush has two colors, 1 and 0, and my canvas is made of silicon.



Official nUI Web Site: http://www.nUIaddon.com
Official nUI Support Forum: http://forums.nUIaddon.com
My day job: http://www.presidio.com/
 
04-16-09, 08:41 AM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Rofl ..

I've been working on a totem addon and was using a lot of lua for loops and the amount of times wow was kicking up an error. Invalid command etc at line whatever near word to .. and I think whats wrong with for i = 1 to 4 ...
 
04-16-09, 08:45 AM   #10
spiel2001
nUI's Author
 
spiel2001's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 7,724
~lol~

Yup... and be careful about loops... remember there's only one thread for the entire UI... the longer you stay in your loop, the longer it is before all the rest of the UI and addons get their turn and the slower the frame rate.
__________________

What people don't get is that I am, ultimately, an artist at heart.
My brush has two colors, 1 and 0, and my canvas is made of silicon.



Official nUI Web Site: http://www.nUIaddon.com
Official nUI Support Forum: http://forums.nUIaddon.com
My day job: http://www.presidio.com/
 
04-16-09, 08:48 AM   #11
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
yep, the first thing I looked for when I realised I was needing for loops was whether the break command existed
 
04-16-09, 04:47 PM   #12
todd3835
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 89
Ah the stress of endless loops...... I used to code in TCL, if anyone knows IRC chat, tcl is the scripting language of linux, and for eggdrop bots...... I designed a file server, and well lets say that the server admins didn't like when I'd initially startup the bot =] for each $file for like 60k files, tends to make the server screech to a halt for like 2 or 3 minutes =] hehehehe Oh, and bug finding times of endless loops, lets just say I got banned off a few servers before I started testing locally =] ctrl+c was my saving grace!

-Todd
 
04-16-09, 05:12 PM   #13
spiel2001
nUI's Author
 
spiel2001's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 7,724
~lol~

Been there.

One of the best pieces of software documentation I ever read was in the "Glossary of Terms" in the back of the original dBase II Programmer's Reference Manual... two entries...

Endless Loop: see "Loop, Endless"
Loop, Endless: see "Endless Loop"
__________________

What people don't get is that I am, ultimately, an artist at heart.
My brush has two colors, 1 and 0, and my canvas is made of silicon.



Official nUI Web Site: http://www.nUIaddon.com
Official nUI Support Forum: http://forums.nUIaddon.com
My day job: http://www.presidio.com/
 
04-18-09, 12:47 AM   #14
Tegarbah
A Wyrmkin Dreamwalker
 
Tegarbah's Avatar
Join Date: Jun 2008
Posts: 58
Well I'm trying to learn to write addons and am going through tutorials.....fun...

Ran the wonderful Hello World! tutorial and it wouldn't work. Spent a couple hours rereading the tutorial and checking every single character to make sure everything was right.....to no avail

FINALLY I read on a wowwiki page:

Knowing that, we place the .lua file before the .xml file because we want the function HelloWorld declared (or defined) before we try to call it in the .xml file.
Check my files and...yep...I got the .xml file listed first. Switch the files around in my Wow UI Designer and poof it works..../sigh
__________________



 
04-18-09, 06:46 AM   #15
spiel2001
nUI's Author
 
spiel2001's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 7,724
I feel your pain man. ~lol~

If it helps you any... I've been doing this for 30 years now... the only reason I'm any good at it at all is because I've already made those mistakes about 500 times... I'm focusing my attention on make much more complicated stupid mistakes now ~grin~
__________________

What people don't get is that I am, ultimately, an artist at heart.
My brush has two colors, 1 and 0, and my canvas is made of silicon.



Official nUI Web Site: http://www.nUIaddon.com
Official nUI Support Forum: http://forums.nUIaddon.com
My day job: http://www.presidio.com/
 
 

WoWInterface » Featured Projects » nUI, MozzFullWorldMap and PartySpotter » Customization » nUI: Developer Chat » nUI API

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