Wednesday, April 18, 2012

LF API info...

... on how to hook one's options into Blizz's addon frame. Can't seem to find it.|||I found this on the Blizzard forums. Not too indepth ... but it should work to get ya started :)

http://forums.worldofwarcraft.com/th...ageNo=15&sid=1

(Here's the post)

HOWTO: Add new categories of options

The new Interface Options frame allows authors to place their configuration frames (aka "panels") alongside the panels for modifying the default UI.

Adding a new panel to the Interface Options frame is a fairly straightforward process. Any frame can be used as a panel as long as it implements the required values and methods.

Once a frame is ready to be used as a panel, it must be registered using the function

InterfaceOptions_AddCategory, i.e. InterfaceOptions_AddCategory(panel)

Panels can be designated as sub-categories of existing options. These panels are listed with smaller text, offset, and tied to parent categories. The parent categories can be expanded or collapsed to toggle display of their sub-categories.

When players select a category of options from the Interface Options frame, the panel associated with that category will be anchored to the right hand side of the Interface Options frame and shown.

The following members and methods are used by the Interface Options frame to display and organize panels.

panel.name - string (required)

The name of the AddOn or group of configuration options. This is the text that will display in the AddOn options list.

panel.parent - string (optional)

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.okay - function (optional)

This method will run when the player clicks "okay" in the Interface Options.

panel.cancel - function (optional)

This method will run when the player clicks "cancel" in the Interface Options. Use this to revert their changes.

panel.default - function (optional)

This method will run when the player clicks "defaults". Use this to revert their changes to your defaults.

EXAMPLE -- Use XML to create a frame, and through its OnLoad function, make the frame a panel.

MyAddOn.xml

<Frame name="ExamplePanel">

<Scripts>

<OnLoad>

ExamplePanel_OnLoad(self);

</OnLoad>

</Scripts>

</Frame>

MyAddOn.lua

function ExamplePanel_OnLoad (panel)

panel.name = "My AddOn"

InterfaceOptions_AddCategory(panel);

end

EXAMPLE -- Dynamically create a frame and use it as a subcategory for "My AddOn".

local panel = CreateFrame("FRAME", "ExampleSubCategory");

panel.name = "My SubCategory";

panel.parent = "My AddOn";

InterfaceOptions_AddCategory(panel);

EXAMPLE -- Create a frame with an okay and a cancel method

--[[ Create a frame to use as the panel ]] --

local panel = CreateFrame("FRAME", "ExamplePanel");

panel.name = "My AddOn";

-- [[ When the player clicks okay, set the original value to the current setting ]] --

panel.okay =

function (self)

self.originalValue = MY_VARIABLE;

end

-- [[ When the player clicks cancel, set the current setting to the original value ]] --

panel.cancel =

function (self)

MY_VARIABLE = self.originalValue;

end

-- [[ Add the panel to the Interface Options ]] --

InterfaceOptions_AddCategory(panel);|||As usual, thanks Moon! Exactly what I was looking for.

No comments:

Post a Comment