vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | MCom |
||
3 | A set of utility functions to simplify addon creation |
||
4 | |||
5 | By: Mugendai |
||
6 | Contact: mugekun@gmail.com |
||
7 | |||
8 | MCom provides several functions designed to lower the amount of code |
||
9 | required to make an addon be configurable. It helps to handle the |
||
10 | things that need to go on to handle user input, either via console |
||
11 | or via some GUI(like Cosmos or Khaos). |
||
12 | |||
13 | It aims mainly at tasks that are repeated in multiple places in every addon. |
||
14 | Any addon that wants to have chat commands needs a chat handler, and functions |
||
15 | for each command it can accept. It also needs functions for updating |
||
16 | the variables that have to do with configuration. Addons may also need |
||
17 | wrapper functions for a GUI interface. They may also need to have multiple |
||
18 | registers to support multiple GUIs, such as Cosmos and Khaos. |
||
19 | |||
20 | These things are all handled by MCom either by registering with it for such |
||
21 | functions, or by calling functions that do the repetative part. |
||
22 | |||
23 | $Id: MCom.lua 2641 2005-10-17 09:26:21Z mugendai $ |
||
24 | $Rev: 2641 $ |
||
25 | $LastChangedBy: mugendai $ |
||
26 | $Date: 2005-10-17 04:26:21 -0500 (Mon, 17 Oct 2005) $ |
||
27 | ]]-- |
||
28 | |||
29 | --If we should update/declare MCom, then do so now |
||
30 | if (MCom_Update) then |
||
31 | |||
32 | if (not Khaos) then |
||
33 | -- Provide Khaos config keywords for MCom mods for when Khaos isn't around |
||
34 | K_TEXT = "text"; |
||
35 | K_CHECKBOX = "text"; -- Not a typo. Checkboxes use the "text" type to describe their right-side |
||
36 | K_BUTTON = "button"; |
||
37 | K_SLIDER = "slider"; |
||
38 | K_EDITBOX = "editbox"; |
||
39 | K_PULLDOWN = "pulldown"; |
||
40 | K_COLORPICKER = "colorpicker"; |
||
41 | K_HEADER = "separator"; |
||
42 | end |
||
43 | |||
44 | if (not myAddOnsList) then |
||
45 | MYADDONS_CATEGORY_BARS = "Bars"; |
||
46 | MYADDONS_CATEGORY_CHAT = "Chat"; |
||
47 | MYADDONS_CATEGORY_CLASS = "Class"; |
||
48 | MYADDONS_CATEGORY_COMBAT = "Combat"; |
||
49 | MYADDONS_CATEGORY_COMPILATIONS = "Compilations"; |
||
50 | MYADDONS_CATEGORY_GUILD = "Guild"; |
||
51 | MYADDONS_CATEGORY_INVENTORY = "Inventory"; |
||
52 | MYADDONS_CATEGORY_MAP = "Map"; |
||
53 | MYADDONS_CATEGORY_OTHERS = "Others"; |
||
54 | MYADDONS_CATEGORY_PROFESSIONS = "Professions"; |
||
55 | MYADDONS_CATEGORY_QUESTS = "Quests"; |
||
56 | MYADDONS_CATEGORY_RAID = "Raid"; |
||
57 | end |
||
58 | |||
59 | -------------------------------------------------- |
||
60 | -- |
||
61 | -- Public Library Functions |
||
62 | -- |
||
63 | -------------------------------------------------- |
||
64 | --[[ |
||
65 | registerSmart ( {reglist} ) |
||
66 | A single function that can register a chat command, and a UI variable at the same time. |
||
67 | You pass only the data you need to, and it will do anything it can with that data. |
||
68 | If you pass enough data to register a UI command and callback, a slash command, a super slash command, |
||
69 | and a sub slash command, this will do all of those things. |
||
70 | |||
71 | Args: |
||
72 | reglist - the table of options, some options will be listed more than once to show when they are needed, but only set them once |
||
73 | { |
||
74 | Data required to register a Cosmos or Khaos command: |
||
75 | (string) uivar - the name of the UI variable |
||
76 | (string) uitype - the type of UI variable |
||
77 | (string) uilabel - the label of the UI variable |
||
78 | |||
79 | Data required to register a Khaos command: |
||
80 | (string) uisec - the ID of the Khaos set to put the option in |
||
81 | |||
82 | Optional data for Cosmos or Khaos options: |
||
83 | (function) func - the function to call when this variable changes, see addSlashCommand for further details on the function |
||
84 | if this is not passed, a generic callback will be provided for you |
||
85 | (string) varbool - the name of the boolean variable to use in the generic setter |
||
86 | (string) varnum - the name of the number variable to use in the generic setter |
||
87 | (string) varstring - the name of the editbox variable to use in the generic setter |
||
88 | (string) varchoice - the name of the pulldown variable to use in the generic setter |
||
89 | (string) varcolor - the name of the color variable to use in the generic setter |
||
90 | (function) update - this function will be called when using the generic setter, and the variable is updated |
||
91 | (function) noupdate - this function will be called when using the generic setter, and the variable is not updated |
||
92 | (function) anyupdate - this function will be called when using the generic setter, whether the variable is updated or not |
||
93 | (boolean) hasbool - set to true if this option has a checkbox in it |
||
94 | |||
95 | (table) uioption - this can either be a table in the form of a Cosmos registration, or a KhaosOption. If it is passed |
||
96 | then it will be used to pull as much data as MCom can make use of out of it. This can allow you to |
||
97 | pass a Cosmos style option, that registers a Khaos option, for instance. It also allows you to set |
||
98 | anything in the Khaos option that MCom doesn't have an argument for. |
||
99 | If this is a Khaos option, it can include an entry called mcopts, which is a table of MCom options to set |
||
100 | for the option |
||
101 | (string) uisec - the ID of the section/set to put the option in, if the section/set already exists, the option wil be |
||
102 | added to it, if it doesn't exist, it will be created |
||
103 | (string) uiseclabel - the name of the section/set to put the option in |
||
104 | (string) uisecdesc - the description of the section/set to put the option in |
||
105 | NOTE: Once passed, the uisec variables will be stored as defaults for further commands |
||
106 | (string) uisep - the ID of the separator/header to put the option in, if the separator/header already exists, then the |
||
107 | option will be added after it, if it doesn't exist, it will be created |
||
108 | NOTE: Once passed, the uisep variable will be stored as default for further commands |
||
109 | (string) uiseplabel - the name of the separator/header to put the option in |
||
110 | (string) uisepdesc - the description of the separator/header to put the option in |
||
111 | (string) uidesc - the description of the UI variable |
||
112 | (number) uicheck - the default value for a checkbox, 1 or 0 |
||
113 | (number) uislider - the default value for a slider |
||
114 | (number) uimin - the minimum value for a slider |
||
115 | (number) uimax - the maximum value for a slider |
||
116 | (string) uitext - the text to show on a UI control |
||
117 | (number) uistep - the increment to use for a slider |
||
118 | (number) uitexton - whether to show the text for the control or not, 1 or 0 |
||
119 | (string) uisuffix - the suffix to show at the end of the slider text |
||
120 | (number) uimul - how much to multiple the slider value by when displaying it |
||
121 | |||
122 | Optional data for Khaos only options: |
||
123 | (table) uiset - this can be an entire KhaosSet, and if it is, the whole thing will be MCom registered |
||
124 | (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 |
||
125 | NOTE: Once passed, the uifolder variable will be stored as default for further commands |
||
126 | (string) uisecdiff - the difficulty of the set to put the option in |
||
127 | (string) uiseccall - the callback of the set to put the option in |
||
128 | (string) uisecdef - the default of the set to put the option in |
||
129 | (string) uiseccom - the commands list of the set to put the option in |
||
130 | NOTE: Once passed, the uisec variables will be stored as defaults for further commands |
||
131 | (string) uisepdiff - the difficulty of the header to put the option in |
||
132 | (string) uisepcall - the callback of the header to put the option in |
||
133 | (string) uisepdef - the default of the header to put the option in |
||
134 | (string) uikey - the key to use for the option |
||
135 | (string) uivalue - the value to use for the option |
||
136 | (number) uidiff - the difficulty of the option |
||
137 | { key = { value = requirement } } uidep - A table listing what key's in a Khaos option set need to have what value set to what requirement |
||
138 | for the option to be enabled |
||
139 | (boolean) uiradio - set to true if the option has a radio control |
||
140 | (function) uifeedback - the function to call to show feedback data |
||
141 | (table) uisetup - the control setup structure |
||
142 | (string) uisliderlow - the text to show on the lower potion of the slider control |
||
143 | (string) uisliderhigh - the text to show on the higher potion of the slider control |
||
144 | (function) uisliderfunc - the function to use to setup the text to show on the slider |
||
145 | { string = value, ... } choices - A list of choices and values to use when using a pulldown, string is the string shown in the pulldown |
||
146 | and value is the value that should be associated with that string. |
||
147 | (boolean) multichoice - set to true if more than one option can be selected in a pulldown |
||
148 | (boolean) hasopacity - set to true if a colorpicker should also have an opacity slider |
||
149 | (color) uicolor - the default color to use in a color picker |
||
150 | (string/table) uichoice - the default option(s) to be selected in a pulldown |
||
151 | (string) uistring - the default string to be set in a textbox |
||
152 | (table) uicallon - the default string to be set in a textbox |
||
153 | (boolean) uidischeck - the value of a checkbox when the option set is disabled |
||
154 | (number) uidisslider - the value of a slider when the option set is disabled |
||
155 | (color) uidiscolor - the value of a color picker when the option set is disabled |
||
156 | (string/table) uidischoice - the value of a pulldown when the option set is disabled |
||
157 | (string) uidisstring - the value of a text box when the option set is disabled |
||
158 | NOTE: Disabled options will use default settings, if they are not passed or nil |
||
159 | |||
160 | Data required to register with myAddOns |
||
161 | NOTE: You do not have to wait for VARIABLES_LOADED to register for myAddOns via MCom |
||
162 | Also, if you have set any section info for a Khaos or Cosmos section, that will be used with myAddOns |
||
163 | (string) addonname - This must be the exact same as the title in the toc file. Defaults to uisec. |
||
164 | or |
||
165 | (string) uisec - Where to place the addon in the myAddOnsList, defaults to uiseclabel |
||
166 | or |
||
167 | (string) uiseclabel - The name to show in myAddOns, defaults to uisec |
||
168 | |||
169 | Optional data for registering with myAddOns |
||
170 | (string) uisec - Where to place the addon in the myAddOnsList, defaults to uiseclabel |
||
171 | (string) uiseclabel - The name to show in myAddOns, defaults to uisec |
||
172 | (string) uisecdesc - NO LONGER USED BY myAddOns - The description to show in myAddOns, defaults to uiseclabel |
||
173 | (string or number) uiver - The version to show in the UI |
||
174 | (string) uidate - The date this version of the addon was released |
||
175 | (string) uiauthor - The name of the author of the addon |
||
176 | (string) uiwww - The website the addon can be found at, if any |
||
177 | (string) uimail - The email address the author can be reached at |
||
178 | (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 |
||
179 | (string) uiframe - NO LONGER USED BY myAddOns - The name of the frame used to detect if your addon is loaded |
||
180 | (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 |
||
181 | 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. |
||
182 | This will also add the frame to UIPanelWindows |
||
183 | ( 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. |
||
184 | |||
185 | Data required to register a standard slash command: |
||
186 | (string) command - the name of the slash command Ex: "/command", or {"/command", "/com"} |
||
187 | (string) comtype - [Required if uitype is not passed, takes precidence over uitype] |
||
188 | the type of data you are expecting from this slash command |
||
189 | MCOM_BOOLT - Expects boolean data, an on, off, 1, or 0 |
||
190 | MCOM_NUMT - Expects a number value |
||
191 | MCOM_MULTIT - Expects a boolean and then a number value, Ex: "/command on 3", this has been surplanted via simply |
||
192 | using hasbool with MCOM_NUMT |
||
193 | MCOM_STRINGT - Expects any string |
||
194 | MCOM_COLORT - Expects a color setup, and optionally opacity |
||
195 | MCOM_CHOICET - Expects a choice from a list of choices, or optionaly multiple choices |
||
196 | MCOM_SIMPLET - No input needed, just calls the function |
||
197 | |||
198 | Optional data for a standard slash command, or sub command: |
||
199 | (function) func - the function to call when this variable changes, see addSlashCommand for further details on the function |
||
200 | if this is not passed, a generic callback will be provided for you |
||
201 | (boolean) hasbool - set to true if this option has a boolean portion |
||
202 | (string) varbool - the name of the boolean variable to use in the generic setter |
||
203 | (string) varnum - the name of the number variable to use in the generic setter |
||
204 | (string) varstring - the name of the string variable to use in the generic setter |
||
205 | (string) varchoice - the name of the choice variable to use in the generic setter |
||
206 | (string) varcolor - the name of the color variable to use in the generic setter |
||
207 | (number) varmin - the minimum value the number variable can be set to when using the generic setter |
||
208 | if not passed, and uimin is passed, uimin will be used |
||
209 | (number) varmax - the maximum value the number variable can be set to when using the generic setter |
||
210 | if not passed, and uimax is passed, uimax will be used |
||
211 | (function) update - this function will be called when using the generic setter, and the variable is updated |
||
212 | (function) noupdate - this function will be called when using the generic setter, and the variable is not updated |
||
213 | (function) anyupdate - this function will be called when using the generic setter, whether the variable is updated or not |
||
214 | (string) textname - specifies the name of the option to display when printing status changes without a UI, only used if |
||
215 | textbool/num/string/choice/color aren't |
||
216 | (string) textbool, textnum, textstring, textchoice, textcolor - the string to print for the corrisponding portion, when not using a UI, |
||
217 | and the variable has been updated in the generic setter. If this string |
||
218 | contains a %s, then it will be replaced with the value its updated to. |
||
219 | (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) |
||
220 | (number) commul - the value to multiply the number by when showing it's status |
||
221 | (number) cominmul - the value to multiply the number by when it is passed in by the user |
||
222 | (string) comaction - The action to perform, see Sky documentation for further details |
||
223 | (number) comsticky - Whether the command is sticky or not(1 or 0), see Sky documentation for further details |
||
224 | (boolean) multichoice - set to true if more than one option can be selected in an MCOM_CHOICET |
||
225 | (boolean) hasopacity - set to true if an MCOM_COLORT should also have an opacity setting |
||
226 | |||
227 | Optional data for a standard slash command only: |
||
228 | (string) comhelp - What message to display as help in Sky for this command, see Sky documentation for further details |
||
229 | ({string}) extrahelp - A table of extra help messages to display, each line in the table is a separate line when printed. |
||
230 | |||
231 | Data required to register a super slash command: |
||
232 | (string) supercom - the name of the super slash command Ex: "/command", or {"/command", "/com"} |
||
233 | |||
234 | Optional data for a super slash command: |
||
235 | (string) comaction - The action to perform, see Sky documentation for further details |
||
236 | (number) comsticky - Whether the command is sticky or not(1 or 0), see Sky documentation for further details |
||
237 | (string) comhelp - What message to display as help in Sky for this command, see Sky documentation for further details |
||
238 | ({string}) extrahelp - A table of extra help messages to display, each line in the table is a separate line when printed. |
||
239 | |||
240 | Data required to register a sub slash command: |
||
241 | (string) supercom - the name of the super slash command to use for this sub slash command Ex: "/command", or {"/command", "/com"} |
||
242 | (string) subcom - the name of the sub command, Ex: "command", or {"command", "com"} |
||
243 | |||
244 | (string) comtype - [Required if uitype is not passed], see above for details |
||
245 | |||
246 | Optional data for a sub command only: |
||
247 | (string) subhelp - What message to display next to the sub command when listing sub commands in the help output. |
||
248 | NOTE: if this is an MCOM_CHOICET then if you put a %s in this string, it will be replaced with a list of |
||
249 | the choices you passed. |
||
250 | |||
251 | Data required for a slash command to update a Cosmos or Khaos variable: |
||
252 | (string) uivar - The UI variable that should be updated |
||
253 | |||
254 | Data required for a slash command to update a Cosmos or Khaos variable, if func does not return a value: |
||
255 | (string) varbool - The variable that the UI variable should be set by |
||
256 | This should be a string containing the name of the variable to update, this can include .'s for tables, Ex: "Something.Value" |
||
257 | When type is MULTI, this specifies the bool variable |
||
258 | (string) varnum - The same as comnum, but used to specify the number variable when type is MULTI, only used for MULTI type |
||
259 | |||
260 | Data required for a slash command to update a Khaos variable: |
||
261 | (string) uisec - The option set ID that the uivar is found in |
||
262 | |||
263 | Data required for a slash command to when type is MCOM_CHOICET: |
||
264 | { 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 |
||
265 | and value is the value that should be associated with that string. |
||
266 | |||
267 | Data required for help window: |
||
268 | ( 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 |
||
269 | is pressed in Khaos or Cosmos, this is also used for myAddOns help if uihelp was not passed. If it is a table, each |
||
270 | entry is a page. |
||
271 | |||
272 | Optional data for help window: |
||
273 | (string) name - Sets the name to refer to the addon as in the help window |
||
274 | (string) infotitle - Sets the title of the help window, if not passed, then name is used with a default string, Ex. "AddonName Help" |
||
275 | } |
||
276 | ]]-- |
||
277 | MCom.registerSmart = function ( inreglist ) |
||
278 | --Get a copy of the registration table |
||
279 | local reglist; |
||
280 | if ( type(inreglist) == "table" ) then |
||
281 | reglist = MCom.table.copy(inreglist); |
||
282 | end |
||
283 | --Make sure reglist is here, and a table |
||
284 | if (type(reglist) == "table") then |
||
285 | --Register the Khaos options set if it has been passed |
||
286 | if ( type(reglist.uiset) == "table" ) then |
||
287 | MCom.uisec = reglist.uiset.id; |
||
288 | MCom.uiseclabel = reglist.uiset.text; |
||
289 | MCom.uisecdesc = reglist.uiset.helptext; |
||
290 | MCom.uisecdiff = reglist.uiset.difficulty; |
||
291 | MCom.uisecdef = reglist.uiset.default; |
||
292 | MCom.uiseccall = reglist.uiset.callback; |
||
293 | MCom.uiseccom = reglist.uiset.commands; |
||
294 | --Register each option in the list |
||
295 | if ( type(reglist.uiset.options) == "table" ) then |
||
296 | for curOption = 1, getn(reglist.uiset.options) do |
||
297 | local newMComSet = MCom.table.copy(reglist); |
||
298 | newMComSet.uiset = nil; |
||
299 | newMComSet.uioption = reglist.uiset.options[curOption]; |
||
300 | MCom.registerSmart( newMComSet ); |
||
301 | end |
||
302 | end |
||
303 | end |
||
304 | |||
305 | --Support for old sytax variables |
||
306 | if (reglist.comvar) then |
||
307 | reglist.varbool = reglist.comvar; |
||
308 | end |
||
309 | if (reglist.comvarmulti) then |
||
310 | reglist.varnum = reglist.comvarmulti; |
||
311 | end |
||
312 | |||
313 | --This will be set to true if we find that uioption is in Khaos format. |
||
314 | local isKhaosOption = nil; |
||
315 | |||
316 | --If option data has been passed use any of it, as needed |
||
317 | if ( type(reglist.uioption) == "table" ) then |
||
318 | --If the option data seems to be Khaos style, then parse it as such |
||
319 | if ( (reglist.uioption.id ~= nil) or (reglist.uioption.key ~= nil) or (reglist.uioption.value ~= nil) or |
||
320 | (reglist.uioption.text ~= nil) or (reglist.uioption.diificulty ~= nil) or (reglist.uioption.helptext ~= nil) or |
||
321 | (reglist.uioption.callback ~= nil) or (reglist.uioption.feedback ~= nil) or (reglist.uioption.check ~= nil) or |
||
322 | (reglist.uioption.radio ~= nil) or (reglist.uioption.type ~= nil) or (reglist.uioption.setup ~= nil) or |
||
323 | (reglist.uioption.default ~= nil) or (reglist.uioption.disabled ~= nil) or (reglist.uioption.dependencies ~= nil) or |
||
324 | (reglist.uioption.mcopts ~= nil) |
||
325 | ) then |
||
326 | isKhaosOption = true; |
||
327 | if (reglist.uivar == nil) then |
||
328 | reglist.uivar = reglist.uioption.id; |
||
329 | end |
||
330 | if (reglist.uikey == nil) then |
||
331 | reglist.uikey = reglist.uioption.key; |
||
332 | end |
||
333 | if (reglist.uivalue == nil) then |
||
334 | reglist.uivalue = reglist.uioption.value; |
||
335 | end |
||
336 | if (reglist.uilabel == nil) then |
||
337 | reglist.uilabel = reglist.uioption.text; |
||
338 | end |
||
339 | if (reglist.uidiff == nil) then |
||
340 | reglist.uidiff = reglist.uioption.difficulty; |
||
341 | end |
||
342 | if (reglist.uidesc == nil) then |
||
343 | reglist.uidesc = reglist.uioption.helptext; |
||
344 | end |
||
345 | if (reglist.uifunc == nil) then |
||
346 | reglist.uifunc = reglist.uioption.callback; |
||
347 | --If this is a Khaos style function, going into Cosmos, then convert the values to Cosmos style |
||
348 | if ((not Khaos) and CosmosMaster_Init and reglist.uifunc) then |
||
349 | reglist.uifunc = function (check, value) reglist.uioption.callback({ checked = (check == 1); slider = value; }); end; |
||
350 | end |
||
351 | end |
||
352 | if (reglist.hasbool == nil) then |
||
353 | reglist.hasbool = reglist.uioption.check; |
||
354 | end |
||
355 | if (reglist.uiradio == nil) then |
||
356 | reglist.uiradio = reglist.uioption.radio; |
||
357 | end |
||
358 | if (reglist.uitype == nil) then |
||
359 | reglist.uitype = reglist.uioption.type; |
||
360 | end |
||
361 | if ( type(reglist.uioption.setup) == "table" ) then |
||
362 | if (reglist.uisetup == nil) then |
||
363 | reglist.uisetup = reglist.uioption.setup; |
||
364 | end |
||
365 | if (reglist.uitext == nil) then |
||
366 | if ( (reglist.uitype == K_BUTTON) or (reglist.uitype == "BUTTON") ) then |
||
367 | reglist.uitext = reglist.uioption.setup.buttonText; |
||
368 | elseif ( (reglist.uitype == K_SLIDER) or (reglist.uitype == "SLIDER") or (reglist.uitype == "BOTH") ) then |
||
369 | reglist.uitext = reglist.uioption.setup.sliderText; |
||
370 | end |
||
371 | end |
||
372 | if (reglist.uimin == nil) then |
||
373 | reglist.uimin = reglist.uioption.setup.sliderMin; |
||
374 | end |
||
375 | if (reglist.uimax == nil) then |
||
376 | reglist.uimax = reglist.uioption.setup.sliderMax; |
||
377 | end |
||
378 | if (reglist.uistep == nil) then |
||
379 | reglist.uistep = reglist.uioption.setup.sliderStep; |
||
380 | end |
||
381 | if (reglist.uisliderlow == nil) then |
||
382 | reglist.uisliderlow = reglist.uioption.setup.sliderLowText; |
||
383 | end |
||
384 | if (reglist.uisliderhigh == nil) then |
||
385 | reglist.uisliderhigh = reglist.uioption.setup.sliderHighText; |
||
386 | end |
||
387 | if (reglist.uisliderfunc == nil) then |
||
388 | reglist.uisliderfunc = reglist.uioption.setup.sliderDisplayFunc; |
||
389 | end |
||
390 | if (reglist.choices == nil) then |
||
391 | reglist.choices = reglist.uioption.setup.options; |
||
392 | end |
||
393 | if (reglist.multichoice == nil) then |
||
394 | reglist.multichoice = reglist.uioption.setup.multiSelect; |
||
395 | end |
||
396 | if (reglist.hasopacity == nil) then |
||
397 | reglist.hasopacity = reglist.uioption.setup.hasOpacity; |
||
398 | end |
||
399 | if (reglist.uicallon == nil) then |
||
400 | reglist.uicallon = reglist.uioption.setup.callOn; |
||
401 | end |
||
402 | end |
||
403 | if (reglist.uifeedback == nil) then |
||
404 | reglist.uifeedback = reglist.uioption.feedback; |
||
405 | end |
||
406 | if ( type(reglist.uioption.default) == "table" ) then |
||
407 | if (reglist.uicheck == nil) then |
||
408 | reglist.uicheck = reglist.uioption.default.checked; |
||
409 | if (reglist.uicheck) then |
||
410 | reglist.uicheck = 1; |
||
411 | else |
||
412 | reglist.uicheck = 0; |
||
413 | end |
||
414 | end |
||
415 | if (reglist.uislider == nil) then |
||
416 | reglist.uislider = reglist.uioption.default.slider; |
||
417 | end |
||
418 | if (reglist.uicolor == nil) then |
||
419 | reglist.uicolor = reglist.uioption.default.color; |
||
420 | end |
||
421 | if (reglist.uitype == K_EDITBOX) then |
||
422 | if (reglist.uistring == nil) then |
||
423 | reglist.uistring = reglist.uioption.default.value; |
||
424 | end |
||
425 | end |
||
426 | if (reglist.uitype == K_PULLDOWN) then |
||
427 | if (reglist.uichoice == nil) then |
||
428 | reglist.uichoice = reglist.uioption.default.value; |
||
429 | end |
||
430 | end |
||
431 | end |
||
432 | if ( type(reglist.uioption.disabled) == "table" ) then |
||
433 | if (reglist.uidischeck == nil) then |
||
434 | reglist.uidischeck = reglist.uioption.disabled.checked; |
||
435 | if (reglist.uidischeck) then |
||
436 | reglist.uidischeck = 1; |
||
437 | else |
||
438 | reglist.uidischeck = 0; |
||
439 | end |
||
440 | end |
||
441 | if (reglist.uidisslider == nil) then |
||
442 | reglist.uidisslider = reglist.uioption.disabled.slider; |
||
443 | end |
||
444 | if (reglist.uidiscolor == nil) then |
||
445 | reglist.uidiscolor = reglist.uioption.disabled.color; |
||
446 | end |
||
447 | if (reglist.uitype == K_EDITBOX) then |
||
448 | if (reglist.uidisstring == nil) then |
||
449 | reglist.uidisstring = reglist.uioption.disabled.value; |
||
450 | end |
||
451 | end |
||
452 | if (reglist.uitype == K_PULLDOWN) then |
||
453 | if (reglist.uidischoice == nil) then |
||
454 | reglist.uidischoice = reglist.uioption.disabled.value; |
||
455 | end |
||
456 | end |
||
457 | end |
||
458 | if (reglist.uidep == nil) then |
||
459 | reglist.uidep = reglist.uioption.dependencies; |
||
460 | end |
||
461 | |||
462 | --If an MCom option set is in here, then use it |
||
463 | if ( type(reglist.uioption.mcopts) == "table" ) then |
||
464 | for curOpt in reglist.uioption.mcopts do |
||
465 | reglist[curOpt] = reglist.uioption.mcopts[curOpt]; |
||
466 | end |
||
467 | end |
||
468 | else |
||
469 | --If it's not Khaos style, we treat it as Cosmos style |
||
470 | if (reglist.uivar == nil) then |
||
471 | reglist.uivar = reglist.uioption[1]; |
||
472 | end |
||
473 | if (reglist.uitype == nil) then |
||
474 | reglist.uitype = reglist.uioption[2]; |
||
475 | end |
||
476 | if (reglist.uilabel == nil) then |
||
477 | reglist.uilabel = reglist.uioption[3]; |
||
478 | end |
||
479 | if (reglist.uidesc == nil) then |
||
480 | reglist.uidesc = reglist.uioption[4]; |
||
481 | end |
||
482 | if (reglist.uifunc == nil) then |
||
483 | reglist.uifunc = reglist.uioption[5]; |
||
484 | --If it's a Cosmos style function, being used in Khaos then convert the arguments to match |
||
485 | if (Khaos and (not CosmosMaster_Init) and reglist.uifunc) then |
||
486 | local checkFunc = function (check) |
||
487 | if (check) then |
||
488 | return 1; |
||
489 | else |
||
490 | return 0; |
||
491 | end |
||
492 | end |
||
493 | reglist.uifunc = function (state) reglist.uioption[5]( checkFunc(state.checked) , state.slider); end; |
||
494 | if ( reglist.func == nil ) then |
||
495 | if (reglist.uitype == "SLIDER") then |
||
496 | reglist.func = function (value) reglist.uioption[5](0,value); end; |
||
497 | else |
||
498 | reglist.func = function (bool, value) reglist.uioption[5](bool,value); end; |
||
499 | end |
||
500 | end |
||
501 | end |
||
502 | end |
||
503 | if (reglist.uicheck == nil) then |
||
504 | reglist.uicheck = reglist.uioption[6]; |
||
505 | end |
||
506 | if (reglist.uislider == nil) then |
||
507 | reglist.uislider = reglist.uioption[7]; |
||
508 | end |
||
509 | if (reglist.uimin == nil) then |
||
510 | reglist.uimin = reglist.uioption[8]; |
||
511 | end |
||
512 | if (reglist.uimax == nil) then |
||
513 | reglist.uimax = reglist.uioption[9]; |
||
514 | end |
||
515 | if (reglist.uitext == nil) then |
||
516 | reglist.uitext = reglist.uioption[10]; |
||
517 | end |
||
518 | if (reglist.uistep == nil) then |
||
519 | reglist.uistep = reglist.uioption[11]; |
||
520 | end |
||
521 | if (reglist.uitexton == nil) then |
||
522 | reglist.uitexton = reglist.uioption[12]; |
||
523 | end |
||
524 | if (reglist.uisuffix == nil) then |
||
525 | reglist.uisuffix = reglist.uioption[13]; |
||
526 | end |
||
527 | if (reglist.uimul == nil) then |
||
528 | reglist.uimul = reglist.uioption[14]; |
||
529 | end |
||
530 | end |
||
531 | end |
||
532 | |||
533 | --Default our regtype to nil |
||
534 | local regtype = nil; |
||
535 | --If we have uitype, then figure out the MCOM type for it |
||
536 | if (reglist.uitype) then |
||
537 | --If we are doing Khaos, then use it's types, and convert Cosmos types |
||
538 | --to Khaos types |
||
539 | if (Khaos) then |
||
540 | if ( reglist.uitype == K_TEXT ) then |
||
541 | if (reglist.hasbool == true) then |
||
542 | regtype = MCOM_BOOLT; |
||
543 | end |
||
544 | elseif ( reglist.uitype == K_SLIDER ) then |
||
545 | regtype = MCOM_NUMT; |
||
546 | elseif ( reglist.uitype == K_EDITBOX ) then |
||
547 | regtype = MCOM_STRINGT; |
||
548 | elseif ( reglist.uitype == K_BUTTON ) then |
||
549 | regtype = MCOM_SIMPLET; |
||
550 | elseif ( reglist.uitype == K_PULLDOWN ) then |
||
551 | regtype = MCOM_CHOICET; |
||
552 | elseif ( reglist.uitype == K_COLORPICKER ) then |
||
553 | regtype = MCOM_COLORT; |
||
554 | elseif (reglist.uitype == "CHECKBOX") then |
||
555 | reglist.uitype = K_TEXT; |
||
556 | regtype = MCOM_BOOLT; |
||
557 | reglist.hasbool = true; |
||
558 | elseif (reglist.uitype == "SLIDER") then |
||
559 | reglist.uitype = K_SLIDER; |
||
560 | regtype = MCOM_NUMT; |
||
561 | elseif (reglist.uitype == "BOTH") then |
||
562 | reglist.uitype = K_SLIDER; |
||
563 | reglist.hasbool = true; |
||
564 | regtype = MCOM_MULTIT; |
||
565 | elseif (reglist.uitype == "BUTTON") then |
||
566 | reglist.uitype = K_BUTTON; |
||
567 | regtype = MCOM_SIMPLET; |
||
568 | elseif (reglist.uitype == "SEPARATOR") then |
||
569 | reglist.uitype = K_HEADER; |
||
570 | end |
||
571 | else |
||
572 | --If we are doing Cosmos, then use it's types, and convert Khaos types |
||
573 | --to Cosmos types |
||
574 | if ( reglist.uitype == K_TEXT ) then |
||
575 | if (reglist.hasbool == true) then |
||
576 | regtype = MCOM_BOOLT; |
||
577 | reglist.uitype = "CHECKBOX"; |
||
578 | end |
||
579 | elseif ( reglist.uitype == K_SLIDER ) then |
||
580 | regtype = MCOM_NUMT; |
||
581 | reglist.uitype = "SLIDER"; |
||
582 | if (reglist.hasbool == true) then |
||
583 | reglist.uitype = "BOTH"; |
||
584 | end |
||
585 | elseif ( reglist.uitype == K_EDITBOX ) then |
||
586 | regtype = MCOM_STRINGT; |
||
587 | elseif ( reglist.uitype == K_BUTTON ) then |
||
588 | regtype = MCOM_SIMPLET; |
||
589 | reglist.uitype = "BUTTON"; |
||
590 | elseif ( reglist.uitype == K_PULLDOWN ) then |
||
591 | regtype = MCOM_CHOICET; |
||
592 | elseif ( reglist.uitype == K_COLORPICKER ) then |
||
593 | regtype = MCOM_COLORT; |
||
594 | elseif (reglist.uitype == K_HEADER) then |
||
595 | reglist.uitype = "SEPARATOR"; |
||
596 | elseif (reglist.uitype == "CHECKBOX") then |
||
597 | regtype = MCOM_BOOLT; |
||
598 | reglist.hasbool = true; |
||
599 | elseif (reglist.uitype == "SLIDER") then |
||
600 | regtype = MCOM_NUMT; |
||
601 | elseif (reglist.uitype == "BOTH") then |
||
602 | regtype = MCOM_MULTIT; |
||
603 | elseif (reglist.uitype == "BUTTON") then |
||
604 | regtype = MCOM_SIMPLET; |
||
605 | end |
||
606 | end |
||
607 | end |
||
608 | --If we have the comtype, use it instead of the uitype |
||
609 | if (reglist.comtype) then |
||
610 | regtype = reglist.comtype; |
||
611 | end |
||
612 | |||
613 | --If regtype is not set, and we have check set, then set type is BOOLT. |
||
614 | if ( (regtype == nil) and (reglist.hasbool == true) ) then |
||
615 | regtype = MCOM_BOOLT; |
||
616 | end |
||
617 | --If regtype is BOOLT, and we dont have check set, then set it. |
||
618 | if ( (regtype == MCOM_BOOLT) and (not reglist.hasbool) ) then |
||
619 | reglist.hasbool = true; |
||
620 | end |
||
621 | --If regtype is MULTIT, and we dont have check set, then set it. |
||
622 | if ( (regtype == MCOM_MULTIT) and (not reglist.hasbool) ) then |
||
623 | reglist.hasbool = true; |
||
624 | end |
||
625 | |||
626 | --If no min, max, or mul were provided for the setter, but was provided for the UI, then use the ui values |
||
627 | --and visa versa |
||
628 | if ( reglist.uimin and (not reglist.varmin) ) then |
||
629 | reglist.varmin = reglist.uimin; |
||
630 | elseif ( reglist.varmin and (not reglist.uimin) ) then |
||
631 | reglist.uimin = reglist.varmin; |
||
632 | end |
||
633 | if ( reglist.uimax and (not reglist.varmax) ) then |
||
634 | reglist.varmax = reglist.uimax; |
||
635 | elseif ( reglist.varmax and (not reglist.uimax) ) then |
||
636 | reglist.uimax = reglist.varmax; |
||
637 | end |
||
638 | if ( reglist.uimul and (not reglist.commul) ) then |
||
639 | reglist.commul = reglist.uimul; |
||
640 | elseif ( reglist.commul and (not reglist.uimul) ) then |
||
641 | reglist.uimul = reglist.commul; |
||
642 | end |
||
643 | if ( not reglist.uimul ) then |
||
644 | reglist.uimul = 1; |
||
645 | end |
||
646 | if ( reglist.commul and ( not reglist.cominmul ) ) then |
||
647 | reglist.cominmul = 1 / reglist.commul; |
||
648 | end |
||
649 | if ( not reglist.commul ) then |
||
650 | reglist.commul = 1; |
||
651 | end |
||
652 | if ( not reglist.cominmul ) then |
||
653 | reglist.cominmul = 1; |
||
654 | end |
||
655 | |||
656 | if (not reglist.func) then |
||
657 | if (reglist.uifunc) then |
||
658 | --If there was no function passed, but a ui func was passed, use the uifunc |
||
659 | reglist.func = reglist.uifunc; |
||
660 | else |
||
661 | --If textname wasn't passed, try and make it from other data |
||
662 | if (not reglist.textname) then |
||
663 | reglist.textname = reglist.uilabel; |
||
664 | end |
||
665 | if (not reglist.textname) then |
||
666 | if ( type(reglist.subcom) == "table" ) then |
||
667 | reglist.textname = reglist.subcom[1]; |
||
668 | else |
||
669 | reglist.textname = reglist.subcom; |
||
670 | end |
||
671 | end |
||
672 | if (not reglist.textname) then |
||
673 | if ( type(reglist.command) == "table" ) then |
||
674 | reglist.textname = reglist.command[1]; |
||
675 | else |
||
676 | reglist.textname = reglist.command; |
||
677 | end |
||
678 | end |
||
679 | |||
680 | --Generate defaults for the text strings if none are passed |
||
681 | if (reglist.textname) then |
||
682 | if (not reglist.textbool) then |
||
683 | reglist.textbool = string.format(MCOM_CHAT_STATUS_B, reglist.textname); |
||
684 | end |
||
685 | if (not reglist.textnum) then |
||
686 | reglist.textnum = string.format(MCOM_CHAT_STATUS_N, reglist.textname); |
||
687 | end |
||
688 | if (not reglist.textstring) then |
||
689 | reglist.textstring = string.format(MCOM_CHAT_STATUS_S, reglist.textname); |
||
690 | end |
||
691 | if (not reglist.textchoice) then |
||
692 | reglist.textchoice = string.format(MCOM_CHAT_STATUS_C, reglist.textname); |
||
693 | end |
||
694 | if (not reglist.textcolor) then |
||
695 | reglist.textcolor = string.format(MCOM_CHAT_STATUS_K, reglist.textname); |
||
696 | end |
||
697 | end |
||
698 | |||
699 | --If there was no function passed, then provide our own generic function |
||
700 | if ((regtype == MCOM_BOOLT) and reglist.varbool) then |
||
701 | reglist.func = function (checked) |
||
702 | if (MCom.updateVar(reglist.varbool, checked, MCOM_BOOLT)) then |
||
703 | --If there is a function to run on an update, call it |
||
704 | if (reglist.update and (type(reglist.update) == "function")) then |
||
705 | reglist.update(reglist.varbool); |
||
706 | end |
||
707 | |||
708 | if (reglist.textbool) then |
||
709 | --Print output to let the player know the command succeeded, if there is no UI |
||
710 | MCom.printStatus(reglist.textbool, MCom.getStringVar(reglist.varbool), true, reglist.textshow); |
||
711 | end |
||
712 | else |
||
713 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
714 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
715 | reglist.noupdate(reglist.varbool); |
||
716 | end |
||
717 | end |
||
718 | --If there is a function to run on any update, then run it |
||
719 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
720 | reglist.anyupdate(reglist.varbool); |
||
721 | end |
||
722 | end; |
||
723 | elseif ( ( (regtype == MCOM_NUMT) and (not reglist.hasbool) ) and reglist.varnum ) then |
||
724 | reglist.func = function (value) |
||
725 | if (MCom.updateVar(reglist.varnum, value, MCOM_NUMT, reglist.varmin, reglist.varmax)) then |
||
726 | --If there is a function to run on an update, call it |
||
727 | if (reglist.update and (type(reglist.update) == "function")) then |
||
728 | reglist.update(reglist.varnum); |
||
729 | end |
||
730 | |||
731 | if (reglist.textnum) then |
||
732 | --Print output to let the player know the command succeeded, if there is no UI |
||
733 | if (value and reglist.commul and MCom.getStringVar(reglist.varnum)) then |
||
734 | value = MCom.math.round( ( MCom.getStringVar(reglist.varnum) * reglist.commul ) * 100 ) / 100; |
||
735 | else |
||
736 | value = MCom.getStringVar(reglist.varnum); |
||
737 | end |
||
738 | MCom.printStatus(reglist.textnum, value, nil, reglist.textshow); |
||
739 | end |
||
740 | else |
||
741 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
742 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
743 | reglist.noupdate(reglist.varnum); |
||
744 | end |
||
745 | end |
||
746 | --If there is a function to run on any update, then run it |
||
747 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
748 | reglist.anyupdate(reglist.varnum); |
||
749 | end |
||
750 | end; |
||
751 | elseif ( ( (regtype == MCOM_STRINGT) and (not reglist.hasbool) ) and reglist.varstring ) then |
||
752 | reglist.func = function (value) |
||
753 | if (MCom.updateVar(reglist.varstring, value, MCOM_STRINGT)) then |
||
754 | --If there is a function to run on an update, call it |
||
755 | if (reglist.update and (type(reglist.update) == "function")) then |
||
756 | reglist.update(reglist.varstring); |
||
757 | end |
||
758 | |||
759 | if (reglist.textstring) then |
||
760 | --Print output to let the player know the command succeeded, if there is no UI |
||
761 | MCom.printStatus(reglist.textstring, MCom.getStringVar(reglist.varstring), nil, reglist.textshow); |
||
762 | end |
||
763 | else |
||
764 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
765 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
766 | reglist.noupdate(reglist.varstring); |
||
767 | end |
||
768 | end |
||
769 | --If there is a function to run on any update, then run it |
||
770 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
771 | reglist.anyupdate(reglist.varstring); |
||
772 | end |
||
773 | end; |
||
774 | elseif ( ( (regtype == MCOM_CHOICET) and (not reglist.hasbool) ) and reglist.varchoice ) then |
||
775 | reglist.func = function (value, name) |
||
776 | if (MCom.updateVar(reglist.varchoice, value, MCOM_CHOICET)) then |
||
777 | --If there is a function to run on an update, call it |
||
778 | if (reglist.update and (type(reglist.update) == "function")) then |
||
779 | reglist.update(reglist.varchoice); |
||
780 | end |
||
781 | |||
782 | if (reglist.textchoice) then |
||
783 | --Print output to let the player know the command succeeded, if there is no UI |
||
784 | MCom.printStatus(reglist.textchoice, name, nil, reglist.textshow); |
||
785 | end |
||
786 | else |
||
787 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
788 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
789 | reglist.noupdate(reglist.varchoice); |
||
790 | end |
||
791 | end |
||
792 | --If there is a function to run on any update, then run it |
||
793 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
794 | reglist.anyupdate(reglist.varchoice); |
||
795 | end |
||
796 | end; |
||
797 | elseif ( ( (regtype == MCOM_COLORT) and (not reglist.hasbool) ) and reglist.varcolor ) then |
||
798 | reglist.func = function (value) |
||
799 | if (MCom.updateVar(reglist.varcolor, value, MCOM_COLORT)) then |
||
800 | --If there is a function to run on an update, call it |
||
801 | if (reglist.update and (type(reglist.update) == "function")) then |
||
802 | reglist.update(reglist.varcolor); |
||
803 | end |
||
804 | |||
805 | if (reglist.textcolor) then |
||
806 | --Build a color string |
||
807 | local curColor = MCom.getStringVar(reglist.varstring); |
||
808 | local curColString = ""; |
||
809 | if ( type(curColor) == "table" ) then |
||
810 | if (curColor.r) then |
||
811 | curColString = string.format(MCOM_CHAT_COM_K_R, MCom.math.round(curColor.r * 100)); |
||
812 | end |
||
813 | if (curColor.g) then |
||
814 | if ( curColString ~= "" ) then |
||
815 | curColString = curColString..", "; |
||
816 | end |
||
817 | curColString = curColString..string.format(MCOM_CHAT_COM_K_G, MCom.math.round(curColor.g * 100)); |
||
818 | end |
||
819 | if (curColor.b) then |
||
820 | if ( curColString ~= "" ) then |
||
821 | curColString = curColString..", "; |
||
822 | end |
||
823 | curColString = curColString..string.format(MCOM_CHAT_COM_K_B, MCom.math.round(curColor.b * 100)); |
||
824 | end |
||
825 | if (reglist.hasopacity) then |
||
826 | local displayOpacity = 1; |
||
827 | if (curColor.opacity) then |
||
828 | displayOpacity = curColor.opacity; |
||
829 | end |
||
830 | if ( curColString ~= "" ) then |
||
831 | curColString = curColString..", "; |
||
832 | end |
||
833 | curColString = curColString..string.format(MCOM_CHAT_COM_K_O, MCom.math.round(displayOpacity * 100)); |
||
834 | end |
||
835 | end |
||
836 | --Print output to let the player know the command succeeded, if there is no UI |
||
837 | MCom.printStatus(reglist.textcolor, curColString, nil, reglist.textshow); |
||
838 | end |
||
839 | else |
||
840 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
841 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
842 | reglist.noupdate(reglist.varcolor); |
||
843 | end |
||
844 | end |
||
845 | --If there is a function to run on any update, then run it |
||
846 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
847 | reglist.anyupdate(reglist.varcolor); |
||
848 | end |
||
849 | end; |
||
850 | elseif ( ( (regtype == MCOM_MULTIT) or ( (regtype == MCOM_NUMT) and reglist.hasbool ) ) and reglist.varbool and reglist.varnum ) then |
||
851 | reglist.func = function (checked, value) |
||
852 | if (MCom.updateVar(reglist.varbool, checked, MCOM_BOOLT)) then |
||
853 | --If there is a function to run on an update, call it |
||
854 | if (reglist.update and (type(reglist.update) == "function")) then |
||
855 | reglist.update(reglist.varbool); |
||
856 | end |
||
857 | |||
858 | if (reglist.textbool) then |
||
859 | --Print output to let the player know the command succeeded, if there is no UI |
||
860 | MCom.printStatus(reglist.textbool, MCom.getStringVar(reglist.varbool), true, reglist.textshow); |
||
861 | end |
||
862 | else |
||
863 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
864 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
865 | reglist.noupdate(reglist.varbool); |
||
866 | end |
||
867 | end |
||
868 | --If there is a function to run on any update, then run it |
||
869 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
870 | reglist.anyupdate(reglist.varbool); |
||
871 | end |
||
872 | |||
873 | --If no value was passed, then don't set it |
||
874 | if (value) then |
||
875 | if (MCom.updateVar(reglist.varnum, value, MCOM_NUMT, reglist.varmin, reglist.varmax)) then |
||
876 | --If there is a function to run on an update, call it |
||
877 | if (reglist.update and (type(reglist.update) == "function")) then |
||
878 | reglist.update(reglist.varnum); |
||
879 | end |
||
880 | |||
881 | if (reglist.textnum) then |
||
882 | --Print output to let the player know the command succeeded, if there is no UI |
||
883 | if (value and reglist.commul and MCom.getStringVar(reglist.varnum)) then |
||
884 | value = MCom.math.round( ( MCom.getStringVar(reglist.varnum) * reglist.commul ) * 100 ) / 100; |
||
885 | else |
||
886 | value = MCom.getStringVar(reglist.varnum); |
||
887 | end |
||
888 | MCom.printStatus(reglist.textnum, value, nil, reglist.textshow); |
||
889 | end |
||
890 | else |
||
891 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
892 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
893 | reglist.noupdate(reglist.varnum); |
||
894 | end |
||
895 | end |
||
896 | end |
||
897 | --If there is a function to run on any update, then run it |
||
898 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
899 | reglist.anyupdate(reglist.varnum); |
||
900 | end |
||
901 | end; |
||
902 | elseif ( ( ( (regtype == MCOM_STRINGT) and reglist.hasbool ) ) and reglist.varbool and reglist.varstring ) then |
||
903 | reglist.func = function (checked, value) |
||
904 | if (MCom.updateVar(reglist.varbool, checked, MCOM_BOOLT)) then |
||
905 | --If there is a function to run on an update, call it |
||
906 | if (reglist.update and (type(reglist.update) == "function")) then |
||
907 | reglist.update(reglist.varbool); |
||
908 | end |
||
909 | |||
910 | if (reglist.textbool) then |
||
911 | --Print output to let the player know the command succeeded, if there is no UI |
||
912 | MCom.printStatus(reglist.textbool, MCom.getStringVar(reglist.varbool), true, reglist.textshow); |
||
913 | end |
||
914 | else |
||
915 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
916 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
917 | reglist.noupdate(reglist.varbool); |
||
918 | end |
||
919 | end |
||
920 | --If there is a function to run on any update, then run it |
||
921 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
922 | reglist.anyupdate(reglist.varbool); |
||
923 | end |
||
924 | |||
925 | --If no value was passed, then don't set it |
||
926 | if (value) then |
||
927 | if (MCom.updateVar(reglist.varstring, value, MCOM_STRINGT)) then |
||
928 | --If there is a function to run on an update, call it |
||
929 | if (reglist.update and (type(reglist.update) == "function")) then |
||
930 | reglist.update(reglist.varstring); |
||
931 | end |
||
932 | |||
933 | if (reglist.textstring) then |
||
934 | --Print output to let the player know the command succeeded, if there is no UI |
||
935 | MCom.printStatus(reglist.textstring, MCom.getStringVar(reglist.varstring), nil, reglist.textshow); |
||
936 | end |
||
937 | else |
||
938 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
939 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
940 | reglist.noupdate(reglist.varstring); |
||
941 | end |
||
942 | end |
||
943 | end |
||
944 | --If there is a function to run on any update, then run it |
||
945 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
946 | reglist.anyupdate(reglist.varstring); |
||
947 | end |
||
948 | end; |
||
949 | elseif ( ( ( (regtype == MCOM_CHOICET) and reglist.hasbool ) ) and reglist.varbool and reglist.varchoice ) then |
||
950 | reglist.func = function (checked, value, name) |
||
951 | if (MCom.updateVar(reglist.varbool, checked, MCOM_BOOLT)) then |
||
952 | --If there is a function to run on an update, call it |
||
953 | if (reglist.update and (type(reglist.update) == "function")) then |
||
954 | reglist.update(reglist.varbool); |
||
955 | end |
||
956 | |||
957 | if (reglist.textbool) then |
||
958 | --Print output to let the player know the command succeeded, if there is no UI |
||
959 | MCom.printStatus(reglist.textbool, MCom.getStringVar(reglist.varbool), true, reglist.textshow); |
||
960 | end |
||
961 | else |
||
962 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
963 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
964 | reglist.noupdate(reglist.varbool); |
||
965 | end |
||
966 | end |
||
967 | --If there is a function to run on any update, then run it |
||
968 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
969 | reglist.anyupdate(reglist.varbool); |
||
970 | end |
||
971 | |||
972 | --If no value was passed, then don't set it |
||
973 | if (value) then |
||
974 | if (MCom.updateVar(reglist.varchoice, value, MCOM_CHOICET)) then |
||
975 | --If there is a function to run on an update, call it |
||
976 | if (reglist.update and (type(reglist.update) == "function")) then |
||
977 | reglist.update(reglist.varchoice); |
||
978 | end |
||
979 | |||
980 | if (reglist.textchoice) then |
||
981 | --Print output to let the player know the command succeeded, if there is no UI |
||
982 | MCom.printStatus(reglist.textchoice, name, nil, reglist.textshow); |
||
983 | end |
||
984 | else |
||
985 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
986 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
987 | reglist.noupdate(reglist.varchoice); |
||
988 | end |
||
989 | end |
||
990 | end |
||
991 | --If there is a function to run on any update, then run it |
||
992 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
993 | reglist.anyupdate(reglist.varchoice); |
||
994 | end |
||
995 | end; |
||
996 | elseif ( ( ( (regtype == MCOM_COLORT) and reglist.hasbool ) ) and reglist.varbool and reglist.varcolor ) then |
||
997 | reglist.func = function (checked, value) |
||
998 | if (MCom.updateVar(reglist.varbool, checked, MCOM_BOOLT)) then |
||
999 | --If there is a function to run on an update, call it |
||
1000 | if (reglist.update and (type(reglist.update) == "function")) then |
||
1001 | reglist.update(reglist.varbool); |
||
1002 | end |
||
1003 | |||
1004 | if (reglist.textbool) then |
||
1005 | --Print output to let the player know the command succeeded, if there is no UI |
||
1006 | MCom.printStatus(reglist.textbool, MCom.getStringVar(reglist.varbool), true, reglist.textshow); |
||
1007 | end |
||
1008 | else |
||
1009 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
1010 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
1011 | reglist.noupdate(reglist.varbool); |
||
1012 | end |
||
1013 | end |
||
1014 | --If there is a function to run on any update, then run it |
||
1015 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
1016 | reglist.anyupdate(reglist.varbool); |
||
1017 | end |
||
1018 | |||
1019 | --If no value was passed, then don't set it |
||
1020 | if (value) then |
||
1021 | if (MCom.updateVar(reglist.varcolor, value, MCOM_COLORT)) then |
||
1022 | --If there is a function to run on an update, call it |
||
1023 | if (reglist.update and (type(reglist.update) == "function")) then |
||
1024 | reglist.update(reglist.varcolor); |
||
1025 | end |
||
1026 | |||
1027 | if (reglist.textcolor) then |
||
1028 | --Build a color string |
||
1029 | local curColor = MCom.getStringVar(reglist.varstring); |
||
1030 | local curColString = ""; |
||
1031 | if ( type(curColor) == "table" ) then |
||
1032 | if (curColor.r) then |
||
1033 | curColString = string.format(MCOM_CHAT_COM_K_R, MCom.math.round(curColor.r * 100)); |
||
1034 | end |
||
1035 | if (curColor.g) then |
||
1036 | if ( curColString ~= "" ) then |
||
1037 | curColString = curColString..", "; |
||
1038 | end |
||
1039 | curColString = curColString..string.format(MCOM_CHAT_COM_K_G, MCom.math.round(curColor.g * 100)); |
||
1040 | end |
||
1041 | if (curColor.b) then |
||
1042 | if ( curColString ~= "" ) then |
||
1043 | curColString = curColString..", "; |
||
1044 | end |
||
1045 | curColString = curColString..string.format(MCOM_CHAT_COM_K_B, MCom.math.round(curColor.b * 100)); |
||
1046 | end |
||
1047 | if (reglist.hasopacity) then |
||
1048 | local displayOpacity = 1; |
||
1049 | if (curColor.opacity) then |
||
1050 | displayOpacity = curColor.opacity; |
||
1051 | end |
||
1052 | if ( curColString ~= "" ) then |
||
1053 | curColString = curColString..", "; |
||
1054 | end |
||
1055 | curColString = curColString..string.format(MCOM_CHAT_COM_K_O, MCom.math.round(displayOpacity * 100)); |
||
1056 | end |
||
1057 | end |
||
1058 | --Print output to let the player know the command succeeded, if there is no UI |
||
1059 | MCom.printStatus(reglist.textcolor, curColString, nil, reglist.textshow); |
||
1060 | end |
||
1061 | else |
||
1062 | --If there is a function to run on an attempted update, that resulted in no change, then run it |
||
1063 | if (reglist.noupdate and (type(reglist.noupdate) == "function")) then |
||
1064 | reglist.noupdate(reglist.varcolor); |
||
1065 | end |
||
1066 | end |
||
1067 | end |
||
1068 | --If there is a function to run on any update, then run it |
||
1069 | if (reglist.anyupdate and (type(reglist.anyupdate) == "function")) then |
||
1070 | reglist.anyupdate(reglist.varcolor); |
||
1071 | end |
||
1072 | end; |
||
1073 | end |
||
1074 | end |
||
1075 | end |
||
1076 | |||
1077 | --If uifolder was not passed, see if there is a compatable uicat for it |
||
1078 | if (not reglist.uifolder) then |
||
1079 | if (reglist.uicat == MYADDONS_CATEGORY_BARS) then |
||
1080 | reglist.uifolder = "bars"; |
||
1081 | elseif (reglist.uicat == MYADDONS_CATEGORY_CHAT) then |
||
1082 | reglist.uifolder = "chat"; |
||
1083 | elseif (reglist.uicat == MYADDONS_CATEGORY_COMBAT) then |
||
1084 | reglist.uifolder = "combat"; |
||
1085 | elseif (reglist.uicat == MYADDONS_CATEGORY_INVENTORY) then |
||
1086 | reglist.uifolder = "inventory"; |
||
1087 | elseif (reglist.uicat == MYADDONS_CATEGORY_QUESTS) then |
||
1088 | reglist.uifolder = "quest"; |
||
1089 | end |
||
1090 | end |
||
1091 | |||
1092 | if (reglist.uitype == "SECTION") then |
||
1093 | --If a Cosmos section has been passed, then we need to store it's data so that |
||
1094 | --when we are ready to register an option, we can then create the option set |
||
1095 | --based on the section data |
||
1096 | MCom.uifolder = reglist.uifolder; |
||
1097 | MCom.uisec = reglist.uisec; |
||
1098 | MCom.uisecabel = reglist.uiseclabel; |
||
1099 | MCom.uisecdesc = reglist.uisecdesc; |
||
1100 | MCom.uisecdiff = reglist.uisecdiff; |
||
1101 | MCom.uiseccall = reglist.uiseccall; |
||
1102 | MCom.uisecdef = reglist.uisecdef; |
||
1103 | MCom.uiseccom = reglist.uiseccom; |
||
1104 | if (not reglist.uisec) then |
||
1105 | reglist.uisec = reglist.uivar; |
||
1106 | MCom.uisec = reglist.uivar; |
||
1107 | end |
||
1108 | if (not reglist.uiseclabel) then |
||
1109 | MCom.uiseclabel = reglist.uilabel; |
||
1110 | end |
||
1111 | if (not reglist.uisecdesc) then |
||
1112 | MCom.uisecdesc = reglist.uidesc; |
||
1113 | end |
||
1114 | end |
||
1115 | |||
1116 | --If no set was passed, then use the previously stored one |
||
1117 | if (not reglist.uisec) then |
||
1118 | reglist.uisec = MCom.uisec; |
||
1119 | end |
||
1120 | |||
1121 | --If the previously stored set exists, and is the same as the one passed, then pull |
||
1122 | --the data from it |
||
1123 | if ( MCom.uisec and (MCom.uisec == reglist.uisec) ) then |
||
1124 | if (not reglist.uiseclabel) then |
||
1125 | reglist.uiseclabel = MCom.uiseclabel; |
||
1126 | end |
||
1127 | if (not reglist.uisecdesc) then |
||
1128 | reglist.uisecdesc = MCom.uisecdesc; |
||
1129 | end |
||
1130 | if (not reglist.uisecdiff) then |
||
1131 | reglist.uisecdiff = MCom.uisecdiff; |
||
1132 | end |
||
1133 | if (not reglist.uiseccall) then |
||
1134 | reglist.uiseccall = MCom.uiseccall; |
||
1135 | end |
||
1136 | if (not reglist.uisecdef) then |
||
1137 | reglist.uisecdef = MCom.uisecdef; |
||
1138 | end |
||
1139 | if (not reglist.uiseccom) then |
||
1140 | reglist.uiseccom = MCom.uiseccom; |
||
1141 | end |
||
1142 | end |
||
1143 | |||
1144 | --Setup stored set with current data |
||
1145 | MCom.uisec = reglist.uisec; |
||
1146 | MCom.uiseclabel = reglist.uiseclabel; |
||
1147 | MCom.uisecdesc = reglist.uisecdesc; |
||
1148 | MCom.uisecdiff = reglist.uisecdiff; |
||
1149 | MCom.uiseccall = reglist.uiseccall; |
||
1150 | MCom.uisecdef = reglist.uisecdef; |
||
1151 | MCom.uiseccom = reglist.uiseccom; |
||
1152 | |||
1153 | --If MyAddOns is loaded, then try to register with it |
||
1154 | if ( myAddOnsList and (MCom.uisec or MCom.uiseclabel or reglist.addonname) ) then |
||
1155 | --Figure out an entry, label, and description |
||
1156 | local addonEntry = MCom.uisec; |
||
1157 | if (not addonEntry) then |
||
1158 | addonEntry = reglist.addonname; |
||
1159 | end |
||
1160 | if (not addonEntry) then |
||
1161 | addonEntry = MCom.uilabel; |
||
1162 | end |
||
1163 | local addonName = reglist.addonname; |
||
1164 | if (not addonName) then |
||
1165 | addonName = addonEntry; |
||
1166 | end |
||
1167 | if (not addonName) then |
||
1168 | addonName = reglist.uiseclabel; |
||
1169 | end |
||
1170 | if ( (not myAddOnsFrame_Register) and MCom.uiseclabel ) then |
||
1171 | addonName = MCom.uiseclabel; |
||
1172 | end |
||
1173 | local addonDesc = reglist.uisecdesc; |
||
1174 | if (not addonDesc) then |
||
1175 | addonDesc = addonName; |
||
1176 | end |
||
1177 | if (not MCom.MyAddOnsList) then |
||
1178 | MCom.MyAddOnsList = {}; |
||
1179 | end |
||
1180 | |||
1181 | --Default the addon list to an internal one that MCom keeps, until loading is done |
||
1182 | local addonList = MCom.MyAddOnsList; |
||
1183 | --If we have finished loading MyAddOns, then go ahead and use its list |
||
1184 | if (MCom.MyAddOnsLoaded) then |
||
1185 | addonList = myAddOnsList; |
||
1186 | elseif (not MCom.MyAddonsHooked) then |
||
1187 | --If variables haven't loaded yet, then store the registered addons in a temporary list |
||
1188 | --that will will use to add to the real list once variables have loaded |
||
1189 | MCom.MyAddonsHooked = true; |
||
1190 | --Hook the MyAddOns event function so we know when variables have loaded |
||
1191 | MCom.util.hook("myAddOnsFrame_OnEvent", "MCom.myAddOnsFrame_OnEvent", "after"); |
||
1192 | end |
||
1193 | |||
1194 | --Only add this to the list if it isn't already there |
||
1195 | if ( not addonList[addonEntry] ) then |
||
1196 | --If category wasn't passed see if a compatable folder was passed |
||
1197 | if (not reglist.uicat) then |
||
1198 | if (reglist.uifolder == "bars") then |
||
1199 | reglist.uicat = MYADDONS_CATEGORY_BARS; |
||
1200 | elseif (reglist.uifolder == "chat") then |
||
1201 | reglist.uicat = MYADDONS_CATEGORY_CHAT; |
||
1202 | elseif (reglist.uifolder == "combat") then |
||
1203 | reglist.uicat = MYADDONS_CATEGORY_COMBAT; |
||
1204 | elseif (reglist.uifolder == "inventory") then |
||
1205 | reglist.uicat = MYADDONS_CATEGORY_INVENTORY; |
||
1206 | elseif (reglist.uifolder == "quest") then |
||
1207 | reglist.uicat = MYADDONS_CATEGORY_QUESTS; |
||
1208 | else |
||
1209 | reglist.uicat = MYADDONS_CATEGORY_OTHERS; |
||
1210 | end |
||
1211 | end |
||
1212 | |||
1213 | --If no options frame was passed, and this is a Cosmos or Khaos registration, then set |
||
1214 | --the options frame to be the Khaos or Cosmos options frame |
||
1215 | if (not reglist.uioptionsframe) then |
||
1216 | if (Khaos and reglist.uivar and reglist.uitype and reglist.uilabel) then |
||
1217 | reglist.uioptionsframe = "KhaosFrame"; |
||
1218 | elseif (CosmosMaster_Init and reglist.uivar and reglist.uitype and reglist.uilabel ) then |
||
1219 | reglist.uioptionsframe = "CosmosMasterFrame"; |
||
1220 | end |
||
1221 | end |
||
1222 | --If an options frame was passed, and it isn't in the UIPanel's list, then add it |
||
1223 | if (reglist.uioptionsframe and ( not UIPanelWindows[reglist.uioptionsframe] ) ) then |
||
1224 | UIPanelWindows[reglist.uioptionsframe] = {area = "center", pushable = 0}; |
||
1225 | end |
||
1226 | --If uihelp wasn't passed, use infotext |
||
1227 | if (not reglist.uihelp) then |
||
1228 | reglist.uihelp = reglist.infotext; |
||
1229 | end |
||
1230 | --Make usre uihelp is a table or boolean |
||
1231 | if (reglist.uihelp and (type(reglist.uihelp) ~= "table") and (type(reglist.uihelp) ~= "boolean") ) then |
||
1232 | reglist.uihelp = { reglist.uihelp }; |
||
1233 | end |
||
1234 | --Add the addon to the list |
||
1235 | addonList[addonEntry] = { |
||
1236 | details = { |
||
1237 | name = addonName; |
||
1238 | description = addonDesc; |
||
1239 | version = reglist.uiver; |
||
1240 | releaseDate = reglist.uidate, |
||
1241 | author = reglist.uiauthor, |
||
1242 | email = reglist.uimail, |
||
1243 | website = reglist.uiwww, |
||
1244 | category = reglist.uicat; |
||
1245 | frame = reglist.uiframe; |
||
1246 | optionsframe = reglist.uioptionsframe; |
||
1247 | }; |
||
1248 | help = reglist.uihelp; |
||
1249 | supercom = reglist.supercom; |
||
1250 | }; |
||
1251 | end |
||
1252 | end |
||
1253 | |||
1254 | --If the variable name is not prefixed with COS_ and cosmos is the UI then put it on there |
||
1255 | if ( reglist.uivar and CosmosMaster_Init and (not Khaos) ) then |
||
1256 | if ( (string.len(reglist.uivar) < 4) or (string.sub(reglist.uivar, 1, 4) ~= "COS_") ) then |
||
1257 | reglist.uivar = "COS_"..reglist.uivar; |
||
1258 | end |
||
1259 | end |
||
1260 | |||
1261 | if (Khaos and reglist.uivar and reglist.uitype and reglist.uilabel) then |
||
1262 | --If we have Khaos and the data needed to register with it, then try to work that out |
||
1263 | if (reglist.uitype ~= "SECTION") then |
||
1264 | --Only work with valid Khaos types |
||
1265 | if ( (reglist.uitype == K_HEADER) or (reglist.uitype == K_TEXT) or (reglist.uitype == K_CHECKBOX) or |
||
1266 | (reglist.uitype == K_BUTTON) or (reglist.uitype == K_SLIDER) or (reglist.uitype == K_EDITBOX) or |
||
1267 | (reglist.uitype == K_PULLDOWN) or (reglist.uitype == K_COLORPICKER) ) then |
||
1268 | --We have now go through the proccess of preparing a Khaos option, then we will register it |
||
1269 | --If a folder has been passed then store it for use now, and for future registers |
||
1270 | if (reglist.uifolder) then |
||
1271 | MCom.uifolder = reglist.uifolder; |
||
1272 | end |
||
1273 | --If a separator has been passed then store it for use now, and for future registers |
||
1274 | if (reglist.uisep) then |
||
1275 | MCom.uisep = reglist.uisep; |
||
1276 | end |
||
1277 | if (reglist.uitype == K_HEADER) then |
||
1278 | MCom.uisep = reglist.uivar; |
||
1279 | end |
||
1280 | |||
1281 | --If we don't have a uifunc yet, then wrap the func |
||
1282 | if ( (not reglist.uifunc) and reglist.func ) then |
||
1283 | --Wrap it for Khaos |
||
1284 | reglist.uifunc = function (state, keypressed) MCom.SetFromKUI(reglist.uivar, state, keypressed, reglist.choices); end; |
||
1285 | --Add the function to the list of callback functions |
||
1286 | if (reglist.uitype) then |
||
1287 | --Only do this for UI elements that have options |
||
1288 | if ((reglist.uitype == K_SLIDER) or (reglist.uitype == K_PULLDOWN) or (reglist.uitype == K_EDITBOX) or (reglist.uitype == K_COLORPICKER) or (reglist.uitype == K_BUTTON) or ( (reglist.uitype == K_TEXT) and (reglist.hasbool) ) ) then |
||
1289 | --If there is no function list yet, then make it |
||
1290 | if (not MCom.UIFuncList) then |
||
1291 | MCom.UIFuncList = {}; |
||
1292 | end |
||
1293 | --If this function is not yet in the list, then make it |
||
1294 | if (not MCom.UIFuncList[reglist.uivar]) then |
||
1295 | MCom.UIFuncList[reglist.uivar] = {}; |
||
1296 | end |
||
1297 | MCom.UIFuncList[reglist.uivar].func = reglist.func; |
||
1298 | MCom.UIFuncList[reglist.uivar].uitype = reglist.uitype; |
||
1299 | MCom.UIFuncList[reglist.uivar].hasbool = reglist.hasbool; |
||
1300 | end |
||
1301 | end |
||
1302 | end |
||
1303 | |||
1304 | --Make our option structure |
||
1305 | local kOption = {}; |
||
1306 | --If uioption is a Khaos style option, use it as our option structure |
||
1307 | if (isKhaosOption) then |
||
1308 | kOption = reglist.uioption; |
||
1309 | end |
||
1310 | |||
1311 | --Setup the varying parts of the option with MCom data |
||
1312 | kOption.id = reglist.uivar; |
||
1313 | kOption.key = reglist.uikey; |
||
1314 | kOption.value = reglist.uivalue; |
||
1315 | kOption.text = reglist.uilabel; |
||
1316 | kOption.difficulty = reglist.uidiff; |
||
1317 | kOption.helptext = reglist.uidesc; |
||
1318 | kOption.callback = reglist.uifunc; |
||
1319 | if ( reglist.hasbool == nil ) then |
||
1320 | if ( (regtype == MCOM_BOOLT) or (regtype == MCOM_MULTIT) ) then |
||
1321 | reglist.hasbool = true; |
||
1322 | end |
||
1323 | end |
||
1324 | kOption.check = reglist.hasbool; |
||
1325 | kOption.radio = reglist.uiradio; |
||
1326 | kOption.type = reglist.uitype; |
||
1327 | --Setup the setup structure |
||
1328 | if ( type(reglist.uisetup) == "table" ) then |
||
1329 | kOption.setup = reglist.uisetup; |
||
1330 | else |
||
1331 | kOption.setup = {}; |
||
1332 | end |
||
1333 | if (reglist.uitype == K_BUTTON) then |
||
1334 | kOption.setup.buttonText = reglist.uitext; |
||
1335 | end |
||
1336 | |||
1337 | --Setup the slider |
||
1338 | if (reglist.uitype == K_SLIDER) then |
||
1339 | kOption.setup.sliderMin = reglist.uimin; |
||
1340 | kOption.setup.sliderMax = reglist.uimax; |
||
1341 | kOption.setup.sliderStep = reglist.uistep; |
||
1342 | --If no slider display func has been passed, then make a generic one, that behaves the same |
||
1343 | --as the one in Cosmos |
||
1344 | kOption.setup.sliderLowText = reglist.uisliderlow; |
||
1345 | kOption.setup.sliderHighText = reglist.uisliderhigh; |
||
1346 | kOption.setup.sliderText = reglist.text; |
||
1347 | if (not reglist.uisuffix) then |
||
1348 | reglist.uisuffix = ""; |
||
1349 | end |
||
1350 | sliderDisplayFunc = reglist.uisliderfunc; |
||
1351 | if (sliderDisplayFunc == nil) then |
||
1352 | kOption.setup.sliderDisplayFunc = function ( value ) return ( MCom.math.round( ( value * reglist.uimul ) * 100 ) / 100 )..reglist.uisuffix; end; |
||
1353 | end |
||
1354 | end |
||
1355 | kOption.setup.options = reglist.choices; |
||
1356 | kOption.setup.multiSelect = reglist.multichoice; |
||
1357 | kOption.setup.hasOpacity = reglist.hasopacity; |
||
1358 | kOption.setup.callOn = reglist.uicallon; |
||
1359 | |||
1360 | kOption.feedback = reglist.uifeedback; |
||
1361 | --If no feedback has been passed, then make a generic feedback function |
||
1362 | if (not kOption.feedback) then |
||
1363 | if ( reglist.uitype ~= K_HEADER and reglist.uitype ~= K_BUTTON ) then |
||
1364 | kOption.feedback = function(state) |
||
1365 | local retString; --The string to return |
||
1366 | --If it is has a check or radio then set the return string up for that |
||
1367 | if (kOption.check ) then |
||
1368 | if ( state.checked ) then |
||
1369 | retString = string.format(MCOM_FEEDBACK_CHECK, kOption.text, MCOM_CHAT_ENABLED); |
||
1370 | else |
||
1371 | retString = string.format(MCOM_FEEDBACK_CHECK, kOption.text, MCOM_CHAT_DISABLED); |
||
1372 | end |
||
1373 | elseif (kOption.radio ) then |
||
1374 | if ( state.value ) then |
||
1375 | retString = string.format(MCOM_FEEDBACK_RADIO, kOption.text, state.value); |
||
1376 | end |
||
1377 | end |
||
1378 | --If it has a slider then set the string up for that |
||
1379 | if (reglist.uitype == K_SLIDER) then |
||
1380 | if ( state.slider ) then |
||
1381 | if (not retString) then |
||
1382 | retString = string.format(MCOM_FEEDBACK_SLIDER, kOption.text, kOption.setup.sliderDisplayFunc(state.slider) ); |
||
1383 | else |
||
1384 | --If we also have a check or radio, then use a version that displays both that, and this |
||
1385 | retString = string.format(MCOM_FEEDBACK_SLIDER_M, retString, kOption.setup.sliderDisplayFunc(state.slider) ); |
||
1386 | end |
||
1387 | end |
||
1388 | end |
||
1389 | if (reglist.uitype == K_EDITBOX) then |
||
1390 | if ( state.value ) then |
||
1391 | if (not retString) then |
||
1392 | retString = string.format(MCOM_FEEDBACK_EDITBOX, kOption.text, state.value); |
||
1393 | else |
||
1394 | --If we also have a check or radio, then use a version that displays both that, and this |
||
1395 | retString = string.format(MCOM_FEEDBACK_EDITBOX_M, retString, state.value); |
||
1396 | end |
||
1397 | end |
||
1398 | end |
||
1399 | if (reglist.uitype == K_COLORPICKER) then |
||
1400 | if ( state.color ) then |
||
1401 | if (not retString) then |
||
1402 | retString = string.format(MCOM_FEEDBACK_COLOR, MCom.string.colorToString(state.color), kOption.text); |
||
1403 | else |
||
1404 | --If we also have a check or radio, then use a version that displays both that, and this |
||
1405 | retString = string.format(MCOM_FEEDBACK_COLOR_M, MCom.string.colorToString(state.color), retString); |
||
1406 | end |
||
1407 | end |
||
1408 | end |
||
1409 | if (reglist.uitype == K_CHOICE) then |
||
1410 | if ( state.value ) then |
||
1411 | --Create a text list of options |
||
1412 | local options; |
||
1413 | if ( type(state.value) == "table" ) then |
||
1414 | for curOption = 1, table.getn(state.value) do |
||
1415 | if (options) then |
||
1416 | options = options..", "..state.value[curOption]; |
||
1417 | else |
||
1418 | options = state.value[curOption]; |
||
1419 | end |
||
1420 | end |
||
1421 | else |
||
1422 | options = state.value; |
||
1423 | end |
||
1424 | if (not retString) then |
||
1425 | retString = string.format(MCOM_FEEDBACK_CHOICE, kOption.text, options); |
||
1426 | else |
||
1427 | --If we also have a check or radio, then use a version that displays both that, and this |
||
1428 | retString = string.format(MCOM_FEEDBACK_CHOICE_M, retString, options); |
||
1429 | end |
||
1430 | end |
||
1431 | end |
||
1432 | return retString; |
||
1433 | end |
||
1434 | end |
||
1435 | end |
||
1436 | |||
1437 | --Convert the default check state to Khaos style |
||
1438 | if ( reglist.uicheck and ( (reglist.uicheck == 1) or (reglist.uicheck == true) ) ) then |
||
1439 | reglist.uicheck = true; |
||
1440 | else |
||
1441 | reglist.uicheck = false; |
||
1442 | end |
||
1443 | --Convert the disabled check to Khaos format |
||
1444 | if ( reglist.uidischeck and ( (reglist.uidischeck == 1) or (reglist.uidischeck == true) ) ) then |
||
1445 | reglist.uidischeck = true; |
||
1446 | elseif (reglist.uidischeck == 0) then |
||
1447 | reglist.uidischeck = false; |
||
1448 | end |
||
1449 | |||
1450 | --Setup the default structure |
||
1451 | kOption.default = {}; |
||
1452 | if (reglist.hasbool) then |
||
1453 | kOption.default.checked = reglist.uicheck; |
||
1454 | end |
||
1455 | if (reglist.uitype == K_SLIDER) then |
||
1456 | kOption.default.slider = reglist.uislider; |
||
1457 | if (kOption.default.slider == nil) then |
||
1458 | kOption.default.slider = reglist.uimax; |
||
1459 | end |
||
1460 | if (kOption.default.slider == nil) then |
||
1461 | kOption.default.slider = reglist.uimin; |
||
1462 | end |
||
1463 | if (kOption.default.slider == nil) then |
||
1464 | kOption.default.slider = 1; |
||
1465 | end |
||
1466 | end |
||
1467 | if (reglist.uitype == K_COLORPICKER) then |
||
1468 | kOption.default.color = reglist.uicolor; |
||
1469 | end |
||
1470 | if ( (reglist.uitype == K_PULLDOWN) ) then |
||
1471 | kOption.default.value = reglist.uichoice; |
||
1472 | end |
||
1473 | if ( (reglist.uitype == K_EDITBOX) ) then |
||
1474 | kOption.default.value = reglist.uistring; |
||
1475 | end |
||
1476 | |||
1477 | --Setup the disabled structure |
||
1478 | --fallback to default, if disabled is not passed |
||
1479 | kOption.disabled = {}; |
||
1480 | if (reglist.hasbool) then |
||
1481 | kOption.disabled.checked = reglist.uidischeck; |
||
1482 | if (kOption.disabled.checked == nil) then |
||
1483 | kOption.disabled.checked = reglist.uicheck; |
||
1484 | end |
||
1485 | end |
||
1486 | if (reglist.uitype == K_SLIDER) then |
||
1487 | kOption.disabled.slider = reglist.uidisslider; |
||
1488 | if (kOption.disabled.slider == nil) then |
||
1489 | kOption.disabled.slider = reglist.uislider; |
||
1490 | end |
||
1491 | if (kOption.disabled.slider == nil) then |
||
1492 | kOption.disabled.slider = reglist.uimax; |
||
1493 | end |
||
1494 | if (kOption.disabled.slider == nil) then |
||
1495 | kOption.disabled.slider = reglist.uimin; |
||
1496 | end |
||
1497 | if (kOption.disabled.slider == nil) then |
||
1498 | kOption.disabled.slider = 1; |
||
1499 | end |
||
1500 | end |
||
1501 | if (reglist.uitype == K_COLORPICKER) then |
||
1502 | kOption.disabled.color = reglist.uidiscolor; |
||
1503 | if (kOption.disabled.color == nil) then |
||
1504 | kOption.disabled.color = reglist.uicolor; |
||
1505 | end |
||
1506 | end |
||
1507 | if ( (reglist.uitype == K_PULLDOWN) ) then |
||
1508 | kOption.disabled.value = reglist.uidisstring; |
||
1509 | if (kOption.disabled.value == nil) then |
||
1510 | kOption.disabled.value = reglist.uistring; |
||
1511 | end |
||
1512 | end |
||
1513 | if ( (reglist.uitype == K_EDITBOX) ) then |
||
1514 | kOption.disabled.value = reglist.uidischoice; |
||
1515 | if (kOption.disabled.value == nil) then |
||
1516 | kOption.disabled.value = reglist.uichoice; |
||
1517 | end |
||
1518 | end |
||
1519 | --Setup the option dependencies |
||
1520 | kOption.dependencies = reglist.uidep; |
||
1521 | |||
1522 | --Pull the option set from Khaos |
||
1523 | local optionSet = KhaosData.configurationSets[MCom.uisec]; |
||
1524 | --Will be set to true if we need to register this set(as in, it has not yet been registered) |
||
1525 | local needsReg = false; |
||
1526 | --If the set didn't yet exist, then create it |
||
1527 | if (not optionSet) then |
||
1528 | needsReg = true; --New set, so we need to register it |
||
1529 | optionSet = { id = reglist.uisec; |
||
1530 | text = reglist.uiseclabel; |
||
1531 | helptext = reglist.uisecdesc; |
||
1532 | difficulty = reglist.uisecdiff; |
||
1533 | callback = reglist.uiseccall; |
||
1534 | default = reglist.uisecdef; |
||
1535 | commands = reglist.uiseccom }; |
||
1536 | end |
||
1537 | |||
1538 | --If there is no option structure in this set yet, then make one |
||
1539 | if (not optionSet.options) then |
||
1540 | optionSet.options = {}; |
||
1541 | end |
||
1542 | |||
1543 | --Check that this option does not already exist |
||
1544 | local alreadyExists = false; |
||
1545 | for curOpt = 1, table.getn(optionSet.options) do |
||
1546 | if (optionSet.options[curOpt].id == reglist.uivar) then |
||
1547 | alreadyExists = true; |
||
1548 | break; |
||
1549 | end |
||
1550 | end |
||
1551 | |||
1552 | --Only proceed further if the option doesn't already exist |
||
1553 | if (not alreadyExists) then |
||
1554 | --Default the option insertion position to the end of the option list |
||
1555 | local optionPos = table.getn(optionSet.options); |
||
1556 | |||
1557 | --If we have a header specified, then try to find the last position after it |
||
1558 | --and if it doesn't exist yet.. then make it |
||
1559 | if (MCom.uisep) then |
||
1560 | local foundHeader = false; --Set true if we find the header |
||
1561 | --Try to find the header |
||
1562 | for curOpt = 1, table.getn(optionSet.options) do |
||
1563 | --If we have found the header, and we have made it to the next header |
||
1564 | --then break here, to put the option just before this header |
||
1565 | if (foundHeader) then |
||
1566 | if (optionSet.options[curOpt].type == K_HEADER) then |
||
1567 | break; |
||
1568 | end |
||
1569 | end |
||
1570 | --If we found the header, set foundHeader |
||
1571 | if (optionSet.options[curOpt].id == MCom.uisep) then |
||
1572 | foundHeader = true; |
||
1573 | end |
||
1574 | --Set the current option position to this postition |
||
1575 | optionPos = curOpt; |
||
1576 | end |
||
1577 | --If we didn't find the passed header, then make it, at the last spot in the list |
||
1578 | if (not foundHeader) then |
||
1579 | --Make sure a header was passed |
||
1580 | if (reglist.uisep) then |
||
1581 | --If no label was passed for the header, use the header variable name |
||
1582 | if (not reglist.uiseplabel) then |
||
1583 | reglist.uiseplabel = reglist.uisep; |
||
1584 | end |
||
1585 | --If no description was passed for the header, use the header label |
||
1586 | if (not reglist.uisepdesc) then |
||
1587 | reglist.uisepdesc = reglist.uiseplabel; |
||
1588 | end |
||
1589 | --Make the header option structure |
||
1590 | local hOption = { id = reglist.uisep; |
||
1591 | text = reglist.uiseplabel; |
||
1592 | helptext = reglist.uisepdesc; |
||
1593 | type = K_HEADER; |
||
1594 | difficulty = reglist.uisepdiff; }; |
||
1595 | --Itterate the option position up one |
||
1596 | optionPos = optionPos + 1; |
||
1597 | --Shove the header in the last slot in the list |
||
1598 | table.insert(optionSet.options, optionPos, hOption); |
||
1599 | else |
||
1600 | --If we didn't find the header, and there wasn't one passed... then clean out the |
||
1601 | --stored header |
||
1602 | MCom.uisep = nil; |
||
1603 | end |
||
1604 | end |
||
1605 | end |
||
1606 | |||
1607 | --Shove the option into the next spot in the table |
||
1608 | table.insert(optionSet.options, optionPos + 1, kOption); |
||
1609 | |||
1610 | if (needsReg) then |
||
1611 | --If the option set hasn't been registered yet.. then register it |
||
1612 | Khaos.registerOptionSet(MCom.uifolder, optionSet); |
||
1613 | else |
||
1614 | --If the option set has been registered, then we need to validate it, to make sure it's kuhl |
||
1615 | Khaos.validateOptionSet(optionSet); |
||
1616 | end |
||
1617 | end |
||
1618 | end |
||
1619 | end |
||
1620 | elseif (CosmosMaster_Init and reglist.uivar and reglist.uitype and reglist.uilabel ) then |
||
1621 | --Only register valid Cosmos types |
||
1622 | if ( (reglist.uitype == "SECTION") or (reglist.uitype == "SEPARATOR") or (reglist.uitype == "BUTTON") or |
||
1623 | (reglist.uitype == "CHECKBOX") or (reglist.uitype == "SLIDER") or (reglist.uitype == "BOTH") ) then |
||
1624 | --If we don't have Khaos, but do have Cosmos, then register for Cosmos |
||
1625 | --If the section has been passed, then register it |
||
1626 | if (reglist.uisec) then |
||
1627 | --If the section variable name is not prefixed with COS_ then put it on there |
||
1628 | if ( (string.len(reglist.uisec) < 4) or (string.sub(reglist.uisec, 1, 4) ~= "COS_") ) then |
||
1629 | reglist.uisec = "COS_"..reglist.uisec; |
||
1630 | end |
||
1631 | --Register the section |
||
1632 | Cosmos_RegisterConfiguration(reglist.uisec, "SECTION", reglist.uiseclabel, reglist.uisecdesc); |
||
1633 | end |
||
1634 | --If the separator has been passed, then register it |
||
1635 | if (reglist.uisep) then |
||
1636 | --If the separator variable name is not prefixed with COS_ then put it on there |
||
1637 | if ( (string.len(reglist.uisep) < 4) or (string.sub(reglist.uisep, 1, 4) ~= "COS_") ) then |
||
1638 | reglist.uisep = "COS_"..reglist.uisep; |
||
1639 | end |
||
1640 | --If no label is passed for the separator, then use the variable name |
||
1641 | if (not reglist.uiseplabel) then |
||
1642 | reglist.uiseplabel = reglist.uisep; |
||
1643 | end |
||
1644 | --If no description is passed for the separator, then use the label |
||
1645 | if (not reglist.uisepdesc) then |
||
1646 | reglist.uisepdesc = reglist.uiseplabel; |
||
1647 | end |
||
1648 | --Register the seperator |
||
1649 | Cosmos_RegisterConfiguration(reglist.uisep, "SEPARATOR", reglist.uiseplabel, reglist.uisepdesc); |
||
1650 | end |
||
1651 | |||
1652 | --If we don't have a uifunc yet, then wrap the func |
||
1653 | if ( (not reglist.uifunc) and reglist.func ) then |
||
1654 | reglist.uifunc = function (checked, value) MCom.SetFromUI(reglist.uivar, checked, value); end; |
||
1655 | |||
1656 | --Add the function to the list of callback functions |
||
1657 | if (reglist.uitype) then |
||
1658 | --Only do this for UI elements that have options |
||
1659 | if ((reglist.uitype == "CHECKBOX") or (reglist.uitype == "SLIDER") or (reglist.uitype == "BOTH") or (reglist.uitype == "BUTTON")) then |
||
1660 | if (not MCom.UIFuncList) then |
||
1661 | MCom.UIFuncList = {}; |
||
1662 | end |
||
1663 | if (not MCom.UIFuncList[reglist.uivar]) then |
||
1664 | MCom.UIFuncList[reglist.uivar] = {}; |
||
1665 | end |
||
1666 | MCom.UIFuncList[reglist.uivar].func = reglist.func; |
||
1667 | MCom.UIFuncList[reglist.uivar].uitype = reglist.uitype; |
||
1668 | MCom.UIFuncList[reglist.uivar].hasbool = reglist.hasbool; |
||
1669 | end |
||
1670 | end |
||
1671 | end |
||
1672 | |||
1673 | --Convert the default check state to Cosmos style |
||
1674 | if ( reglist.uicheck and ( (reglist.uicheck == 1) or (reglist.uicheck == true) ) ) then |
||
1675 | reglist.uicheck = 1; |
||
1676 | else |
||
1677 | reglist.uicheck = 0; |
||
1678 | end |
||
1679 | |||
1680 | --Register with Cosmos if available |
||
1681 | Cosmos_RegisterConfiguration(reglist.uivar, reglist.uitype, reglist.uilabel, reglist.uidesc, |
||
1682 | reglist.uifunc, reglist.uicheck, reglist.uislider, reglist.uimin, reglist.uimax, reglist.uitext, |
||
1683 | reglist.uistep, reglist.uitexton, reglist.uisuffix, reglist.uimul |
||
1684 | ); |
||
1685 | end |
||
1686 | end |
||
1687 | |||
1688 | --If we have enough data to register a slash command, then do it |
||
1689 | --We need to make sure to pass the right ordered var data to the function |
||
1690 | local comVar = reglist.varbool; |
||
1691 | local comVarMulti = reglist.varnum; |
||
1692 | if (regtype == MCOM_STRINGT) then |
||
1693 | comVarMulti = reglist.varstring; |
||
1694 | elseif (regtype == MCOM_CHOICET) then |
||
1695 | comVarMulti = reglist.varchoice; |
||
1696 | elseif (regtype == MCOM_COLORT) then |
||
1697 | comVarMulti = reglist.varcolor; |
||
1698 | end |
||
1699 | if (not comVar) then |
||
1700 | comVar = comVarMulti; |
||
1701 | comVarMulti = nil; |
||
1702 | end |
||
1703 | if (reglist.command and reglist.func) then |
||
1704 | --If no command help was passed, but a ui description was, then use the ui description |
||
1705 | if ( ( not reglist.bomhelp ) and ( reglist.uidesc ) ) then |
||
1706 | reglist.bomhelp = reglist.uidesc; |
||
1707 | end |
||
1708 | MCom.addSlashCom(reglist.command, reglist.func, reglist.comaction, reglist.comsticky, reglist.comhelp, regtype, reglist.uisec, reglist.uivar, comVar, comVarMulti, reglist.varmin, reglist.varmax, reglist.commul, reglist.cominmul, reglist.hasbool, reglist.choices, reglist.multichoice, reglist.hasopacity, reglist.extrahelp); |
||
1709 | end |
||
1710 | --If we have enough data to register a super slash command, then do it |
||
1711 | if (reglist.supercom) then |
||
1712 | MCom.addSlashSuperCom(reglist.supercom, reglist.comaction, reglist.comsticky, reglist.comhelp, reglist.extrahelp); |
||
1713 | end |
||
1714 | --If we have enough data to register a sub slash command, then do it |
||
1715 | if (reglist.supercom and reglist.subcom and reglist.func) then |
||
1716 | --If no sub command help was passed, but a ui description was, then use the ui description |
||
1717 | if ( ( not reglist.subhelp ) and ( reglist.uidesc ) ) then |
||
1718 | reglist.subhelp = reglist.uidesc; |
||
1719 | end |
||
1720 | MCom.addSlashSubCom(reglist.supercom, reglist.subcom, reglist.func, reglist.subhelp, regtype, reglist.uisec, reglist.uivar, comVar, comVarMulti, reglist.varmin, reglist.varmax, reglist.commul, reglist.cominmul, reglist.hasbool, reglist.choices, reglist.multichoice, reglist.hasopacity); |
||
1721 | end |
||
1722 | |||
1723 | --If we should be adding an info option, then handle this now |
||
1724 | if (reglist.infotext) then |
||
1725 | --Setup a function to display addon information, if data is available for it |
||
1726 | local infofunc = nil; |
||
1727 | if (reglist.infotext) then |
||
1728 | --If reglist.infotext isn't already a table, then turn it into one |
||
1729 | if (type(reglist.infotext) ~= "table") then |
||
1730 | reglist.infotext = { reglist.infotext }; |
||
1731 | end |
||
1732 | --Setup a default info title if we dont have one |
||
1733 | local curInfoTitle = reglist.infotitle; |
||
1734 | if (not curInfoTitle) then |
||
1735 | curInfoTitle = MCOM_HELP_GENERIC_TITLE; |
||
1736 | if (reglist.name) then |
||
1737 | curInfoTitle = string.format(MCOM_HELP_TITLE, reglist.name); |
||
1738 | end |
||
1739 | end |
||
1740 | |||
1741 | --If this is not a boolean, then add the slash command info to the end of the text as a new page |
||
1742 | if ( type(reglist.infotext) ~= "boolean" ) then |
||
1743 | infofunc = function () |
||
1744 | --Get the info text and title |
||
1745 | local infotext = MCom.table.copy(reglist.infotext); |
||
1746 | local infotitle = curInfoTitle; |
||
1747 | --If the text isn't a table turn it into one |
||
1748 | if (type(infotext) ~= "table" ) then |
||
1749 | infotext = { infotext }; |
||
1750 | end |
||
1751 | if (reglist.supercom) then |
||
1752 | --Add the slash command info on to it |
||
1753 | infotext[table.getn(infotext) + 1] = MCom.PrintSlashCommandInfo(MCom.getComID(reglist.supercom), true); |
||
1754 | end |
||
1755 | --Show the text frame |
||
1756 | MCom.textFrame( { text = infotext; title = infotitle; } ); |
||
1757 | end; |
||
1758 | elseif ( reglist.supercom ) then |
||
1759 | infofunc = function () |
||
1760 | --Set the text as the slash command info |
||
1761 | local infotext = MCom.PrintSlashCommandInfo(MCom.getComID(reglist.supercom), true); |
||
1762 | local infotitle = curInfoTitle; |
||
1763 | --Show the text frame |
||
1764 | MCom.textFrame( { text = infotext; title = infotitle; } ); |
||
1765 | end; |
||
1766 | end |
||
1767 | end |
||
1768 | |||
1769 | --If we have an info function, then add options to access it |
||
1770 | if (infofunc) then |
||
1771 | --Use the generic description |
||
1772 | local infoDesc = MCOM_HELP_GENERIC; |
||
1773 | --If a name has been passed for this mod, then use it in the description |
||
1774 | if (reglist.name) then |
||
1775 | infoDesc = string.format(MCOM_HELP_CONFIG_INFO, reglist.name); |
||
1776 | end |
||
1777 | --If we have Khaos or Cosmos then register with them |
||
1778 | if (Khaos or CosmosMaster_Init and reglist.name) then |
||
1779 | --Setup the difficulty of the help button |
||
1780 | local infodiff = reglist.uisecdiff; |
||
1781 | if (not infodiff) then |
||
1782 | infodiff = reglist.uidiff; |
||
1783 | end |
||
1784 | if (not infodiff) then |
||
1785 | infodiff = 1; |
||
1786 | end |
||
1787 | --Setup the name to display |
||
1788 | local infoName = string.format(MCOM_HELP_CONFIG, reglist.name); |
||
1789 | --Register the option |
||
1790 | MCom.registerSmart( { |
||
1791 | uivar = reglist.name.."MComInfo"; --The option name for the UI |
||
1792 | uitype = K_BUTTON; --The option type for the UI |
||
1793 | uilabel = infoName; --The label to use for the checkbox in the UI |
||
1794 | uidesc = infoDesc; --The description to use for the checkbox in the UI |
||
1795 | uidiff = infodiff; --The option's difficulty in Khaos |
||
1796 | uifunc = infofunc; --The function to call |
||
1797 | uitext = MCOM_HELP_GENERIC_TITLE; --The text to show on the button |
||
1798 | } ); |
||
1799 | end |
||
1800 | --Register the sub slash command |
||
1801 | if ( reglist.supercom ) then |
||
1802 | MCom.registerSmart( { |
||
1803 | supercom = reglist.supercom; |
||
1804 | subcom = MCOM_HELP_COMMAND; |
||
1805 | subhelp = infoDesc; |
||
1806 | comtype = MCOM_SIMPLET; |
||
1807 | func = infofunc; |
||
1808 | } ); |
||
1809 | end |
||
1810 | end |
||
1811 | end |
||
1812 | end |
||
1813 | end; |
||
1814 | |||
1815 | --[[ |
||
1816 | getStringVar ( string value ) |
||
1817 | Accepts a variable as a string, and returns the value. |
||
1818 | However this can parse complex variable names that contain . |
||
1819 | such as "Something.Variable" |
||
1820 | |||
1821 | It does not handle "Something['Variable']".. Just use the . |
||
1822 | format instead. This also works for number indexes. |
||
1823 | |||
1824 | Args: |
||
1825 | varString - the variable to get, encapsulated in a string, ex: |
||
1826 | "Something.Variable.Monkey.Hippo" |
||
1827 | |||
1828 | Returns: |
||
1829 | the contents of the variable in the passed string |
||
1830 | ]]-- |
||
1831 | MCom.getStringVar = function (varString) |
||
1832 | if (Sea and Sea.util and Sea.util.getValue) then |
||
1833 | return Sea.util.getValue(varString); |
||
1834 | else |
||
1835 | --Legorols get string var code, no GCs, and no need to store each entry |
||
1836 | if ( type(varString) ~= "string" ) then |
||
1837 | return nil; |
||
1838 | end; |
||
1839 | |||
1840 | -- Table we reuse with calls to split |
||
1841 | if ( not MCom.valueTable ) then |
||
1842 | MCom.valueTable = {}; |
||
1843 | end |
||
1844 | |||
1845 | -- Split the variable name at ".", first field is a global name |
||
1846 | local fields = MCom.util.split(varString, ".", MCom.valueTable); |
||
1847 | local encloser, member = getglobal(fields[1]), fields[2]; |
||
1848 | |||
1849 | -- If encloser is the only field, it's a global, return its value |
||
1850 | if ( not member ) then |
||
1851 | return encloser; |
||
1852 | end |
||
1853 | |||
1854 | -- If there are subsequent fields present, get to deeper levels |
||
1855 | for i = 3, table.getn(fields) do |
||
1856 | if ( type(encloser) ~= "table" ) then |
||
1857 | return nil; |
||
1858 | end |
||
1859 | encloser = encloser[member]; |
||
1860 | member = fields[i]; |
||
1861 | end |
||
1862 | |||
1863 | -- Encloser is now the last but one field, member is the last field |
||
1864 | if ( type(encloser) == "table" ) then |
||
1865 | return encloser[member]; |
||
1866 | end |
||
1867 | -- Error occured, encloser is not a table, return nil |
||
1868 | end |
||
1869 | end; |
||
1870 | --Alias for compatability |
||
1871 | MCom.stringToVar = MCom.getStringVar; |
||
1872 | |||
1873 | --[[ |
||
1874 | stringVarToGetFunc ( string varString ) |
||
1875 | Accepts a variable as a string, and returns a function that |
||
1876 | returns the value. |
||
1877 | However this can parse complex variable names that contain . |
||
1878 | such as "Something.Variable" |
||
1879 | |||
1880 | This is alot like getStringVar. However, getStringVar has to |
||
1881 | generate several objects that will need to be garbage |
||
1882 | collected. The function returned by stringVarToFunc does |
||
1883 | not generate any amount of GCs worth worying about. So if |
||
1884 | you are needing to do this very often, like OnUpdate, then |
||
1885 | it is best to use this function to convert to a function, |
||
1886 | and simply call that functin to get the data you need. |
||
1887 | |||
1888 | It does not handle "Something['Variable']".. Just use the . |
||
1889 | format instead. This also works for number indexes. |
||
1890 | |||
1891 | Args: |
||
1892 | varString - the variable to get, encapsulated in a string, ex: |
||
1893 | "Something.Variable.Monkey.Hippo" |
||
1894 | |||
1895 | Returns: |
||
1896 | a function that when called will return the data in the passed variable |
||
1897 | ]]-- |
||
1898 | MCom.stringVarToGetFunc = function (varString) |
||
1899 | if ( type(varString) == "string" ) then |
||
1900 | --Seperate the variable by the .'s into a list |
||
1901 | local valList = MCom.util.split(varString, "."); |
||
1902 | --The function we will return |
||
1903 | local varFunc; |
||
1904 | |||
1905 | --Only proceed if we have a variable to work with |
||
1906 | if (valList and valList[1]) then |
||
1907 | --If it's a table make it a function that will parse the parts |
||
1908 | if (getn(valList) > 1) then |
||
1909 | --Create the function |
||
1910 | varFunc = function () |
||
1911 | --Get the global variable |
||
1912 | local value = getglobal(valList[1]); |
||
1913 | --Go through each entry in the table and get that variable |
||
1914 | for curPart = 2, getn(valList) do |
||
1915 | --Only get the variable if it is a table |
||
1916 | if ( ( type(value) == "table" ) and value[ valList[curPart] ] ) then |
||
1917 | --Get the variable |
||
1918 | value = value[ valList[curPart] ]; |
||
1919 | else |
||
1920 | --Something was invalid, return nil |
||
1921 | return; |
||
1922 | end |
||
1923 | end |
||
1924 | --We got the value, so return it |
||
1925 | return value; |
||
1926 | end; |
||
1927 | else |
||
1928 | --This is a simple variable, so just return the global |
||
1929 | varFunc = function () |
||
1930 | return getglobal(valList[1]); |
||
1931 | end; |
||
1932 | end |
||
1933 | end |
||
1934 | --Return the function |
||
1935 | return varFunc; |
||
1936 | end |
||
1937 | end; |
||
1938 | |||
1939 | --[[ |
||
1940 | setStringVar ( string varString, value ) |
||
1941 | Sets a variable, specified by a string, to a value. |
||
1942 | However this can parse complex variable names that contain . |
||
1943 | such as "Something.Variable" |
||
1944 | |||
1945 | It does not handle "Something['Variable']".. Just use the . |
||
1946 | format instead. This also works for number indexes. |
||
1947 | |||
1948 | Args: |
||
1949 | varString - the variable to set, encapsulated in a string, ex: |
||
1950 | "Something.Variable.Monkey.Hippo" |
||
1951 | value - the value to set the variable to, can be any type |
||
1952 | ]]-- |
||
1953 | MCom.setStringVar = function (varString, value) |
||
1954 | if (Sea and Sea.util and Sea.util.setValue) then |
||
1955 | return Sea.util.setValue(varString, value); |
||
1956 | else |
||
1957 | --Legorols set string var code, no GCs, and no need to store each entry |
||
1958 | if ( type(varString) ~= "string" ) then |
||
1959 | return false; |
||
1960 | end; |
||
1961 | |||
1962 | -- Table we reuse with calls to split |
||
1963 | if ( not MCom.valueTable ) then |
||
1964 | MCom.valueTable = {}; |
||
1965 | end |
||
1966 | |||
1967 | -- Split the variable name at ".", first field is a global name |
||
1968 | local fields = MCom.util.split(varString, ".", MCom.valueTable); |
||
1969 | local encloser, member = getglobal(fields[1]), fields[2]; |
||
1970 | |||
1971 | -- If encloser is the only field, variable is a global, set its value |
||
1972 | if ( not member ) then |
||
1973 | setglobal(varString, value); |
||
1974 | return true; |
||
1975 | end |
||
1976 | |||
1977 | -- If there are subsequent fields present, get to deeper levels |
||
1978 | for i = 3, table.getn(fields) do |
||
1979 | if ( type(encloser) ~= "table" ) then |
||
1980 | return false; |
||
1981 | end |
||
1982 | encloser = encloser[member]; |
||
1983 | member = fields[i]; |
||
1984 | end |
||
1985 | |||
1986 | -- Encloser is now the last but one field, member is the last field |
||
1987 | if ( type(encloser) == "table" ) then |
||
1988 | encloser[member] = value; |
||
1989 | return true; |
||
1990 | end |
||
1991 | |||
1992 | -- Error occured, encloser is not a table |
||
1993 | return false; |
||
1994 | end |
||
1995 | end; |
||
1996 | |||
1997 | --[[ |
||
1998 | stringVarToSetFunc ( string varString ) |
||
1999 | Returns a function that can be used to set the passed string |
||
2000 | to a value. However this can parse complex variable names |
||
2001 | that contain . such as "Something.Variable" |
||
2002 | |||
2003 | This is alot like setStringVar. However, setStringVar has to |
||
2004 | generate several objects that will need to be garbage |
||
2005 | collected. The function returned by stringVarToSetFunc does |
||
2006 | not generate any amount of GCs worth worying about. So if |
||
2007 | you are needing to do this very often, like OnUpdate, then |
||
2008 | it is best to use this function to convert to a function, |
||
2009 | and simply call that functin to set the data you need. |
||
2010 | |||
2011 | It does not handle "Something['Variable']".. Just use the . |
||
2012 | format instead. This also works for number indexes. |
||
2013 | |||
2014 | Args: |
||
2015 | varString - the variable to set, encapsulated in a string, ex: |
||
2016 | "Something.Variable.Monkey.Hippo" |
||
2017 | |||
2018 | Returns: |
||
2019 | function ( number value) - a function that when called will |
||
2020 | set the string passed here, to the value passed to the function. |
||
2021 | ]]-- |
||
2022 | MCom.stringVarToSetFunc = function (varString) |
||
2023 | if ( type(varString) == "string" ) then |
||
2024 | --Seperate the variable by the .'s into a list |
||
2025 | local valList = MCom.util.split(varString, "."); |
||
2026 | --The function we will return |
||
2027 | local varFunc; |
||
2028 | |||
2029 | --Only proceed if we have a variable to work with |
||
2030 | if (valList and valList[1]) then |
||
2031 | --If it's a table make it a function that will parse the parts |
||
2032 | if (getn(valList) > 1) then |
||
2033 | --Create the function |
||
2034 | varFunc = function (value) |
||
2035 | --Get the global variable |
||
2036 | local var = getglobal(valList[1]); |
||
2037 | --Go through each entry in the table and get that variable |
||
2038 | for curPart = 2, getn(valList) do |
||
2039 | --If we have reached the last entry in the list, then set it |
||
2040 | if ( curPart == getn(valList) ) then |
||
2041 | if ( type(var) == "table" ) then |
||
2042 | var[ valList[curPart] ] = value; |
||
2043 | else |
||
2044 | return; |
||
2045 | end |
||
2046 | else |
||
2047 | --Only get the variable if it is a table |
||
2048 | if ( ( type(var) == "table" ) and var[ valList[curPart] ] ) then |
||
2049 | --Get the variable |
||
2050 | var = var[ valList[curPart] ]; |
||
2051 | else |
||
2052 | --Something was invalid, return nil |
||
2053 | return; |
||
2054 | end |
||
2055 | end |
||
2056 | end |
||
2057 | end; |
||
2058 | else |
||
2059 | --This is a simple variable, so just return the global |
||
2060 | varFunc = function (value) |
||
2061 | setglobal(valList[1], value); |
||
2062 | end; |
||
2063 | end |
||
2064 | end |
||
2065 | --Return the function |
||
2066 | return varFunc; |
||
2067 | end |
||
2068 | end; |
||
2069 | |||
2070 | --[[ |
||
2071 | updateVar ( string varname, value [, string vartype, number varmin, number varmax] ) |
||
2072 | updates the variable contained in varname, to value. |
||
2073 | Handles things different based on the type of var varname is. |
||
2074 | If it should be a bool, then it only accepts 1 and 0, or -1 to invert the current setting. |
||
2075 | For number, it makes sure it is in the range varmin and varmax. |
||
2076 | |||
2077 | Args: |
||
2078 | varname - name of the variable to update, wrapped in a string, can be complex like "Something.Variable" |
||
2079 | value - what to set it to, should be 1, 0, or -1 for bool, any number for number type, or any string for string type |
||
2080 | |||
2081 | Optional: |
||
2082 | vartype - should be one of the MCOM_ types |
||
2083 | varmin - specifies the minimum value for a number type |
||
2084 | varmax - specifies the maximum value for a number type |
||
2085 | |||
2086 | Returns: |
||
2087 | if the value changed from its origional value, returns true |
||
2088 | ]]-- |
||
2089 | MCom.updateVar = function (varname, value, vartype, varmin, varmax) |
||
2090 | if (varname and value) then |
||
2091 | -- store the old value of the variable |
||
2092 | local oldValue = MCom.getStringVar(varname); |
||
2093 | |||
2094 | if (vartype == MCOM_BOOLT) then |
||
2095 | --If a -1 is passed, invert the value |
||
2096 | if (value and (value == -1)) then |
||
2097 | if (oldValue == 1) then |
||
2098 | value = 0; |
||
2099 | else |
||
2100 | value = 1; |
||
2101 | end |
||
2102 | end |
||
2103 | |||
2104 | --Update the value |
||
2105 | if (value and (value==1)) then |
||
2106 | value = 1; |
||
2107 | else |
||
2108 | value = 0; |
||
2109 | end |
||
2110 | elseif (vartype == MCOM_NUMT) then |
||
2111 | --if its a number and max/min were specified, make sure it's in range |
||
2112 | if (varmin and (value < varmin)) then |
||
2113 | value = varmin; |
||
2114 | end |
||
2115 | if (varmax and (value > varmax)) then |
||
2116 | value = varmax; |
||
2117 | end |
||
2118 | end |
||
2119 | |||
2120 | local didUpdate = false; |
||
2121 | if (vartype == MCOM_COLORT) then |
||
2122 | --If we don't have an old value, then make one |
||
2123 | if ( not oldValue ) then |
||
2124 | didUpdate = true; |
||
2125 | oldValue = {}; |
||
2126 | end |
||
2127 | --if its a color then make sure the color parts are in range |
||
2128 | if (value.r) then |
||
2129 | if (value.r > 1) then |
||
2130 | value.r = 1; |
||
2131 | end |
||
2132 | if (value.r < 0) then |
||
2133 | value.r = 0; |
||
2134 | end |
||
2135 | if (oldValue.r ~= value.r) then |
||
2136 | didUpdate = true; |
||
2137 | end |
||
2138 | else |
||
2139 | value.r = oldValue.r; |
||
2140 | end |
||
2141 | if (value.g) then |
||
2142 | if (value.g > 1) then |
||
2143 | value.g = 1; |
||
2144 | end |
||
2145 | if (value.g < 0) then |
||
2146 | value.g = 0; |
||
2147 | end |
||
2148 | if (oldValue.g ~= value.g) then |
||
2149 | didUpdate = true; |
||
2150 | end |
||
2151 | else |
||
2152 | value.g = oldValue.g; |
||
2153 | end |
||
2154 | if (value.b) then |
||
2155 | if (value.b > 1) then |
||
2156 | value.b = 1; |
||
2157 | end |
||
2158 | if (value.b < 0) then |
||
2159 | value.b = 0; |
||
2160 | end |
||
2161 | if (oldValue.b ~= value.b) then |
||
2162 | didUpdate = true; |
||
2163 | end |
||
2164 | else |
||
2165 | value.b = oldValue.b; |
||
2166 | end |
||
2167 | if (value.opacity) then |
||
2168 | if (value.opacity > 1) then |
||
2169 | value.opacity = 1; |
||
2170 | end |
||
2171 | if (value.opacity < 0) then |
||
2172 | value.opacity = 0; |
||
2173 | end |
||
2174 | if (oldValue.opacity ~= value.opacity) then |
||
2175 | didUpdate = true; |
||
2176 | end |
||
2177 | else |
||
2178 | value.opacity = oldValue.opacity; |
||
2179 | end |
||
2180 | else |
||
2181 | --if the value changed, return true |
||
2182 | if (value ~= oldValue) then |
||
2183 | didUpdate = true; |
||
2184 | end |
||
2185 | end |
||
2186 | |||
2187 | if (didUpdate) then |
||
2188 | MCom.setStringVar(varname, value); |
||
2189 | return true; |
||
2190 | end |
||
2191 | end |
||
2192 | end; |
||
2193 | |||
2194 | --[[ |
||
2195 | printStatus ( string text, [string/number/bool] value, bool isbool, bool show ) |
||
2196 | If Cosmos is not found printStatus will print out a status message, intended to let user know when an option has |
||
2197 | been changed, when there is no GUI available. |
||
2198 | |||
2199 | Args: |
||
2200 | text - the text to print, this can include a %s, and value(or enabled/disabled for bool) will be put in place of the %s |
||
2201 | Ex: "This option has been %s" for bool, or "This option has been set to %s" for number or string |
||
2202 | |||
2203 | Optional: |
||
2204 | value - what value to display, can be a string, a number, or a bool |
||
2205 | isbool - if this is true, then the value will be treated as a bool, and if true(or 1) then the %s will contain |
||
2206 | the world "Enabled" or "Disabled" for false(or 0) |
||
2207 | show - if this is true, then the text will be printed whether there is a UI or not |
||
2208 | ]]-- |
||
2209 | MCom.printStatus = function (text, value, isbool, show) |
||
2210 | if ( ( not MCom.hasUI() ) or show ) then |
||
2211 | --Convert to string |
||
2212 | if (type(value) == "number") then |
||
2213 | value = tostring(value); |
||
2214 | end |
||
2215 | --If it's boolean or nill convert to 1 or 0 |
||
2216 | if ((type(value) == "boolean") or (type(value) == "nil")) then |
||
2217 | if (value) then |
||
2218 | value = "1"; |
||
2219 | else |
||
2220 | value = "0"; |
||
2221 | end |
||
2222 | end |
||
2223 | if (type(value) == "string") then |
||
2224 | local outText = value; |
||
2225 | --If it's a bool convert to Enabled/Disabled |
||
2226 | if (isbool) then |
||
2227 | outText = MCOM_CHAT_DISABLED; |
||
2228 | if (value == "1") then |
||
2229 | outText = MCOM_CHAT_ENABLED; |
||
2230 | end |
||
2231 | end |
||
2232 | --Format and print the message |
||
2233 | local msg = string.format(text, outText); |
||
2234 | MCom.IO.printc(ChatTypeInfo["SYSTEM"], msg); |
||
2235 | end |
||
2236 | end |
||
2237 | end; |
||
2238 | |||
2239 | --[[ |
||
2240 | hasUI ( ) |
||
2241 | Tells whether or not a UI, like Cosmos or Khaos is present. |
||
2242 | |||
2243 | Returns: |
||
2244 | true - there is a UI |
||
2245 | false - there is no UI |
||
2246 | ]]-- |
||
2247 | MCom.hasUI = function (varString) |
||
2248 | local hasUI = true; |
||
2249 | if ( ( CosmosMaster_Init == nil ) and ( Khaos == nil ) ) then |
||
2250 | hasUI = false; |
||
2251 | end |
||
2252 | |||
2253 | return hasUI; |
||
2254 | end; |
||
2255 | |||
2256 | --[[ |
||
2257 | updateUI ( string slashcom, string subcom ) |
||
2258 | Updates the UI(Cosmos or Khaos) with the values of the variable associated with the slash command |
||
2259 | passed to the function. If this is done on a super slash command, then all sub commands |
||
2260 | will be updated, unless a specific on is specified. |
||
2261 | |||
2262 | Args: |
||
2263 | slashcom - The slash commmand, or super slash command to update the variable from. |
||
2264 | |||
2265 | Optional: |
||
2266 | subcom - If slashcom is a super slash command, you can use this to specify which slash |
||
2267 | command to update. |
||
2268 | ]]-- |
||
2269 | MCom.updateUI = function (slashcom, subcom) |
||
2270 | if (MCom.SlashComs) then |
||
2271 | --Get the command IDs |
||
2272 | local comid, subcomid = MCom.getComID(slashcom, subcom); |
||
2273 | if (comid) then |
||
2274 | --Get the command |
||
2275 | local command = MCom.SlashComs[comid]; |
||
2276 | --If we have a subcommand, then lets use it |
||
2277 | if (subcomid) then |
||
2278 | command = { command.commands[subcomid] }; |
||
2279 | elseif (command.commands) then |
||
2280 | command = command.commands; |
||
2281 | end |
||
2282 | |||
2283 | --If command isnt a table, then turn it into one |
||
2284 | if (type(command) ~= "table") then |
||
2285 | command = { command }; |
||
2286 | end |
||
2287 | local didUpdate = nil; |
||
2288 | if (KhaosData and KhaosData.configurationSets) then |
||
2289 | --If we have Khaos around, then lets update for it |
||
2290 | local curCom = nil; |
||
2291 | local newValMulti = nil; |
||
2292 | local newVal = nil; |
||
2293 | --Go trhough all commands and update them |
||
2294 | for curComID in command do |
||
2295 | --Grab the current command structure |
||
2296 | curCom = command[curComID]; |
||
2297 | if (curCom.uisec and KhaosData.configurationSets[curCom.uisec] and curCom.uivar and curCom.comvar) then |
||
2298 | --get the value of the variable |
||
2299 | newVal = MCom.getStringVar(curCom.comvar); |
||
2300 | if (newVal) then |
||
2301 | --Grab the second variable, if there is one |
||
2302 | newValMulti = MCom.getStringVar(curCom.comvarmulti); |
||
2303 | |||
2304 | --Deault param to change is value |
||
2305 | local param = "value"; |
||
2306 | --If it's a boolean, or we have a boolean as well.. then update the boolean part |
||
2307 | if ( (curCom.comtype == MCOM_BOOLT) or (curCom.comtype == MCOM_MULTIT) or curCom.hasbool) then |
||
2308 | --Make sure the value is in true/false form |
||
2309 | if (newVal == 1) then |
||
2310 | newVal = true; |
||
2311 | else |
||
2312 | newVal = false; |
||
2313 | end |
||
2314 | --Update the value |
||
2315 | Khaos.setSetKeyParameter(curCom.uisec, curCom.uivar, "checked", newVal); |
||
2316 | end |
||
2317 | --If it isn't a boolean type then proccess either the other types, or secondary part |
||
2318 | if ( curCom.comtype ~= MCOM_BOOLT ) then |
||
2319 | --If we have a second part variable, then use it now |
||
2320 | if (newValMulti) then |
||
2321 | newVal = newValMulti; |
||
2322 | end |
||
2323 | |||
2324 | --Handle number types as sliders |
||
2325 | if ( (curCom.comtype == MCOM_NUMT) or (curCom.comtype == MCOM_MULTIT) ) then |
||
2326 | param = "slider"; |
||
2327 | end |
||
2328 | |||
2329 | --Handle color types as color pickers |
||
2330 | if (curCom.comtype == MCOM_COLORT) then |
||
2331 | param = "color"; |
||
2332 | end |
||
2333 | |||
2334 | --Update the value |
||
2335 | Khaos.setSetKeyParameter(curCom.uisec, curCom.uivar, param, newVal); |
||
2336 | end |
||
2337 | didUpdate = true; |
||
2338 | end |
||
2339 | end |
||
2340 | end |
||
2341 | --If we updated something, then update the Khaos display |
||
2342 | if (didUpdate) then |
||
2343 | Khaos.refresh(); |
||
2344 | end |
||
2345 | else |
||
2346 | --We only need to update Cosmos if it exists |
||
2347 | if (CosmosMaster_Init) then |
||
2348 | local curCom = nil; |
||
2349 | local newValMulti = nil; |
||
2350 | local newVal = nil; |
||
2351 | --Go trhough all commands and update them |
||
2352 | for curComID in command do |
||
2353 | curCom = command[curComID]; |
||
2354 | if (curCom.uivar and curCom.comvar) then |
||
2355 | --get the value of the variable |
||
2356 | newVal = MCom.getStringVar(curCom.comvar); |
||
2357 | if (newVal) then |
||
2358 | newValMulti = MCom.getStringVar(curCom.comvarmulti); |
||
2359 | if ((curCom.comtype ~= MCOM_MULTIT) or ((curCom.comtype == MCOM_MULTIT) and newValMulti)) then |
||
2360 | --if its a boolean, then set the checkbox |
||
2361 | if ((curCom.comtype == MCOM_BOOLT) or (curCom.comtype == MCOM_MULTIT)) then |
||
2362 | Cosmos_UpdateValue(curCom.uivar, CSM_CHECKONOFF, newVal); |
||
2363 | didUpdate = true; |
||
2364 | end |
||
2365 | --if its a number, then set the slider |
||
2366 | if ((curCom.comtype == MCOM_NUMT) or (curCom.comtype == MCOM_MULTIT)) then |
||
2367 | if (curCom.comtype == MCOM_MULTIT) then |
||
2368 | newVal = newValMulti; |
||
2369 | end |
||
2370 | Cosmos_UpdateValue(curCom.uivar, CSM_SLIDERVALUE, newVal); |
||
2371 | didUpdate = true; |
||
2372 | end |
||
2373 | end |
||
2374 | end |
||
2375 | end |
||
2376 | end |
||
2377 | --If we updated something, then update the Cosmos display |
||
2378 | if (didUpdate) then |
||
2379 | CosmosMaster_DrawData(); |
||
2380 | end |
||
2381 | end |
||
2382 | end |
||
2383 | end |
||
2384 | end |
||
2385 | end; |
||
2386 | |||
2387 | |||
2388 | --[[ |
||
2389 | getComID ( [string/number] slashcom, string subcom ) |
||
2390 | Gets the ID of the slashcom in the slash commands list, as well as a |
||
2391 | sub slash command, if you specify that you want a sub commands ID. |
||
2392 | |||
2393 | Args: |
||
2394 | slashcom - The slash commmand, or super slash command to get the ID of. |
||
2395 | If you pass the ID itself, that ID will be used when getting |
||
2396 | the sub command. This can be a list of commands, instead of |
||
2397 | just one, in which case, it will return the first one in the |
||
2398 | list that it finds. Don't forget the / ex. "/command" |
||
2399 | Optional: |
||
2400 | slashcom - The sub command you want to get, if you want one. This can |
||
2401 | be a list instead of just one command, the first one found |
||
2402 | will be used. |
||
2403 | |||
2404 | Returns: |
||
2405 | commandid - If it finds the command, it returns the ID, otherwise it returns nil. |
||
2406 | subcommand - If it finds the subcommand it also returns that, otherwise, nil. |
||
2407 | ]]-- |
||
2408 | MCom.getComID = function (command, subcom) |
||
2409 | local commandid = nil; |
||
2410 | local subcommandid = nil; |
||
2411 | if (MCom.SlashComs) then |
||
2412 | --If the ID was passed, then use it |
||
2413 | if ((type(command) == "number") and MCom.SlashComs[command]) then |
||
2414 | commandid = command; |
||
2415 | else |
||
2416 | --make sure command is a table |
||
2417 | if (type(command) ~= "table") then |
||
2418 | command = {command}; |
||
2419 | end |
||
2420 | --find the command in the table |
||
2421 | for curCom in command do |
||
2422 | for curListCom in MCom.SlashComs do |
||
2423 | if (MCom.SlashComs[curListCom].basecommand) then |
||
2424 | for curBaseCom in MCom.SlashComs[curListCom].basecommand do |
||
2425 | if (MCom.SlashComs[curListCom].basecommand[curBaseCom] == command[curCom]) then |
||
2426 | commandid = curListCom; |
||
2427 | break; |
||
2428 | end |
||
2429 | end |
||
2430 | if (commandid) then |
||
2431 | break; |
||
2432 | end |
||
2433 | end |
||
2434 | end |
||
2435 | end |
||
2436 | end |
||
2437 | |||
2438 | if (commandid and subcom) then |
||
2439 | --make sure sub command is a table |
||
2440 | if (type(subcom) ~= "table") then |
||
2441 | subcom = {subcom}; |
||
2442 | end |
||
2443 | --Try and find the subcommand in the list |
||
2444 | for curSub in subcom do |
||
2445 | for curCom in MCom.SlashComs[commandid].commands do |
||
2446 | if (MCom.SlashComs[commandid].commands[curCom].command) then |
||
2447 | for curComCom in MCom.SlashComs[commandid].commands[curCom].command do |
||
2448 | if (MCom.SlashComs[commandid].commands[curCom].command[curComCom] == subcom[curSub]) then |
||
2449 | subcommandid = curCom; |
||
2450 | break; |
||
2451 | end |
||
2452 | end |
||
2453 | if (subcommandid) then |
||
2454 | break; |
||
2455 | end |
||
2456 | end |
||
2457 | end |
||
2458 | end |
||
2459 | end |
||
2460 | end |
||
2461 | return commandid, subcommandid; |
||
2462 | end; |
||
2463 | |||
2464 | --[[ |
||
2465 | saveConfig ( {reglist} ) |
||
2466 | This will store all of the variables you want into a per realm, per character table(MComStorage) inside the passed variable. |
||
2467 | This is meant to facilatate storing/loading variables on a per realm, per character basis. You must register the passed |
||
2468 | variable for saving, yourself. |
||
2469 | |||
2470 | Args: |
||
2471 | reglist - This contains all options for this save procedure |
||
2472 | { |
||
2473 | Required: |
||
2474 | (string) configVar - The name of the config variable, this should have been registered for save by you, and must be a table with a simple |
||
2475 | variable name. IE no .'s or []'s |
||
2476 | |||
2477 | Optional: |
||
2478 | (string) storeVar - The name of the variable to load/store the data in. If not passed then configVar.MComStorage is used. Remember to register |
||
2479 | it for saving. |
||
2480 | (string) exactVar - If you pass this, then data will be stored in this var, regardless of realm/character. It will go into this exact var. This |
||
2481 | takes precidence over storeVar. |
||
2482 | (string) realm - This allows you to specify the realm to store to, if not passed, then the current realm will be used. |
||
2483 | (string) character - This allows you to specify the character to store to, if not passed, then the current character will be used. |
||
2484 | NOTE: For all the following, this will only work on root level variables. I.E. Whatever_Config.Variable. For this you would pass "Variable" |
||
2485 | (string or table) saveList - The names of all variables in the config to be stored, if this is not passed, then MCom will try to store |
||
2486 | all variables except the MComStorage variable. |
||
2487 | (string or table) ignoreList - The names of any variables that you want MCom to not store. |
||
2488 | (string or table) uiList - These variables will only be stored if there is no UI available. Any options that you have the UI controlling |
||
2489 | should be included in here, so you can leave it up to the UI to properly load/save them. |
||
2490 | (string or table) nonUIList - If this list is declared, then uiList will be ignored, and all variables, except these, will be considered UI |
||
2491 | variables. |
||
2492 | (string or table) forceList - After going through the normal vars, MCom will go through and save these vars, even if they are nil. This list |
||
2493 | is affected by the rules set by the above lists as well. |
||
2494 | } |
||
2495 | |||
2496 | Returns: |
||
2497 | true - Some data was saved |
||
2498 | false - No data was saved |
||
2499 | ]]-- |
||
2500 | MCom.saveConfig = function ( reglist ) |
||
2501 | --We will set this true, if we saved any data |
||
2502 | local didSave = false; |
||
2503 | --Make sure we have the required info in the right form |
||
2504 | if ( reglist and ( type(reglist) == "table" ) and reglist.configVar ) then |
||
2505 | --Get the config variable table |
||
2506 | local varTable = MCom.getStringVar(reglist.configVar); |
||
2507 | --Only proceed if the config variable is a table |
||
2508 | if ( type(varTable) == "table" ) then |
||
2509 | --Get the realm and character name |
||
2510 | local realm = reglist.realm; |
||
2511 | if (not realm) then |
||
2512 | realm = GetCVar("RealmName"); |
||
2513 | end |
||
2514 | local character = reglist.character; |
||
2515 | if (not character) then |
||
2516 | character = UnitName("player") |
||
2517 | end |
||
2518 | |||
2519 | --Setup the variable to store data in. |
||
2520 | local storeVar = MCom.getStringVar(reglist.exactVar); |
||
2521 | --If we don't have an exactVar and we have the server and character name then generate the storeVar |
||
2522 | if ( (not storeVar) and realm and character and ( ( character ~= UKNOWNBEING ) and ( character ~= UNKNOWNOBJECT ) ) ) then |
||
2523 | --Get the storage var if one was passed |
||
2524 | storeVar = MCom.getStringVar(reglist.storeVar); |
||
2525 | if (not storeVar) then |
||
2526 | --If the MComStorage variable isn't there yet, or isn't a table, then set it as an empty table |
||
2527 | if (type(varTable.MComStorage) ~= "table") then |
||
2528 | varTable.MComStorage = {}; |
||
2529 | end |
||
2530 | storeVar = varTable.MComStorage; |
||
2531 | end |
||
2532 | |||
2533 | --If this realm doesn't exist, then create it |
||
2534 | if (not storeVar[realm]) then |
||
2535 | storeVar[realm] = {}; |
||
2536 | end |
||
2537 | --If this character doesn't exist, then create it |
||
2538 | if (not storeVar[realm][character]) then |
||
2539 | storeVar[realm][character] = {}; |
||
2540 | end |
||
2541 | --Set storeVar to use the current realm/char |
||
2542 | storeVar = storeVar[realm][character]; |
||
2543 | end |
||
2544 | |||
2545 | --If we have the variable to store to, then we are good to go |
||
2546 | if (storeVar) then |
||
2547 | --Go through all the variables in the table |
||
2548 | for curVar in varTable do |
||
2549 | --Ignore the MComStorage variable |
||
2550 | if (curVar ~= "MComStorage") then |
||
2551 | --This will become true if we shouldn't store this variable |
||
2552 | local doIgnore = false; |
||
2553 | |||
2554 | --If we have a list of vars to save, then go through them, and if this var is not in there, then ignore it |
||
2555 | if (reglist.saveList) then |
||
2556 | --Default to ignoring now |
||
2557 | doIgnore = true; |
||
2558 | --Make sure the saveList is a table |
||
2559 | if (type(reglist.saveList) ~= "table") then |
||
2560 | reglist.saveList = { reglist.saveList }; |
||
2561 | end |
||
2562 | --Go through the list and see if we find the variable, if we do, then we don't ignore it |
||
2563 | for i, curSaveCheck in reglist.saveList do |
||
2564 | if (curVar == curSaveCheck) then |
||
2565 | doIgnore = false; |
||
2566 | break; |
||
2567 | end |
||
2568 | end |
||
2569 | end |
||
2570 | |||
2571 | --If we are supposed to ignore this guy, then do so now |
||
2572 | if (not doIgnore) then |
||
2573 | --If we have a list of vars to ignore, then go through them, and if this var is in there, then ignore it |
||
2574 | if (reglist.ignoreList) then |
||
2575 | --Make sure the ignoreList is a table |
||
2576 | if (type(reglist.ignoreList) ~= "table") then |
||
2577 | reglist.ignoreList = { reglist.ignoreList }; |
||
2578 | end |
||
2579 | --Go through the list and see if we find the variable, if we do, then ignore it |
||
2580 | for i, curIgnoreCheck in reglist.ignoreList do |
||
2581 | if (curVar == curIgnoreCheck) then |
||
2582 | doIgnore = true; |
||
2583 | break; |
||
2584 | end |
||
2585 | end |
||
2586 | end |
||
2587 | |||
2588 | --If we are supposed to ignore this guy, then do so now |
||
2589 | if (not doIgnore) then |
||
2590 | if (reglist.nonUIList) then |
||
2591 | --Since these are UI vars, then we should only be ignoring them if the UI is around |
||
2592 | if ( MCom.hasUI() ) then |
||
2593 | --Unless we find this in the list, we should be ignoring it |
||
2594 | doIgnore = true; |
||
2595 | --Make sure the nonUIList is a table |
||
2596 | if (type(reglist.nonUIList) ~= "table") then |
||
2597 | nonUIList = { reglist.nonUIList }; |
||
2598 | end |
||
2599 | --Go through the list and see if we find the variable, if we do, then don't ignore it |
||
2600 | for i, curUICheck in reglist.nonUIList do |
||
2601 | if (curVar == curUICheck) then |
||
2602 | doIgnore = false; |
||
2603 | break; |
||
2604 | end |
||
2605 | end |
||
2606 | end |
||
2607 | else |
||
2608 | if (reglist.uiList) then |
||
2609 | --Since these are UI vars, then we should only be ignoring them if the UI is around |
||
2610 | if ( MCom.hasUI() ) then |
||
2611 | --Make sure the uiList is a table |
||
2612 | if (type(reglist.uiList) ~= "table") then |
||
2613 | uiList = { reglist.uiList }; |
||
2614 | end |
||
2615 | --Go through the list and see if we find the variable, if we do, then ignore it |
||
2616 | for i, curUICheck in reglist.uiList do |
||
2617 | if (curVar == curUICheck) then |
||
2618 | doIgnore = true; |
||
2619 | break; |
||
2620 | end |
||
2621 | end |
||
2622 | end |
||
2623 | end |
||
2624 | end |
||
2625 | |||
2626 | --If we are supposed to ignore this guy, then do so now |
||
2627 | if (not doIgnore) then |
||
2628 | --Store the variable |
||
2629 | storeVar[curVar] = varTable[curVar]; |
||
2630 | --Set that we saved data |
||
2631 | didSave = true; |
||
2632 | end |
||
2633 | end |
||
2634 | end |
||
2635 | end |
||
2636 | end |
||
2637 | |||
2638 | --If a forced list has been passed, then go through it |
||
2639 | if (reglist.forceList) then |
||
2640 | --Make sure it is a table |
||
2641 | if ( type(reglist.forceList) ~= "table" ) then |
||
2642 | reglist.forceList = { reglist.forceList }; |
||
2643 | end |
||
2644 | --Go through all the variables in the table |
||
2645 | for i, curVar in reglist.forceList do |
||
2646 | --Ignore the MComStorage variable |
||
2647 | if (curVar ~= "MComStorage") then |
||
2648 | --This will become true if we shouldn't store this variable |
||
2649 | local doIgnore = false; |
||
2650 | |||
2651 | --If we have a list of vars to save, then go through them, and if this var is not in there, then ignore it |
||
2652 | if (reglist.saveList) then |
||
2653 | --Default to ignoring now |
||
2654 | doIgnore = true; |
||
2655 | --Make sure the saveList is a table |
||
2656 | if (type(reglist.saveList) ~= "table") then |
||
2657 | reglist.saveList = { reglist.saveList }; |
||
2658 | end |
||
2659 | --Go through the list and see if we find the variable, if we do, then we don't ignore it |
||
2660 | for i, curSaveCheck in reglist.saveList do |
||
2661 | if (curVar == curSaveCheck) then |
||
2662 | doIgnore = false; |
||
2663 | break; |
||
2664 | end |
||
2665 | end |
||
2666 | end |
||
2667 | |||
2668 | --If we are supposed to ignore this guy, then do so now |
||
2669 | if (not doIgnore) then |
||
2670 | --If we have a list of vars to ignore, then go through them, and if this var is in there, then ignore it |
||
2671 | if (reglist.ignoreList) then |
||
2672 | --Make sure the ignoreList is a table |
||
2673 | if (type(reglist.ignoreList) ~= "table") then |
||
2674 | reglist.ignoreList = { reglist.ignoreList }; |
||
2675 | end |
||
2676 | --Go through the list and see if we find the variable, if we do, then ignore it |
||
2677 | for i, curIgnoreCheck in reglist.ignoreList do |
||
2678 | if (curVar == curIgnoreCheck) then |
||
2679 | doIgnore = true; |
||
2680 | break; |
||
2681 | end |
||
2682 | end |
||
2683 | end |
||
2684 | |||
2685 | --If we are supposed to ignore this guy, then do so now |
||
2686 | if (not doIgnore) then |
||
2687 | if (reglist.nonUIList) then |
||
2688 | --Since these are UI vars, then we should only be ignoring them if the UI is around |
||
2689 | if ( MCom.hasUI() ) then |
||
2690 | --Unless we find this in the list, we should be ignoring it |
||
2691 | doIgnore = true; |
||
2692 | --Make sure the nonUIList is a table |
||
2693 | if (type(reglist.nonUIList) ~= "table") then |
||
2694 | nonUIList = { reglist.nonUIList }; |
||
2695 | end |
||
2696 | --Go through the list and see if we find the variable, if we do, then don't ignore it |
||
2697 | for i, curUICheck in reglist.nonUIList do |
||
2698 | if (curVar == curUICheck) then |
||
2699 | doIgnore = false; |
||
2700 | break; |
||
2701 | end |
||
2702 | end |
||
2703 | end |
||
2704 | else |
||
2705 | if (reglist.uiList) then |
||
2706 | --Since these are UI vars, then we should only be ignoring them if the UI is around |
||
2707 | if ( MCom.hasUI() ) then |
||
2708 | --Make sure the uiList is a table |
||
2709 | if (type(reglist.uiList) ~= "table") then |
||
2710 | uiList = { reglist.uiList }; |
||
2711 | end |
||
2712 | --Go through the list and see if we find the variable, if we do, then ignore it |
||
2713 | for i, curUICheck in reglist.uiList do |
||
2714 | if (curVar == curUICheck) then |
||
2715 | doIgnore = true; |
||
2716 | break; |
||
2717 | end |
||
2718 | end |
||
2719 | end |
||
2720 | end |
||
2721 | end |
||
2722 | |||
2723 | --If we are supposed to ignore this guy, then do so now |
||
2724 | if (not doIgnore) then |
||
2725 | --Store the variable |
||
2726 | storeVar[curVar] = varTable[curVar]; |
||
2727 | --Set that we saved data |
||
2728 | didSave = true; |
||
2729 | end |
||
2730 | end |
||
2731 | end |
||
2732 | end |
||
2733 | end |
||
2734 | end |
||
2735 | end |
||
2736 | end |
||
2737 | end |
||
2738 | --Return if we saved data or not |
||
2739 | return didSave; |
||
2740 | end; |
||
2741 | |||
2742 | --[[ |
||
2743 | loadConfig ( {reglist} ) |
||
2744 | This will load all variables stored in the passed table in MComStorage. This only works on variables that have stored the data using |
||
2745 | MCom.saveConfig |
||
2746 | |||
2747 | Args: |
||
2748 | reglist - This contains all options for this load procedure |
||
2749 | { |
||
2750 | Required: |
||
2751 | (string) configVar - The name of the config variable, this should have been registered for save by you, and must be a table with a simple |
||
2752 | variable name. IE no .'s or []'s |
||
2753 | |||
2754 | Optional: |
||
2755 | (string) storeVar - The name of the variable to load/store the data in. If not passed then configVar.MComStorage is used. Remember to register |
||
2756 | it for saving. |
||
2757 | (string) exactVar - If you pass this, then data will be loaded from this var, regardless of realm/character. It will get from this exact var. This |
||
2758 | takes precidence over storeVar. |
||
2759 | (string) realm - This allows you to specify the realm to load from, if not passed, then the current realm will be used. |
||
2760 | (string) character - This allows you to specify the character to load from, if not passed, then the current character will be used. |
||
2761 | NOTE: For all the following, this will only work on root level variables. I.E. Whatever_Config.Variable. For this you would pass "Variable" |
||
2762 | (string or table) loadList - The names of all variables in the config to be loaded, if this is not passed, then MCom will try to load |
||
2763 | all variables except the MComStorage variable. |
||
2764 | (string or table) ignoreList - The names of any variables that you want MCom to not load. |
||
2765 | (string or table) uiList - These variables will only be loaded if there is no UI available. Any options that you have the UI controlling |
||
2766 | should be included in here, so you can leave it up to the UI to properly load/save them. |
||
2767 | (string or table) nonUIList - If this list is declared, then uiList will be ignored, and all variables, except these, will be considered UI |
||
2768 | variables. |
||
2769 | (string or table) forceList - After going through the normal vars, MCom will go through and load these vars, even if they are nil. |
||
2770 | is affected by the rules set by the above lists as well. |
||
2771 | } |
||
2772 | |||
2773 | Returns: |
||
2774 | true - Some data was loaded |
||
2775 | false - No data was loaded |
||
2776 | ]]-- |
||
2777 | MCom.loadConfig = function ( reglist ) |
||
2778 | --We will set this true, if we loaded any data |
||
2779 | local didLoad = false; |
||
2780 | --Make sure we have the required info in the right form |
||
2781 | if ( reglist and ( type(reglist) == "table" ) and reglist.configVar ) then |
||
2782 | --Get the config variable table |
||
2783 | local varTable = MCom.getStringVar(reglist.configVar); |
||
2784 | --Only proceed if the config variable is a table |
||
2785 | if ( type(varTable) == "table" ) then |
||
2786 | |||
2787 | |||
2788 | --Get the realm and character name |
||
2789 | local realm = reglist.realm; |
||
2790 | if (not realm) then |
||
2791 | realm = GetCVar("RealmName"); |
||
2792 | end |
||
2793 | local character = reglist.character; |
||
2794 | if (not character) then |
||
2795 | character = UnitName("player") |
||
2796 | end |
||
2797 | |||
2798 | --Setup the variable to load data from |
||
2799 | local storeVar = MCom.getStringVar(reglist.exactVar); |
||
2800 | --If we don't have an exactVar and we have the server and character name then generate the storeVar |
||
2801 | if ( (not storeVar) and realm and character and ( ( character ~= UKNOWNBEING ) and ( character ~= UNKNOWNOBJECT ) ) ) then |
||
2802 | --Get the storage var if one was passed |
||
2803 | storeVar = MCom.getStringVar(reglist.storeVar); |
||
2804 | if (not storeVar) then |
||
2805 | --If the MComStorage variable isn't there yet, or isn't a table, then set it as an empty table |
||
2806 | if (type(varTable.MComStorage) ~= "table") then |
||
2807 | varTable.MComStorage = {}; |
||
2808 | end |
||
2809 | storeVar = varTable.MComStorage; |
||
2810 | end |
||
2811 | |||
2812 | --If this realm doesn't exist, then create it |
||
2813 | if (not storeVar[realm]) then |
||
2814 | storeVar[realm] = {}; |
||
2815 | end |
||
2816 | --If this character doesn't exist, then create it |
||
2817 | if (not storeVar[realm][character]) then |
||
2818 | storeVar[realm][character] = {}; |
||
2819 | end |
||
2820 | --Set storeVar to use the current realm/char |
||
2821 | storeVar = storeVar[realm][character]; |
||
2822 | end |
||
2823 | |||
2824 | --If we have the variable to load from, then we are good to go |
||
2825 | if (storeVar) then |
||
2826 | --Go through all the variables in the table |
||
2827 | for curVar in storeVar do |
||
2828 | --This will become true if we shouldn't load this variable |
||
2829 | local doIgnore = false; |
||
2830 | |||
2831 | --If we have a list of vars to load, then go through them, and if this var is not in there, then ignore it |
||
2832 | if (reglist.loadList) then |
||
2833 | --Default to ignoring now |
||
2834 | doIgnore = true; |
||
2835 | --Make sure the loadList is a table |
||
2836 | if (type(reglist.loadList) ~= "table") then |
||
2837 | reglist.loadList = { reglist.loadList }; |
||
2838 | end |
||
2839 | --Go through the list and see if we find the variable, if we do, then we don't ignore it |
||
2840 | for i, curLoadCheck in reglist.loadList do |
||
2841 | if (curVar == curLoadCheck) then |
||
2842 | doIgnore = false; |
||
2843 | break; |
||
2844 | end |
||
2845 | end |
||
2846 | end |
||
2847 | |||
2848 | --If we are supposed to ignore this guy, then do so now |
||
2849 | if (not doIgnore) then |
||
2850 | --If we have a list of vars to ignore, then go through them, and if this var is in there, then ignore it |
||
2851 | if (reglist.ignoreList) then |
||
2852 | --Make sure the ignoreList is a table |
||
2853 | if (type(reglist.ignoreList) ~= "table") then |
||
2854 | reglist.ignoreList = { reglist.ignoreList }; |
||
2855 | end |
||
2856 | --Go through the list and see if we find the variable, if we do, then ignore it |
||
2857 | for i, curIgnoreCheck in reglist.ignoreList do |
||
2858 | if (curVar == curIgnoreCheck) then |
||
2859 | doIgnore = true; |
||
2860 | break; |
||
2861 | end |
||
2862 | end |
||
2863 | end |
||
2864 | |||
2865 | --If we are supposed to ignore this guy, then do so now |
||
2866 | if (not doIgnore) then |
||
2867 | if (reglist.nonUIList) then |
||
2868 | --Since these are UI vars, then we should only be ignoring them if the UI is around |
||
2869 | if ( MCom.hasUI() ) then |
||
2870 | --Unless we find this in the list, we should be ignoring it |
||
2871 | doIgnore = true; |
||
2872 | --Make sure the nonUIList is a table |
||
2873 | if (type(reglist.nonUIList) ~= "table") then |
||
2874 | nonUIList = { reglist.nonUIList }; |
||
2875 | end |
||
2876 | --Go through the list and see if we find the variable, if we do, then don't ignore it |
||
2877 | for i, curUICheck in reglist.nonUIList do |
||
2878 | if (curVar == curUICheck) then |
||
2879 | doIgnore = false; |
||
2880 | break; |
||
2881 | end |
||
2882 | end |
||
2883 | end |
||
2884 | else |
||
2885 | if (reglist.uiList) then |
||
2886 | --Since these are UI vars, then we should only be ignoring them if the UI is around |
||
2887 | if ( MCom.hasUI() ) then |
||
2888 | --Make sure the uiList is a table |
||
2889 | if (type(reglist.uiList) ~= "table") then |
||
2890 | uiList = { reglist.uiList }; |
||
2891 | end |
||
2892 | --Go through the list and see if we find the variable, if we do, then ignore it |
||
2893 | for i, curUICheck in reglist.uiList do |
||
2894 | if (curVar == curUICheck) then |
||
2895 | doIgnore = true; |
||
2896 | break; |
||
2897 | end |
||
2898 | end |
||
2899 | end |
||
2900 | end |
||
2901 | end |
||
2902 | |||
2903 | --If we are supposed to ignore this guy, then do so now |
||
2904 | if (not doIgnore) then |
||
2905 | --Load the variable |
||
2906 | varTable[curVar] = storeVar[curVar]; |
||
2907 | --Set that we loaded data |
||
2908 | didLoad = true; |
||
2909 | end |
||
2910 | end |
||
2911 | end |
||
2912 | end |
||
2913 | |||
2914 | --If a forced list has been passed, then go through it |
||
2915 | if (reglist.forceList) then |
||
2916 | --Make sure it is a table |
||
2917 | if ( type(reglist.forceList) ~= "table" ) then |
||
2918 | reglist.forceList = { reglist.forceList }; |
||
2919 | end |
||
2920 | --Go through all the variables in the table |
||
2921 | for i, curVar in reglist.forceList do |
||
2922 | --This will become true if we shouldn't load this variable |
||
2923 | local doIgnore = false; |
||
2924 | |||
2925 | --If we have a list of vars to load, then go through them, and if this var is not in there, then ignore it |
||
2926 | if (reglist.loadList) then |
||
2927 | --Default to ignoring now |
||
2928 | doIgnore = true; |
||
2929 | --Make sure the loadList is a table |
||
2930 | if (type(reglist.loadList) ~= "table") then |
||
2931 | reglist.loadList = { reglist.loadList }; |
||
2932 | end |
||
2933 | --Go through the list and see if we find the variable, if we do, then we don't ignore it |
||
2934 | for i, curLoadCheck in reglist.loadList do |
||
2935 | if (curVar == curLoadCheck) then |
||
2936 | doIgnore = false; |
||
2937 | break; |
||
2938 | end |
||
2939 | end |
||
2940 | end |
||
2941 | |||
2942 | --If we are supposed to ignore this guy, then do so now |
||
2943 | if (not doIgnore) then |
||
2944 | --If we have a list of vars to ignore, then go through them, and if this var is in there, then ignore it |
||
2945 | if (reglist.ignoreList) then |
||
2946 | --Make sure the ignoreList is a table |
||
2947 | if (type(reglist.ignoreList) ~= "table") then |
||
2948 | reglist.ignoreList = { reglist.ignoreList }; |
||
2949 | end |
||
2950 | --Go through the list and see if we find the variable, if we do, then ignore it |
||
2951 | for i, curIgnoreCheck in reglist.ignoreList do |
||
2952 | if (curVar == curIgnoreCheck) then |
||
2953 | doIgnore = true; |
||
2954 | break; |
||
2955 | end |
||
2956 | end |
||
2957 | end |
||
2958 | |||
2959 | --If we are supposed to ignore this guy, then do so now |
||
2960 | if (not doIgnore) then |
||
2961 | if (reglist.nonUIList) then |
||
2962 | --Since these are UI vars, then we should only be ignoring them if the UI is around |
||
2963 | if ( MCom.hasUI() ) then |
||
2964 | --Unless we find this in the list, we should be ignoring it |
||
2965 | doIgnore = true; |
||
2966 | --Make sure the nonUIList is a table |
||
2967 | if (type(reglist.nonUIList) ~= "table") then |
||
2968 | nonUIList = { reglist.nonUIList }; |
||
2969 | end |
||
2970 | --Go through the list and see if we find the variable, if we do, then don't ignore it |
||
2971 | for i, curUICheck in reglist.nonUIList do |
||
2972 | if (curVar == curUICheck) then |
||
2973 | doIgnore = false; |
||
2974 | break; |
||
2975 | end |
||
2976 | end |
||
2977 | end |
||
2978 | else |
||
2979 | if (reglist.uiList) then |
||
2980 | --Since these are UI vars, then we should only be ignoring them if the UI is around |
||
2981 | if ( MCom.hasUI() ) then |
||
2982 | --Make sure the uiList is a table |
||
2983 | if (type(reglist.uiList) ~= "table") then |
||
2984 | uiList = { reglist.uiList }; |
||
2985 | end |
||
2986 | --Go through the list and see if we find the variable, if we do, then ignore it |
||
2987 | for i, curUICheck in reglist.uiList do |
||
2988 | if (curVar == curUICheck) then |
||
2989 | doIgnore = true; |
||
2990 | break; |
||
2991 | end |
||
2992 | end |
||
2993 | end |
||
2994 | end |
||
2995 | end |
||
2996 | |||
2997 | --If we are supposed to ignore this guy, then do so now |
||
2998 | if (not doIgnore) then |
||
2999 | --Load the variable |
||
3000 | varTable[curVar] = storeVar[curVar]; |
||
3001 | --Set that we loaded data |
||
3002 | didLoad = true; |
||
3003 | end |
||
3004 | end |
||
3005 | end |
||
3006 | end |
||
3007 | end |
||
3008 | end |
||
3009 | end |
||
3010 | end |
||
3011 | --Return if we loaded data or not |
||
3012 | return didLoad; |
||
3013 | end; |
||
3014 | |||
3015 | --[[ |
||
3016 | safeLoad ( configVar ) |
||
3017 | Used to ensure that when variables are loaded into a table based variable, that none of the defaults |
||
3018 | are niled out. |
||
3019 | Call this after you have setup the defaults for your table, but before VARIABLES_LOADED occurs. |
||
3020 | When the variables are loaded, anything that is missing will be filled in with the defaults. |
||
3021 | |||
3022 | Args: |
||
3023 | Required: |
||
3024 | (string) configVar - The name of the config variable, this should have been registered for save by you, and must be a table with a simple |
||
3025 | variable name. IE no .'s or []'s |
||
3026 | ]]-- |
||
3027 | MCom.safeLoad = function ( configVar ) |
||
3028 | if (not MCom.didVarsLoaded) then |
||
3029 | --Get the actual config table |
||
3030 | local varTable = MCom.getStringVar(configVar); |
||
3031 | if ( type(varTable) == "table" ) then |
||
3032 | --If we don't have a table of safe loads yet, then make one |
||
3033 | if (not MCom.safeLoads) then |
||
3034 | MCom.safeLoads = {}; |
||
3035 | end |
||
3036 | if (not MCom.safeLoads.addonLoaded) then |
||
3037 | MCom.safeLoads.addonLoaded = {}; |
||
3038 | end |
||
3039 | if (not MCom.safeLoads.varsLoaded) then |
||
3040 | MCom.safeLoads.varsLoaded = {}; |
||
3041 | end |
||
3042 | |||
3043 | --Store this config for loading later |
||
3044 | MCom.safeLoads.addonLoaded[configVar] = varTable; |
||
3045 | |||
3046 | --Hook for the VARIABLES_LOADED event |
||
3047 | if (not MCom.HookedOnEvent) then |
||
3048 | MCom.HookedOnEvent = true; |
||
3049 | MCom.util.hook("UIParent_OnEvent", "MCom.UIParent_OnEvent", "after"); |
||
3050 | end |
||
3051 | --Hook for the ADDON_LOADED event |
||
3052 | if (not MCom.RegisteredAddonLoaded) then |
||
3053 | UIParent:RegisterEvent("ADDON_LOADED"); |
||
3054 | end |
||
3055 | end |
||
3056 | end |
||
3057 | end; |
||
3058 | |||
3059 | --[[ |
||
3060 | varsLoaded |
||
3061 | This will simply check to see if the variables needed to be able to use MCom.loadConfig have been loaded. |
||
3062 | To use this properly you must have an OnEvent function. You must have registered for the "UNIT_NAME_UPDATE" |
||
3063 | event. In your OnEvent handler you need to check if that event has occured, and if it has if the arg1 is player. |
||
3064 | You should also have a variable that keeps up with whether or not you have loaded your config, and only try to |
||
3065 | do so if it hasn't loaded. |
||
3066 | |||
3067 | Ex (somewhere in the OnLoad handler) this will either register with the UI to call ModName.LoadConfig when |
||
3068 | they load their configuration, or it will register a "UNIT_NAME_UPDATE" event for you: |
||
3069 | MCom.registerForLoad(ModName.LoadConfig); |
||
3070 | |||
3071 | Ex (somewhere in the OnEvent handler) this will handle waiting till the right vars are loaded before calling |
||
3072 | the config, when there is no UI around: |
||
3073 | if (( event == "UNIT_NAME_UPDATE" ) and (arg1 == "player") and (not ModName.VarsLoaded)) then |
||
3074 | if ( MCom.varsLoaded() ) then |
||
3075 | ModName.VarsLoaded = true; |
||
3076 | ModName.LoadConfig(); |
||
3077 | end |
||
3078 | end |
||
3079 | |||
3080 | NOTE: Make sure you're LoadConfig function only loads the config once, as some UIs might call the function more |
||
3081 | than once. |
||
3082 | |||
3083 | Returns: |
||
3084 | true - the variables needed to load the config are present and proper |
||
3085 | false - the variables needed to load the config are not present or not proper |
||
3086 | |||
3087 | ]]-- |
||
3088 | MCom.varsLoaded = function () |
||
3089 | --Get the realm and character names |
||
3090 | local realm = GetCVar("RealmName"); |
||
3091 | local character = UnitName("player"); |
||
3092 | --If we have the needed data, in proper format, then return true, otherwise return false |
||
3093 | if ( realm and character and ( character ~= UKNOWNBEING ) and ( character ~= UNKNOWNOBJECT ) ) then |
||
3094 | return true; |
||
3095 | end |
||
3096 | return false; |
||
3097 | end; |
||
3098 | |||
3099 | --[[ |
||
3100 | registerVarsLoaded ( function callback ) |
||
3101 | This will call the passed function back when the variables have been loaded by the game, or the |
||
3102 | UI. This would be an optimal time to load |
||
3103 | |||
3104 | Args: |
||
3105 | callback( vltype ) - the function to be called when the variables have been loaded |
||
3106 | Args: |
||
3107 | (string) vltype - indicates what kind of load has occured, "UIParent" for normal, "Khaos", or "Cosmos" |
||
3108 | ]]-- |
||
3109 | MCom.registerVarsLoaded = function ( callback ) |
||
3110 | --Add this callback to the list |
||
3111 | if (not MCom.varsLoadedList) then |
||
3112 | MCom.varsLoadedList = {}; |
||
3113 | end |
||
3114 | table.insert(MCom.varsLoadedList, callback); |
||
3115 | |||
3116 | --Only register for the load notice once |
||
3117 | if (not MCom.LoadNoticeRegistered) then |
||
3118 | MCom.LoadNoticeRegistered = true; |
||
3119 | --Try to register with Khaos |
||
3120 | if (Khaos) then |
||
3121 | Khaos.registerConfigurationLoadNotice( { onConfigurationChange = MCom.VariablesLoaded; id = "MCom"; description = "Handles all MCom registered load notices"; } ); |
||
3122 | elseif (Cosmos_RegisterVarsLoaded) then |
||
3123 | --Try to register with Cosmos |
||
3124 | Cosmos_RegisterVarsLoaded( MCom.VariablesLoaded ); |
||
3125 | else |
||
3126 | --Hook the event function of UIParent so we know when VARS_LOADED occurs |
||
3127 | if (not MCom.HookedOnEvent) then |
||
3128 | MCom.HookedOnEvent = true; |
||
3129 | MCom.util.hook("UIParent_OnEvent", "MCom.UIParent_OnEvent", "after"); |
||
3130 | end |
||
3131 | MCom.UseVarsLoadedEvent = true; |
||
3132 | end |
||
3133 | end |
||
3134 | end; |
||
3135 | |||
3136 | --[[ |
||
3137 | DEPRICATED! For Backward compatability only. |
||
3138 | USE MCom.registerVarsLoaded |
||
3139 | ]]-- |
||
3140 | MCom.registerForLoad = function ( callback ) |
||
3141 | --Try to register with Khaos |
||
3142 | if (Khaos and this:GetName()) then |
||
3143 | Khaos.registerConfigurationLoadNotice( { onConfigurationChange = callback; id = this:GetName(); description = ""; } ); |
||
3144 | elseif (Cosmos_RegisterVarsLoaded) then |
||
3145 | --Try to register with Cosmos |
||
3146 | Cosmos_RegisterVarsLoaded( callback ); |
||
3147 | else |
||
3148 | --No UI around, so we register the event |
||
3149 | this:RegisterEvent( "UNIT_NAME_UPDATE" ); |
||
3150 | end |
||
3151 | return false; |
||
3152 | end; |
||
3153 | |||
3154 | --[[ |
||
3155 | addSlashCom ( [string/{string, ...}] command, function comfunc, string comaction, bool comsticky, string comhelp, string comtype, string uisec, string uivar, string comvar, string comvarmulti, number commin, number commax, number commul, number cominmul, bool hasbool, {string = string, ...} choices, bool multichoice, bool hasopacity, {string, ...} extrahelp ) |
||
3156 | Registers a standard slash command. This will register with Sky, if it exists. |
||
3157 | addSlashCom makes its own chat handler function. The function expects a particular kind of input, specified by comtype. |
||
3158 | |||
3159 | For boolean input, it will require that the user pass on, off, 1, or 0, to consider the command valid. It will then call |
||
3160 | the function you pass, and will pass a 1, 0, or a -1, standing for True, False, and no input(I suggest you make it invert |
||
3161 | the current value in this case). If Cosmos is loaded, and you have passed uivar and comvar, it will update the cosmos |
||
3162 | variable after the function has completed. |
||
3163 | |||
3164 | If the slash command is already registered with MCom, nothing will happen. |
||
3165 | |||
3166 | Args: |
||
3167 | command - The slash command(s) you want to register. Ex: "/command". This can be a string or a table of strings if you |
||
3168 | want more than one command. |
||
3169 | comfunc - The function that the should be called when the slash command is used, and valid. If the function returns a value |
||
3170 | that value will be used to update a cosmos variable, if uivar has been passed. You don't have to return a value |
||
3171 | to do this, but if you don't then you need to use comvar, and comvarmulti(for multi type). For multi type it |
||
3172 | should return the bool then the value, like so: "return enabled, value;" |
||
3173 | BOOL - function (bool enabled) |
||
3174 | NUMBER - function (number value) |
||
3175 | MULTI - function (bool enabled, number value) |
||
3176 | STRING - function (string value) |
||
3177 | SIMPLE - function () |
||
3178 | |||
3179 | Optional: |
||
3180 | comaction - The action to perform, see Sky documentation for further details |
||
3181 | comsticky - Whether the command is sticky or not(1 or 0), see Sky documentation for further details |
||
3182 | comhelp - What message to display as help in Sky for this command, see Sky documentation for further details |
||
3183 | comtype - the type of data you are expecting from this slash command |
||
3184 | MCOM_BOOLT - Expects boolean data, an on, off, 1, or 0 |
||
3185 | MCOM_NUMT - Expects a number value |
||
3186 | MCOM_MULTIT - Expects a boolean and then a number value, Ex: "/command on 3" |
||
3187 | MCOM_STRINGT - Expects any string |
||
3188 | MCOM_SIMPLET - No input needed, just calls the function |
||
3189 | commin - the minimum value the number variable can be set to, for help display only |
||
3190 | commax - the maximum value the number variable can be set to, for help display only |
||
3191 | commul - the value to multiply the number by when showing it's status |
||
3192 | cominmul - A value to multiply the number passed in by the user(for number types only) |
||
3193 | hasbool - If this option has a boolean part, set this to true |
||
3194 | multichoice - Set this true if this is a choice type and can have multiple choices selected |
||
3195 | hasopacity - Set this true if this is a color type that should also have an opacity setting |
||
3196 | extrahelp - A table of extra help messages to display, each line is printed on a seperate line |
||
3197 | |||
3198 | These are required if you want to update a Cosmos or Khaos variable: |
||
3199 | uivar - The Cosmos variable that should be updated, if you want this slash command to update a cosmos variable |
||
3200 | These are required if you want to update a Cosmos or Khaos variable, and your function doesn't return the updated value: |
||
3201 | comvar - The variable that the cosmos variable should be set by, if you want this slash command to update a cosmos variable |
||
3202 | This should be a string containing the name of the variable to update, this can include .'s for tables, Ex: "Something.Value" |
||
3203 | When type is MULTI, this specifies the bool variable |
||
3204 | comvarmulti - The same as comvar, but used to specify the number variable when type is MULTI, only used for MULTI type |
||
3205 | |||
3206 | This is required if you want to update a Khaos variable: |
||
3207 | uisec - The option set ID that the uivar is found in |
||
3208 | |||
3209 | This is required is you are using a MCOM_CHOICET type: |
||
3210 | choices - The list of choices |
||
3211 | ]]-- |
||
3212 | MCom.addSlashCom = function (command, comfunc, comaction, comsticky, comhelp, comtype, uisec, uivar, comvar, comvarmulti, commin, commax, commul, cominmul, hasbool, choices, multichoice, hasopacity, extrahelp) |
||
3213 | --We need at bare minimum command, and comfunc |
||
3214 | if (command and comfunc) then |
||
3215 | --If we dont have our chat command list yet, make one |
||
3216 | if (not MCom.SlashComs) then |
||
3217 | MCom.SlashComs = {}; |
||
3218 | end |
||
3219 | --make sure command is a table |
||
3220 | if (type(command) ~= "table") then |
||
3221 | command = {command}; |
||
3222 | end |
||
3223 | |||
3224 | --If the command is not in the list yet, then add it |
||
3225 | if (not MCom.getComID(command)) then |
||
3226 | table.insert(MCom.SlashComs, {}); |
||
3227 | local commandid = getn(MCom.SlashComs); |
||
3228 | |||
3229 | --Set the commands various elements |
||
3230 | MCom.SlashComs[commandid].basecommand = command; |
||
3231 | MCom.SlashComs[commandid].comfunc = comfunc; |
||
3232 | if (comtype) then |
||
3233 | MCom.SlashComs[commandid].comtype = comtype; |
||
3234 | elseif (MCom.SlashComs[commandid].comtype == nil) then |
||
3235 | --Default to simple type |
||
3236 | MCom.SlashComs[commandid].comtype = MCOM_SIMPLET; |
||
3237 | end |
||
3238 | if (uisec) then |
||
3239 | MCom.SlashComs[commandid].uisec = uisec; |
||
3240 | end |
||
3241 | if (uivar) then |
||
3242 | MCom.SlashComs[commandid].uivar = uivar; |
||
3243 | end |
||
3244 | if (comvar) then |
||
3245 | MCom.SlashComs[commandid].comvar = comvar; |
||
3246 | end |
||
3247 | if (comvarmulti) then |
||
3248 | MCom.SlashComs[commandid].comvarmulti = comvarmulti; |
||
3249 | end |
||
3250 | if (commim) then |
||
3251 | MCom.SlashComs[commandid].commin = commin; |
||
3252 | end |
||
3253 | if (commax) then |
||
3254 | MCom.SlashComs[commandid].commax = commax; |
||
3255 | end |
||
3256 | if (commul) then |
||
3257 | MCom.SlashComs[commandid].commul = commul; |
||
3258 | end |
||
3259 | if (cominmul) then |
||
3260 | MCom.SlashComs[commandid].cominmul = cominmul; |
||
3261 | end |
||
3262 | if (extrahelp) then |
||
3263 | MCom.SlashComs[commandid].extrahelp = extrahelp; |
||
3264 | end |
||
3265 | if (hasbool) then |
||
3266 | MCom.SlashComs[commandid].hasbool = hasbool; |
||
3267 | end |
||
3268 | if (choices) then |
||
3269 | MCom.SlashComs[commandid].choices = choices; |
||
3270 | end |
||
3271 | if (multichoice) then |
||
3272 | MCom.SlashComs[commandid].multichoice = multichoice; |
||
3273 | end |
||
3274 | if (hasopacity) then |
||
3275 | MCom.SlashComs[commandid].hasopacity = hasopacity; |
||
3276 | end |
||
3277 | |||
3278 | --Register the command with Sky, or the default method |
||
3279 | if ( Sky ) then |
||
3280 | --Register the command with Sky |
||
3281 | Sky.registerSlashCommand( |
||
3282 | { |
||
3283 | id=string.upper(command[1]).."_COMMAND"; |
||
3284 | commands = command; |
||
3285 | onExecute = function (msg) MCom.SlashCommandHandler(commandid, msg); end; |
||
3286 | action = comaction; |
||
3287 | sticky = comsticky; |
||
3288 | helpText = comhelp; |
||
3289 | } |
||
3290 | ); |
||
3291 | else |
||
3292 | SlashCmdList[string.upper(string.sub(command[1], 2))] = function (msg) MCom.SlashCommandHandler(commandid, msg); end; |
||
3293 | for curCom = 1, getn(command) do |
||
3294 | setglobal("SLASH_"..string.upper(string.sub(command[1], 2))..curCom, command[curCom]); |
||
3295 | end |
||
3296 | end |
||
3297 | end |
||
3298 | end |
||
3299 | end; |
||
3300 | |||
3301 | --[[ |
||
3302 | addSlashSuperCom ( [string/{string, ...}] command, string comaction, number comsticky, string comhelp ) |
||
3303 | This registers a slash command that will have sub commands in it. See addSlashSubCom for more details on sub commands. |
||
3304 | |||
3305 | If the slash command is already registered with MCom, nothing will happen. |
||
3306 | |||
3307 | Args: |
||
3308 | command - The slash command(s) you want to register. Ex: "/command". This can be a string or a table of strings if you |
||
3309 | want more than one command. |
||
3310 | |||
3311 | Optional: |
||
3312 | comaction - The action to perform, see Sky documentation for further details |
||
3313 | comsticky - Whether the command is sticky or not(1 or 0), see Sky documentation for further details |
||
3314 | comhelp - What message to display as help in Sky for this command, see Sky documentation for further details |
||
3315 | extrahelp - A table of extra help messages to display, each line is printed on a seperate line |
||
3316 | ]]-- |
||
3317 | MCom.addSlashSuperCom = function (command, comaction, comsticky, comhelp, extrahelp) |
||
3318 | --We need at bare minimum command |
||
3319 | if (command) then |
||
3320 | --If we dont have our chat command list yet, make one |
||
3321 | if (not MCom.SlashComs) then |
||
3322 | MCom.SlashComs = {}; |
||
3323 | end |
||
3324 | --make sure command is a table |
||
3325 | if (type(command) ~= "table") then |
||
3326 | command = {command}; |
||
3327 | end |
||
3328 | |||
3329 | --If the command is not in the list yet, then add it |
||
3330 | if (not MCom.getComID(command)) then |
||
3331 | table.insert(MCom.SlashComs, {}); |
||
3332 | local commandid = getn(MCom.SlashComs); |
||
3333 | |||
3334 | MCom.SlashComs[commandid].basecommand = command; |
||
3335 | if (extrahelp) then |
||
3336 | MCom.SlashComs[commandid].extrahelp = extrahelp; |
||
3337 | end |
||
3338 | |||
3339 | --Register the command with Sky, or the default method |
||
3340 | if ( Sky ) then |
||
3341 | Sky.registerSlashCommand( |
||
3342 | { |
||
3343 | id=string.upper(command[1]).."_COMMAND"; |
||
3344 | commands = command; |
||
3345 | onExecute = function (msg) MCom.SlashCommandHandler(commandid, msg); end; |
||
3346 | action = comaction; |
||
3347 | sticky = comsticky; |
||
3348 | helpText = comhelp; |
||
3349 | } |
||
3350 | ); |
||
3351 | else |
||
3352 | SlashCmdList[string.upper(string.sub(command[1], 2))] = function (msg) MCom.SlashCommandHandler(commandid, msg); end; |
||
3353 | for curCom = 1, getn(command) do |
||
3354 | setglobal("SLASH_"..string.upper(string.sub(command[1], 2))..curCom, command[curCom]); |
||
3355 | end |
||
3356 | end |
||
3357 | end |
||
3358 | end |
||
3359 | end; |
||
3360 | |||
3361 | --[[ |
||
3362 | addSlashSubCom ( [string/{string, ...}] basecommand, [string/{string, ...}] subcommand, function comfunc, string comhelp, string comtype, string uisec, string uivar, string comvar, string comvarmulti, number commin, number commax, number commul, number cominmul, bool hasbool, {string = string, ...} choices, bool multichoice, bool hasopacity) |
||
3363 | This is like addSlashCom, but it registers a sub command to be used with a super command. |
||
3364 | A sub command is one that is entered after the super command is entered. |
||
3365 | Example: |
||
3366 | Normal command: "/modcommand on" |
||
3367 | Sub command, with super command of mod: "/mod command on" |
||
3368 | |||
3369 | Using super and sub commands allows you to register only one actual real command, which helps to clean up the listing of slash |
||
3370 | commands, and helps to prevent using a slash command that may already be there. It also makes it easier for the user to remember |
||
3371 | and use, as if the user simply types the super command by itself they will get a listing of all sub commands, and usage. |
||
3372 | |||
3373 | If the slash command is already registered with MCom, nothing will happen. |
||
3374 | |||
3375 | Args: |
||
3376 | basecommand - The super command that this sub command goes with. Can be a single command or a list of commands. |
||
3377 | subcommand - The sub command(s) you want to register. Ex: "command". This can be a string or a table of strings if you |
||
3378 | want more than one command. |
||
3379 | comfunc - The function that the should be called when the slash command is used, and valid. If the function returns a value |
||
3380 | that value will be used to update a cosmos variable, if uivar has been passed. You don't have to return a value |
||
3381 | to do this, but if you don't then you need to use comvar, and comvarmulti(for multi type). For multi type it |
||
3382 | should return the bool then the value, like so: "return enabled, value;" |
||
3383 | BOOL - function (bool enabled) |
||
3384 | NUMBER - function (number value) |
||
3385 | MULTI - function (bool enabled, number value) |
||
3386 | STRING - function (string value) |
||
3387 | SIMPLE - function () |
||
3388 | |||
3389 | Optional: |
||
3390 | comhelp - What message to display next to the sub command when listing sub commands in the help output. |
||
3391 | NOTE: if this is an MCOM_CHOICET then if you put a %s in this string, it will be replaces with a list of |
||
3392 | the choices you passed. |
||
3393 | comtype - the type of data you are expecting from this slash command |
||
3394 | MCOM_BOOLT - Expects boolean data, an on, off, 1, or 0 |
||
3395 | MCOM_NUMT - Expects a number value |
||
3396 | MCOM_MULTIT - Expects a boolean and then a number value, Ex: "/command on 3" |
||
3397 | MCOM_STRINGT - Expects any string |
||
3398 | MCOM_SIMPLET - No input needed, just calls the function |
||
3399 | commin - the minimum value the number variable can be set to, for help display only |
||
3400 | commax - the maximum value the number variable can be set to, for help display only |
||
3401 | commul - the value to multiply the number by when showing it's status |
||
3402 | cominmul - A value to multiply the number passed in by the user(for number types only) |
||
3403 | hasbool - If this option has a boolean part, set this to true |
||
3404 | multichoice - Set this true if this is a choice type and can have multiple choices selected |
||
3405 | hasopacity - Set this true if this is a color type that should also have an opacity setting |
||
3406 | |||
3407 | These are required if you want to update a Cosmos variable: |
||
3408 | uivar - The Cosmos variable that should be updated, if you want this slash command to update a cosmos variable |
||
3409 | These are required if you want to update a Cosmos variable, and your function doesn't return the updated value: |
||
3410 | comvar - The variable that the cosmos variable should be set by, if you want this slash command to update a cosmos variable |
||
3411 | This should be a string containing the name of the variable to update, this can include .'s for tables, Ex: "Something.Value" |
||
3412 | When type is MULTI, this specifies the bool variable |
||
3413 | comvarmulti - The same as comvar, but used to specify the number variable when type is MULTI, only used for MULTI type |
||
3414 | |||
3415 | This is required if you want to update a Khaos variable: |
||
3416 | uisec - The option set ID that the uivar is found in |
||
3417 | |||
3418 | This is required is you are using a MCOM_CHOICET type: |
||
3419 | choices - The list of choices |
||
3420 | ]]-- |
||
3421 | MCom.addSlashSubCom = function (basecommand, subcommand, comfunc, comhelp, comtype, uisec, uivar, comvar, comvarmulti, commin, commax, commul, cominmul, hasbool, choices, multichoice, hasopacity) |
||
3422 | --We need at bare minimum commandid, subcommand, and comfunc |
||
3423 | if (basecommand and subcommand and comfunc) then |
||
3424 | --If we don't have a chat com list, then we shouldn't do anything |
||
3425 | if (MCom.SlashComs) then |
||
3426 | --Make sure basecommand is a table |
||
3427 | if (type(basecommand) ~= "table") then |
||
3428 | basecommand = {basecommand}; |
||
3429 | end |
||
3430 | |||
3431 | --get the ID of the super command, if it is in the list |
||
3432 | local commandid = MCom.getComID(basecommand); |
||
3433 | |||
3434 | --no commandid means no nothing |
||
3435 | if (commandid) then |
||
3436 | --If this super command doesn't have a list of sub commands yet, then make one |
||
3437 | if (not MCom.SlashComs[commandid].commands) then |
||
3438 | MCom.SlashComs[commandid].commands = {}; |
||
3439 | end |
||
3440 | |||
3441 | --If the sub command isn't a table turn it to one |
||
3442 | if (type(subcommand) ~= "table") then |
||
3443 | subcommand = {subcommand}; |
||
3444 | end |
||
3445 | |||
3446 | --Try and find the subcommand in the list |
||
3447 | local monkey, subcommandid = MCom.getComID(commandid, subcommand); |
||
3448 | |||
3449 | --Make sure this sub command doesn't already exist |
||
3450 | if (not subcommandid) then |
||
3451 | --Make the sub command |
||
3452 | table.insert(MCom.SlashComs[commandid].commands, {}); |
||
3453 | subcommandid = getn(MCom.SlashComs[commandid].commands); |
||
3454 | |||
3455 | --Setup the sub commands elements |
||
3456 | MCom.SlashComs[commandid].commands[subcommandid].command = subcommand; |
||
3457 | MCom.SlashComs[commandid].commands[subcommandid].comfunc = comfunc; |
||
3458 | if (comhelp) then |
||
3459 | MCom.SlashComs[commandid].commands[subcommandid].comhelp = comhelp; |
||
3460 | end |
||
3461 | if (comtype) then |
||
3462 | MCom.SlashComs[commandid].commands[subcommandid].comtype = comtype; |
||
3463 | elseif (MCom.SlashComs[commandid].commands[subcommandid].comtype == nil) then |
||
3464 | --Default to simple type |
||
3465 | MCom.SlashComs[commandid].commands[subcommandid].comtype = MCOM_SIMPLET; |
||
3466 | end |
||
3467 | if (uisec) then |
||
3468 | MCom.SlashComs[commandid].commands[subcommandid].uisec = uisec; |
||
3469 | end |
||
3470 | if (uivar) then |
||
3471 | MCom.SlashComs[commandid].commands[subcommandid].uivar = uivar; |
||
3472 | end |
||
3473 | if (comvar) then |
||
3474 | MCom.SlashComs[commandid].commands[subcommandid].comvar = comvar; |
||
3475 | end |
||
3476 | if (comvarmulti) then |
||
3477 | MCom.SlashComs[commandid].commands[subcommandid].comvarmulti = comvarmulti; |
||
3478 | end |
||
3479 | if (commin) then |
||
3480 | MCom.SlashComs[commandid].commands[subcommandid].commin = commin; |
||
3481 | end |
||
3482 | if (commax) then |
||
3483 | MCom.SlashComs[commandid].commands[subcommandid].commax = commax; |
||
3484 | end |
||
3485 | if (commul) then |
||
3486 | MCom.SlashComs[commandid].commands[subcommandid].commul = commul; |
||
3487 | end |
||
3488 | if (cominmul) then |
||
3489 | MCom.SlashComs[commandid].commands[subcommandid].cominmul = cominmul; |
||
3490 | end |
||
3491 | if (hasbool) then |
||
3492 | MCom.SlashComs[commandid].commands[subcommandid].hasbool = hasbool; |
||
3493 | end |
||
3494 | if (choices) then |
||
3495 | MCom.SlashComs[commandid].commands[subcommandid].choices = choices; |
||
3496 | end |
||
3497 | if (multichoice) then |
||
3498 | MCom.SlashComs[commandid].commands[subcommandid].multichoice = multichoice; |
||
3499 | end |
||
3500 | if (hasopacity) then |
||
3501 | MCom.SlashComs[commandid].commands[subcommandid].hasopacity = hasopacity; |
||
3502 | end |
||
3503 | end |
||
3504 | end |
||
3505 | end |
||
3506 | end |
||
3507 | end; |
||
3508 | |||
3509 | --[[ |
||
3510 | callHook ( (string) hook, (any) a1..a20 ) |
||
3511 | Calls the origional hooked function. |
||
3512 | |||
3513 | Args: |
||
3514 | (string) hook - The name of the origional function to call |
||
3515 | (any) a1..a20 - Any variables that need to be passed to the function |
||
3516 | |||
3517 | Returns: |
||
3518 | Whatever the passed function returns |
||
3519 | ]]-- |
||
3520 | MCom.callHook = function ( hook, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20 ) |
||
3521 | --Make sure we have a hook |
||
3522 | if ( hook ) then |
||
3523 | --If we can use Sea, then do so |
||
3524 | if ( Sea ) then |
||
3525 | if ( Sea.util and Sea.util.Hooks and Sea.util.Hooks[hook] and Sea.util.Hooks[hook].orig ) then |
||
3526 | return Sea.util.Hooks[hook].orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); |
||
3527 | end |
||
3528 | elseif ( MCom.util.Hooks and MCom.util.Hooks[hook] and MCom.util.Hooks[hook].orig ) then |
||
3529 | --Use the MCom list if Sea isn't available |
||
3530 | return MCom.util.Hooks[hook].orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); |
||
3531 | end |
||
3532 | end |
||
3533 | end; |
||
3534 | |||
3535 | --[[ |
||
3536 | textFrame ( { reglist } ) |
||
3537 | Displays the passed text in a multipage scrollable frame. |
||
3538 | This will not be available if the ItemTextFrame has been opened by the game. |
||
3539 | |||
3540 | Args: |
||
3541 | reglist - Either a table with the options, or a string or list of strings to display as |
||
3542 | the text. |
||
3543 | { |
||
3544 | Required: |
||
3545 | (string or table) text - The text you want to display, if this is a table, then each |
||
3546 | numbered entry will be a page. |
||
3547 | |||
3548 | Optional: |
||
3549 | (string) title - The title to display at the top of the frame. |
||
3550 | (string) material - The appearance to use for the frame, can be "Stone", "Parchment", "Marble", "Silver", |
||
3551 | or "Bronze", defaults to "Stone" font with a black background. |
||
3552 | (number) textscale - What size to scale the text to, relative to normal (Ex. 1 is normal, 0.5 is half), |
||
3553 | defaults to 0.85 |
||
3554 | } |
||
3555 | |||
3556 | Returns: |
||
3557 | true - The text frame was displayed |
||
3558 | true - The text frame was not displayed |
||
3559 | ]]-- |
||
3560 | MCom.textFrame = function ( reglist ) |
||
3561 | --We have to have a reglist |
||
3562 | if (reglist) then |
||
3563 | --We need to hook some of the functions of the ItemTextFrame so we can have it |
||
3564 | --behave properly for this usage. |
||
3565 | local TextFrame = "MComText"; |
||
3566 | if ( not getglobal(TextFrame.."Frame") ) then |
||
3567 | TextFrame = "ItemText"; |
||
3568 | if (not MCom.HasHookedText) then |
||
3569 | MCom.HasHookedText = true; |
||
3570 | MCom.util.hook("ItemTextNextPage", "MCom.ItemTextNextPage", "after"); |
||
3571 | MCom.util.hook("ItemTextPrevPage", "MCom.ItemTextPrevPage", "after"); |
||
3572 | MCom.util.hook("CloseItemText", "MCom.CloseItemText", "after"); |
||
3573 | MCom.util.hook("ItemTextFrame_OnEvent", "MCom.ItemTextFrame_OnEvent", "before"); |
||
3574 | end |
||
3575 | end |
||
3576 | |||
3577 | --Only display the frame if it isn't already visible |
||
3578 | if ( (not MCom.NoTextAvail) and ( not getglobal(TextFrame.."Frame"):IsVisible() ) ) then |
||
3579 | --If this isn't a table, then turn it into one |
||
3580 | if ( type(reglist) ~= "table" ) then |
||
3581 | reglist = { text = { reglist }; }; |
||
3582 | end |
||
3583 | --If this is a table of strings, then move the strings into text |
||
3584 | if ( ( not reglist.text ) and reglist[1] ) then |
||
3585 | reglist.text = {}; |
||
3586 | for curPage = 1, table.getn(reglist) do |
||
3587 | reglist.text[curPage] = reglist[curPage]; |
||
3588 | reglist[curPage] = nil; |
||
3589 | end |
||
3590 | end |
||
3591 | --If text isn't a table then make it one |
||
3592 | if ( type(reglist.text) ~= "table" ) then |
||
3593 | reglist.text = { reglist.text }; |
||
3594 | end |
||
3595 | --Set the current text and page, to what was passed |
||
3596 | MCom.CurText = reglist.text; |
||
3597 | MCom.CurTextPage = 1; |
||
3598 | --If there was no title passed, set it as an empty string |
||
3599 | if (not reglist.title) then |
||
3600 | reglist.title = ""; |
||
3601 | end |
||
3602 | --Got through all the pages and add some extra fluff new lines to let the user scroll down further |
||
3603 | for curPage in MCom.CurText do |
||
3604 | if (MCom.CurText[curPage]) then |
||
3605 | MCom.CurText[curPage] = MCom.CurText[curPage].."\n\n\n\n"; |
||
3606 | end |
||
3607 | end |
||
3608 | --Set the title of the frame |
||
3609 | getglobal(TextFrame.."TitleText"):SetText(reglist.title); |
||
3610 | --Hide the scrollframe and status bar |
||
3611 | getglobal(TextFrame.."ScrollFrame"):Hide(); |
||
3612 | getglobal(TextFrame.."StatusBar"):Hide(); |
||
3613 | --Setup the look of the frame to the passed look |
||
3614 | local material = Stone; |
||
3615 | --Make sure the material is one of the available materials |
||
3616 | local textColor = {1,1,1}; |
||
3617 | if ( reglist.material and MATERIAL_TEXT_COLOR_TABLE[reglist.material] ) then |
||
3618 | material = reglist.material; |
||
3619 | textColor = MATERIAL_TEXT_COLOR_TABLE[material]; |
||
3620 | end |
||
3621 | getglobal(TextFrame.."PageText"):SetTextColor(textColor[1], textColor[2], textColor[3]); |
||
3622 | |||
3623 | if (not material) then |
||
3624 | if (MComTextFrame) then |
||
3625 | MComTextTopLeft:Show(); |
||
3626 | MComTextTop:Show(); |
||
3627 | MComTextTopRight:Show(); |
||
3628 | MComTextBotLeft:Show(); |
||
3629 | MComTextBot:Show(); |
||
3630 | MComTextBotRight:Show(); |
||
3631 | MComItemTextTopLeft:Hide(); |
||
3632 | MComItemTextTopRight:Hide(); |
||
3633 | MComItemTextBotLeft:Hide(); |
||
3634 | MComItemTextBotRight:Hide(); |
||
3635 | getglobal(TextFrame.."MaterialTopLeft"):Hide(); |
||
3636 | getglobal(TextFrame.."MaterialTopRight"):Hide(); |
||
3637 | getglobal(TextFrame.."MaterialBotLeft"):Hide(); |
||
3638 | getglobal(TextFrame.."MaterialBotRight"):Hide(); |
||
3639 | MComSpellBookIcon:Hide(); |
||
3640 | MComTextFrame:SetWidth(512); |
||
3641 | MComTextCloseButton:SetPoint("CENTER", MComTextFrame, "TOPRIGHT", -58, -19); |
||
3642 | MComTextScrollFrame:SetPoint("TOPRIGHT", MComTextFrame, "TOPRIGHT", -82, -58); |
||
3643 | MComTextScrollFrame:SetWidth(408); |
||
3644 | MComTextScrollFrame:SetHeight(406); |
||
3645 | MComTextScrollFrameMiddle:Show(); |
||
3646 | MComTextTitleText:SetPoint("CENTER", MComTextFrame, "CENTER", -14, 230); |
||
3647 | MComTextCurrentPage:SetPoint("TOP", MComTextFrame, "TOP", -14, -34); |
||
3648 | MComTextNextPageButton:SetPoint("CENTER", MComTextFrame, "TOPRIGHT", -86, -32); |
||
3649 | MComTextPrevPageButton:SetPoint("CENTER", MComTextFrame, "TOPLEFT", 32, -32); |
||
3650 | MComTextPageText:SetWidth(400); |
||
3651 | else |
||
3652 | getglobal(TextFrame.."MaterialTopLeft"):SetVertexColor(0,0,0); |
||
3653 | getglobal(TextFrame.."MaterialTopRight"):SetVertexColor(0,0,0); |
||
3654 | getglobal(TextFrame.."MaterialBotLeft"):SetVertexColor(0,0,0); |
||
3655 | getglobal(TextFrame.."MaterialBotRight"):SetVertexColor(0,0,0); |
||
3656 | end |
||
3657 | else |
||
3658 | if (MComTextFrame) then |
||
3659 | MComTextTopLeft:Hide(); |
||
3660 | MComTextTop:Hide(); |
||
3661 | MComTextTopRight:Hide(); |
||
3662 | MComTextBotLeft:Hide(); |
||
3663 | MComTextBot:Hide(); |
||
3664 | MComTextBotRight:Hide(); |
||
3665 | MComItemTextTopLeft:Show(); |
||
3666 | MComItemTextTopRight:Show(); |
||
3667 | MComItemTextBotLeft:Show(); |
||
3668 | MComItemTextBotRight:Show(); |
||
3669 | MComSpellBookIcon:Show(); |
||
3670 | MComTextFrame:SetWidth(384); |
||
3671 | MComTextCloseButton:SetPoint("CENTER", MComTextFrame, "TOPRIGHT", -45, -26); |
||
3672 | MComTextScrollFrame:SetPoint("TOPRIGHT", MComTextFrame, "TOPRIGHT", -66, -76); |
||
3673 | MComTextScrollFrame:SetWidth(280); |
||
3674 | MComTextScrollFrame:SetHeight(355); |
||
3675 | MComTextScrollFrameMiddle:Hide(); |
||
3676 | MComTextTitleText:SetPoint("CENTER", MComTextFrame, "CENTER", 6, 230); |
||
3677 | MComTextCurrentPage:SetPoint("TOP", MComTextFrame, "TOP", 10, -50); |
||
3678 | MComTextNextPageButton:SetPoint("CENTER", MComTextFrame, "TOPRIGHT", -55, -56); |
||
3679 | MComTextPrevPageButton:SetPoint("CENTER", MComTextFrame, "TOPLEFT", 90, -56); |
||
3680 | MComTextPageText:SetWidth(270); |
||
3681 | end |
||
3682 | getglobal(TextFrame.."MaterialTopLeft"):SetVertexColor(1,1,1); |
||
3683 | getglobal(TextFrame.."MaterialTopRight"):SetVertexColor(1,1,1); |
||
3684 | getglobal(TextFrame.."MaterialBotLeft"):SetVertexColor(1,1,1); |
||
3685 | getglobal(TextFrame.."MaterialBotRight"):SetVertexColor(1,1,1); |
||
3686 | end |
||
3687 | |||
3688 | --If the look is parchment, then hide the extra textures |
||
3689 | if ( material == "Parchment" ) then |
||
3690 | getglobal(TextFrame.."MaterialTopLeft"):Hide(); |
||
3691 | getglobal(TextFrame.."MaterialTopRight"):Hide(); |
||
3692 | getglobal(TextFrame.."MaterialBotLeft"):Hide(); |
||
3693 | getglobal(TextFrame.."MaterialBotRight"):Hide(); |
||
3694 | elseif (material) then |
||
3695 | getglobal(TextFrame.."MaterialTopLeft"):Show(); |
||
3696 | getglobal(TextFrame.."MaterialTopRight"):Show(); |
||
3697 | getglobal(TextFrame.."MaterialBotLeft"):Show(); |
||
3698 | getglobal(TextFrame.."MaterialBotRight"):Show(); |
||
3699 | getglobal(TextFrame.."MaterialTopLeft"):SetTexture("Interface\\ItemTextFrame\\ItemText-"..material.."-TopLeft"); |
||
3700 | getglobal(TextFrame.."MaterialTopRight"):SetTexture("Interface\\ItemTextFrame\\ItemText-"..material.."-TopRight"); |
||
3701 | getglobal(TextFrame.."MaterialBotLeft"):SetTexture("Interface\\ItemTextFrame\\ItemText-"..material.."-BotLeft"); |
||
3702 | getglobal(TextFrame.."MaterialBotRight"):SetTexture("Interface\\ItemTextFrame\\ItemText-"..material.."-BotRight"); |
||
3703 | end |
||
3704 | --Default the scrollbar positions for all pages to the top |
||
3705 | MCom.CurText.Scroll = {}; |
||
3706 | for curPage in MCom.CurText do |
||
3707 | MCom.CurText.Scroll[curPage] = { Value = 0; }; |
||
3708 | end |
||
3709 | |||
3710 | --Resize the text |
||
3711 | if (not reglist.textscale) then |
||
3712 | reglist.textscale = 0.85; |
||
3713 | if (MComTextFrame) then |
||
3714 | reglist.textscale = 1; |
||
3715 | end |
||
3716 | end |
||
3717 | MCom.PageWidth = getglobal(TextFrame.."PageText"):GetWidth(); |
||
3718 | MCom.PageScale = getglobal(TextFrame.."PageText"):GetScale(); |
||
3719 | getglobal(TextFrame.."PageText"):SetWidth(MCom.PageWidth / reglist.textscale); |
||
3720 | getglobal(TextFrame.."PageText"):SetScale(MCom.PageScale * reglist.textscale); |
||
3721 | |||
3722 | --Update it with the new text |
||
3723 | MCom.UpdateTextPage(); |
||
3724 | --Show the frame |
||
3725 | getglobal(TextFrame.."Frame"):Show(); |
||
3726 | return true; |
||
3727 | end |
||
3728 | end |
||
3729 | return false; |
||
3730 | end |
||
3731 | |||
3732 | -------------------------------------------------- |
||
3733 | -- |
||
3734 | -- Private Library Functions |
||
3735 | -- |
||
3736 | -------------------------------------------------- |
||
3737 | --[[ Updates the text in the text frame ]]-- |
||
3738 | MCom.UpdateTextPage = function () |
||
3739 | --Only do this if CurText is a table |
||
3740 | if ( type(MCom.CurText) == "table" ) then |
||
3741 | local TextFrame = "MComText"; |
||
3742 | if ( not getglobal(TextFrame.."Frame") ) then |
||
3743 | TextFrame = "ItemText"; |
||
3744 | end |
||
3745 | --If there is more than one page then setup the frame for that |
||
3746 | if ( table.getn(MCom.CurText) > 1 ) then |
||
3747 | --Show the text that shows the current page number |
||
3748 | local pageText = string.format(MCOM_PAGE_TEXT, MCom.CurTextPage, table.getn(MCom.CurText)); |
||
3749 | if (pageText) then |
||
3750 | getglobal(TextFrame.."CurrentPage"):SetText(pageText); |
||
3751 | getglobal(TextFrame.."CurrentPage"):Show(); |
||
3752 | else |
||
3753 | getglobal(TextFrame.."CurrentPage"):Hide(); |
||
3754 | end |
||
3755 | --If we have gone passed the first page, then enable the previous page button |
||
3756 | if ( MCom.CurTextPage > 1 ) then |
||
3757 | getglobal(TextFrame.."PrevPageButton"):Show(); |
||
3758 | else |
||
3759 | getglobal(TextFrame.."PrevPageButton"):Hide(); |
||
3760 | end |
||
3761 | --If we are not on the last page, then enable the next page button |
||
3762 | if ( MCom.CurTextPage < table.getn(MCom.CurText) ) then |
||
3763 | getglobal(TextFrame.."NextPageButton"):Show(); |
||
3764 | else |
||
3765 | getglobal(TextFrame.."NextPageButton"):Hide(); |
||
3766 | end |
||
3767 | else |
||
3768 | --There is only one page, so hide the page controls |
||
3769 | getglobal(TextFrame.."CurrentPage"):Hide(); |
||
3770 | getglobal(TextFrame.."PrevPageButton"):Hide(); |
||
3771 | getglobal(TextFrame.."NextPageButton"):Hide(); |
||
3772 | end |
||
3773 | |||
3774 | --Hide the scroll frame |
||
3775 | getglobal(TextFrame.."ScrollFrame"):Hide(); |
||
3776 | --Set the text for this page |
||
3777 | getglobal(TextFrame.."PageText"):SetText(MCom.CurText[MCom.CurTextPage]); |
||
3778 | --Update the scrollframe and show if neccisary |
||
3779 | getglobal(TextFrame.."ScrollFrame"):UpdateScrollChildRect(); |
||
3780 | getglobal(TextFrame.."ScrollFrame"):Show(); |
||
3781 | --Reset the scroll bar position to the one stored for this page |
||
3782 | getglobal(TextFrame.."ScrollFrameScrollBar"):SetValue(MCom.CurText.Scroll[MCom.CurTextPage].Value); |
||
3783 | else |
||
3784 | MCom.CurText = nil; |
||
3785 | end |
||
3786 | end; |
||
3787 | |||
3788 | --[[ Adds any entry missing in the toTable from the fromTable ]]-- |
||
3789 | MCom.LoadSafeTable = function (toTable, fromTable) |
||
3790 | --Make sure we have tables to work with |
||
3791 | if ( ( type(toTable) == "table" ) and ( type(fromTable) == "table" ) ) then |
||
3792 | --Go through each entry in the from table |
||
3793 | for curEntry in fromTable do |
||
3794 | --If the from entry is a table, then we need to parse each of its entries |
||
3795 | if ( type( fromTable[curEntry] ) == "table" ) then |
||
3796 | --If the to table is not already a table, then turn it into one |
||
3797 | if ( type( toTable[curEntry] ) ~= "table" ) then |
||
3798 | toTable[curEntry] = {}; |
||
3799 | end |
||
3800 | --Load the entries from the current from table entry into the current to table entry |
||
3801 | MCom.LoadSafeTable( toTable[curEntry], fromTable[curEntry] ); |
||
3802 | elseif ( toTable[curEntry] == nil ) then |
||
3803 | --If this entry is not a table, and it is nil, then load from the from table |
||
3804 | toTable[curEntry] = fromTable[curEntry]; |
||
3805 | end |
||
3806 | end |
||
3807 | end |
||
3808 | end; |
||
3809 | |||
3810 | --[[ Calls all frames registered for variables loaded notification ]]-- |
||
3811 | MCom.VariablesLoaded = function () |
||
3812 | --Only proceed if we have a list of callbacks |
||
3813 | if ( type(MCom.varsLoadedList) == "table" ) then |
||
3814 | --Figure out what type of load notice was used |
||
3815 | local regType = "UIParent"; |
||
3816 | if (Khaos) then |
||
3817 | regType = "Khaos"; |
||
3818 | elseif (Cosmos_RegisterVarsLoaded) then |
||
3819 | regType = "Cosmos"; |
||
3820 | end |
||
3821 | --Call all the callbacks, and pass the type of load notice |
||
3822 | for i = 1, table.getn(MCom.varsLoadedList) do |
||
3823 | if ( type(MCom.varsLoadedList[i]) == "function" ) then |
||
3824 | MCom.varsLoadedList[i](regType); |
||
3825 | end |
||
3826 | end |
||
3827 | end |
||
3828 | end; |
||
3829 | |||
3830 | --[[ Parses a boolean command ]]-- |
||
3831 | MCom.ParseBoolCommand = function (value) |
||
3832 | --If it's a boolean then treat it as one |
||
3833 | if (value) then |
||
3834 | value = string.upper(value); |
||
3835 | if ( string.find(value, string.upper(MCOM_CHAT_ON) ) ) then |
||
3836 | value = 1; |
||
3837 | else |
||
3838 | if ( string.find(value, string.upper(MCOM_CHAT_OFF) ) ) then |
||
3839 | value = 0; |
||
3840 | else |
||
3841 | if ( string.find(value, "1") ) then |
||
3842 | value = 1; |
||
3843 | else |
||
3844 | if ( string.find(value, "0") ) then |
||
3845 | value = 0; |
||
3846 | else |
||
3847 | value = nil; |
||
3848 | end |
||
3849 | end |
||
3850 | end |
||
3851 | end |
||
3852 | else |
||
3853 | --If there was no data passed for this boolean, then send -1 to the functions |
||
3854 | value = -1; |
||
3855 | end |
||
3856 | |||
3857 | return value; |
||
3858 | end; |
||
3859 | |||
3860 | --[[ Parses a number command ]]-- |
||
3861 | MCom.ParseNumCommand = function (cominmul, value) |
||
3862 | if (value) then |
||
3863 | --Get the valid decimal portion only |
||
3864 | local dump, dump1; |
||
3865 | dump, dump1, value = string.find(value, "(%d*%.*%d+)"); |
||
3866 | --If we got a valid decimal, multiply it by cominmul |
||
3867 | if (value) then |
||
3868 | if (not cominmul) then |
||
3869 | cominmul = 1; |
||
3870 | end |
||
3871 | value = value * cominmul; |
||
3872 | end |
||
3873 | end |
||
3874 | |||
3875 | return value; |
||
3876 | end; |
||
3877 | |||
3878 | --[[ Parses a choice command ]]-- |
||
3879 | MCom.ParseChoiceCommand = function (choices, multichoice, value) |
||
3880 | retVal = nil; |
||
3881 | name = nil; |
||
3882 | --Make sure we have the needed data |
||
3883 | if (choices and value) then |
||
3884 | --Split the list by spaces |
||
3885 | value = MCom.util.split(value, " "); |
||
3886 | --Make sure it is in table format |
||
3887 | if (type(value) ~= "table") then |
||
3888 | value = {value}; |
||
3889 | end |
||
3890 | --Go through all passed choices, and keep any that are in the available list |
||
3891 | for choice in value do |
||
3892 | local curChoice = value[choice]; |
||
3893 | --If this isn't a viable choice, then see if there is one with any capitalization |
||
3894 | if (not choices[curChoice]) then |
||
3895 | for curCheck in choices do |
||
3896 | if ( string.lower(curChoice) == string.lower( curCheck ) ) then |
||
3897 | curChoice = curCheck; |
||
3898 | break; |
||
3899 | end |
||
3900 | end |
||
3901 | end |
||
3902 | --Make sure we have a good choice |
||
3903 | if ( choices[curChoice] ) then |
||
3904 | --If it is multichoice, add it to the list |
||
3905 | if (multichoice) then |
||
3906 | if (retVal == nil) then |
||
3907 | retVal = {}; |
||
3908 | end |
||
3909 | table.insert(retVal, choices[curChoice]); |
||
3910 | --Make a named list of the selected choices |
||
3911 | if (name) then |
||
3912 | name = name..", "..curChoice; |
||
3913 | else |
||
3914 | name = curChoice; |
||
3915 | end |
||
3916 | else |
||
3917 | --If it's single choice, then return it |
||
3918 | retVal = choices[curChoice]; |
||
3919 | name = curChoice; |
||
3920 | break; |
||
3921 | end |
||
3922 | end |
||
3923 | end |
||
3924 | end |
||
3925 | |||
3926 | return retVal, name; |
||
3927 | end; |
||
3928 | |||
3929 | --[[ Parses a color command ]]-- |
||
3930 | MCom.ParseColorCommand = function (hasopacity, value1, value2, value3, value4) |
||
3931 | local value = nil; |
||
3932 | local dump, dump1; |
||
3933 | --Make sure we have atleast the R the G and the B |
||
3934 | if (value1 and value2 and value3) then |
||
3935 | --Get valid decimals for all three values, and divide them to a percent format |
||
3936 | value = {}; |
||
3937 | dump, dump1, value1 = string.find(value1, "(%d*%.*%d+)"); |
||
3938 | if (value1) then |
||
3939 | value.r = value1/100; |
||
3940 | end |
||
3941 | dump, dump1, value2 = string.find(value2, "(%d*%.*%d+)"); |
||
3942 | if (value1) then |
||
3943 | value.g = value2/100; |
||
3944 | end |
||
3945 | dump, dump1, value3 = string.find(value3, "(%d*%.*%d+)"); |
||
3946 | if (value3) then |
||
3947 | value.b = value3/100; |
||
3948 | end |
||
3949 | if (hasopacity and value4) then |
||
3950 | --If we are supposed to have an opacity part then |
||
3951 | --Get a valid decimal for opacity, and divide it to a percent format |
||
3952 | dump, dump1, value3 = string.find(value4, "(%d*%.*%d+)"); |
||
3953 | if (value4) then |
||
3954 | value.opacity = value4/100; |
||
3955 | end |
||
3956 | end |
||
3957 | --If we didn't have all three values, then return nil |
||
3958 | if ( not (value1 and value2 and value3) ) then |
||
3959 | value = nil; |
||
3960 | end |
||
3961 | --If we are supposed to have opacity, and it wasn't passed, then return nil |
||
3962 | if (hasopacity and (not value4) ) then |
||
3963 | value = nil; |
||
3964 | end |
||
3965 | end |
||
3966 | |||
3967 | return value; |
||
3968 | end; |
||
3969 | |||
3970 | --[[ The slash command handler used by MCom slash commands ]]-- |
||
3971 | MCom.SlashCommandHandler = function (commandid, msg) |
||
3972 | --Only works if we have some registered slash commands |
||
3973 | if (MCom.SlashComs and MCom.SlashComs[commandid]) then |
||
3974 | --Get a shorthand for the current command |
||
3975 | curCommand = MCom.SlashComs[commandid]; |
||
3976 | --Only proccess the message if there is one |
||
3977 | if ((msg and (msg ~= "")) or ((curCommand.comtype) and (curCommand.comtype == MCOM_BOOLT))) then |
||
3978 | local subcommand, value; |
||
3979 | local isSimple = true; --Set true if the command is a standard, not super, slash command |
||
3980 | local comType = nil; --Stores the type of command |
||
3981 | local badCommand = nil; --Set true if the data for the command turns out bad |
||
3982 | |||
3983 | if (not curCommand.commands) then |
||
3984 | --This is simple so unpack it to the values |
||
3985 | if (msg) then |
||
3986 | value = MCom.util.split(msg, " "); |
||
3987 | end |
||
3988 | else |
||
3989 | --This is a super command, so unpack the subcommand and values |
||
3990 | isSimple = nil; |
||
3991 | --Get the position of the subcommand, and the rest goes into msg2 |
||
3992 | local first, last, msg2 = string.find(msg, " (.*)"); |
||
3993 | --If we got the subcommand position then get that portion to the subcommand |
||
3994 | if (first) then |
||
3995 | subcommand = string.sub(msg, 1, first - 1); |
||
3996 | else |
||
3997 | --If we didn't find a position then we have only the subcommand |
||
3998 | subcommand = msg; |
||
3999 | end |
||
4000 | --Move the rest of the values into msg |
||
4001 | msg = msg2; |
||
4002 | --If we have values in msg, then parse them out |
||
4003 | if (msg) then |
||
4004 | value = MCom.util.split(msg, " "); |
||
4005 | end |
||
4006 | |||
4007 | if (subcommand) then |
||
4008 | --Try and find an exact match of the subcommand in the list |
||
4009 | local subcommandid = nil; |
||
4010 | for curCom in MCom.SlashComs[commandid].commands do |
||
4011 | if (MCom.SlashComs[commandid].commands[curCom].command) then |
||
4012 | for curComCom in MCom.SlashComs[commandid].commands[curCom].command do |
||
4013 | if (MCom.SlashComs[commandid].commands[curCom].command[curComCom] == subcommand) then |
||
4014 | subcommandid = curCom; |
||
4015 | break; |
||
4016 | end |
||
4017 | end |
||
4018 | if (subcommandid) then |
||
4019 | break; |
||
4020 | end |
||
4021 | end |
||
4022 | end |
||
4023 | |||
4024 | if (not subcommandid) then |
||
4025 | --Try and find a similar match of the subcommand in the list |
||
4026 | for curCom in MCom.SlashComs[commandid].commands do |
||
4027 | if (MCom.SlashComs[commandid].commands[curCom].command) then |
||
4028 | for curComCom in MCom.SlashComs[commandid].commands[curCom].command do |
||
4029 | if (string.find(MCom.SlashComs[commandid].commands[curCom].command[curComCom], subcommand)) then |
||
4030 | subcommandid = curCom; |
||
4031 | break; |
||
4032 | end |
||
4033 | end |
||
4034 | if (subcommandid) then |
||
4035 | break; |
||
4036 | end |
||
4037 | end |
||
4038 | end |
||
4039 | end |
||
4040 | |||
4041 | if (not subcommandid) then |
||
4042 | --We didn't find the sub command, so we've got a bad command |
||
4043 | badCommand = true; |
||
4044 | else |
||
4045 | --We found the sub command so change curCommand to point at it |
||
4046 | curCommand = curCommand.commands[subcommandid]; |
||
4047 | end |
||
4048 | else |
||
4049 | --No subcommand passed, so thats a bad command |
||
4050 | badCommand = true; |
||
4051 | end |
||
4052 | end |
||
4053 | --We only want to continue if the command was good |
||
4054 | if (not badCommand) then |
||
4055 | --Get the command type |
||
4056 | if (curCommand.comtype) then |
||
4057 | comType = curCommand.comtype; |
||
4058 | end |
||
4059 | |||
4060 | local retVal, retVal2; |
||
4061 | |||
4062 | if ( ( (comType == MCOM_BOOLT) or curCommand.hasbool ) and (value == nil) ) then |
||
4063 | --If nothing was passed and its a bool command then invert it |
||
4064 | curCommand.comfunc(-1); |
||
4065 | elseif ( (comType ~= MCOM_SIMPLET) ) then |
||
4066 | --If it's not a simply command parse the data if we have data |
||
4067 | if (value) then |
||
4068 | --Setup a list of variables to use for checking the passed data |
||
4069 | local checkVal = value[1]; |
||
4070 | local checkVal2 = value[2]; |
||
4071 | local checkVal3 = value[3]; |
||
4072 | local checkVal4 = value[4]; |
||
4073 | --This stores the boolean portion of the command, if it has two parts |
||
4074 | local boolVal = value; |
||
4075 | --This stores the display name for choice types |
||
4076 | local name = nil; |
||
4077 | if ( (comType == MCOM_MULTIT) or (curCommand.hasbool and (comType ~= MCOM_BOOLT)) ) then |
||
4078 | --Since the first value was the boolean, move the other values down in the list |
||
4079 | checkVal = value[2]; |
||
4080 | checkVal2 = value[3]; |
||
4081 | checkVal3 = value[4]; |
||
4082 | checkVal4 = value[5]; |
||
4083 | |||
4084 | --Remove the boolean part of the message |
||
4085 | local dump1, dump2; |
||
4086 | dump1, dump2, msg = string.find(msg, " (.*)"); |
||
4087 | end |
||
4088 | |||
4089 | --If it is a multi part, or a boolean, then parse the first value as boolean |
||
4090 | if ( (comType == MCOM_BOOLT) or (comType == MCOM_MULTIT) or curCommand.hasbool ) then |
||
4091 | boolVal = MCom.ParseBoolCommand(value[1]); |
||
4092 | value = boolVal; |
||
4093 | end |
||
4094 | |||
4095 | --Parse the value, or secondary as the appropriate type |
||
4096 | if ( (comType == MCOM_NUMT) or (comType == MCOM_MULTIT) ) then |
||
4097 | value = MCom.ParseNumCommand(curCommand.cominmul, checkVal); |
||
4098 | elseif (comType == MCOM_STRINGT) then |
||
4099 | --For string we pass the message so spaces can be included |
||
4100 | value = msg; |
||
4101 | elseif (comType == MCOM_CHOICET) then |
||
4102 | --For choice we pass the message so as many passed choices as are passed can be used on a multichoice |
||
4103 | value, name = MCom.ParseChoiceCommand(curCommand.choices, curCommand.multichoice, msg); |
||
4104 | elseif (comType == MCOM_COLORT) then |
||
4105 | value = MCom.ParseColorCommand(curCommand.hasopacity, checkVal, checkVal2, checkVal3, checkVal4); |
||
4106 | end |
||
4107 | |||
4108 | if ( (comType == MCOM_MULTIT) or (curCommand.hasbool and (comType ~= MCOM_BOOLT)) ) then |
||
4109 | --Handle the two part commands |
||
4110 | if (boolVal or value) then |
||
4111 | --Call the function |
||
4112 | retVal, retVal2 = curCommand.comfunc(boolVal, value, name); |
||
4113 | else |
||
4114 | --We got bad data |
||
4115 | badCommand = true; |
||
4116 | end |
||
4117 | else |
||
4118 | --Handle the one part commands |
||
4119 | if (value) then |
||
4120 | --Call the function |
||
4121 | retVal = curCommand.comfunc(value, name); |
||
4122 | else |
||
4123 | --We got bad data |
||
4124 | badCommand = true; |
||
4125 | end |
||
4126 | end |
||
4127 | else |
||
4128 | badCommand = true; |
||
4129 | end |
||
4130 | else |
||
4131 | --It's a simple type, so just call it and quit |
||
4132 | curCommand.comfunc(); |
||
4133 | return; |
||
4134 | end |
||
4135 | |||
4136 | if (not badCommand) then |
||
4137 | --If Khaos is around, then we update the variable with it, if possible |
||
4138 | if (Khaos and (curCommand.comvar or retVal) and curCommand.uivar and curCommand.uisec) then |
||
4139 | --Make sure the passed set exists |
||
4140 | if ( KhaosData.configurationSets and (KhaosData.configurationSets[curCommand.uisec]) ) then |
||
4141 | --get the value of the variable |
||
4142 | local newVal = MCom.getStringVar(curCommand.comvar); |
||
4143 | --If a value was returned from the setter function, then use it |
||
4144 | if (retVal) then |
||
4145 | newVal = retVal; |
||
4146 | end |
||
4147 | if (newVal) then |
||
4148 | --Get the second part variable if there is one |
||
4149 | local newValMulti = MCom.getStringVar(curCommand.comvarmulti); |
||
4150 | --If a value was returned from the setter function from the second part, then use it |
||
4151 | if (retVal2) then |
||
4152 | newValMulti = retVal2; |
||
4153 | end |
||
4154 | |||
4155 | --Default param type is value |
||
4156 | local param = "value"; |
||
4157 | --If we have a boolean type, or boolean portion, then update that |
||
4158 | if ( (comType == MCOM_BOOLT) or (comType == MCOM_MULTIT) or curCommand.hasbool) then |
||
4159 | --Make sure its in true/false format |
||
4160 | if (newVal == 1) then |
||
4161 | newVal = true; |
||
4162 | else |
||
4163 | newVal = false; |
||
4164 | end |
||
4165 | --Update the boolean variable |
||
4166 | Khaos.setSetKeyParameter(curCommand.uisec, curCommand.uivar, "checked", newVal); |
||
4167 | end |
||
4168 | --If it isn't a boolean type, then update the other types, or secondary variable |
||
4169 | if ( comType ~= MCOM_BOOLT ) then |
||
4170 | --If we have a secondary variable, then switch to using it |
||
4171 | if (newValMulti) then |
||
4172 | newVal = newValMulti; |
||
4173 | end |
||
4174 | |||
4175 | --Treat number types as sliders |
||
4176 | if ( (comType == MCOM_NUMT) or (comType == MCOM_MULTIT) ) then |
||
4177 | param = "slider"; |
||
4178 | end |
||
4179 | |||
4180 | --Treat color types as color pickers |
||
4181 | if (comType == MCOM_COLORT) then |
||
4182 | param = "color"; |
||
4183 | end |
||
4184 | |||
4185 | --Update the variable |
||
4186 | Khaos.setSetKeyParameter(curCommand.uisec, curCommand.uivar, param, newVal); |
||
4187 | end |
||
4188 | end |
||
4189 | end |
||
4190 | else |
||
4191 | if(CosmosMaster_Init and (curCommand.comvar or retVal) and curCommand.uivar) then |
||
4192 | --get the value of the variable |
||
4193 | local newVal = MCom.getStringVar(curCommand.comvar); |
||
4194 | if (retVal) then |
||
4195 | newVal = retVal; |
||
4196 | end |
||
4197 | if (newVal) then |
||
4198 | local newValMulti = MCom.getStringVar(curCommand.comvarmulti); |
||
4199 | if (retVal2) then |
||
4200 | newValMulti = retVal2; |
||
4201 | end |
||
4202 | if (((comType ~= MCOM_MULTIT) and (not ((comType ~= MCOM_BOOLT) and curCommand.hasbool))) or (((comType == MCOM_MULTIT) or ((comType ~= MCOM_BOOLT) and curCommand.hasbool)) and newValMulti)) then |
||
4203 | --if its a boolean, then set the checkbox |
||
4204 | if ((comType == MCOM_BOOLT) or (comType == MCOM_MULTIT)) then |
||
4205 | Cosmos_UpdateValue(curCommand.uivar, CSM_CHECKONOFF, newVal); |
||
4206 | end |
||
4207 | --if its a number, then set the slider |
||
4208 | if ((comType == MCOM_NUMT) or (comType == MCOM_MULTIT)) then |
||
4209 | if (comType == MCOM_MULTIT) then |
||
4210 | newVal = newValMulti; |
||
4211 | end |
||
4212 | Cosmos_UpdateValue(curCommand.uivar, CSM_SLIDERVALUE, newVal); |
||
4213 | end |
||
4214 | end |
||
4215 | end |
||
4216 | end |
||
4217 | end |
||
4218 | return; |
||
4219 | end |
||
4220 | end |
||
4221 | elseif ((curCommand.comtype) and (curCommand.comtype == MCOM_SIMPLET)) then |
||
4222 | --If the command is a standard simple command, then just execute it |
||
4223 | curCommand.comfunc(); |
||
4224 | return; |
||
4225 | end |
||
4226 | |||
4227 | --If we didn't find any valid commands we print out the help |
||
4228 | local infoText = MCom.PrintSlashCommandInfo(commandid, true); |
||
4229 | MCom.textFrame( { text = infoText; title = MCOM_HELP_GENERIC_TITLE; } ); |
||
4230 | end |
||
4231 | end; |
||
4232 | |||
4233 | --[[ Either prints out, or adds to a string the current chat line ]]-- |
||
4234 | MCom.PrintSlashCommandLine = function ( asString, chatLine, extraLine ) |
||
4235 | --If it's supposed to be in a string then add this to the string |
||
4236 | if ( asString ) then |
||
4237 | --If it isn't a string yet, then just set it to this line |
||
4238 | if ( type(asString) ~= "string" ) then |
||
4239 | asString = chatLine; |
||
4240 | else |
||
4241 | --It's already a string so add a newline and then this line |
||
4242 | if (extraLine) then |
||
4243 | asString = asString.."\n\n"..chatLine |
||
4244 | else |
||
4245 | asString = asString.."\n"..chatLine |
||
4246 | end |
||
4247 | end |
||
4248 | --Return the string |
||
4249 | return asString; |
||
4250 | else |
||
4251 | --Print out the chat line |
||
4252 | MCom.IO.printc(ChatTypeInfo["SYSTEM"], chatLine); |
||
4253 | end |
||
4254 | end |
||
4255 | |||
4256 | --[[ Prints the help for a chat command ]]-- |
||
4257 | MCom.PrintSlashCommandInfo = function (commandid, asString) |
||
4258 | if (MCom.SlashComs[commandid]) then |
||
4259 | local chatLine = ""; --The current line of text to be printed |
||
4260 | local basecommand = MCom.SlashComs[commandid].basecommand[1]; |
||
4261 | |||
4262 | --Construct a list of the aliases for the command, if any |
||
4263 | local aliasList = ""; |
||
4264 | if (getn(MCom.SlashComs[commandid].basecommand) > 1) then |
||
4265 | for curCom = 2, getn(MCom.SlashComs[commandid].basecommand) do |
||
4266 | if (aliasList ~= "") then |
||
4267 | aliasList = aliasList..", "; |
||
4268 | else |
||
4269 | aliasList = basecommand..", "; |
||
4270 | end |
||
4271 | aliasList = aliasList..MCom.SlashComs[commandid].basecommand[curCom]; |
||
4272 | end |
||
4273 | end |
||
4274 | |||
4275 | --Print list of aliases, if there are any |
||
4276 | if (aliasList ~= "") then |
||
4277 | chatLine = string.format(MCOM_CHAT_COM_ALIAS, aliasList); |
||
4278 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4279 | end |
||
4280 | |||
4281 | local isSimple = true; --Set true if this command does not have sub commands |
||
4282 | local eSample = nil; --Set to something if a simple command is found |
||
4283 | local bSample = nil; --Set to something if a bool command is found |
||
4284 | local nSample = nil; --Set to something if a num command is found |
||
4285 | local nSampleV = nil; --Set to and example value for a number command |
||
4286 | local sSample = nil; --Set to something if a string command is found |
||
4287 | local cSample = nil; --Set to something if a choice command is found |
||
4288 | local cnSampleV = nil; --Set to and example value for a choice command |
||
4289 | local cmSample = nil; --Set to something if a multi choice command is found |
||
4290 | local cmnSampleV = nil; --Set to and example value for a multi choice command |
||
4291 | local koSample = nil; --Set to something if a color with opacity command is found |
||
4292 | local bnSample = nil; --Set to something if a bool and num command is found |
||
4293 | local bnSampleV = nil; --Set to and example value for a bool and number command |
||
4294 | local bsSample = nil; --Set to something if a bool and string command is found |
||
4295 | local bcSample = nil; --Set to something if a bool and choice command is found |
||
4296 | local bcnSampleV = nil; --Set to and example value for a bool and choice command |
||
4297 | local bcmSample = nil; --Set to something if a bool and multi choice command is found |
||
4298 | local bcmnSampleV = nil; --Set to and example value for a bool and multi choice command |
||
4299 | local bkoSample = nil; --Set to something if a bool and color with opacity command is found |
||
4300 | |||
4301 | --If this command has sub commands, then print a list of them |
||
4302 | if (MCom.SlashComs[commandid].commands) then |
||
4303 | asString = MCom.PrintSlashCommandLine(asString, MCOM_CHAT_COM_COMMANDS, true); |
||
4304 | isSimple = nil; --This is not a simple command, lets remember that |
||
4305 | for curCom = 1, getn(MCom.SlashComs[commandid].commands) do |
||
4306 | local curComType = MCOM_SIMPLET; --Default our type to simple |
||
4307 | local curComBool = false; --Default has bool to false |
||
4308 | local curComChoices = nil; --The choices for a choice type |
||
4309 | local curComMulti = false; --Default multi choice to false |
||
4310 | local curComOpacity = false; --Default has opacity to false |
||
4311 | local curComValue = nil; --The value of the variable associated with the command |
||
4312 | local curComValueMulti = nil; --The value of the multi variable associated with the command |
||
4313 | local curComMin = nil; --The minimum a value can be set to |
||
4314 | local curComMax = nil; --The maximum a value can be set to |
||
4315 | local curComMul = 1; --The value to multiply numbers by when showing status |
||
4316 | --If a type is specified look it up |
||
4317 | if (MCom.SlashComs[commandid].commands[curCom].comtype) then |
||
4318 | curComType = MCom.SlashComs[commandid].commands[curCom].comtype; |
||
4319 | end |
||
4320 | --If a hasbool is specified look it up |
||
4321 | if (MCom.SlashComs[commandid].commands[curCom].hasbool) then |
||
4322 | curComBool = true; |
||
4323 | end |
||
4324 | --If choices are specified look them up |
||
4325 | if (MCom.SlashComs[commandid].commands[curCom].choices) then |
||
4326 | curComChoices = MCom.SlashComs[commandid].commands[curCom].choices; |
||
4327 | end |
||
4328 | --If a multichoioce is specified look it up |
||
4329 | if (MCom.SlashComs[commandid].commands[curCom].multichoice) then |
||
4330 | curComMulti = true; |
||
4331 | end |
||
4332 | --If a hasopacity is specified look it up |
||
4333 | if (MCom.SlashComs[commandid].commands[curCom].hasopacity) then |
||
4334 | curComOpacity = MCom.SlashComs[commandid].commands[curCom].hasopacity; |
||
4335 | end |
||
4336 | --If a comvar is specified look it up |
||
4337 | if (MCom.SlashComs[commandid].commands[curCom].comvar ~= nil) then |
||
4338 | curComValue = MCom.getStringVar(MCom.SlashComs[commandid].commands[curCom].comvar); |
||
4339 | end |
||
4340 | --If a comvarmulti is specified look it up |
||
4341 | if (MCom.SlashComs[commandid].commands[curCom].comvarmulti ~= nil) then |
||
4342 | curComValueMulti = MCom.getStringVar(MCom.SlashComs[commandid].commands[curCom].comvarmulti); |
||
4343 | end |
||
4344 | --If a commin is specified look it up |
||
4345 | if (MCom.SlashComs[commandid].commands[curCom].commin ~= nil) then |
||
4346 | curComMin = MCom.SlashComs[commandid].commands[curCom].commin; |
||
4347 | end |
||
4348 | --If a commax is specified look it up |
||
4349 | if (MCom.SlashComs[commandid].commands[curCom].commax ~= nil) then |
||
4350 | curComMax = MCom.SlashComs[commandid].commands[curCom].commax; |
||
4351 | end |
||
4352 | --If a commul is specified look it up |
||
4353 | if (MCom.SlashComs[commandid].commands[curCom].commul ~= nil) then |
||
4354 | curComMul = MCom.SlashComs[commandid].commands[curCom].commul; |
||
4355 | end |
||
4356 | |||
4357 | --Store this command as a sample of whatever type it is |
||
4358 | if ((not eSample) and (curComType == MCOM_SIMPLET)) then |
||
4359 | eSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4360 | end |
||
4361 | if ((not bSample) and (curComType == MCOM_BOOLT)) then |
||
4362 | bSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4363 | end |
||
4364 | if (not curComBool) then |
||
4365 | if ((not nSample) and (curComType == MCOM_NUMT)) then |
||
4366 | nSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4367 | --Get a valid sample number |
||
4368 | nSampleV = curComMin; |
||
4369 | if (not nSampleV) then |
||
4370 | nSampleV = curComMax; |
||
4371 | end |
||
4372 | if (not nSampleV) then |
||
4373 | nSampleV = MCOM_CHAT_COM_EXAMPLE_O_N; |
||
4374 | end |
||
4375 | end |
||
4376 | if ((not sSample) and (curComType == MCOM_STRINGT)) then |
||
4377 | sSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4378 | end |
||
4379 | if (not curComMulti) then |
||
4380 | if ((not cSample) and (curComType == MCOM_CHOICET)) then |
||
4381 | cSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4382 | --Get a valid sample choice |
||
4383 | for sampleV in curComChoices do |
||
4384 | cSampleV = sampleV; |
||
4385 | break; |
||
4386 | end |
||
4387 | end |
||
4388 | else |
||
4389 | if ((not cmSample) and (curComType == MCOM_CHOICET)) then |
||
4390 | cmSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4391 | --Get a valid sample choice |
||
4392 | local count = 0; |
||
4393 | --Construct an example with two valid choices |
||
4394 | for sampleV in curComChoices do |
||
4395 | count = count + 1; |
||
4396 | if (cmSampleV) then |
||
4397 | cmSampleV = cmSampleV.." "..sampleV; |
||
4398 | else |
||
4399 | cmSampleV = sampleV; |
||
4400 | end |
||
4401 | if (count > 1) then |
||
4402 | break; |
||
4403 | end |
||
4404 | end |
||
4405 | end |
||
4406 | end |
||
4407 | if (not curComOpacity) then |
||
4408 | if ((not kSample) and (curComType == MCOM_COLORT)) then |
||
4409 | kSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4410 | end |
||
4411 | else |
||
4412 | if ((not koSample) and (curComType == MCOM_COLORT)) then |
||
4413 | koSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4414 | end |
||
4415 | end |
||
4416 | else |
||
4417 | if ((not bnSample) and ((curComType == MCOM_NUMT) or (curComType == MCOM_MULTIT))) then |
||
4418 | bnSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4419 | --Get a valid sample number |
||
4420 | bnSampleV = curComMin; |
||
4421 | if (not bnSampleV) then |
||
4422 | bnSampleV = curComMax; |
||
4423 | end |
||
4424 | if (not bnSampleV) then |
||
4425 | bnSampleV = MCOM_CHAT_COM_EXAMPLE_O_N; |
||
4426 | end |
||
4427 | end |
||
4428 | if ((not bsSample) and (curComType == MCOM_STRINGT)) then |
||
4429 | bsSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4430 | end |
||
4431 | if (not curComMulti) then |
||
4432 | if ((not bcSample) and (curComType == MCOM_CHOICET)) then |
||
4433 | bcSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4434 | --Get a valid sample choice |
||
4435 | for sampleV in curComChoices do |
||
4436 | bcSampleV = sampleV; |
||
4437 | break; |
||
4438 | end |
||
4439 | end |
||
4440 | else |
||
4441 | if ((not bcmSample) and (curComType == MCOM_CHOICET)) then |
||
4442 | bcmSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4443 | --Get a valid sample choice |
||
4444 | local count = 0; |
||
4445 | --Construct an example with two valid choices |
||
4446 | for sampleV in curComChoices do |
||
4447 | count = count + 1; |
||
4448 | if (bcmSampleV) then |
||
4449 | bcmSampleV = bcmSampleV.." "..sampleV; |
||
4450 | else |
||
4451 | bcmSampleV = sampleV; |
||
4452 | end |
||
4453 | if (count > 1) then |
||
4454 | break; |
||
4455 | end |
||
4456 | end |
||
4457 | end |
||
4458 | end |
||
4459 | if (not curComOpacity) then |
||
4460 | if ((not bkSample) and (curComType == MCOM_COLORT)) then |
||
4461 | bkSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4462 | end |
||
4463 | else |
||
4464 | if ((not bkoSample) and (curComType == MCOM_COLORT)) then |
||
4465 | bkoSample = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4466 | end |
||
4467 | end |
||
4468 | end |
||
4469 | |||
4470 | --If help was specified look it up |
||
4471 | local curHelp = MCOM_CHAT_COM_NOINFO; |
||
4472 | if (MCom.SlashComs[commandid].commands[curCom].comhelp) then |
||
4473 | curHelp = MCom.SlashComs[commandid].commands[curCom].comhelp; |
||
4474 | end |
||
4475 | --If we have a choice type, then make a list of the choices, and tack that onto the help |
||
4476 | if ( curComType == MCOM_CHOICET ) then |
||
4477 | if (curHelp == MCOM_CHAT_COM_NOINFO) then |
||
4478 | curHelp = MCOM_CHAT_COM_CLIST; |
||
4479 | end |
||
4480 | local curChoices = nil; |
||
4481 | for curChoice in curComChoices do |
||
4482 | if (curChoices) then |
||
4483 | curChoices = curChoices..", "..curChoice; |
||
4484 | else |
||
4485 | curChoices = curChoice; |
||
4486 | end |
||
4487 | end |
||
4488 | curHelp = string.format(curHelp, curChoices); |
||
4489 | end |
||
4490 | |||
4491 | --If we have aliases for this sub command then make a list |
||
4492 | local comList = MCom.SlashComs[commandid].commands[curCom].command[1]; |
||
4493 | if (getn(MCom.SlashComs[commandid].commands[curCom].command) > 1) then |
||
4494 | for curAlias = 2, getn(MCom.SlashComs[commandid].commands[curCom].command) do |
||
4495 | comList = comList.."/"..MCom.SlashComs[commandid].commands[curCom].command[curAlias]; |
||
4496 | end |
||
4497 | end |
||
4498 | |||
4499 | --Prepare the type string |
||
4500 | local curComTypeString = curComType; |
||
4501 | if ( curComType == MCOM_MULTIT ) then |
||
4502 | curComTypeString = MCOM_NUMT; |
||
4503 | end |
||
4504 | if ( curComMulti and (curComType == MCOM_CHOICET) ) then |
||
4505 | curComTypeString = MCOM_CHAT_C_M; |
||
4506 | end |
||
4507 | if ( curComOpacity and (curComType == MCOM_COLORT) ) then |
||
4508 | curComTypeString = MCOM_CHAT_K_O; |
||
4509 | end |
||
4510 | if ( curComBool and (not (curComType == MCOM_BOOLT) ) ) then |
||
4511 | curComTypeString = MCOM_BOOLT..curComTypeString; |
||
4512 | end |
||
4513 | --If we have a number type, then display the min and max values |
||
4514 | if ( ( curComType == MCOM_NUMT ) or ( curComType == MCOM_MULTIT ) ) then |
||
4515 | local curRangeString = nil; |
||
4516 | if (curComMin) then |
||
4517 | curRangeString = string.format(MCOM_CHAT_COM_N_MIN, curComMin * curComMul); |
||
4518 | end |
||
4519 | if (curComMax) then |
||
4520 | if (curRangeString) then |
||
4521 | curRangeString = curRangeString..", "; |
||
4522 | else |
||
4523 | curRangeString = ""; |
||
4524 | end |
||
4525 | curRangeString = curRangeString..string.format(MCOM_CHAT_COM_N_MAX, curComMax * curComMul); |
||
4526 | end |
||
4527 | if (curRangeString) then |
||
4528 | curComTypeString = curComTypeString..string.format(MCOM_CHAT_COM_N_RANGE, curRangeString); |
||
4529 | end |
||
4530 | end |
||
4531 | |||
4532 | --Prepare the command info |
||
4533 | local curValString = nil; |
||
4534 | if ( ( curComType == MCOM_SIMPLET ) or ( curComValue == nil ) ) then |
||
4535 | chatLine = string.format(MCOM_CHAT_COM_SUBCOMMAND_S, comList, curComTypeString, curHelp); |
||
4536 | elseif ( curComValue ~= nil ) then |
||
4537 | --If it is a bool, or has a bool, then get the boolean part |
||
4538 | if ( curComBool or ( curComType == MCOM_BOOLT ) ) then |
||
4539 | if ( curComValue == 1 ) then |
||
4540 | curValString = MCOM_CHAT_ON; |
||
4541 | else |
||
4542 | curValString = MCOM_CHAT_OFF; |
||
4543 | end |
||
4544 | end |
||
4545 | --If this doesn't have a boolean part, then handle curcomvalue |
||
4546 | if (not curComBool) then |
||
4547 | --Handle number type |
||
4548 | if ( ( curComType == MCOM_NUMT ) or ( curComType == MCOM_MULTIT ) ) then |
||
4549 | curValString = ( MCom.math.round( ( curComValue * curComMul ) * 100 ) / 100 ); |
||
4550 | end |
||
4551 | --Handle string type |
||
4552 | if ( curComType == MCOM_STRINGT ) then |
||
4553 | curValString = curComValue; |
||
4554 | end |
||
4555 | --If it's a choice type, then handle the one choice, or a list of choices |
||
4556 | if (curComType == MCOM_CHOICET) then |
||
4557 | --If we don't have a table of choices, then just use the values |
||
4558 | if ( type(curComChoices) ~= "table" ) then |
||
4559 | --If this can not have multiple choices, then use just the one |
||
4560 | if (not curComMulti) then |
||
4561 | curValString = curComValue; |
||
4562 | elseif ( type(curComValue) == "table" ) then |
||
4563 | --This is a multi choice selection, so make a list of selected choices |
||
4564 | curValString = curComValue[1]; |
||
4565 | if ( curValString ~= nil ) then |
||
4566 | for curVal = 2, table.getn(curComValue) do |
||
4567 | if ( curComValue[curVal] ~= nil ) then |
||
4568 | curValString = curValString..", "..curComValue[curVal]; |
||
4569 | end |
||
4570 | end |
||
4571 | end |
||
4572 | end |
||
4573 | else |
||
4574 | --If we have a table of choices, then make a table indexed by value |
||
4575 | local curChoiceDex = {}; |
||
4576 | for curChoice in curComChoices do |
||
4577 | curChoiceDex[curComChoices[curChoice]] = curChoice; |
||
4578 | end |
||
4579 | --If this can not have multiple choices, then use just the one |
||
4580 | if (not curComMulti) then |
||
4581 | curValString = curChoiceDex[curComValue]; |
||
4582 | elseif ( type(curComValue) == "table" ) then |
||
4583 | --This is a multi choice selection, so make a list of selected choices |
||
4584 | curValString = curChoiceDex[curComValue[1]]; |
||
4585 | if ( curValString ~= nil ) then |
||
4586 | for curVal = 2, table.getn(curComValue) do |
||
4587 | if ( ( curComValue[curVal] ~= nil ) and ( curChoiceDex[curComValue[curVal]] ~= nil ) ) then |
||
4588 | curValString = curValString..", "..curChoiceDex[curComValue[curVal]]; |
||
4589 | end |
||
4590 | end |
||
4591 | end |
||
4592 | end |
||
4593 | end |
||
4594 | end |
||
4595 | --If it's a color type, then handle the color parts |
||
4596 | if (curComType == MCOM_COLORT) then |
||
4597 | if ( type(curComValue) == "table" ) then |
||
4598 | local curColString = ""; |
||
4599 | if (curComValue.r) then |
||
4600 | curColString = string.format(MCOM_CHAT_COM_K_R, MCom.math.round(curComValue.r * 100)); |
||
4601 | end |
||
4602 | if (curComValue.g) then |
||
4603 | if ( curColString ~= "" ) then |
||
4604 | curColString = curColString..", "; |
||
4605 | end |
||
4606 | curColString = curColString..string.format(MCOM_CHAT_COM_K_G, MCom.math.round(curComValue.g * 100)); |
||
4607 | end |
||
4608 | if (curComValue.b) then |
||
4609 | if ( curColString ~= "" ) then |
||
4610 | curColString = curColString..", "; |
||
4611 | end |
||
4612 | curColString = curColString..string.format(MCOM_CHAT_COM_K_B, MCom.math.round(curComValue.b * 100)); |
||
4613 | end |
||
4614 | if (curComOpacity) then |
||
4615 | local displayOpacity = 1; |
||
4616 | if (curComValue.opacity) then |
||
4617 | displayOpacity = curComValue.opacity; |
||
4618 | end |
||
4619 | if ( curColString ~= "" ) then |
||
4620 | curColString = curColString..", "; |
||
4621 | end |
||
4622 | curColString = curColString..string.format(MCOM_CHAT_COM_K_O, MCom.math.round(displayOpacity * 100)); |
||
4623 | end |
||
4624 | if ( curColString ~= "" ) then |
||
4625 | curColString = curColString..", "; |
||
4626 | end |
||
4627 | curColString = curColString..string.format(MCOM_CHAT_COM_K_X, MCom.string.colorToString(curComValue)); |
||
4628 | curValString = curColString; |
||
4629 | end |
||
4630 | end |
||
4631 | elseif ( curComValueMulti ~= nil ) then |
||
4632 | --If we have a second variable, then prepare the second part of the string |
||
4633 | if ( curValString == nil ) then |
||
4634 | curValString = ""; |
||
4635 | else |
||
4636 | curValString = curValString..", "; |
||
4637 | end |
||
4638 | --Handle number type |
||
4639 | if ( ( curComType == MCOM_NUMT ) or ( curComType == MCOM_MULTIT ) ) then |
||
4640 | curValString = curValString..( MCom.math.round( ( curComValueMulti * curComMul ) * 100 ) / 100 ); |
||
4641 | end |
||
4642 | --Handle string type |
||
4643 | if ( curComType == MCOM_STRINGT ) then |
||
4644 | curValString = curValString..curComValueMulti; |
||
4645 | end |
||
4646 | --If it's a choice type, then handle the one choice, or a list of choices |
||
4647 | if (curComType == MCOM_CHOICET) then |
||
4648 | --If we don't have a table of choices, then just use the values |
||
4649 | if ( type(curComChoices) ~= "table" ) then |
||
4650 | --If this can not have multiple choices, then use just the one |
||
4651 | if (not curComMulti) then |
||
4652 | curValString = curValString..curComValueMulti; |
||
4653 | elseif ( type(curComValueMulti) == "table" ) then |
||
4654 | --This is a multi choice selection, so make a list of selected choices |
||
4655 | curValString = curValString..curComValueMulti[1]; |
||
4656 | if ( curComValueMulti[1] ~= nil ) then |
||
4657 | for curVal = 2, table.getn(curComValueMulti) do |
||
4658 | if ( curComValueMulti[curVal] ~= nil ) then |
||
4659 | curValString = curValString..", "..curComValueMulti[curVal]; |
||
4660 | end |
||
4661 | end |
||
4662 | end |
||
4663 | end |
||
4664 | else |
||
4665 | --If we have a table of choices, then make a table indexed by value |
||
4666 | local curChoiceDex = {}; |
||
4667 | for curChoice in curComChoices do |
||
4668 | curChoiceDex[curComChoices[curChoice]] = curChoice; |
||
4669 | end |
||
4670 | --If this can not have multiple choices, then use just the one |
||
4671 | if (not curComMulti) then |
||
4672 | curValString = curValString..curChoiceDex[curComValueMulti]; |
||
4673 | elseif ( type(curComValueMulti) == "table" ) then |
||
4674 | --This is a multi choice selection, so make a list of selected choices |
||
4675 | curValString = curValString..curChoiceDex[curComValueMulti[1]]; |
||
4676 | if ( curChoiceDex[curComValueMulti[1]] ~= nil ) then |
||
4677 | for curVal = 2, table.getn(curComValueMulti) do |
||
4678 | if ( ( curComValueMulti[curVal] ~= nil ) and ( curChoiceDex[curComValueMulti[curVal]] ~= nil ) ) then |
||
4679 | curValString = curValString..", "..curChoiceDex[curComValueMulti[curVal]]; |
||
4680 | end |
||
4681 | end |
||
4682 | end |
||
4683 | end |
||
4684 | end |
||
4685 | end |
||
4686 | --If it's a color type, then handle the color parts |
||
4687 | if (curComType == MCOM_COLORT) then |
||
4688 | if ( type(curComValueMulti) == "table" ) then |
||
4689 | local curColString = ""; |
||
4690 | if (curComValueMulti.r) then |
||
4691 | curColString = string.format(MCOM_CHAT_COM_K_R, MCom.math.round(curComValueMulti.r * 100)); |
||
4692 | end |
||
4693 | if (curComValueMulti.g) then |
||
4694 | if ( curColString ~= "" ) then |
||
4695 | curColString = curColString.." "; |
||
4696 | end |
||
4697 | curColString = curColString..string.format( MCOM_CHAT_COM_K_G, MCom.math.round(curComValueMulti.g * 100)); |
||
4698 | end |
||
4699 | if (curComValueMulti.b) then |
||
4700 | if ( curColString ~= "" ) then |
||
4701 | curColString = curColString.." "; |
||
4702 | end |
||
4703 | curColString = curColString..string.format(MCOM_CHAT_COM_K_B, MCom.math.round(curComValueMulti.b * 100)); |
||
4704 | end |
||
4705 | if (curComOpacity) then |
||
4706 | if (curComValueMulti.opacity) then |
||
4707 | if ( curColString ~= "" ) then |
||
4708 | curColString = curColString.." "; |
||
4709 | end |
||
4710 | curColString = curColString..string.format(MCOM_CHAT_COM_K_O, MCom.math.round(curComValueMulti.opacity * 100)); |
||
4711 | end |
||
4712 | end |
||
4713 | if ( curColString ~= "" ) then |
||
4714 | curColString = curColString..", "; |
||
4715 | end |
||
4716 | curColString = curColString..string.format(MCOM_CHAT_COM_K_X, MCom.string.colorToString(curComValueMulti)); |
||
4717 | curValString = curValString..curColString; |
||
4718 | end |
||
4719 | end |
||
4720 | end |
||
4721 | if ( ( curValString ~= nil ) and ( curValString ~= "" ) and ( curValString ~= ", " ) ) then |
||
4722 | chatLine = string.format(MCOM_CHAT_COM_SUBCOMMAND, comList, curComTypeString, curValString, curHelp); |
||
4723 | else |
||
4724 | chatLine = string.format(MCOM_CHAT_COM_SUBCOMMAND_S, comList, curComTypeString, curHelp); |
||
4725 | end |
||
4726 | end |
||
4727 | |||
4728 | --Print out the command info |
||
4729 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4730 | end |
||
4731 | else |
||
4732 | --This is a simple command, find out what type it is, and set the correct sample |
||
4733 | if (MCom.SlashComs[commandid].comtype == MCOM_BOOLT) then |
||
4734 | bSample = true; |
||
4735 | else |
||
4736 | if (not MCom.SlashComs[commandid].hasbool) then |
||
4737 | if (MCom.SlashComs[commandid].comtype == MCOM_NUMT) then |
||
4738 | nSample = true; |
||
4739 | --Get a valid sample number |
||
4740 | nSampleV = MCom.SlashComs[commandid].commin; |
||
4741 | if (not nSampleV) then |
||
4742 | nSampleV = MCom.SlashComs[commandid].commax; |
||
4743 | end |
||
4744 | if (not nSampleV) then |
||
4745 | nSampleV = MCOM_CHAT_COM_EXAMPLE_O_N; |
||
4746 | end |
||
4747 | elseif (MCom.SlashComs[commandid].comtype == MCOM_STRINGT) then |
||
4748 | sSample = true; |
||
4749 | elseif (MCom.SlashComs[commandid].comtype == MCOM_CHOICET) then |
||
4750 | if (not MCom.SlashComs[commandid].multichoice) then |
||
4751 | cSample = true; |
||
4752 | --Get a valid sample choice |
||
4753 | for sampleV in MCom.SlashComs[commandid].choices do |
||
4754 | cSampleV = sampleV; |
||
4755 | break; |
||
4756 | end |
||
4757 | else |
||
4758 | cmSample = true; |
||
4759 | --Get a valid sample choice |
||
4760 | local count = 0; |
||
4761 | --Construct an example with two valid choices |
||
4762 | for sampleV in MCom.SlashComs[commandid].choices do |
||
4763 | count = count + 1; |
||
4764 | if (cmSampleV) then |
||
4765 | cmSampleV = cmSampleV.." "..sampleV; |
||
4766 | else |
||
4767 | cmSampleV = sampleV; |
||
4768 | end |
||
4769 | if (count > 1) then |
||
4770 | break; |
||
4771 | end |
||
4772 | end |
||
4773 | end |
||
4774 | elseif (MCom.SlashComs[commandid].comtype == MCOM_COLORT) then |
||
4775 | if (not MCom.SlashComs[commandid].hasopacity) then |
||
4776 | kSample = true; |
||
4777 | else |
||
4778 | okSample = true; |
||
4779 | end |
||
4780 | else |
||
4781 | eSample = true; |
||
4782 | end |
||
4783 | else |
||
4784 | if (MCom.SlashComs[commandid].comtype == MCOM_NUMT) then |
||
4785 | bnSample = true; |
||
4786 | elseif (MCom.SlashComs[commandid].comtype == MCOM_MULTIT) then |
||
4787 | bnSample = true; |
||
4788 | --Get a valid sample number |
||
4789 | bnSampleV = MCom.SlashComs[commandid].commin; |
||
4790 | if (not bnSampleV) then |
||
4791 | bnSampleV = MCom.SlashComs[commandid].commax; |
||
4792 | end |
||
4793 | if (not bnSampleV) then |
||
4794 | bnSampleV = MCOM_CHAT_COM_EXAMPLE_O_N; |
||
4795 | end |
||
4796 | elseif (MCom.SlashComs[commandid].comtype == MCOM_STRINGT) then |
||
4797 | bsSample = true; |
||
4798 | elseif (MCom.SlashComs[commandid].comtype == MCOM_CHOICET) then |
||
4799 | if (not MCom.SlashComs[commandid].multichoice) then |
||
4800 | bcSample = true; |
||
4801 | --Get a valid sample choice |
||
4802 | for sampleV in MCom.SlashComs[commandid].choices do |
||
4803 | bcSampleV = sampleV; |
||
4804 | break; |
||
4805 | end |
||
4806 | else |
||
4807 | bcmSample = true; |
||
4808 | --Get a valid sample choice |
||
4809 | local count = 0; |
||
4810 | --Construct an example with two valid choices |
||
4811 | for sampleV in MCom.SlashComs[commandid].choices do |
||
4812 | count = count + 1; |
||
4813 | if (bcmSampleV) then |
||
4814 | bcmSampleV = bcmSampleV.." "..sampleV; |
||
4815 | else |
||
4816 | bcmSampleV = sampleV; |
||
4817 | end |
||
4818 | if (count > 1) then |
||
4819 | break; |
||
4820 | end |
||
4821 | end |
||
4822 | end |
||
4823 | elseif (MCom.SlashComs[commandid].comtype == MCOM_COLORT) then |
||
4824 | if (not MCom.SlashComs[commandid].hasopacity) then |
||
4825 | bkSample = true; |
||
4826 | else |
||
4827 | bokSample = true; |
||
4828 | end |
||
4829 | else |
||
4830 | eSample = true; |
||
4831 | end |
||
4832 | end |
||
4833 | end |
||
4834 | end |
||
4835 | |||
4836 | --Print basic usage info |
||
4837 | local usageLine = MCOM_CHAT_COM_USAGE; |
||
4838 | if (bSample or bnSample or bsSample or bcSample or bcmSample or bkSample or bkoSample) then |
||
4839 | usageLine = usageLine.."\n\n"..MCOM_CHAT_COM_USAGE_B; |
||
4840 | end |
||
4841 | if (bnSample) then |
||
4842 | usageLine = usageLine.."\n\n"..string.format(MCOM_CHAT_COM_USAGE_B_M, MCOM_NUMT, MCOM_CHAT_COM_USAGE_B_N); |
||
4843 | elseif (bsSample) then |
||
4844 | usageLine = usageLine.."\n\n"..string.format(MCOM_CHAT_COM_USAGE_B_M, MCOM_STRINGT, MCOM_CHAT_COM_USAGE_B_S); |
||
4845 | elseif (bcSample or bcmSample) then |
||
4846 | usageLine = usageLine.."\n\n"..string.format(MCOM_CHAT_COM_USAGE_B_M, MCOM_CHOICET, MCOM_CHAT_COM_USAGE_B_C); |
||
4847 | elseif (bkSample or bkoSample) then |
||
4848 | usageLine = usageLine.."\n\n"..string.format(MCOM_CHAT_COM_USAGE_B_M, MCOM_COLORT, MCOM_CHAT_COM_USAGE_B_K); |
||
4849 | end |
||
4850 | asString = MCom.PrintSlashCommandLine(asString, usageLine, true); |
||
4851 | |||
4852 | --Print detailed usage info |
||
4853 | if (isSimple) then |
||
4854 | --If its simple we print the simple versions of the usage info, but only for the command type |
||
4855 | if (eSample) then |
||
4856 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_E, basecommand); |
||
4857 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4858 | end |
||
4859 | if (bSample) then |
||
4860 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_S, basecommand, MCOM_CHAT_COM_B); |
||
4861 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4862 | end |
||
4863 | if (nSample) then |
||
4864 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_S, basecommand, MCOM_CHAT_COM_N); |
||
4865 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4866 | end |
||
4867 | if (sSample) then |
||
4868 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_S, basecommand, MCOM_CHAT_COM_S); |
||
4869 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4870 | end |
||
4871 | if (cSample) then |
||
4872 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_S, basecommand, MCOM_CHAT_COM_C); |
||
4873 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4874 | end |
||
4875 | if (cmSample) then |
||
4876 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_S, basecommand, MCOM_CHAT_COM_C_M); |
||
4877 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4878 | end |
||
4879 | if (kSample) then |
||
4880 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_S, basecommand, MCOM_CHAT_COM_K); |
||
4881 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4882 | end |
||
4883 | if (koSample) then |
||
4884 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_S, basecommand, MCOM_CHAT_COM_K_O); |
||
4885 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4886 | end |
||
4887 | if (bnSample) then |
||
4888 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_M, basecommand, MCOM_CHAT_COM_N); |
||
4889 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4890 | end |
||
4891 | if (bsSample) then |
||
4892 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_M, basecommand, MCOM_CHAT_COM_S); |
||
4893 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4894 | end |
||
4895 | if (bcSample) then |
||
4896 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_M, basecommand, MCOM_CHAT_COM_C); |
||
4897 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4898 | end |
||
4899 | if (bcmSample) then |
||
4900 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_M, basecommand, MCOM_CHAT_COM_C_M); |
||
4901 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4902 | end |
||
4903 | if (bkSample) then |
||
4904 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_M, basecommand, MCOM_CHAT_COM_K); |
||
4905 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4906 | end |
||
4907 | if (bkoSample) then |
||
4908 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S_M, basecommand, MCOM_CHAT_COM_K_O); |
||
4909 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4910 | end |
||
4911 | else |
||
4912 | --If its not simple then we print usage info for any type of subcommand used |
||
4913 | if (eSample) then |
||
4914 | chatLine = string.format(MCOM_CHAT_COM_USAGE_E, basecommand); |
||
4915 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4916 | end |
||
4917 | if (bSample) then |
||
4918 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S, MCOM_BOOLT, basecommand, MCOM_CHAT_COM_B); |
||
4919 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4920 | end |
||
4921 | if (nSample) then |
||
4922 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S, MCOM_NUMT, basecommand, MCOM_CHAT_COM_N); |
||
4923 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4924 | end |
||
4925 | if (sSample) then |
||
4926 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S, MCOM_STRINGT, basecommand, MCOM_CHAT_COM_S); |
||
4927 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4928 | end |
||
4929 | if (cSample) then |
||
4930 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S, MCOM_CHOICET, basecommand, MCOM_CHAT_COM_C); |
||
4931 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4932 | end |
||
4933 | if (cmSample) then |
||
4934 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S, MCOM_CHAT_C_M, basecommand, MCOM_CHAT_COM_C_M); |
||
4935 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4936 | end |
||
4937 | if (kSample) then |
||
4938 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S, MCOM_COLORT, basecommand, MCOM_CHAT_COM_K); |
||
4939 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4940 | end |
||
4941 | if (koSample) then |
||
4942 | chatLine = string.format(MCOM_CHAT_COM_USAGE_S, MCOM_CHAT_K_O, basecommand, MCOM_CHAT_COM_K_O); |
||
4943 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4944 | end |
||
4945 | if (bnSample) then |
||
4946 | chatLine = string.format(MCOM_CHAT_COM_USAGE_M, MCOM_BOOLT..MCOM_NUMT, basecommand, MCOM_CHAT_COM_N); |
||
4947 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4948 | end |
||
4949 | if (bsSample) then |
||
4950 | chatLine = string.format(MCOM_CHAT_COM_USAGE_M, MCOM_BOOLT..MCOM_STRINGT, basecommand, MCOM_CHAT_COM_S); |
||
4951 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4952 | end |
||
4953 | if (bcSample) then |
||
4954 | chatLine = string.format(MCOM_CHAT_COM_USAGE_M, MCOM_BOOLT..MCOM_CHOICET, basecommand, MCOM_CHAT_COM_C); |
||
4955 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4956 | end |
||
4957 | if (bcmSample) then |
||
4958 | chatLine = string.format(MCOM_CHAT_COM_USAGE_M, MCOM_BOOLT..MCOM_CHAT_C_M, basecommand, MCOM_CHAT_COM_C_M); |
||
4959 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4960 | end |
||
4961 | if (bkSample) then |
||
4962 | chatLine = string.format(MCOM_CHAT_COM_USAGE_M, MCOM_BOOLT..MCOM_COLORT, basecommand, MCOM_CHAT_COM_K); |
||
4963 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4964 | end |
||
4965 | if (bkoSample) then |
||
4966 | chatLine = string.format(MCOM_CHAT_COM_USAGE_M, MCOM_BOOLT..MCOM_CHAT_K_O, basecommand, MCOM_CHAT_COM_K_M); |
||
4967 | asString = MCom.PrintSlashCommandLine(asString, chatLine, true); |
||
4968 | end |
||
4969 | end |
||
4970 | |||
4971 | --Print extra help for the command |
||
4972 | if (MCom.SlashComs[commandid].extrahelp) then |
||
4973 | if (type(MCom.SlashComs[commandid].extrahelp) ~= "table") then |
||
4974 | MCom.SlashComs[commandid].extrahelp = { MCom.SlashComs[commandid].extrahelp }; |
||
4975 | end |
||
4976 | --Add an extra line before the extra help |
||
4977 | if (asString) then |
||
4978 | asString = asString.."\n"; |
||
4979 | end |
||
4980 | for curHelp in MCom.SlashComs[commandid].extrahelp do |
||
4981 | asString = MCom.PrintSlashCommandLine(asString, MCom.SlashComs[commandid].extrahelp[curHelp]); |
||
4982 | end |
||
4983 | end |
||
4984 | |||
4985 | --Print example usage |
||
4986 | asString = MCom.PrintSlashCommandLine(asString, MCOM_CHAT_COM_EXAMPLE, true); |
||
4987 | if (isSimple) then |
||
4988 | --If it's simple we print an example for the appropriate type |
||
4989 | if (eSample) then |
||
4990 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_E, basecommand); |
||
4991 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
4992 | end |
||
4993 | if (bSample) then |
||
4994 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_S, basecommand, MCOM_CHAT_COM_EXAMPLE_O_B); |
||
4995 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
4996 | end |
||
4997 | if (nSample) then |
||
4998 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_S, basecommand, nSampleV); |
||
4999 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5000 | end |
||
5001 | if (sSample) then |
||
5002 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_S, basecommand, MCOM_CHAT_COM_EXAMPLE_O_S); |
||
5003 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5004 | end |
||
5005 | if (cSample) then |
||
5006 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_S, basecommand, cSampleV); |
||
5007 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5008 | end |
||
5009 | if (cmSample) then |
||
5010 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_S, basecommand, cmSampleV); |
||
5011 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5012 | end |
||
5013 | if (kSample) then |
||
5014 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_S, basecommand, MCOM_CHAT_COM_EXAMPLE_O_K); |
||
5015 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5016 | end |
||
5017 | if (koSample) then |
||
5018 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_S, basecommand, MCOM_CHAT_COM_EXAMPLE_O_K_O); |
||
5019 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5020 | end |
||
5021 | if (bnSample) then |
||
5022 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_M, basecommand, bnSampleV); |
||
5023 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5024 | end |
||
5025 | if (bsSample) then |
||
5026 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_M, basecommand, MCOM_CHAT_COM_EXAMPLE_O_S); |
||
5027 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5028 | end |
||
5029 | if (bcSample) then |
||
5030 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_M, basecommand, bcSampleV); |
||
5031 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5032 | end |
||
5033 | if (bcmSample) then |
||
5034 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_M, basecommand, bcmSampleV); |
||
5035 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5036 | end |
||
5037 | if (bkSample) then |
||
5038 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_M, basecommand, MCOM_CHAT_COM_EXAMPLE_O_K); |
||
5039 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5040 | end |
||
5041 | if (bkoSample) then |
||
5042 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S_M, basecommand, MCOM_CHAT_COM_EXAMPLE_O_K_O); |
||
5043 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5044 | end |
||
5045 | else |
||
5046 | --If it's not simple we print an example for each type used |
||
5047 | if (eSample) then |
||
5048 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_E, basecommand, eSample); |
||
5049 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5050 | end |
||
5051 | if (bSample) then |
||
5052 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S, basecommand, bSample, MCOM_CHAT_COM_EXAMPLE_O_B); |
||
5053 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5054 | end |
||
5055 | if (nSample) then |
||
5056 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S, basecommand, nSample, nSampleV); |
||
5057 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5058 | end |
||
5059 | if (sSample) then |
||
5060 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S, basecommand, sSample, MCOM_CHAT_COM_EXAMPLE_O_S); |
||
5061 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5062 | end |
||
5063 | if (cSample) then |
||
5064 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S, basecommand, cSample, cSampleV); |
||
5065 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5066 | end |
||
5067 | if (cmSample) then |
||
5068 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S, basecommand, cmSample, cmSampleV); |
||
5069 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5070 | end |
||
5071 | if (kSample) then |
||
5072 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S, basecommand, kSample, MCOM_CHAT_COM_EXAMPLE_O_K); |
||
5073 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5074 | end |
||
5075 | if (koSample) then |
||
5076 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_S, basecommand, koSample, MCOM_CHAT_COM_EXAMPLE_O_K_O); |
||
5077 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5078 | end |
||
5079 | if (bnSample) then |
||
5080 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_M, basecommand, bnSample, bnSampleV); |
||
5081 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5082 | end |
||
5083 | if (bsSample) then |
||
5084 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_M, basecommand, bsSample, MCOM_CHAT_COM_EXAMPLE_O_S); |
||
5085 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5086 | end |
||
5087 | if (bcSample) then |
||
5088 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_M, basecommand, bcSample, bcSampleV); |
||
5089 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5090 | end |
||
5091 | if (bcmSample) then |
||
5092 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_M, basecommand, bcmSample, bcmSampleV); |
||
5093 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5094 | end |
||
5095 | if (bkSample) then |
||
5096 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_M, basecommand, bkSample, MCOM_CHAT_COM_EXAMPLE_O_K); |
||
5097 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5098 | end |
||
5099 | if (bkoSample) then |
||
5100 | chatLine = string.format(MCOM_CHAT_COM_EXAMPLE_M, basecommand, bkoSample, MCOM_CHAT_COM_EXAMPLE_O_K_O); |
||
5101 | asString = MCom.PrintSlashCommandLine(asString, chatLine); |
||
5102 | end |
||
5103 | end |
||
5104 | end |
||
5105 | --Return the string |
||
5106 | return asString; |
||
5107 | end; |
||
5108 | |||
5109 | --[[ The Cosmos callback function handler ]]-- |
||
5110 | MCom.SetFromUI = function (option, checked, value) |
||
5111 | if (not MCom.UIFuncList) then |
||
5112 | MCom.UIFuncList = {}; |
||
5113 | end |
||
5114 | |||
5115 | --Get the info for this function |
||
5116 | local funcInfo = MCom.UIFuncList[option]; |
||
5117 | if (funcInfo) then |
||
5118 | local func = funcInfo.func; |
||
5119 | local funcType = funcInfo.uitype; |
||
5120 | --Call the appropriate kind of function for this kind of element |
||
5121 | if (func and funcType) then |
||
5122 | if (funcType == "CHECKBOX") then |
||
5123 | func(checked); |
||
5124 | elseif (funcType == "SLIDER") then |
||
5125 | func(value); |
||
5126 | elseif (funcType == "BOTH") then |
||
5127 | func(checked, value); |
||
5128 | else |
||
5129 | func(); |
||
5130 | end |
||
5131 | end |
||
5132 | end |
||
5133 | end; |
||
5134 | |||
5135 | --[[ The Khaos callback function handler ]]-- |
||
5136 | MCom.SetFromKUI = function (option, state, keypressed, choices) |
||
5137 | if (not MCom.UIFuncList) then |
||
5138 | MCom.UIFuncList = {}; |
||
5139 | end |
||
5140 | |||
5141 | --Get the info for this function |
||
5142 | local funcInfo = MCom.UIFuncList[option]; |
||
5143 | if (funcInfo) then |
||
5144 | local func = funcInfo.func; |
||
5145 | local funcType = funcInfo.uitype; |
||
5146 | |||
5147 | --split into hasbool and not hasbool sections. |
||
5148 | |||
5149 | --Call the appropriate kind of function for this kind of element |
||
5150 | if (func and funcType) then |
||
5151 | local checked = nil; |
||
5152 | if (funcInfo.hasbool) then |
||
5153 | checked = 0; |
||
5154 | if (state and state.checked) then |
||
5155 | checked = 1; |
||
5156 | end |
||
5157 | end |
||
5158 | |||
5159 | local value = nil; |
||
5160 | local name = nil; |
||
5161 | --If it's a bool then call it as such |
||
5162 | if ((funcType == K_TEXT) and funcInfo.hasbool) then |
||
5163 | func(checked); |
||
5164 | else |
||
5165 | --Handle the value from the right variable for this type |
||
5166 | if (funcType == K_SLIDER) then |
||
5167 | value = state.slider; |
||
5168 | elseif ( funcType == K_EDITBOX ) then |
||
5169 | value = state.value; |
||
5170 | elseif (funcType == K_PULLDOWN) then |
||
5171 | value = state.value; |
||
5172 | --If we don't have a table of choices, then just use the values |
||
5173 | if ( type(choices) ~= "table" ) then |
||
5174 | --If this can not have multiple choices, then use just the one |
||
5175 | if ( type(value) ~= "table" ) then |
||
5176 | name = value; |
||
5177 | else |
||
5178 | --This is a multi choice selection, so make a list of selected choices |
||
5179 | name = value[1]; |
||
5180 | if ( name ~= nil ) then |
||
5181 | for curVal = 2, table.getn(value) do |
||
5182 | if ( value[curVal] ~= nil ) then |
||
5183 | name = name..", "..value[curVal]; |
||
5184 | end |
||
5185 | end |
||
5186 | end |
||
5187 | end |
||
5188 | else |
||
5189 | --If we have a table of choices, then make a table indexed by value |
||
5190 | local curChoiceDex = {}; |
||
5191 | for curChoice in choices do |
||
5192 | curChoiceDex[choices[curChoice]] = curChoice; |
||
5193 | end |
||
5194 | --If this can not have multiple choices, then use just the one |
||
5195 | if ( type(value) ~= "table" ) then |
||
5196 | name = curChoiceDex[value]; |
||
5197 | else |
||
5198 | --This is a multi choice selection, so make a list of selected choices |
||
5199 | name = curChoiceDex[value[1]]; |
||
5200 | if ( name ~= nil ) then |
||
5201 | for curVal = 2, table.getn(value) do |
||
5202 | if ( ( value[curVal] ~= nil ) and ( curChoiceDex[value[curVal]] ~= nil ) ) then |
||
5203 | name = name..", "..curChoiceDex[value[curVal]]; |
||
5204 | end |
||
5205 | end |
||
5206 | end |
||
5207 | end |
||
5208 | end |
||
5209 | elseif (funcType == K_COLORPICKER) then |
||
5210 | value = state.color; |
||
5211 | end |
||
5212 | |||
5213 | --If it's a button, then just call it |
||
5214 | if (funcType == K_BUTTON) then |
||
5215 | func(); |
||
5216 | else |
||
5217 | --If it has a bool call it with the bool, and the value, otherwise, just the value |
||
5218 | if (funcInfo.hasbool) then |
||
5219 | func(checked, value, name); |
||
5220 | else |
||
5221 | func(value, name); |
||
5222 | end |
||
5223 | end |
||
5224 | end |
||
5225 | end |
||
5226 | end |
||
5227 | end; |
||
5228 | |||
5229 | -------------------------------------------------- |
||
5230 | -- |
||
5231 | -- Hooked Functions |
||
5232 | -- |
||
5233 | -------------------------------------------------- |
||
5234 | MCom.ItemTextPrevPage = function () |
||
5235 | --Switch to the previous page if there is one |
||
5236 | if ( type(MCom.CurText) == "table" ) then |
||
5237 | local TextFrame = "MComText"; |
||
5238 | if ( not getglobal(TextFrame.."Frame") ) then |
||
5239 | TextFrame = "ItemText"; |
||
5240 | end |
||
5241 | if ( MCom.CurTextPage > 1 ) then |
||
5242 | --Store the current position and range of the scrollbar so we can restore this, the next time the page is visited |
||
5243 | MCom.CurText.Scroll[MCom.CurTextPage].Value = getglobal(TextFrame.."ScrollFrameScrollBar"):GetValue(); |
||
5244 | MCom.CurText.Scroll[MCom.CurTextPage].Range = getglobal(TextFrame.."ScrollFrame"):GetVerticalScrollRange(); |
||
5245 | --Flip the page |
||
5246 | MCom.CurTextPage = MCom.CurTextPage - 1; |
||
5247 | --If a scroll range was recorded for this page, then adjust to those values |
||
5248 | if (MCom.CurText.Scroll[MCom.CurTextPage].Range) then |
||
5249 | getglobal(TextFrame.."ScrollFrameScrollBar"):SetMinMaxValues(0, MCom.CurText.Scroll[MCom.CurTextPage].Range); |
||
5250 | end |
||
5251 | --Update the page |
||
5252 | MCom.UpdateTextPage(); |
||
5253 | end |
||
5254 | else |
||
5255 | MCom.CurText = nil; |
||
5256 | end |
||
5257 | end; |
||
5258 | |||
5259 | MCom.ItemTextNextPage = function () |
||
5260 | --Switch to the previous page if there is one |
||
5261 | if ( type(MCom.CurText) == "table" ) then |
||
5262 | local TextFrame = "MComText"; |
||
5263 | if ( not getglobal(TextFrame.."Frame") ) then |
||
5264 | TextFrame = "ItemText"; |
||
5265 | end |
||
5266 | if ( MCom.CurTextPage < table.getn(MCom.CurText) ) then |
||
5267 | --Store the current position and range of the scrollbar so we can restore this, the next time the page is visited |
||
5268 | MCom.CurText.Scroll[MCom.CurTextPage].Value = getglobal(TextFrame.."ScrollFrameScrollBar"):GetValue(); |
||
5269 | MCom.CurText.Scroll[MCom.CurTextPage].Range = getglobal(TextFrame.."ScrollFrame"):GetVerticalScrollRange(); |
||
5270 | --Flip the page |
||
5271 | MCom.CurTextPage = MCom.CurTextPage + 1; |
||
5272 | --If a scroll range was recorded for this page, then adjust to those values |
||
5273 | if (MCom.CurText.Scroll[MCom.CurTextPage].Range) then |
||
5274 | getglobal(TextFrame.."ScrollFrameScrollBar"):SetMinMaxValues(0, MCom.CurText.Scroll[MCom.CurTextPage].Range); |
||
5275 | end |
||
5276 | --Update the page |
||
5277 | MCom.UpdateTextPage(); |
||
5278 | end |
||
5279 | else |
||
5280 | MCom.CurText = nil; |
||
5281 | end |
||
5282 | end; |
||
5283 | |||
5284 | --When the item text is closed, let's reset it to normal, and confirm that MCom |
||
5285 | --can now make use of it |
||
5286 | MCom.CloseItemText = function () |
||
5287 | local TextFrame = "MComText"; |
||
5288 | if ( not getglobal(TextFrame.."Frame") ) then |
||
5289 | TextFrame = "ItemText"; |
||
5290 | end |
||
5291 | MCom.CurText = nil; |
||
5292 | MCom.NoTextAvail = nil; |
||
5293 | --Remove the vertex color |
||
5294 | getglobal(TextFrame.."MaterialTopLeft"):SetVertexColor(1,1,1); |
||
5295 | getglobal(TextFrame.."MaterialTopRight"):SetVertexColor(1,1,1); |
||
5296 | getglobal(TextFrame.."MaterialBotLeft"):SetVertexColor(1,1,1); |
||
5297 | getglobal(TextFrame.."MaterialBotRight"):SetVertexColor(1,1,1); |
||
5298 | |||
5299 | --Resize the text to normal |
||
5300 | if (MCom.PageWidth and MCom.PageScale) then |
||
5301 | getglobal(TextFrame.."PageText"):SetWidth(MCom.PageWidth); |
||
5302 | getglobal(TextFrame.."PageText"):SetScale(MCom.PageScale); |
||
5303 | end |
||
5304 | end; |
||
5305 | |||
5306 | MCom.ItemTextFrame_OnEvent = function (event) |
||
5307 | --If the game is doing something with the text frame, then clear the MCom text |
||
5308 | --and set the frame as unavailable for MCom to use |
||
5309 | if ( ( event == "ITEM_TEXT_BEGIN" ) or ( event == "ITEM_TEXT_TRANSLATION" ) or |
||
5310 | ( event == "ITEM_TEXT_READY" ) ) then |
||
5311 | local TextFrame = "MComText"; |
||
5312 | if ( not getglobal(TextFrame.."Frame") ) then |
||
5313 | TextFrame = "ItemText"; |
||
5314 | MCom.CurText = nil; |
||
5315 | MCom.NoTextAvail = true; |
||
5316 | --Remove the vertex color |
||
5317 | getglobal(TextFrame.."MaterialTopLeft"):SetVertexColor(1,1,1); |
||
5318 | getglobal(TextFrame.."MaterialTopRight"):SetVertexColor(1,1,1); |
||
5319 | getglobal(TextFrame.."MaterialBotLeft"):SetVertexColor(1,1,1); |
||
5320 | getglobal(TextFrame.."MaterialBotRight"):SetVertexColor(1,1,1); |
||
5321 | |||
5322 | --Resize the text to normal |
||
5323 | if (MCom.PageWidth and MCom.PageScale) then |
||
5324 | getglobal(TextFrame.."PageText"):SetWidth(MCom.PageWidth); |
||
5325 | getglobal(TextFrame.."PageText"):SetScale(MCom.PageScale); |
||
5326 | end |
||
5327 | end |
||
5328 | end |
||
5329 | end; |
||
5330 | |||
5331 | MCom.myAddOnsFrame_OnEvent = function () |
||
5332 | --If this is variables loaded, then load in the MCom registered addons |
||
5333 | if (event == "VARIABLES_LOADED") then |
||
5334 | MCom.MyAddOnsLoaded = true; |
||
5335 | --If this vesion of myAddons supports the registration method, then use it |
||
5336 | if(myAddOnsFrame_Register) then |
||
5337 | for curAddon in MCom.MyAddOnsList do |
||
5338 | local help = nil; |
||
5339 | --If we have a table of help, then get a copy of it, and add the slash command help if available |
||
5340 | if ( type(MCom.MyAddOnsList[curAddon].help) == "table" ) then |
||
5341 | help = MCom.table.copy(MCom.MyAddOnsList[curAddon].help); |
||
5342 | if (MCom.MyAddOnsList[curAddon].supercom) then |
||
5343 | --Add the slash command info on to it |
||
5344 | help[table.getn(help) + 1] = MCom.PrintSlashCommandInfo(MCom.getComID(MCom.MyAddOnsList[curAddon].supercom), true); |
||
5345 | end |
||
5346 | elseif ( ( MCom.MyAddOnsList[curAddon].help == "boolean" ) and MCom.MyAddOnsList[curAddon].help and MCom.MyAddOnsList[curAddon].supercom ) then |
||
5347 | --If help is a boolean and we have slash command info, then generate the help from the slash command info |
||
5348 | help = MCom.PrintSlashCommandInfo(MCom.getComID(MCom.MyAddOnsList[curAddon].supercom), true); |
||
5349 | end |
||
5350 | -- Register the addon in myAddOns |
||
5351 | myAddOnsFrame_Register(MCom.MyAddOnsList[curAddon].details, help); |
||
5352 | end |
||
5353 | else |
||
5354 | --Use the old method of adding an addon to the list |
||
5355 | for curAddon in MCom.MyAddOnsList do |
||
5356 | myAddOnsList[curAddon] = MCom.MyAddOnsList[curAddon].details; |
||
5357 | end |
||
5358 | end |
||
5359 | end |
||
5360 | end; |
||
5361 | |||
5362 | MCom.UIParent_OnEvent = function () |
||
5363 | if ( event == "VARIABLES_LOADED" ) then |
||
5364 | if (not MCom.didVarsLoaded) then |
||
5365 | MCom.didVarsLoaded = true; |
||
5366 | --If we have anything that needs to be safe loaded, then load it now |
||
5367 | if ( type(MCom.safeLoads) == "table" ) then |
||
5368 | local curConfig; |
||
5369 | if ( type(MCom.safeLoads.varsLoaded) == "table" ) then |
||
5370 | --Load any safe load that has changed |
||
5371 | for curLoad in MCom.safeLoads.varsLoaded do |
||
5372 | --Get the variable for the current safe load |
||
5373 | curConfig = MCom.getStringVar(curLoad); |
||
5374 | --Load the stored data into the empty entries of the current config if the table has been replaced |
||
5375 | if ( ( type(curConfig) == "table" ) and ( curConfig ~= MCom.safeLoads.varsLoaded[curLoad] ) ) then |
||
5376 | MCom.LoadSafeTable( curConfig, MCom.safeLoads.varsLoaded[curLoad] ); |
||
5377 | end |
||
5378 | end |
||
5379 | end |
||
5380 | |||
5381 | --Deal with any old style entries |
||
5382 | for curLoad in MCom.safeLoads do |
||
5383 | if ( ( curLoad ~= "addonLoaded" ) and ( curLoad ~= "varsLoaded" ) ) then |
||
5384 | --Get the variable for the current safe load |
||
5385 | curConfig = MCom.getStringVar(curLoad); |
||
5386 | --Load the stored data into the empty entries of the current config |
||
5387 | if ( ( type(curConfig) == "table" ) ) then |
||
5388 | MCom.LoadSafeTable( curConfig, MCom.safeLoads[curLoad] ); |
||
5389 | end |
||
5390 | end |
||
5391 | end |
||
5392 | end |
||
5393 | |||
5394 | --Clear the safe loads table |
||
5395 | MCom.safeLoads = nil; |
||
5396 | |||
5397 | --If we are using this as the vars loaded event, then call the vars loaded callbacks |
||
5398 | if (MCom.UseVarsLoadedEvent) then |
||
5399 | MCom.VariablesLoaded(); |
||
5400 | end |
||
5401 | end |
||
5402 | end |
||
5403 | |||
5404 | if ( event == "ADDON_LOADED" ) then |
||
5405 | --If we have anything that needs to be safe loaded, then load it now |
||
5406 | if ( type(MCom.safeLoads) == "table" ) then |
||
5407 | local curConfig; |
||
5408 | if ( type(MCom.safeLoads.addonLoaded) == "table" ) then |
||
5409 | --Load any safe load that has changed |
||
5410 | for curLoad in MCom.safeLoads.addonLoaded do |
||
5411 | --Get the variable for the current safe load |
||
5412 | curConfig = MCom.getStringVar(curLoad); |
||
5413 | --Load the stored data into the empty entries of the current config if the table has been replaced |
||
5414 | if ( ( type(curConfig) == "table" ) and ( curConfig ~= MCom.safeLoads.addonLoaded[curLoad] ) ) then |
||
5415 | MCom.LoadSafeTable( curConfig, MCom.safeLoads.addonLoaded[curLoad] ); |
||
5416 | --Move the entry to the variables loaded table to be checked for loading once more |
||
5417 | MCom.safeLoads.varsLoaded[curLoad] = MCom.safeLoads.addonLoaded[curLoad]; |
||
5418 | MCom.safeLoads.addonLoaded[curLoad] = nil; |
||
5419 | end |
||
5420 | end |
||
5421 | end |
||
5422 | |||
5423 | --Deal with any old style entries |
||
5424 | for curLoad in MCom.safeLoads do |
||
5425 | if ( ( curLoad ~= "addonLoaded" ) and ( curLoad ~= "varsLoaded" ) ) then |
||
5426 | --Get the variable for the current safe load |
||
5427 | curConfig = MCom.getStringVar(curLoad); |
||
5428 | --Load the stored data into the empty entries of the current config |
||
5429 | if ( ( type(curConfig) == "table" ) ) then |
||
5430 | MCom.LoadSafeTable( curConfig, MCom.safeLoads[curLoad] ); |
||
5431 | end |
||
5432 | end |
||
5433 | end |
||
5434 | end |
||
5435 | end |
||
5436 | end |
||
5437 | |||
5438 | -------------------------------------------------- |
||
5439 | -- |
||
5440 | -- Sea Wrapper Functions |
||
5441 | -- |
||
5442 | -------------------------------------------------- |
||
5443 | --Wrappers used to ensure MCom functions without Sea, for those who just |
||
5444 | --absolutely refuse to use Sea |
||
5445 | MCom.math = {}; |
||
5446 | MCom.math.round = function (x) |
||
5447 | if (Sea and Sea.math and Sea.math.round) then |
||
5448 | --Call origional |
||
5449 | return Sea.math.round(x); |
||
5450 | else |
||
5451 | --Same as origional |
||
5452 | if(x - math.floor(x) > 0.5) then |
||
5453 | x = x + 0.5; |
||
5454 | end |
||
5455 | return math.floor(x); |
||
5456 | end |
||
5457 | end; |
||
5458 | |||
5459 | MCom.math.hexFromInt = function (intval, minlength) |
||
5460 | if (Sea and Sea.math and Sea.math.hexFromInt) then |
||
5461 | --Call origional |
||
5462 | return Sea.math.hexFromInt(intval, minlength); |
||
5463 | else |
||
5464 | --Same as origional |
||
5465 | if ( minlength == nil ) then |
||
5466 | minlength = "2"; |
||
5467 | end |
||
5468 | return string.format("%"..minlength.."x", intval ); |
||
5469 | end |
||
5470 | end; |
||
5471 | |||
5472 | MCom.table = {}; |
||
5473 | MCom.table.copy = function ( t, recursionList ) |
||
5474 | if (Sea and Sea.table and Sea.table.copy) then |
||
5475 | --Call origional |
||
5476 | return Sea.table.copy(t, recursionList); |
||
5477 | else |
||
5478 | --Same as origional |
||
5479 | if ( not recursionList ) then recursionList = {} end; |
||
5480 | if ( type(t) ~= "table" ) then |
||
5481 | return t; |
||
5482 | end |
||
5483 | |||
5484 | local newTable = {}; |
||
5485 | if ( recursionList[t] ) then |
||
5486 | return recursionList[t]; |
||
5487 | else |
||
5488 | recursionList[t] = newTable; |
||
5489 | for k,v in t do |
||
5490 | --If it's a table we want to recurse. But the second half of this if checks to see if it |
||
5491 | --is a reference to a frame, which looks like a table, and does a normal copy in such a |
||
5492 | --case |
||
5493 | if ( ( type(v) == "table" ) and not ( v[0] and ( type(v[0]) == "userdata" ) ) ) then |
||
5494 | newTable[k] = MCom.table.copy(v, recursionList); |
||
5495 | else |
||
5496 | newTable[k] = v; |
||
5497 | end |
||
5498 | end |
||
5499 | |||
5500 | return newTable; |
||
5501 | end |
||
5502 | end |
||
5503 | end; |
||
5504 | |||
5505 | MCom.table.push = function ( table, val ) |
||
5506 | if (Sea and Sea.table and Sea.table.copy) then |
||
5507 | --Call origional |
||
5508 | return Sea.table.push(table, val); |
||
5509 | else |
||
5510 | --Same as origional |
||
5511 | if(not table or not table.n) then |
||
5512 | return nil; |
||
5513 | end |
||
5514 | table.n = table.n+1; |
||
5515 | table[table.n] = val; |
||
5516 | end |
||
5517 | end; |
||
5518 | |||
5519 | MCom.IO = {}; |
||
5520 | MCom.IO.printc = function ( color, pString ) |
||
5521 | if (Sea and Sea.IO and Sea.IO.printc) then |
||
5522 | --Call origional |
||
5523 | Sea.IO.printc(color, pString); |
||
5524 | else |
||
5525 | --Simple colored print, not as capable as Sea's functions |
||
5526 | if ( color == nil ) then |
||
5527 | color = NORMAL_FONT_COLOR; |
||
5528 | end |
||
5529 | ChatFrame1:AddMessage(pString, color.r, color.g, color.b); |
||
5530 | end |
||
5531 | end; |
||
5532 | |||
5533 | MCom.util = {}; |
||
5534 | MCom.util.split = function ( text, separator, oldTable, noPurge ) |
||
5535 | if (Sea and Sea.util and Sea.util.split and Sea.version) then |
||
5536 | --Call origional |
||
5537 | return Sea.util.split( text, separator, oldTable, noPurge ); |
||
5538 | else |
||
5539 | --Using Legorols version |
||
5540 | local value; |
||
5541 | local init, mstart, mend = 1; |
||
5542 | local t, oldn = oldTable, 0; |
||
5543 | |||
5544 | if ( not t ) then |
||
5545 | t = {}; |
||
5546 | else |
||
5547 | oldn = table.getn(t); |
||
5548 | table.setn(t, 0); |
||
5549 | end |
||
5550 | |||
5551 | -- Using string.find instead of string.gfind to avoid garbage generation |
||
5552 | repeat |
||
5553 | mstart, mend, value = string.find(text, "([^"..separator.."]+)", init); |
||
5554 | if ( value ) then |
||
5555 | table.insert(t, value) |
||
5556 | init = mend + 1; |
||
5557 | end |
||
5558 | until not value; |
||
5559 | |||
5560 | if ( not noPurge ) then |
||
5561 | for i = table.getn(t)+1, oldn do |
||
5562 | t[i] = nil; |
||
5563 | end |
||
5564 | end |
||
5565 | |||
5566 | return t; |
||
5567 | end |
||
5568 | end; |
||
5569 | |||
5570 | MCom.util.hook = function (orig, new, hooktype, scriptElementName) |
||
5571 | if (Sea and Sea.util and Sea.util.hook and Sea.version and ( Sea.version >= 1.05 ) ) then |
||
5572 | Sea.util.hook(orig, new, hooktype, scriptElementName); |
||
5573 | else |
||
5574 | --Modified hook function from origional, uses Sea's hook list if available |
||
5575 | if (not MCom.util.Hooks) then |
||
5576 | MCom.util.Hooks = {}; |
||
5577 | end |
||
5578 | local hookList = MCom.util.Hooks; |
||
5579 | |||
5580 | --If Sea is around, then use it's list |
||
5581 | if (Sea and Sea.util and Sea.util.hook) then |
||
5582 | if(not Sea.util.Hooks) then |
||
5583 | Sea.util.Hooks = {}; |
||
5584 | end |
||
5585 | hookList = Sea.util.Hooks; |
||
5586 | end |
||
5587 | |||
5588 | local origCopy = orig; |
||
5589 | if (scriptElementName) then |
||
5590 | orig = orig.."."..scriptElementName; |
||
5591 | end |
||
5592 | |||
5593 | if(not hooktype) then |
||
5594 | hooktype = "before"; |
||
5595 | end |
||
5596 | if(not hookList[orig]) then |
||
5597 | hookList[orig] = {}; |
||
5598 | hookList[orig].before = {}; |
||
5599 | hookList[orig].before.n = 0; |
||
5600 | hookList[orig].after = {}; |
||
5601 | hookList[orig].after.n = 0; |
||
5602 | hookList[orig].hide = {}; |
||
5603 | hookList[orig].hide.n = 0; |
||
5604 | hookList[orig].replace = {}; |
||
5605 | hookList[orig].replace.n = 0; |
||
5606 | hookList[orig].orig = MCom.getStringVar(orig); |
||
5607 | -- Set up the hook the first time |
||
5608 | if (scriptElementName) then |
||
5609 | hookList[orig].orig = MCom.getStringVar(origCopy):GetScript(scriptElementName); |
||
5610 | MCom.getStringVar(origCopy):SetScript(scriptElementName, function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) return MCom.util.hookHandler(orig,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); end); |
||
5611 | else |
||
5612 | hookList[orig].orig = MCom.getStringVar(orig); |
||
5613 | MCom.setStringVar(orig,function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) return MCom.util.hookHandler(orig,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); end); |
||
5614 | end |
||
5615 | else |
||
5616 | for key,value in hookList[orig][hooktype] do |
||
5617 | -- NOTE THIS SHOULD BE VALUE! VALUE! *NOT* KEY! |
||
5618 | if(value == MCom.getStringVar(new)) then |
||
5619 | return; |
||
5620 | end |
||
5621 | end |
||
5622 | end |
||
5623 | -- intentionally will error if bad type is passed |
||
5624 | MCom.table.push(hookList[orig][hooktype], MCom.getStringVar(new)); |
||
5625 | end |
||
5626 | end; |
||
5627 | |||
5628 | MCom.util.unhook = function (orig, new, hooktype, scriptElementName) |
||
5629 | if (Sea and Sea.util and Sea.util.unhook and Sea.version and ( Sea.version >= 1.05 ) ) then |
||
5630 | Sea.util.unhook(orig, new, hooktype, scriptElementName); |
||
5631 | else |
||
5632 | --Modified unhook function from origional, uses Sea's hook list if available |
||
5633 | if (not MCom.util.Hooks) then |
||
5634 | MCom.util.Hooks = {}; |
||
5635 | end |
||
5636 | local hookList = MCom.util.Hooks; |
||
5637 | --If Sea is around, then use it's list |
||
5638 | if (Sea and Sea.util and Sea.util.hook) then |
||
5639 | if(not Sea.util.Hooks) then |
||
5640 | Sea.util.Hooks = {}; |
||
5641 | end |
||
5642 | hookList = Sea.util.Hooks; |
||
5643 | end |
||
5644 | |||
5645 | if(not hooktype) then |
||
5646 | hooktype = "before"; |
||
5647 | end |
||
5648 | local l,g; |
||
5649 | local origCopy = orig; |
||
5650 | if (scriptElementName) then |
||
5651 | orig = orig.."."..scriptElementName; |
||
5652 | end |
||
5653 | if(not hookList[orig]) then |
||
5654 | hookList[orig] = {}; |
||
5655 | hookList[orig].before = {}; |
||
5656 | hookList[orig].before.n = 0; |
||
5657 | hookList[orig].after = {}; |
||
5658 | hookList[orig].after.n = 0; |
||
5659 | hookList[orig].hide = {}; |
||
5660 | hookList[orig].hide.n = 0; |
||
5661 | hookList[orig].replace = {}; |
||
5662 | hookList[orig].replace.n = 0; |
||
5663 | if (scriptElementName) then |
||
5664 | hookList[orig].orig = MCom.getStringVar(origCopy):GetScript(scriptElementName); |
||
5665 | MCom.getStringVar(origCopy):SetScript(scriptElementName, function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) return MCom.util.hookHandler(orig,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); end); |
||
5666 | else |
||
5667 | hookList[orig].orig = MCom.getStringVar(orig); |
||
5668 | MCom.setStringVar(orig,function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) return MCom.util.hookHandler(orig,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); end); |
||
5669 | end |
||
5670 | end |
||
5671 | l = hookList[orig][hooktype]; |
||
5672 | g = MCom.getStringVar(new); |
||
5673 | if ( l ) then |
||
5674 | for key,value in l do |
||
5675 | if(value == g) then |
||
5676 | l[key] = nil; |
||
5677 | return; |
||
5678 | end |
||
5679 | end |
||
5680 | end |
||
5681 | end |
||
5682 | end; |
||
5683 | |||
5684 | if (Sea and Sea.util and Sea.util.hookHandler and Sea.version) then |
||
5685 | MCom.util.hookHandler = Sea.util.hookHandler; |
||
5686 | else |
||
5687 | MCom.util.hookHandler = function (name,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) |
||
5688 | local called = false; |
||
5689 | local continue = true; |
||
5690 | local retval = nil; |
||
5691 | local ra1,ra2,ra3,ra4,ra5,ra6,ra7,ra8,ra9,ra10,ra11,ra12,ra13,ra14,ra15,ra16,ra17,ra18,ra19,ra20; |
||
5692 | local hookList = MCom.util.Hooks; |
||
5693 | |||
5694 | --If Sea is around, then use it's list |
||
5695 | if (Sea and Sea.util and Sea.util.hook) then |
||
5696 | hookList = Sea.util.Hooks; |
||
5697 | end |
||
5698 | |||
5699 | if ( not hookList[name] ) then |
||
5700 | hookList[name] = {}; |
||
5701 | hookList[name].before = {}; |
||
5702 | hookList[name].before.n = 0; |
||
5703 | hookList[name].after = {}; |
||
5704 | hookList[name].after.n = 0; |
||
5705 | hookList[name].hide = {}; |
||
5706 | hookList[name].hide.n = 0; |
||
5707 | hookList[name].replace = {}; |
||
5708 | hookList[name].replace.n = 0; |
||
5709 | end |
||
5710 | for key,value in hookList[name].hide do |
||
5711 | if(type(value) == "function") then |
||
5712 | if(not value(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)) then |
||
5713 | continue = false; |
||
5714 | end |
||
5715 | called = true; |
||
5716 | end |
||
5717 | end |
||
5718 | if(not continue) then |
||
5719 | return; |
||
5720 | end |
||
5721 | for key,value in hookList[name].before do |
||
5722 | if(type(value) == "function") then |
||
5723 | value(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); |
||
5724 | called = true; |
||
5725 | end |
||
5726 | end |
||
5727 | continue = false; |
||
5728 | local replacedFunction = false; |
||
5729 | for key,value in hookList[name].replace do |
||
5730 | if(type(value) == "function") then |
||
5731 | replacedFunction = true; |
||
5732 | local callOrig = false; |
||
5733 | callOrig,ra1,ra2,ra3,ra4,ra5,ra6,ra7,ra8,ra9,ra10,ra11,ra12,ra13,ra14,ra15,ra16,ra17,ra18,ra19,ra20 = value(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); |
||
5734 | if(callOrig) then |
||
5735 | continue = true; |
||
5736 | else |
||
5737 | retval = true; |
||
5738 | end |
||
5739 | called = true; |
||
5740 | end |
||
5741 | end |
||
5742 | if(continue or (not replacedFunction)) then |
||
5743 | if (hookList[name].orig) then |
||
5744 | ra1,ra2,ra3,ra4,ra5,ra6,ra7,ra8,ra9,ra10,ra11,ra12,ra13,ra14,ra15,ra16,ra17,ra18,ra19,ra20 = hookList[name].orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); |
||
5745 | end |
||
5746 | retval = true; |
||
5747 | end |
||
5748 | for key,value in hookList[name].after do |
||
5749 | if(type(value) == "function") then |
||
5750 | value(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20); |
||
5751 | called = true; |
||
5752 | end |
||
5753 | end |
||
5754 | if(not called) then |
||
5755 | --[[ Disabled Complete Unhhoking Sept 17, 2005 - Incompatible with Frame Script Element Hooks - Liable to erase hooks loaded after the first hook. |
||
5756 | MCom.setStringVar(name,hookList[name].orig); |
||
5757 | hookList[name] = nil; |
||
5758 | ]]-- |
||
5759 | end |
||
5760 | if (retval) then |
||
5761 | if (type(ra1) == "table") then |
||
5762 | return unpack(ra1); |
||
5763 | else |
||
5764 | return ra1,ra2,ra3,ra4,ra5,ra6,ra7,ra8,ra9,ra10,ra11,ra12,ra13,ra14,ra15,ra16,ra17,ra18,ra19,ra20; |
||
5765 | end |
||
5766 | end |
||
5767 | end; |
||
5768 | end; |
||
5769 | |||
5770 | MCom.wow = { tooltip = {}; }; |
||
5771 | MCom.wow.tooltip.get = function ( tooltip, row, value ) |
||
5772 | if (Sea and Sea.wow and Sea.wow.tooltip and Sea.wow.tooltip.get) then |
||
5773 | --Call origional |
||
5774 | return Sea.wow.tooltip.get( tooltip, row, value ); |
||
5775 | else |
||
5776 | --Default to GameTooltip |
||
5777 | if (not tooltip) then |
||
5778 | tooltip = "GameTooltip"; |
||
5779 | end |
||
5780 | --Default to first row |
||
5781 | if (not row) then |
||
5782 | row = 1; |
||
5783 | end |
||
5784 | |||
5785 | local text, left, right, leftRed, leftGreen, leftBlue, leftAlpha, rightRed, rightGreen, rightBlue, rightAlpha; |
||
5786 | |||
5787 | --Get the left tooltip |
||
5788 | if ( ( value == nil ) or ( value == "left" ) or ( value == "leftColor" ) ) then |
||
5789 | text = getglobal(tooltip.."TextLeft"..row); |
||
5790 | |||
5791 | --Get the left tooltip text |
||
5792 | if ( ( value == nil ) or ( value == "left" ) ) then |
||
5793 | if ( text and text:IsVisible() ) then |
||
5794 | left = text:GetText(); |
||
5795 | end |
||
5796 | --If this is all they want, then return it now |
||
5797 | if ( value == "left" ) then |
||
5798 | return left; |
||
5799 | end |
||
5800 | end |
||
5801 | --Get the left tooltip color |
||
5802 | if ( ( value == nil ) or ( value == "leftColor" ) ) then |
||
5803 | if ( text and text:IsVisible() ) then |
||
5804 | leftRed, leftGreen, leftBlue, leftAlpha = text:GetTextColor(); |
||
5805 | end |
||
5806 | --If this is all they want, then return it now |
||
5807 | if ( value == "leftColor" ) then |
||
5808 | return leftRed, leftGreen, leftBlue, leftAlpha; |
||
5809 | end |
||
5810 | end |
||
5811 | end |
||
5812 | |||
5813 | --Get the right tooltip |
||
5814 | if ( ( value == nil ) or ( value == "right" ) or ( value == "rightColor" ) ) then |
||
5815 | text = getglobal(tooltip.."TextRight"..row); |
||
5816 | |||
5817 | --Get the right tooltip text |
||
5818 | if ( ( value == nil ) or ( value == "right" ) ) then |
||
5819 | if ( text and text:IsVisible() ) then |
||
5820 | right = text:GetText(); |
||
5821 | end |
||
5822 | --If this is all they want, then return it now |
||
5823 | if ( value == "right" ) then |
||
5824 | return right; |
||
5825 | end |
||
5826 | end |
||
5827 | --Get the right tooltip color |
||
5828 | if ( ( value == nil ) or ( value == "rightColor" ) ) then |
||
5829 | |||
5830 | if ( text and text:IsVisible() ) then |
||
5831 | rightRed, rightGreen, rightBlue, rightAlpha = text:GetTextColor(); |
||
5832 | end |
||
5833 | --If this is all they want, then return it now |
||
5834 | if ( value == "rightColor" ) then |
||
5835 | return rightRed, rightGreen, rightBlue, rightAlpha; |
||
5836 | end |
||
5837 | end |
||
5838 | end |
||
5839 | |||
5840 | --If no individual value was specified, return the entire row |
||
5841 | return left, right, leftRed, leftGreen, leftBlue, leftAlpha, rightRed, rightGreen, rightBlue, rightAlpha; |
||
5842 | end |
||
5843 | end; |
||
5844 | |||
5845 | MCom.string = {}; |
||
5846 | MCom.string.colorToString = function ( color ) |
||
5847 | if (Sea and Sea.string and Sea.string.colorToString) then |
||
5848 | --Call origional |
||
5849 | return Sea.string.colorToString(color); |
||
5850 | |||
5851 | if ( not color ) then |
||
5852 | return "FFFFFFFF"; |
||
5853 | end |
||
5854 | local rString = MCom.math.hexFromInt(math.floor(255*color.r)); |
||
5855 | local gString = MCom.math.hexFromInt(math.floor(255*color.g)); |
||
5856 | local bString = MCom.math.hexFromInt(math.floor(255*color.b)); |
||
5857 | local aString; |
||
5858 |
|
||
5859 | |||
5860 | aString = MCom.math.hexFromInt(math.floor(255*color.a)); |
||
5861 | elseif ( color.opacity ) then |
||
5862 | aString = MCom.math.hexFromInt(math.floor(255*color.opacity)); |
||
5863 | end |
||
5864 |
|
||
5865 | |||
5866 | return aString..rString..gString..bString; |
||
5867 | else |
||
5868 | return rString..gString..bString; |
||
5869 |
end; |
||
5870 | |||
5871 | end; |
||
5872 | end |
||
5873 |
|
||
5874 |
|