WoW:Using the Interface Options Addons panel
These are the commands that are needed to use Blizzard's Interface Options Addons framework.
As we use a Frame, we can do anything we like within it. Just like doing any other GUI Frame. You can also do sub-categories within these panels as well.
Most of this has been taken from One Blue post on the World of Warcraft Forums (http://forums.worldofwarcraft.com/thread.html?topicId=2968233433&sid=1&pageNo=15#294).
Description of the panel parts[edit]
- panel.name - a required string
- is the name of the Category to be listed in the Interface Options - Addon list.
- panel.okay - Optional function()
- This is a function that is called when the player presses the Okay button.
- panel.cancel - Optional function()
- This is a function that is called when the player presses the Cancel Button.
- panel.default - Optional function()
- This is a function that is called when the player presses the Default Button.
- panel.parent - an optional string
- Name of the parent of the AddOn or group of configuration options. This identifies "panel" as the child of another category. If the parent category doesn't exist, "panel" will be displayed as a regular category.
- panel.refresh - Optional function()
- This method will run when the Interface Options frame calls its OnShow function and after defaults have been applied via the panel.default method described above. Use this to refresh your panel's UI in case settings have been changed without player interaction. (-- from a post by Zootfizzle)
Example XML with Okay and Cancel buttons[edit]
This example is taken from an addon called SC_ChaChing, available from http://wowui.incgamers.com/?p=mod&m=4934.
The XML frame[edit]
All we need to do first is to create the Frame. As we are using the Interface Options - Addon panels, we do not need to use any sizing or movement options.
The OnLoad script calls the Panel_OnLoad() function.
- XML Frame
<Frame name="SC_ChaChingGUIFrame"> . . . <Scripts> <OnLoad> SC_ChaChingPanel_OnLoad(self); </OnLoad> </Scripts> </Frame>
The Lua function[edit]
All we need to do with this function, is to set the name of the panel. Along with the Functions needed for the Okay and Cancel Buttons. Then to call the function that adds the Category to the Interface Options - Addon Category list.
- Lua Function
function SC_ChaChingPanel_OnLoad(panel) . . . -- Set the name for the Category for the Panel -- panel.name = "SC_ChaChing " .. GetAddOnMetadata("SC_ChaChing", "Version"); -- When the player clicks okay, run this function. -- panel.okay = function (self) SC_ChaChingPanel_Close(); end; -- When the player clicks cancel, run this function. -- panel.cancel = function (self) SC_ChaChingPanel_CancelOrLoad(); end; -- Add the panel to the Interface Options -- InterfaceOptions_AddCategory(panel); end
Example entirely in Lua[edit]
MyAddon = {}; MyAddon.panel = CreateFrame( "Frame", "MyAddonPanel", UIParent ); -- Register in the Interface Addon Options GUI -- Set the name for the Category for the Options Panel MyAddon.panel.name = "MyAddon"; -- Add the panel to the Interface Options InterfaceOptions_AddCategory(MyAddon.panel); -- Make a child panel MyAddon.childpanel = CreateFrame( "Frame", "MyAddonChild", MyAddon.panel); MyAddon.childpanel.name = "MyChild"; -- Specify childness of this panel (this puts it under the little red [+], instead of giving it a normal AddOn category) MyAddon.childpanel.parent = MyAddon.panel.name; -- Add the child to the Interface Options InterfaceOptions_AddCategory(MyAddon.childpanel);
Directly opening your options panel[edit]
If you wish to open your addon's options panel directly, you can do so by calling this function:
InterfaceOptionsFrame_OpenToCategory(panel);
Or
InterfaceOptionsFrame_OpenToCategory(panel.name);
Note: Call this function twice (in a row), there is a bug in Blizzard's code which makes the first call (after login or /reload) fail. It opens interface options but not on the addon's interface options; instead it opens the default interface options. If you call it twice in a row, it works as intended.
Removing an existing options panel[edit]
If you wish to remove any of the options panels for whatever reason after they have been created (maybe to modify another addon's options) there is no blizzard function avalible to do this but it can be done with the folowing function:
function RemoveInterfaceOptions(Parent, Child) local bChildPanel = true; if (Child == nil) then -- Assume we are removing the whole panel if no child was specified Child = Parent; bChildPanel = false; AceConfigDialog3.BlizOptions[Parent] = nil; else AceConfigDialog3.BlizOptions[Parent][Parent.."\001".. Child] = nil; end; for Key,Value in pairs(INTERFACEOPTIONS_ADDONCATEGORIES) do if (bChildPanel and ((Value.parent == Parent) and (Value.name == Child))) then -- We are looking for a child panel and this is it... INTERFACEOPTIONS_ADDONCATEGORIES[Key] = nil; end; if (not(bChildPanel) and ((Value.parent == nil) and (Value.name == Child))) then -- We are looking for a parent and this is it... INTERFACEOPTIONS_ADDONCATEGORIES[Key] = nil; elseif (not(bChildPanel) and ((Value.parent == Parent))) then -- We are looking for a parent and this is it's child... INTERFACEOPTIONS_ADDONCATEGORIES[Key] = nil; end; end; InterfaceAddOnsList_Update(); end;
This function takes two peramiters "Parent" and "Child" and they are both strings:
- Parent is the name of the main panel (normally the name of the addon)
- Child is the name of any child panels you wish to remove
If both Parent and Child are given then the function removes only the child panel from the parent. If however only the parent is given then the whole panel and all child panels are removed.