Advanced Topics - Extending FlexBar

PLEASE NOTE - THERE ARE CHANGES FROM 1.36

Introduction:  The creation of variants of FlexBar (FlexBarEx, the original Matrix Flexbar and adding the detection of fear to FlexBar) got me to thinking.  The problem with these is that they fork the FlexBar Code, making it hard for their creators to keep up with changes I make in the original FlexBar.  To help these folks out I've added in a few arctitectural features to ensure that they can add code in that will survive new versions (hopefully unchanged).

The addition of the Scripts Editor and the ability to run scripts on ProfileLoaded has paved the way to allowing these extension to be done within the FlexBar environment instead of through outside code modules.

Handling WoW Events:  (NOTE - This is changed since 1.36 PLEASE READ)

In order to effectively code in the WoW environment, you must be able to register for its events and respond to them.  In 1.32-1.36 this was done by making an entry in the FBEventHandlers table.  This is problematic in that, if I am already listening for that event you could overwrite my code.

In 1.37 I addressed this with 2 new functions:

function FB_RegisterEvent(event, name, callback, wowevent)
function FB_UnregisterEvent(event, name)

The call to RegisterEvent requrest the event name (either a WoW event like UNIT_HEALTH, or a FlexBar event like "mouseentergroup", a name for your handler for this event, a callback function to handle the event, and a flag to let FlexBar know if it is a WoW event or not.

Unregister simply takes the event and name and deletes it from the table.

Note:  For WoW events, FlexBar Code will execute first followed by other functions for that event in the order they were registered.  For FB events, the event will be raised and acted on before the registered code is run.

Example:

function SDK_TargetChanged()

    FB_RaiseEvent("TargetChanged")

end

FB_RegisterEvent("PLAYER_TARGET_CHANGED","SDK_tgtchange",SDK_TargetChanged,true)

Save this as "SDK Target Change Event Addition"

then

/flexbar runscript script='SDK Target Change Event Addition' on='ProfileLoaded'

and you will now get a Target Changed event in FlexBar.

Conditionals:

Conditionals are also handled by a table (FBConditions).  They are indexed by a lower case condition name (EG: FBConditions["hasbuff"]) and return either true or false - NOT NIL.  Please see FlexBar_Conditionals.lua for examples. 

Two conventions:  If a condition has a target (argument) and it is not provided, return false.  If several targets are passed, and ANY of them are true, return true.

Slash Commands:

Slash commands are easy to add with WoW_UtilityClasses.lua loaded:

MyCmd = Command_Class:New("MyCmd","/mycmd")

After this you can either add sub-commands with:

MyCmd:AddCommand("command",callback,"group","usage")

and parameters to that command with

MyCmd:AddParam("command","param",Required,Strict,{ types },{ bounds }, default)

Or, if you just require a simple command, override MyCmd:Dispatch(msg) to deal with it:

function MyCmd:Dispatch(msg)

local util = Utility_Class:New()

util:Echo(msg)

end

 

These abilities will make FlexBar extensible for other people, without requiring that they remake all their changes each version.