MCom.registerSmart
From WoWWiki
This article is a part of the documentation of the MCom function library
--[[
registerSmart ( {reglist} )
A single function that can register a chat command, and a UI variable at the same time.
You pass only the data you need to, and it will do anything it can with that data.
If you pass enough data to register a UI command and callback, a slash command, a super slash command,
and a sub slash command, this will do all of those things.
Args:
reglist - the table of options, some options will be listed more than once to show when they are needed, but only set them once
{
Data required to register a Cosmos or Khaos command:
(string) uivar - the name of the UI variable
(string) uitype - the type of UI variable
(string) uilabel - the label of the UI variable
Data required to register a Khaos command:
(string) uisec - the ID of the Khaos set to put the option in
Optional data for Cosmos or Khaos options:
(function) func - the function to call when this variable changes, see addSlashCommand for further details on the function
if this is not passed, a generic callback will be provided for you
(string) varbool - the name of the boolean variable to use in the generic setter
(string) varnum - the name of the number variable to use in the generic setter
(string) varstring - the name of the editbox variable to use in the generic setter
(string) varchoice - the name of the pulldown variable to use in the generic setter
(string) varcolor - the name of the color variable to use in the generic setter
(function) update - this function will be called when using the generic setter, and the variable is updated
(function) noupdate - this function will be called when using the generic setter, and the variable is not updated
(function) anyupdate - this function will be called when using the generic setter, whether the variable is updated or not
(boolean) hasbool - set to true if this option has a checkbox in it
(table) uioption - this can either be a table in the form of a Cosmos registration, or a KhaosOption. If it is passed
then it will be used to pull as much data as MCom can make use of out of it. This can allow you to
pass a Cosmos style option, that registers a Khaos option, for instance. It also allows you to set
anything in the Khaos option that MCom doesn't have an argument for.
If this is a Khaos option, it can include an entry called mcopts, which is a table of MCom options to set
for the option
(string) uisec - the ID of the section/set to put the option in, if the section/set already exists, the option wil be
added to it, if it doesn't exist, it will be created
(string) uiseclabel - the name of the section/set to put the option in
(string) uisecdesc - the description of the section/set to put the option in
NOTE: Once passed, the uisec variables will be stored as defaults for further commands
(string) uisep - the ID of the separator/header to put the option in, if the separator/header already exists, then the
option will be added after it, if it doesn't exist, it will be created
NOTE: Once passed, the uisep variable will be stored as default for further commands
(string) uiseplabel - the name of the separator/header to put the option in
(string) uisepdesc - the description of the separator/header to put the option in
(string) uidesc - the description of the UI variable
(number) uicheck - the default value for a checkbox, 1 or 0
(number) uislider - the default value for a slider
(number) uimin - the minimum value for a slider
(number) uimax - the maximum value for a slider
(string) uitext - the text to show on a UI control
(number) uistep - the increment to use for a slider
(number) uitexton - whether to show the text for the control or not, 1 or 0
(string) uisuffix - the suffix to show at the end of the slider text
(number) uimul - how much to multiple the slider value by when displaying it
Optional data for Khaos only options:
(table) uiset - this can be an entire KhaosSet, and if it is, the whole thing will be MCom registered
(string) uifolder - the Khaos folder to put the option in, if you don't pass this, and uicat is passed with a compatible type, uicat will be used
NOTE: Once passed, the uifolder variable will be stored as default for further commands
(string) uisecdiff - the difficulty of the set to put the option in
(string) uiseccall - the callback of the set to put the option in
(string) uisecdef - the default of the set to put the option in
(string) uiseccom - the commands list of the set to put the option in
NOTE: Once passed, the uisec variables will be stored as defaults for further commands
(string) uisepdiff - the difficulty of the header to put the option in
(string) uisepcall - the callback of the header to put the option in
(string) uisepdef - the default of the header to put the option in
(string) uikey - the key to use for the option
(string) uivalue - the value to use for the option
(number) uidiff - the difficulty of the option
{ key = { value = requirement } } uidep - A table listing what key's in a Khaos option set need to have what value set to what requirement
for the option to be enabled
(boolean) uiradio - set to true if the option has a radio control
(function) uifeedback - the function to call to show feedback data
(table) uisetup - the control setup structure
(string) uisliderlow - the text to show on the lower potion of the slider control
(string) uisliderhigh - the text to show on the higher potion of the slider control
(function) uisliderfunc - the function to use to setup the text to show on the slider
{ string = value, ... } choices - A list of choices and values to use when using a pulldown, string is the string shown in the pulldown
and value is the value that should be associated with that string.
(boolean) multichoice - set to true if more than one option can be selected in a pulldown
(boolean) hasopacity - set to true if a colorpicker should also have an opacity slider
(color) uicolor - the default color to use in a color picker
(string/table) uichoice - the default option(s) to be selected in a pulldown
(string) uistring - the default string to be set in a textbox
(table) uicallon - the default string to be set in a textbox
(boolean) uidischeck - the value of a checkbox when the option set is disabled
(number) uidisslider - the value of a slider when the option set is disabled
(color) uidiscolor - the value of a color picker when the option set is disabled
(string/table) uidischoice - the value of a pulldown when the option set is disabled
(string) uidisstring - the value of a text box when the option set is disabled
NOTE: Disabled options will use default settings, if they are not passed or nil
Data required to register with myAddOns
NOTE: You do not have to wait for VARIABLES_LOADED to register for myAddOns via MCom
Also, if you have set any section info for a Khaos or Cosmos section, that will be used with myAddOns
(string) addonname - This must be the exact same as the title in the toc file. Defaults to uisec.
or
(string) uisec - Where to place the addon in the myAddOnsList, defaults to uiseclabel
or
(string) uiseclabel - The name to show in myAddOns, defaults to uisec
Optional data for registering with myAddOns
(string) uisec - Where to place the addon in the myAddOnsList, defaults to uiseclabel
(string) uiseclabel - The name to show in myAddOns, defaults to uisec
(string) uisecdesc - NO LONGER USED BY myAddOns - The description to show in myAddOns, defaults to uiseclabel
(string or number) uiver - The version to show in the UI
(string) uidate - The date this version of the addon was released
(string) uiauthor - The name of the author of the addon
(string) uiwww - The website the addon can be found at, if any
(string) uimail - The email address the author can be reached at
(string) uicat - The category to place the addon in, if you don't pass this, and uifolder is passed with a compatible type, uifolder will be used
(string) uiframe - NO LONGER USED BY myAddOns - The name of the frame used to detect if your addon is loaded
(string) uioptionsframe - The name of the frame to show when the myAddOns options button is pressed for this Addon. If this is not passed, and
you are registering a Cosmos or Khaos option at the same time as this, then Cosmos or Khaos will be set as the options frame.
This will also add the frame to UIPanelWindows
( string or {string} ) uihelp - The help text to display in myAddOns and in slash command, and Khaos help. If it is a table, each entry is a page.
Data required to register a standard slash command:
(string) command - the name of the slash command Ex: "/command", or {"/command", "/com"}
(string) comtype - [Required if uitype is not passed, takes precidence over uitype]
the type of data you are expecting from this slash command
MCOM_BOOLT - Expects boolean data, an on, off, 1, or 0
MCOM_NUMT - Expects a number value
MCOM_MULTIT - Expects a boolean and then a number value, Ex: "/command on 3", this has been surplanted via simply
using hasbool with MCOM_NUMT
MCOM_STRINGT - Expects any string
MCOM_COLORT - Expects a color setup, and optionally opacity
MCOM_CHOICET - Expects a choice from a list of choices, or optionaly multiple choices
MCOM_SIMPLET - No input needed, just calls the function
Optional data for a standard slash command, or sub command:
(function) func - the function to call when this variable changes, see addSlashCommand for further details on the function
if this is not passed, a generic callback will be provided for you
(boolean) hasbool - set to true if this option has a boolean portion
(string) varbool - the name of the boolean variable to use in the generic setter
(string) varnum - the name of the number variable to use in the generic setter
(string) varstring - the name of the string variable to use in the generic setter
(string) varchoice - the name of the choice variable to use in the generic setter
(string) varcolor - the name of the color variable to use in the generic setter
(number) varmin - the minimum value the number variable can be set to when using the generic setter
if not passed, and uimin is passed, uimin will be used
(number) varmax - the maximum value the number variable can be set to when using the generic setter
if not passed, and uimax is passed, uimax will be used
(function) update - this function will be called when using the generic setter, and the variable is updated
(function) noupdate - this function will be called when using the generic setter, and the variable is not updated
(function) anyupdate - this function will be called when using the generic setter, whether the variable is updated or not
(string) textname - specifies the name of the option to display when printing status changes without a UI, only used if
textbool/num/string/choice/color aren't
(string) textbool, textnum, textstring, textchoice, textcolor - the string to print for the corrisponding portion, when not using a UI,
and the variable has been updated in the generic setter. If this string
contains a %s, then it will be replaced with the value its updated to.
(boolean) textshow - if this is true, then the text will be printed on update, whether or not a UI is around(when using the generic setter)
(number) commul - the value to multiply the number by when showing it's status
(number) cominmul - the value to multiply the number by when it is passed in by the user
(string) comaction - The action to perform, see Sky documentation for further details
(number) comsticky - Whether the command is sticky or not(1 or 0), see Sky documentation for further details
(boolean) multichoice - set to true if more than one option can be selected in an MCOM_CHOICET
(boolean) hasopacity - set to true if an MCOM_COLORT should also have an opacity setting
Optional data for a standard slash command only:
(string) comhelp - What message to display as help in Sky for this command, see Sky documentation for further details
({string}) extrahelp - A table of extra help messages to display, each line in the table is a separate line when printed.
Data required to register a super slash command:
(string) supercom - the name of the super slash command Ex: "/command", or {"/command", "/com"}
Optional data for a super slash command:
(string) comaction - The action to perform, see Sky documentation for further details
(number) comsticky - Whether the command is sticky or not(1 or 0), see Sky documentation for further details
(string) comhelp - What message to display as help in Sky for this command, see Sky documentation for further details
({string}) extrahelp - A table of extra help messages to display, each line in the table is a separate line when printed.
Data required to register a sub slash command:
(string) supercom - the name of the super slash command to use for this sub slash command Ex: "/command", or {"/command", "/com"}
(string) subcom - the name of the sub command, Ex: "command", or {"command", "com"}
(string) comtype - [Required if uitype is not passed], see above for details
Optional data for a sub command only:
(string) subhelp - What message to display next to the sub command when listing sub commands in the help output.
NOTE: if this is an MCOM_CHOICET then if you put a %s in this string, it will be replaced with a list of
the choices you passed.
Data required for a slash command to update a Cosmos or Khaos variable:
(string) uivar - The UI variable that should be updated
Data required for a slash command to update a Cosmos or Khaos variable, if func does not return a value:
(string) varbool - The variable that the UI variable should be set by
This should be a string containing the name of the variable to update, this can include .'s for tables, Ex: "Something.Value"
When type is MULTI, this specifies the bool variable
(string) varnum - The same as comnum, but used to specify the number variable when type is MULTI, only used for MULTI type
Data required for a slash command to update a Khaos variable:
(string) uisec - The option set ID that the uivar is found in
Data required for a slash command to when type is MCOM_CHOICET:
{ string = value, ... } choices - A list of choices and values to use when using a MCOM_CHOICET, string is the string passed in from the console
and value is the value that should be associated with that string.
Data required for help window:
( string or {string} ) infotext - If this is passed the text will be shown in a help window then the slash command help is used, or when the help button
is pressed in Khaos or Cosmos, this is also used for myAddOns help if uihelp was not passed. If it is a table, each
entry is a page.
Optional data for help window:
(string) name - Sets the name to refer to the addon as in the help window
(string) infotitle - Sets the title of the help window, if not passed, then name is used with a default string, Ex. "AddonName Help"
}
]]--
