Wikia

WoWWiki

Using the Interface Options Addons panel

Talk0
101,699pages on
this wiki
Revision as of 19:20, August 9, 2010 by Tcaresset (Talk | contribs)

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

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

This example is taken from an addon called SC_ChaChing, available from http://wowui.incgamers.com/?p=mod&m=4934.

The XML frame

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

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

 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

If you wish to open your addon's options panel directly – for example, with a slash command – you can do so by calling a single function:

 InterfaceOptionsFrame_OpenToCategory(panel);

Or

 InterfaceOptionsFrame_OpenToCategory(panel.name);

Around Wikia's network

Random Wiki