Thread Tools Display Modes
05-22-11, 02:41 PM   #1
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Enabling and disabling oUF elements

I need some help to understand how this actually works or what exactly is self:DisableElement supposed to do and where and how should we use it.

Say I have a custom DebuffHighlight element. Do I have a way to disable other DebuffHighlight elements provided I know theirs names?

I'll just start with what I think I know so far (I'll take the default oUF threat element as example):

An element registers itself with oUF through oUF:AddElement("name", update_func, enable_func, disable_func)

An element enables itself when its prerequisites are met (i.e. self.Threat is not nil)

oUF:AddElement creates an entry in a table called elements for every registered element that looks like this:
Code:
["element name"] = {
	update = update function of the element
	enable = enable function of the element
	disable = disable function of the element
}
We have another table self.__elements which contains the update functions of the enabled elements for the current unit frame(self). This gets populated by initObject() by calling self:EnableElement with every element name from the elements table.

Well when I run
Code:
print(self:IsElementEnabled("Health"))
from within my layout (at the end of the style function as I think that is the point where all element are enabled and applied), I expect it to return true and the index in the table where the update function is found. It returns nothing.

When I run
Code:
print(#self.__elements)
I expect it to return the number of update function, thus the number of used elements for the current frame. When ran from the layout this always returns 1.

I thought then that I should run this from an element itself. print(#self.__elements) then returns another number so I suppose that's the way to go, but how do I know in what order the element are loaded. By the numbers it returns a can tell that not all elements used in the layout are loaded before my print call.

I kinda lost myself, hope someone could shed some light on it for me :)

Last edited by Rainrider : 05-22-11 at 02:42 PM. Reason: Damn smilies
  Reply With Quote
05-22-11, 05:11 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I don't have an answer to your initial question offhand, but in my layout, before enabling my custom DebuffHighlight element, I check for the presence of other plugins that I know create a similar element. If the user has one of them enabled, I assume they want to use that instead of the functionality built into my layout, and don't enable mine. As long as your layout isn't incompatible with those plugins (eg. they don't require support from the layout, or you added the 2-5 lines of code to support them) then I think that's a better way to go than forcibly overriding the user's choices.
  Reply With Quote
05-23-11, 05:23 AM   #3
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Thanks for the reply Phanx. I just looked at oUF_Phanx. From your dispel element you do
Code:
if select( 4, GetAddOnInfo( "oUF_DebuffHighlight" ) ) then return end
I don't try to enforce my choice on the user, one could still make this a config option and let them deside. But lots of people install oUF layouts just to test them, often without deactivating standalone elements required by the layouts they used before. And this leads to support issues. Yes, I could change the elements names (i.e. self.MyThret instead of self.Threat) but would prefer to use the same layout code for the element and let them choose. I though self:DisableElement would be the easy way to do this, but wasn't able to find out how to use this.
  Reply With Quote
05-23-11, 09:40 AM   #4
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Elements aren't enabled on layouts until after the style function has been called. The basic call sequence for oUF is:
1. Call :Spawn()
2. Override the frames metatable with the oUF proxy version.
3. Do basic setup of the frames functionality (event, update, etc).
4. Call the style function.
5. More setup stuff.
6. Iterate over the registered oUF elements and attempt to enable each and every one of them on the frame.
7. Iterate callbacks and run them on the frame.
8. Disable Blizzard frames and do the last bit of unit specific setup.
9. Return the frame

What you could do, is check for the existence of the elements you want to disable/enable through a callback, as these are called after the elements have been registered.

The callback system is actually leftovers from the time before oUF had a element system, but it won't be removed as it still serves a proper purpose to layouts and external modules.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
05-23-11, 12:18 PM   #5
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Does this mean that all elements are registered before the callback? I then have to reenable the other element as else the events get unregistered by the disable function of the element. Is this correct? Would it be possible to post a code example for a callback. Thank you very much for your reply.
  Reply With Quote
05-23-11, 12:48 PM   #6
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
1. yes
2. events are registered on a per function basis. One element unregistering shouldn't effect another.
2. no
3:
Code:
oUF:RegisterInitCallback(function(self)
 -- do something with self:w
end)
self is the frame.
__________________
「貴方は1人じゃないよ」

Last edited by haste : 05-23-11 at 12:52 PM. Reason: Messed up the numbers :(
  Reply With Quote
05-23-11, 02:30 PM   #7
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
oUF_DebuffHighlight won't enable at all if you don't set self.DebuffHighlightBackdrop, self.DebuffHighlightBackdropBorder, or self.DebuffHighlight. Couldn't you just name your custom object self.DebuffHighlightCustom instead?
  Reply With Quote
05-23-11, 07:55 PM   #8
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
@haste
Thank you very much

@Saiket
Originally Posted by Rainrider View Post
Yes, I could change the elements names (i.e. self.MyThret instead of self.Threat) but would prefer to use the same layout code for the element and let them choose. I though self:DisableElement would be the easy way to do this, but wasn't able to find out how to use this.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Enabling and disabling oUF elements


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