vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | SUPERMACRO_VERSION = "3.14"; |
2 | UIPanelWindows["SuperMacroFrame"] = { area = "left", pushable = 7, whileDead = 1 }; |
||
3 | UIPanelWindows["SuperMacroOptionsFrame"] = { area = "left", pushable = 0, whileDead = 1 }; |
||
4 | MACRO_ROWS = 3; |
||
5 | MACRO_COLUMNS = 10; |
||
6 | MACROS_REGULAR_SHOWN = 36; |
||
7 | MACROS_SUPER_SHOWN = MACRO_ROWS * MACRO_COLUMNS; |
||
8 | MAX_MACROS = 18; |
||
9 | --MAX_TOTAL_MACROS = 36; |
||
10 | NUM_MACRO_ICONS_SHOWN = 30;--20 |
||
11 | NUM_ICONS_PER_ROW = 5;--5 |
||
12 | NUM_ICON_ROWS = 6;--4 |
||
13 | MACRO_ROW_HEIGHT = 36; |
||
14 | MACRO_ICON_ROW_HEIGHT = 36; |
||
15 | --MACRO_MAX_LETTERS = 255; |
||
16 | EXTEND_MAX_LETTERS = 7000; |
||
17 | SUPER_MAX_LETTERS = 7000; |
||
18 | PRINT_COLOR_DEF = {r=1, g=1, b=1}; |
||
19 | SM_VARS = {}; -- options variables, Saved |
||
20 | --SM_VARS.hideAction = 0; |
||
21 | --SM_VARS.printColor = PRINT_COLOR_DEF; |
||
22 | --SM_VARS.macroTip1 = 1; |
||
23 | --SM_VARS.macroTip2 = 0; |
||
24 | --SM_VARS.minimap = 1; |
||
25 | --SM_VARS.replaceIcon = 1; |
||
26 | --SM_VARS.checkCooldown = 1; |
||
27 | SM_EXTEND = {}; -- ingame extended, Saved |
||
28 | SM_SUPER={}; -- supers' names, texture, body, Saved |
||
29 | SM_ORDERED={}; -- supers in alphabetical order |
||
30 | SM_ACTION={}; -- hold actions that have supers, for current player |
||
31 | SM_ACTION_SUPER={}; -- hold actions for supers, Saved per character |
||
32 | SM_MACRO_ICON={}; -- hold all available icons and their id |
||
33 | SM_ACTION_SPELL={}; -- hold macros that cast spell or items |
||
34 | SM_ACTION_SPELL.regular={}; |
||
35 | SM_ACTION_SPELL.super={}; |
||
36 | SM_AliasFunctions={}; -- functions to replace aliases |
||
37 | SM_AliasFunctions.low=0; |
||
38 | SM_AliasFunctions.high=0; |
||
39 | |||
40 | local oldextend; |
||
41 | |||
42 | function SuperMacroFrame_OnLoad() |
||
43 | PanelTemplates_SetNumTabs(this, 2); |
||
44 | SuperMacroFrame.selectedTab = 1; |
||
45 | PanelTemplates_UpdateTabs(this); |
||
46 | SuperMacroFrameTitle:SetText(SUPERMACRO_TITLE.." "..SUPERMACRO_VERSION); |
||
47 | SuperMacroFrameCharacterMacroText:SetText(format(CHARACTER_SPECIFIC_MACROS, UnitName("player"))); |
||
48 | SM_UpdateAction(); |
||
49 | this:RegisterEvent("VARIABLES_LOADED"); |
||
50 | this:RegisterEvent("TRADE_SKILL_SHOW"); |
||
51 | this:RegisterEvent("CRAFT_SHOW"); |
||
52 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
53 | lastActionUsed = nil; |
||
54 | SuperMacroFrame_SetAccountMacros(); |
||
55 | SM_MACRO_ICON=SM_LoadMacroIcons(); |
||
56 | if ( not Print ) then |
||
57 | Print=Printd; |
||
58 | end |
||
59 | end |
||
60 | |||
61 | function SuperMacroFrame_OnShow() |
||
62 | SuperMacroFrame.extendChanged=nil; |
||
63 | SuperMacroFrame_Update(); |
||
64 | PlaySound("igCharacterInfoOpen"); |
||
65 | end |
||
66 | |||
67 | function SuperMacroFrame_OnHide() |
||
68 | SuperMacroPopupFrame:Hide(); |
||
69 | SuperMacroFrame_SaveMacro(); |
||
70 | PlaySound("igCharacterInfoClose"); |
||
71 | if ( SuperMacroFrame.extendChanged ) then |
||
72 | SuperMacroSaveExtend(); |
||
73 | end |
||
74 | SuperMacroFrame.extendChanged=nil; |
||
75 | -- purge empty extends |
||
76 | for m,e in ipairs(SM_EXTEND) do |
||
77 | if ( e=="" ) then |
||
78 | SM_EXTEND[m]=nil; |
||
79 | end |
||
80 | end |
||
81 | SuperMacroRunScriptExtend(); |
||
82 | end |
||
83 | |||
84 | function SuperMacroFrame_SetAccountMacros() |
||
85 | local numAccountMacros, numCharacterMacros = GetNumMacros(); |
||
86 | if ( numAccountMacros > 0 ) then |
||
87 | SuperMacroFrame_SelectMacro(1); |
||
88 | else |
||
89 | SuperMacroFrame_SetCharacterMacros(); |
||
90 | end |
||
91 | end |
||
92 | |||
93 | function SuperMacroFrame_SetCharacterMacros() |
||
94 | local numAccountMacros, numCharacterMacros = GetNumMacros(); |
||
95 | if ( numCharacterMacros > 0 ) then |
||
96 | SuperMacroFrame_SelectMacro(19); |
||
97 | else |
||
98 | SuperMacroFrame_SelectMacro(nil); |
||
99 | end |
||
100 | end |
||
101 | |||
102 | function SuperMacroFrame_ShowFrame( tab ) |
||
103 | if ( tab~="regular" ) then |
||
104 | SuperMacroFrameRegularFrame:Hide(); |
||
105 | else |
||
106 | SuperMacroFrameRegularFrame:Show(); |
||
107 | end |
||
108 | if ( tab~="super" ) then |
||
109 | SuperMacroFrameSuperFrame:Hide(); |
||
110 | else |
||
111 | SM_ORDERED=SortSuperMacroList(); |
||
112 | SuperMacroFrameSuperFrame:Show(); |
||
113 | end |
||
114 | end |
||
115 | |||
116 | function SuperMacroFrame_Update() |
||
117 | -- determine to show regular or super macros from SM_VARS.tabShown |
||
118 | -- START show regular frame |
||
119 | if ( SM_VARS.tabShown=="regular" ) then |
||
120 | SuperMacroFrame_ShowFrame("regular"); |
||
121 | local numMacros; |
||
122 | local numAccountMacros, numCharacterMacros = GetNumMacros(); |
||
123 | local macroButton, macroIcon, macroName; |
||
124 | local name, texture, body, isLocal; |
||
125 | local selectedName, selectedBody, selectedIcon; |
||
126 | |||
127 | -- Disable Buttons |
||
128 | if ( SuperMacroPopupFrame:IsVisible() ) then |
||
129 | SuperMacroEditButton:Disable(); |
||
130 | SuperMacroDeleteButton:Disable(); |
||
131 | SuperMacroSaveButton:Disable(); |
||
132 | else |
||
133 | SuperMacroEditButton:Enable(); |
||
134 | SuperMacroDeleteButton:Enable(); |
||
135 | SuperMacroSaveButton:Enable(); |
||
136 | end |
||
137 | |||
138 | if ( not SuperMacroFrame.selectedMacro or (numAccountMacros+numCharacterMacros==0) ) then |
||
139 | SuperMacroDeleteButton:Disable(); |
||
140 | SuperMacroEditButton:Disable(); |
||
141 | SuperMacroSaveButton:Disable(); |
||
142 | SuperMacroFrameSelectedMacroName:SetText(''); |
||
143 | SuperMacroFrameText:SetText(''); |
||
144 | SuperMacroFrameSelectedMacroButtonIcon:SetTexture(''); |
||
145 | end |
||
146 | |||
147 | -- Macro List |
||
148 | for j=0, MAX_MACROS, MAX_MACROS do |
||
149 | if ( j == 0 ) then |
||
150 | numMacros = numAccountMacros; |
||
151 | else |
||
152 | numMacros = numCharacterMacros; |
||
153 | end |
||
154 | for i=1, MAX_MACROS do |
||
155 | local macroID = i+j; |
||
156 | getglobal("SuperMacroButton"..macroID.."ID"):SetText(macroID); |
||
157 | macroButton = getglobal("SuperMacroButton"..macroID); |
||
158 | macroIcon = getglobal("SuperMacroButton"..macroID.."Icon"); |
||
159 | macroName = getglobal("SuperMacroButton"..macroID.."Name"); |
||
160 | if ( i <= numMacros ) then |
||
161 | name, texture, body, isLocal = GetMacroInfo(macroID); |
||
162 | macroButton:SetID(macroID); |
||
163 | macroIcon:SetTexture(texture); |
||
164 | macroName:SetText(name); |
||
165 | macroButton:Enable(); |
||
166 | -- Highlight Selected Macro |
||
167 | if ( macroID == SuperMacroFrame.selectedMacro ) then |
||
168 | macroButton:SetChecked(1); |
||
169 | SuperMacroFrameSelectedMacroName:SetText(name); |
||
170 | SuperMacroFrameText:SetText(body); |
||
171 | SuperMacroFrameSelectedMacroButton:SetID(macroID); |
||
172 | SuperMacroFrameSelectedMacroButtonIcon:SetTexture(texture); |
||
173 | else |
||
174 | macroButton:SetChecked(0); |
||
175 | end |
||
176 | else |
||
177 | macroButton:SetChecked(0); |
||
178 | macroIcon:SetTexture(""); |
||
179 | macroName:SetText(""); |
||
180 | macroButton:Disable(); |
||
181 | end |
||
182 | end |
||
183 | end |
||
184 | |||
185 | --Update New Button |
||
186 | if ( numAccountMacros == MAX_MACROS ) then |
||
187 | SuperMacroNewAccountButton:Disable(); |
||
188 | else |
||
189 | SuperMacroNewAccountButton:Enable(); |
||
190 | end |
||
191 | if ( numCharacterMacros == MAX_MACROS ) then |
||
192 | SuperMacroNewCharacterButton:Disable(); |
||
193 | else |
||
194 | SuperMacroNewCharacterButton:Enable(); |
||
195 | end |
||
196 | |||
197 | end |
||
198 | -- END update regular frame |
||
199 | |||
200 | -- START show super frame |
||
201 | if ( SM_VARS.tabShown=="super" ) then |
||
202 | SuperMacroFrame_ShowFrame("super"); |
||
203 | local numMacros=SM_SUPER_SIZE or GetNumSuperMacros(); |
||
204 | local macroButton, macroIcon, macroName; |
||
205 | local name, texture, body; |
||
206 | |||
207 | -- Disable Buttons |
||
208 | if ( SuperMacroPopupFrame:IsVisible() ) then |
||
209 | SuperMacroNewSuperButton:Disable(); |
||
210 | SuperMacroSaveSuperButton:Disable(); |
||
211 | SuperMacroDeleteSuperButton:Disable(); |
||
212 | SuperMacroEditButton:Disable(); |
||
213 | else |
||
214 | SuperMacroNewSuperButton:Enable(); |
||
215 | SuperMacroSaveSuperButton:Enable(); |
||
216 | SuperMacroDeleteSuperButton:Enable(); |
||
217 | SuperMacroEditButton:Enable(); |
||
218 | end |
||
219 | |||
220 | if ( not SuperMacroFrame.selectedSuper or GetNumSuperMacros()==0) then |
||
221 | --[[ |
||
222 | SuperMacroSaveSuperButton:Enable(); |
||
223 | SuperMacroDeleteSuperButton:Enable(); |
||
224 | SuperMacroEditButton:Enable(); |
||
225 | else |
||
226 | --]] |
||
227 | SuperMacroSaveSuperButton:Disable(); |
||
228 | SuperMacroDeleteSuperButton:Disable(); |
||
229 | SuperMacroEditButton:Disable(); |
||
230 | SuperMacroFrameSelectedMacroName:SetText(''); |
||
231 | SuperMacroFrameSuperText:SetText(''); |
||
232 | SuperMacroFrameSelectedMacroSuperButtonIcon:SetTexture(''); |
||
233 | end |
||
234 | |||
235 | -- Macro List |
||
236 | local offset=FauxScrollFrame_GetOffset(SuperMacroFrameSuperScrollFrame); |
||
237 | local firstmacro = offset*MACRO_COLUMNS+1; |
||
238 | local lastmacro = firstmacro + MACRO_ROWS*MACRO_COLUMNS -1; |
||
239 | |||
240 | for i=1, MACROS_SUPER_SHOWN do |
||
241 | getglobal("SuperMacroSuperButton"..i.."ID"):SetText(firstmacro+i-1); |
||
242 | macroButton = getglobal("SuperMacroSuperButton"..i); |
||
243 | macroIcon = getglobal("SuperMacroSuperButton"..i.."Icon"); |
||
244 | macroName = getglobal("SuperMacroSuperButton"..i.."Name"); |
||
245 | local macroID = firstmacro+i-1; |
||
246 | if ( macroID <= numMacros ) then |
||
247 | name, texture, body = GetOrderedSuperMacroInfo(macroID); |
||
248 | macroButton:SetID(macroID); |
||
249 | macroIcon:SetTexture(texture); |
||
250 | macroName:SetText(name); |
||
251 | macroButton:Enable(); |
||
252 | -- Highlight Selected Macro |
||
253 | if ( macroID == SuperMacroFrame.selectedSuper ) then |
||
254 | macroButton:SetChecked(1); |
||
255 | SuperMacroFrameSelectedMacroName:SetText(name); |
||
256 | SuperMacroFrameSuperText:SetText(body); |
||
257 | SuperMacroFrameSelectedMacroSuperButtonIcon:SetTexture(texture); |
||
258 | else |
||
259 | macroButton:SetChecked(0); |
||
260 | end |
||
261 | else |
||
262 | macroButton:SetChecked(0); |
||
263 | macroIcon:SetTexture(""); |
||
264 | macroName:SetText(""); |
||
265 | macroButton:Disable(); |
||
266 | end |
||
267 | end |
||
268 | |||
269 | -- Scroll frame stuff |
||
270 | FauxScrollFrame_Update(SuperMacroFrameSuperScrollFrame, ceil(numMacros/10), MACRO_ROWS, MACRO_ROW_HEIGHT ); |
||
271 | |||
272 | end |
||
273 | -- END update super frame |
||
274 | end |
||
275 | |||
276 | function SuperMacroFrame_AddMacroLine(line) |
||
277 | if ( SuperMacroFrameText:IsVisible() ) then |
||
278 | SuperMacroFrameText:SetText(SuperMacroFrameText:GetText()..line); |
||
279 | end |
||
280 | end |
||
281 | |||
282 | function SuperMacroButton_OnClick( button ) |
||
283 | local id=this:GetID(); |
||
284 | if ( SuperMacroFrame.extendChanged and SuperMacroFrame.selectedMacro ) then |
||
285 | SuperMacroSaveExtend(); |
||
286 | end |
||
287 | SuperMacroFrame_SaveMacro(); |
||
288 | SuperMacroFrame_SelectMacro(id); |
||
289 | SuperMacroFrame_Update(); |
||
290 | SuperMacroPopupFrame:Hide(); |
||
291 | SuperMacroFrameText:ClearFocus(); |
||
292 | local macro=SuperMacroFrameSelectedMacroName:GetText(); |
||
293 | local extendText=SM_EXTEND[macro]; |
||
294 | if ( extendText ) then |
||
295 | SuperMacroFrameExtendText:SetText(extendText); |
||
296 | else |
||
297 | SuperMacroFrameExtendText:SetText(""); |
||
298 | end |
||
299 | if ( button=="RightButton" ) then |
||
300 | RunMacro(id); |
||
301 | end |
||
302 | end |
||
303 | |||
304 | function SuperMacroSuperButton_OnClick( button ) |
||
305 | local id=this:GetID(); |
||
306 | SuperMacroFrame_SaveSuperMacro(); |
||
307 | SuperMacroFrame_SelectSuperMacro(id); |
||
308 | SuperMacroFrame_Update(); |
||
309 | SuperMacroPopupFrame:Hide(); |
||
310 | SuperMacroFrameSuperText:ClearFocus(); |
||
311 | if ( button=="RightButton" ) then |
||
312 | RunSuperMacro(id); |
||
313 | end |
||
314 | end |
||
315 | |||
316 | function SuperMacroFrame_SelectSuperMacro(id) |
||
317 | SuperMacroFrame.selectedSuper = id; |
||
318 | end |
||
319 | |||
320 | function SuperMacroFrame_SelectMacro(id) |
||
321 | SuperMacroFrame.selectedMacro = id; |
||
322 | end |
||
323 | |||
324 | function SuperMacroNewAccountButton_OnClick() |
||
325 | SuperMacroFrame_SaveMacro(); |
||
326 | SuperMacroSaveExtend(); |
||
327 | oldextend=nil; |
||
328 | SuperMacroPopupFrame.mode = "newaccount"; |
||
329 | SuperMacroPopupFrame:Show(); |
||
330 | end |
||
331 | |||
332 | function SuperMacroNewCharacterButton_OnClick() |
||
333 | SuperMacroFrame_SaveMacro(); |
||
334 | SuperMacroSaveExtend(); |
||
335 | oldextend=nil; |
||
336 | SuperMacroPopupFrame.mode = "newcharacter"; |
||
337 | SuperMacroPopupFrame:Show(); |
||
338 | end |
||
339 | |||
340 | function SuperMacroNewSuperButton_OnClick() |
||
341 | SuperMacroFrame_SaveSuperMacro(); |
||
342 | SuperMacroPopupFrame.mode = "newsuper"; |
||
343 | SuperMacroPopupFrame:Show(); |
||
344 | end |
||
345 | |||
346 | function SuperMacroEditButton_OnClick() |
||
347 | if ( SuperMacroFrame.extendChanged ) then |
||
348 | SuperMacroSaveExtend(); |
||
349 | end |
||
350 | -- erase old name extend |
||
351 | oldextend=SuperMacroFrameExtendText:GetText(); |
||
352 | local oldmacro=SelectedMacroName(); |
||
353 | --SM_EXTEND[oldmacro]=nil; |
||
354 | if ( not SameMacroName() ) then |
||
355 | SuperMacroSaveExtend(oldmacro, 1); -- delete old extend |
||
356 | end |
||
357 | SuperMacroFrame_SaveMacro(); |
||
358 | SuperMacroPopupFrame.mode = "edit"; |
||
359 | SuperMacroPopupFrame.oldname=SuperMacroFrameSelectedMacroName:GetText(); |
||
360 | SuperMacroPopupFrame:Show(); |
||
361 | end |
||
362 | |||
363 | function SuperMacroFrame_HideDetails() |
||
364 | SuperMacroEditButton:Hide(); |
||
365 | SuperMacroFrameCharLimitText:Hide(); |
||
366 | SuperMacroFrameText:Hide(); |
||
367 | SuperMacroFrameSelectedMacroName:Hide(); |
||
368 | SuperMacroFrameSelectedMacroBackground:Hide(); |
||
369 | SuperMacroFrameSelectedMacroButton:Hide(); |
||
370 | end |
||
371 | |||
372 | function SuperMacroFrame_ShowDetails() |
||
373 | SuperMacroEditButton:Show(); |
||
374 | SuperMacroFrameCharLimitText:Show(); |
||
375 | SuperMacroFrameEnterMacroText:Show(); |
||
376 | SuperMacroFrameText:Show(); |
||
377 | SuperMacroFrameSelectedMacroName:Show(); |
||
378 | SuperMacroFrameSelectedMacroBackground:Show(); |
||
379 | SuperMacroFrameSelectedMacroButton:Show(); |
||
380 | end |
||
381 | |||
382 | function SuperMacroPopupFrame_OnShow() |
||
383 | if ( this.mode == "newaccount" or this.mode == "newcharacter" ) then |
||
384 | SuperMacroFrameText:Hide(); |
||
385 | SuperMacroFrameSelectedMacroButtonIcon:SetTexture(""); |
||
386 | SuperMacroPopupFrame.selectedIcon = nil; |
||
387 | elseif ( this.mode == "newsuper" ) then |
||
388 | SuperMacroFrameSuperText:Hide(); |
||
389 | SuperMacroFrameSelectedMacroSuperButtonIcon:SetTexture(""); |
||
390 | SuperMacroPopupFrame.selectedIcon = nil; |
||
391 | end |
||
392 | SuperMacroFrameText:ClearFocus(); |
||
393 | SuperMacroFrameSuperText:ClearFocus(); |
||
394 | SuperMacroPopupEditBox:SetFocus(); |
||
395 | |||
396 | PlaySound("igCharacterInfoOpen"); |
||
397 | SuperMacroPopupFrame_Update(); |
||
398 | SuperMacroPopupOkayButton_Update(); |
||
399 | |||
400 | -- Disable Buttons |
||
401 | SuperMacroEditButton:Disable(); |
||
402 | SuperMacroDeleteButton:Disable(); |
||
403 | SuperMacroNewAccountButton:Disable(); |
||
404 | SuperMacroNewCharacterButton:Disable(); |
||
405 | end |
||
406 | |||
407 | function SuperMacroPopupFrame_OnHide() |
||
408 | if ( this.mode == "newaccount" or this.mode == "newcharacter" ) then |
||
409 | SuperMacroFrameText:Show(); |
||
410 | SuperMacroFrameText:SetFocus(); |
||
411 | elseif ( this.mode == "newsuper" ) then |
||
412 | SuperMacroFrameSuperText:Show(); |
||
413 | SuperMacroFrameSuperText:SetFocus(); |
||
414 | end |
||
415 | |||
416 | -- Enable Buttons |
||
417 | SuperMacroEditButton:Enable(); |
||
418 | SuperMacroDeleteButton:Enable(); |
||
419 | local numAccountMacros, numCharacterMacros = GetNumMacros(); |
||
420 | if ( numAccountMacros < MAX_MACROS ) then |
||
421 | SuperMacroNewAccountButton:Enable(); |
||
422 | end |
||
423 | if ( numCharacterMacros < MAX_MACROS ) then |
||
424 | SuperMacroNewCharacterButton:Enable(); |
||
425 | end |
||
426 | end |
||
427 | |||
428 | function SuperMacroPopupFrame_Update() |
||
429 | local numMacroIcons = GetNumMacroIcons(); |
||
430 | local macroPopupIcon, macroPopupButton; |
||
431 | local macroPopupOffset = FauxScrollFrame_GetOffset( SuperMacroPopupScrollFrame ); |
||
432 | local index; |
||
433 | |||
434 | -- Determine whether we're creating a new macro or editing an existing one |
||
435 | if ( this.mode == "newaccount" or this.mode == "newcharacter" ) then |
||
436 | SuperMacroPopupEditBox:SetText(""); |
||
437 | elseif ( this.mode == "newsuper" ) then |
||
438 | SuperMacroPopupEditBox:SetText(""); |
||
439 | elseif ( this.mode == "edit" ) then |
||
440 | local name; |
||
441 | if ( SM_VARS.tabShown=="regular") then |
||
442 | name = GetMacroInfo(SuperMacroFrame.selectedMacro); |
||
443 | elseif ( SM_VARS.tabShown=="super" ) then |
||
444 | name = GetOrderedSuperMacroInfo(SuperMacroFrame.selectedSuper); |
||
445 | end |
||
446 | SuperMacroPopupEditBox:SetText(name); |
||
447 | end |
||
448 | |||
449 | -- Icon list |
||
450 | for i=1, NUM_MACRO_ICONS_SHOWN do |
||
451 | macroPopupIcon = getglobal("SuperMacroPopupButton"..i.."Icon"); |
||
452 | macroPopupButton = getglobal("SuperMacroPopupButton"..i); |
||
453 | index = (macroPopupOffset * NUM_ICONS_PER_ROW) + i; |
||
454 | if ( index <= numMacroIcons ) then |
||
455 | macroPopupIcon:SetTexture(GetMacroIconInfo(index)); |
||
456 | macroPopupButton:Show(); |
||
457 | else |
||
458 | macroPopupIcon:SetTexture(""); |
||
459 | macroPopupButton:Hide(); |
||
460 | end |
||
461 | if ( index == SuperMacroPopupFrame.selectedIcon ) then |
||
462 | macroPopupButton:SetChecked(1); |
||
463 | else |
||
464 | macroPopupButton:SetChecked(nil); |
||
465 | end |
||
466 | end |
||
467 | |||
468 | -- Scrollbar stuff |
||
469 | FauxScrollFrame_Update(SuperMacroPopupScrollFrame, ceil(numMacroIcons / NUM_ICONS_PER_ROW) , NUM_ICON_ROWS, MACRO_ICON_ROW_HEIGHT ); |
||
470 | end |
||
471 | |||
472 | function SuperMacroPopupOkayButton_Update() |
||
473 | if ( (strlen(SuperMacroPopupEditBox:GetText()) > 0) and SuperMacroPopupFrame.selectedIcon ) then |
||
474 | SuperMacroPopupOkayButton:Enable(); |
||
475 | else |
||
476 | SuperMacroPopupOkayButton:Disable(); |
||
477 | end |
||
478 | if ( SuperMacroPopupFrame.mode == "edit" and (strlen(SuperMacroPopupEditBox:GetText()) > 0) ) then |
||
479 | SuperMacroPopupOkayButton:Enable(); |
||
480 | end |
||
481 | end |
||
482 | |||
483 | function SuperMacroPopupButton_OnClick() |
||
484 | SuperMacroPopupFrame.selectedIcon = this:GetID() + (FauxScrollFrame_GetOffset(SuperMacroPopupScrollFrame) * NUM_ICONS_PER_ROW); |
||
485 | if ( SM_VARS.tabShown=="regular" ) then |
||
486 | SuperMacroFrameSelectedMacroButtonIcon:SetTexture( GetMacroIconInfo(SuperMacroPopupFrame.selectedIcon)); |
||
487 | elseif ( SM_VARS.tabShown=="super" ) then |
||
488 | SuperMacroFrameSelectedMacroSuperButtonIcon:SetTexture( GetMacroIconInfo(SuperMacroPopupFrame.selectedIcon)); |
||
489 | end |
||
490 | SuperMacroPopupOkayButton_Update(); |
||
491 | SuperMacroPopupFrame_Update(); |
||
492 | end |
||
493 | |||
494 | function SuperMacroPopupOkayButton_OnClick() |
||
495 | local index = 1; |
||
496 | local texture=SuperMacroFrameSelectedMacroSuperButtonIcon:GetTexture(); |
||
497 | local macroname=SuperMacroPopupEditBox:GetText(); |
||
498 | if ( SuperMacroPopupFrame.mode == "newaccount" ) then |
||
499 | index = CreateMacro(macroname, SuperMacroPopupFrame.selectedIcon, nil, nil, false ); |
||
500 | SuperMacroFrame_SelectMacro(index); |
||
501 | elseif ( SuperMacroPopupFrame.mode == "newcharacter" ) then |
||
502 | index = CreateMacro(macroname, SuperMacroPopupFrame.selectedIcon, nil, nil, true ); |
||
503 | SuperMacroFrame_SelectMacro(index); |
||
504 | elseif ( SuperMacroPopupFrame.mode == "newsuper" ) then |
||
505 | index = CreateSuperMacro(macroname, texture, ''); |
||
506 | SuperMacroFrame_SelectSuperMacro(index); |
||
507 | elseif ( SuperMacroPopupFrame.mode == "edit" ) then |
||
508 | if ( SM_VARS.tabShown=="regular" ) then |
||
509 | index = EditMacro(SuperMacroFrame.selectedMacro, macroname, SuperMacroPopupFrame.selectedIcon); |
||
510 | if ( GetMacroIndexByName(SuperMacroPopupFrame.oldname)==0 ) then |
||
511 | SM_UpdateActionSpell(SuperMacroPopupFrame.oldname, "regular", ''); |
||
512 | end |
||
513 | SM_UpdateActionSpell(macroname, "regular", GetMacroInfo(index, "body")); |
||
514 | SuperMacroFrame_SelectMacro(index); |
||
515 | elseif ( SM_VARS.tabShown=="super" ) then |
||
516 | local oldsuper=GetOrderedSuperMacroInfo(SuperMacroFrame.selectedSuper); |
||
517 | if ( SM_SUPER[macroname] ) then |
||
518 | macroname=SuperMacroPopupFrame.oldname; |
||
519 | end |
||
520 | index = EditSuperMacro(SuperMacroFrame.selectedSuper, macroname, texture); |
||
521 | SuperMacroFrame_SelectSuperMacro(index); |
||
522 | SuperMacro_UpdateAction(oldsuper, macroname); |
||
523 | end |
||
524 | end |
||
525 | SuperMacroPopupFrame:Hide(); |
||
526 | SuperMacroFrame_Update(); |
||
527 | |||
528 | -- if edited name, use oldextend |
||
529 | if ( oldextend ) then |
||
530 | SuperMacroFrameExtendText:SetText(oldextend); |
||
531 | elseif ( SameMacroName() ) then |
||
532 | -- get extend with same name, else empty |
||
533 | local text = SuperMacroGetExtend( GetMacroInfo( SameMacroName(),"name" ) ) ; |
||
534 | if ( text ) then |
||
535 | SuperMacroFrameExtendText:SetText( text ); |
||
536 | end |
||
537 | else |
||
538 | SuperMacroFrameExtendText:SetText(""); |
||
539 | end |
||
540 | SuperMacroSaveExtend(); |
||
541 | oldextend=nil; |
||
542 | end |
||
543 | |||
544 | function SuperMacroOptionsButton_OnClick() |
||
545 | if ( SuperMacroOptionsFrame:IsVisible() ) then |
||
546 | HideUIPanel(SuperMacroOptionsFrame); |
||
547 | else |
||
548 | ShowUIPanel(SuperMacroOptionsFrame); |
||
549 | end |
||
550 | end |
||
551 | |||
552 | function SuperMacroFrame_SaveMacro() |
||
553 | if ( SuperMacroFrame.textChanged and SuperMacroFrame.selectedMacro ) then |
||
554 | EditMacro(SuperMacroFrame.selectedMacro, nil, nil, SuperMacroFrameText:GetText()); |
||
555 | SuperMacroFrame.textChanged = nil; |
||
556 | SM_UpdateActionSpell( GetMacroInfo(SuperMacroFrame.selectedMacro, "name"), "regular", SuperMacroFrameText:GetText()); |
||
557 | end |
||
558 | end |
||
559 | |||
560 | function SuperMacroFrame_SaveSuperMacro() |
||
561 | if ( SuperMacroFrame.textChanged and SuperMacroFrame.selectedSuper ) then |
||
562 | local macroName = SelectedMacroName(); |
||
563 | local macroTexture = SuperMacroFrameSelectedMacroSuperButtonIcon:GetTexture(); |
||
564 | local macroBody = SuperMacroFrameSuperText:GetText(); |
||
565 | SM_SUPER[macroName] = {macroName,macroTexture,macroBody}; |
||
566 | SuperMacroFrame.textChanged = nil; |
||
567 | SM_UpdateActionSpell(macroName, "super", macroBody); |
||
568 | end |
||
569 | end |
||
570 | |||
571 | function SuperMacroFrame_OnEvent(event) |
||
572 | if ( event=="TRADE_SKILL_SHOW") then |
||
573 | if ( not old_SM_TradeSkillSkillButton_OnClick) then |
||
574 | old_SM_TradeSkillSkillButton_OnClick = TradeSkillSkillButton_OnClick; |
||
575 | TradeSkillSkillButton_OnClick = SM_TradeSkillSkillButton_OnClick; |
||
576 | SM_TradeSkillItem_OnClick(); |
||
577 | end |
||
578 | end |
||
579 | if ( event=="CRAFT_SHOW") then |
||
580 | if ( not old_SM_CraftButton_OnClick) then |
||
581 | old_SM_CraftButton_OnClick = CraftButton_OnClick; |
||
582 | CraftButton_OnClick = SM_CraftButton_OnClick; |
||
583 | SM_CraftItem_OnClick(); |
||
584 | end |
||
585 | end |
||
586 | if ( event=="VARIABLES_LOADED" ) then |
||
587 | if ( not SM_VARS.hideAction ) then |
||
588 | SM_VARS.hideAction = 0; |
||
589 | end |
||
590 | if ( not SM_VARS.printColor ) then |
||
591 | SM_VARS.printColor = PRINT_COLOR_DEF; |
||
592 | end |
||
593 | if ( not SM_VARS.macroTip1 ) then |
||
594 | SM_VARS.macroTip1= 1; |
||
595 | end |
||
596 | if ( not SM_VARS.macroTip2 ) then |
||
597 | SM_VARS.macroTip2= 0; |
||
598 | end |
||
599 | if ( not SM_VARS.minimap ) then |
||
600 | SM_VARS.minimap = 1; |
||
601 | end |
||
602 | if ( not SM_VARS.replaceIcon ) then |
||
603 | SM_VARS.replaceIcon = 1; |
||
604 | end |
||
605 | if ( not SM_VARS.checkCooldown ) then |
||
606 | SM_VARS.checkCooldown = 1; |
||
607 | end |
||
608 | if ( not SM_VARS.tabShown ) then |
||
609 | SM_VARS.tabShown = "regular"; |
||
610 | end |
||
611 | if ( SM_VARS.tabShown=="regular" ) then |
||
612 | SuperMacroFrame.selectedTab = 1; |
||
613 | PanelTemplates_UpdateTabs(this); |
||
614 | elseif ( SM_VARS.tabShown=="super" ) then |
||
615 | SuperMacroFrame.selectedTab = 2; |
||
616 | PanelTemplates_UpdateTabs(this); |
||
617 | end |
||
618 | HideActionText(); |
||
619 | ToggleSMMinimap(); |
||
620 | SuperMacroRunScriptExtend(); |
||
621 | SuperMacroFrame.extendChanged=nil; |
||
622 | SM_ORDERED=SortSuperMacroList(); |
||
623 | local player=UnitName("player").." of "..GetRealmName(); |
||
624 | if ( not SM_ACTION_SUPER[player] ) then |
||
625 | SM_ACTION_SUPER[player]={}; |
||
626 | end |
||
627 | SM_ACTION=SM_ACTION_SUPER[player]; |
||
628 | SM_UpdateActionSpell(); |
||
629 | |||
630 | -- update alias replacement function |
||
631 | -- ASF aka Alias-Spellchecker-Filter |
||
632 | if (ReplaceAlias and ASFOptions.aliasOn) then |
||
633 | SM_InsertAliasFunction(ReplaceAlias); |
||
634 | end |
||
635 | -- ChatAlias |
||
636 | if (CA_ParseMessage) then |
||
637 | SM_InsertAliasFunction(ReplaceAlias, -1); |
||
638 | -- this messes up newlines, so should not run during RunMacro |
||
639 | end |
||
640 | -- for any other alias addons, do tinsert(SM_AliasFunctions, your_function) inside your mod |
||
641 | |||
642 | end |
||
643 | if ( event=="PLAYER_ENTERING_WORLD" ) then |
||
644 | SM_UpdateActionSpell(); |
||
645 | end |
||
646 | if ( event=="PLAYER_LEAVING_WORLD" ) then |
||
647 | SM_ACTION_SUPER[player]=SM_ACTION; |
||
648 | end |
||
649 | end |
||
650 | |||
651 | function RunMacro(index) |
||
652 | -- close edit boxes, then enter body line by line |
||
653 | if ( SuperMacroFrame_SaveMacro ) then |
||
654 | SuperMacroFrame_SaveMacro(); |
||
655 | end |
||
656 | if ( MacroFrame_SaveMacro ) then |
||
657 | MacroFrame_SaveMacro(); |
||
658 | end |
||
659 | local body; |
||
660 | if ( type(index) == "number" ) then |
||
661 | body = GetMacroInfo(index, "body"); |
||
662 | elseif ( type(index) == "string" ) then |
||
663 | body = GetMacroInfo(GetMacroIndexByName(index),"body"); |
||
664 | end |
||
665 | if ( not body ) then return; end |
||
666 | |||
667 | if ( ChatFrameEditBox:IsVisible() ) then |
||
668 | ChatEdit_OnEscapePressed(ChatFrameEditBox); |
||
669 | end |
||
670 | |||
671 | body = SM_ReplaceAlias(body); |
||
672 | |||
673 | --SM_MacroRunning = true; |
||
674 | while ( strlen(body)>0 ) do |
||
675 | local block, line; |
||
676 | body, block, line=FindBlock(body); |
||
677 | if ( block ) then |
||
678 | RunScript(block); |
||
679 | else |
||
680 | RunLine(line); |
||
681 | end |
||
682 | end |
||
683 | --SM_MacroRunning = nil; |
||
684 | end |
||
685 | |||
686 | Macro=RunMacro; |
||
687 | |||
688 | function RunSuperMacro(index) |
||
689 | if ( SuperMacroFrame_SaveSuperMacro ) then |
||
690 | SuperMacroFrame_SaveSuperMacro(); |
||
691 | end |
||
692 | local _,body=nil; |
||
693 | if ( type(index)=="number") then |
||
694 | _,_,body = GetOrderedSuperMacroInfo(index); |
||
695 | elseif ( type(index) == "string" ) then |
||
696 | body = GetSuperMacroInfo(index,"body"); |
||
697 | end |
||
698 | if ( not body ) then return; end |
||
699 | |||
700 | if ( ChatFrameEditBox:IsVisible() ) then |
||
701 | ChatEdit_OnEscapePressed(ChatFrameEditBox); |
||
702 | end |
||
703 | |||
704 | body = SM_ReplaceAlias(body); |
||
705 | |||
706 | --SM_MacroRunning = true; |
||
707 | while ( strlen(body)>0 ) do |
||
708 | local block, line; |
||
709 | body, block, line=FindBlock(body); |
||
710 | if ( block ) then |
||
711 | RunScript(block); |
||
712 | else |
||
713 | RunLine(line); |
||
714 | end |
||
715 | end |
||
716 | --SM_MacroRunning = nil; |
||
717 | end |
||
718 | |||
719 | function FindBlock(body) |
||
720 | local a,b,block=strfind(body,"^/script (%-%-%-%-%[%[.-%-%-%-%-%]%])[\n]*"); |
||
721 | if ( block ) then |
||
722 | body=strsub(body,b+1); |
||
723 | return body, block; |
||
724 | end |
||
725 | local a,b,line=strfind(body,"^([^\n]*)[\n]*"); |
||
726 | if ( line ) then |
||
727 | body=strsub(body,b+1); |
||
728 | return body, nil, line; |
||
729 | end |
||
730 | end |
||
731 | |||
732 | function RunBody(text) |
||
733 | local body=text; |
||
734 | local length = strlen(body); |
||
735 | for w in string.gfind(body, "[^\n]+") do |
||
736 | RunLine(w); |
||
737 | end |
||
738 | end |
||
739 | |||
740 | function RunLine(...) |
||
741 | -- execute a line in a macro |
||
742 | -- if script or cast, then rectify and RunScript |
||
743 | -- else send to chat edit box |
||
744 | for k=1,arg.n do |
||
745 | local text=arg[k]; |
||
746 | |||
747 | -- replace aliases |
||
748 | text = SM_ReplaceAlias(text, -1); |
||
749 | |||
750 | if ( string.find(text, "^/cast") ) then |
||
751 | local i, book = SM_FindSpell(gsub(text,"^%s*/cast%s*(%w.*[%w%)])%s*$","%1")); |
||
752 | if ( i ) then |
||
753 | CastSpell(i,book); |
||
754 | end |
||
755 | else |
||
756 | if ( string.find(text,"^/script ")) then |
||
757 | RunScript(gsub(text,"^/script ","")); |
||
758 | else |
||
759 | text = gsub( text, "\n", ""); -- cannot send newlines, will disconnect |
||
760 | ChatFrameEditBox:SetText(text); |
||
761 | ChatEdit_SendText(ChatFrameEditBox); |
||
762 | end |
||
763 | end |
||
764 | end -- for |
||
765 | end -- RunLine() |
||
766 | |||
767 | function SM_ReplaceAlias(body, after) |
||
768 | local size, step; |
||
769 | if ( after==-1 ) then |
||
770 | size, step = SM_AliasFunctions.low, -1; |
||
771 | else |
||
772 | size, step = SM_AliasFunctions.high, 1; |
||
773 | end |
||
774 | for i=step, size, step do |
||
775 | body = SM_AliasFunctions[i](body); |
||
776 | end |
||
777 | return body; |
||
778 | end |
||
779 | |||
780 | function SM_InsertAliasFunction(func, pos) |
||
781 | if ( pos==-1 ) then |
||
782 | SM_AliasFunctions.low = SM_AliasFunctions.low - 1; |
||
783 | SM_AliasFunctions[SM_AliasFunctions.low]=func; |
||
784 | return SM_AliasFunctions.low; |
||
785 | else |
||
786 | SM_AliasFunctions.high = SM_AliasFunctions.high + 1; |
||
787 | SM_AliasFunctions[SM_AliasFunctions.high]=func; |
||
788 | return SM_AliasFunctions.high; |
||
789 | end |
||
790 | end |
||
791 | |||
792 | function SM_FindSpell(spell) |
||
793 | local s = gsub(spell, "%s*(.-)%s*%(.*","%1"); |
||
794 | local r; |
||
795 | local num = tonumber(gsub( spell, "%D*(%d+)%D*", "%1"),10); |
||
796 | if ( string.find(spell, "%(%s*[Rr]acial")) then |
||
797 | r = "racial" |
||
798 | elseif ( string.find(spell, "%(%s*[Ss]ummon")) then |
||
799 | r = "summon" |
||
800 | elseif ( string.find(spell, "%(%s*[Aa]pprentice")) then |
||
801 | r = "apprentice" |
||
802 | elseif ( string.find(spell, "%(%s*[Jj]ourneyman")) then |
||
803 | r = "journeyman" |
||
804 | elseif ( string.find(spell, "%(%s*[Ee]xpert")) then |
||
805 | r = "expert" |
||
806 | elseif ( string.find(spell, "%(%s*[Aa]rtisan")) then |
||
807 | r = "artisan" |
||
808 | elseif ( string.find(spell, "%(%s*[Mm]aster")) then |
||
809 | r = "master" |
||
810 | elseif ( string.find(spell, "[Rr]ank%s*%d+") and num and num > 0) then |
||
811 | r = gsub(spell, ".*%(.*[Rr]ank%s*(%d+).*", "Rank "..num); |
||
812 | else |
||
813 | r = "" |
||
814 | end |
||
815 | return FindSpell(s,r); |
||
816 | end |
||
817 | |||
818 | function FindSpell(spell, rank) |
||
819 | local i = 1; |
||
820 | local booktype = { "spell", "pet", }; |
||
821 | --local booktype = "spell"; |
||
822 | local s,r; |
||
823 | local ys, yr; |
||
824 | for k, book in booktype do |
||
825 | while spell do |
||
826 | s, r = GetSpellName(i,book); |
||
827 | if ( not s ) then |
||
828 | i = 1; |
||
829 | break; |
||
830 | end |
||
831 | if ( string.lower(s) == string.lower(spell)) then ys=true; end |
||
832 | if ( (r == rank) or (r and rank and string.lower(r) == string.lower(rank))) then yr=true; end |
||
833 | if ( rank=='' and ys and (not GetSpellName(i+1, book) or string.lower(GetSpellName(i+1, book)) ~= string.lower(spell) )) then |
||
834 | yr = true; -- use highest spell rank if omitted |
||
835 | end |
||
836 | if ( ys and yr ) then |
||
837 | return i,book; |
||
838 | end |
||
839 | i=i+1; |
||
840 | ys = nil; |
||
841 | yr = nil; |
||
842 | end |
||
843 | end |
||
844 | return; |
||
845 | end |
||
846 | |||
847 | function SuperMacroSaveExtendButton_OnClick() |
||
848 | SuperMacroSaveExtend(); |
||
849 | SuperMacroRunScriptExtend(); |
||
850 | end |
||
851 | |||
852 | function SuperMacroDeleteExtendButton_OnClick() |
||
853 | SuperMacroSaveExtend(SelectedMacroName(),1); |
||
854 | SuperMacroRunScriptExtend(); |
||
855 | end |
||
856 | |||
857 | function SuperMacroSaveExtend(macro, delete) |
||
858 | local text=SuperMacroFrameExtendText:GetText(); |
||
859 | if ( delete ) then text = nil; end |
||
860 | if ( not macro ) then |
||
861 | macro = SelectedMacroName(); |
||
862 | end |
||
863 | if ( macro ) then |
||
864 | if ( text and text~="" ) then |
||
865 | SM_EXTEND[macro]=text; |
||
866 | else |
||
867 | SM_EXTEND[macro]=nil; |
||
868 | if ( macro == SelectedMacroName() ) then |
||
869 | SuperMacroFrameExtendText:SetText(''); |
||
870 | end |
||
871 | end |
||
872 | end |
||
873 | SuperMacroFrame.extendChanged=nil; |
||
874 | SuperMacroFrameExtendText:ClearFocus(); |
||
875 | end |
||
876 | |||
877 | function SuperMacroGetExtend(macro) |
||
878 | return SM_EXTEND[macro]; |
||
879 | end |
||
880 | |||
881 | function SuperMacroRunScriptExtend() |
||
882 | for m,e in pairs(SM_EXTEND) do |
||
883 | if ( e ) then |
||
884 | RunScript(e); |
||
885 | end |
||
886 | end |
||
887 | end |
||
888 | |||
889 | function SuperMacroDeleteButton_OnClick() |
||
890 | -- check other macros with same name to see if save extend |
||
891 | local macro=GetMacroInfo(SuperMacroFrame.selectedMacro,"name"); |
||
892 | if ( SameMacroName()==false ) then |
||
893 | SuperMacroSaveExtend(macro,1); -- delete extend |
||
894 | end |
||
895 | DeleteMacro(SuperMacroFrame.selectedMacro); |
||
896 | SuperMacroFrame_OnLoad(); |
||
897 | SuperMacroFrame_Update(); |
||
898 | local name = GetMacroInfo(1,"name"); |
||
899 | oldextend = SM_EXTEND[name]; |
||
900 | if ( oldextend ) then |
||
901 | SuperMacroFrameExtendText:SetText(oldextend); |
||
902 | end |
||
903 | oldextend = nil; |
||
904 | SuperMacroFrameText:ClearFocus(); |
||
905 | end |
||
906 | |||
907 | function SuperMacroDeleteSuperButton_OnClick() |
||
908 | DeleteSuperMacro(SuperMacroFrame.selectedSuper); |
||
909 | --SuperMacroFrame_OnLoad(); |
||
910 | SuperMacroFrame_Update(); |
||
911 | local name = GetOrderedSuperMacroInfo(1); |
||
912 | SuperMacroFrameSuperText:ClearFocus(); |
||
913 | end |
||
914 | |||
915 | function SameMacroName(macroindex) |
||
916 | if ( not macroindex and SuperMacroFrame.selectedMacro ) then |
||
917 | macroindex = SuperMacroFrame.selectedMacro; |
||
918 | else |
||
919 | return; -- error check for nil, no macro selected |
||
920 | end |
||
921 | local macro=GetMacroInfo(macroindex,"name"); |
||
922 | local prevmacro, nextmacro = GetMacroInfo(macroindex-1,"name"), GetMacroInfo(macroindex+1,"name"); |
||
923 | if ( prevmacro == macro ) then |
||
924 | return macroindex-1; |
||
925 | elseif ( nextmacro == macro ) then |
||
926 | return macroindex+1; |
||
927 | else |
||
928 | return false; -- must check "==false" |
||
929 | -- don't check "not SameMacroName()" unless error check or no macro selected |
||
930 | end |
||
931 | end |
||
932 | |||
933 | function SelectedMacroName() |
||
934 | return SuperMacroFrameSelectedMacroName:GetText(); |
||
935 | end |
||
936 | |||
937 | local oldGetMacroInfo=GetMacroInfo; |
||
938 | function GetMacroInfo(index, code) |
||
939 | if ( not index ) then return; end |
||
940 | -- code can be "name", "texture", "body", "islocal" |
||
941 | local a={}; |
||
942 | a.name,a.texture,a.body,a.islocal=oldGetMacroInfo(index); |
||
943 | if (not code) then |
||
944 | return a.name,a.texture,a.body,a.islocal; |
||
945 | else |
||
946 | return a[code]; |
||
947 | end |
||
948 | end |
||
949 | |||
950 | function SetActionMacro( actionid , macro ) |
||
951 | local macroid = GetMacroIndexByName( macro ) |
||
952 | if ( macroid and actionid > 0 and actionid <= 120 ) then |
||
953 | PickupAction( actionid ); |
||
954 | PickupMacro( macroid ); |
||
955 | PlaceAction ( actionid ); |
||
956 | end |
||
957 | end |
||
958 | |||
959 | function ToggleSMMinimap() |
||
960 | if ( SM_VARS.minimap == 1 ) then |
||
961 | SuperMacroMinimapButton:Show(); |
||
962 | else |
||
963 | SuperMacroMinimapButton:Hide(); |
||
964 | end |
||
965 | end |
||
966 | |||
967 | function SM_UpdateAction() |
||
968 | -- Update Macros on action bars |
||
969 | local function doUpdate(button) |
||
970 | if ( button ) then |
||
971 | button:SetScript("OnLeave", SM_ActionButton_OnLeave); |
||
972 | local oldscript=button:GetScript("OnClick"); |
||
973 | button:SetScript("OnClick", function() |
||
974 | if ( not SM_ActionButton_OnClick() ) then |
||
975 | oldscript(); |
||
976 | end |
||
977 | end); |
||
978 | |||
979 | -- refresh buttons on load |
||
980 | local macroName = getglobal(button:GetName().."Name") and getglobal(button:GetName().."Name"):GetText(); |
||
981 | if ( macroName ) then |
||
982 | local macroID = GetMacroIndexByName(macroName); |
||
983 | if ( macroID ) then |
||
984 | local name, texture, body, isLocal = GetMacroInfo(macroID); |
||
985 | EditMacro(macroID, nil, nil, body, isLocal); |
||
986 | end |
||
987 | end |
||
988 | end |
||
989 | end |
||
990 | for i=1,12 do |
||
991 | doUpdate(getglobal("ActionButton"..i)); |
||
992 | doUpdate(getglobal("BonusActionButton"..i)); |
||
993 | doUpdate(getglobal("MultiBarBottomLeftButton"..i)); |
||
994 | doUpdate(getglobal("MultiBarBottomRightButton"..i)); |
||
995 | doUpdate(getglobal("MultiBarRightButton"..i)); |
||
996 | doUpdate(getglobal("MultiBarLeftButton"..i)); |
||
997 | end |
||
998 | if ( FUActionButton1 ) then |
||
999 | for i=1,72 do |
||
1000 | doUpdate(getglobal("FUActionButton"..i)); |
||
1001 | end |
||
1002 | end |
||
1003 | ---[[ |
||
1004 | if ( DAB_ActionButton_1 ) then |
||
1005 | for i=1, 120 do |
||
1006 | doUpdate(getglobal("DAB_ActionButton_"..i)); |
||
1007 | end |
||
1008 | end |
||
1009 | --]] |
||
1010 | end |
||
1011 | |||
1012 | function GetNumSuperMacros() |
||
1013 | return getn(SM_ORDERED); |
||
1014 | end |
||
1015 | |||
1016 | function GetSuperMacroInfo( superName, code) |
||
1017 | if ( not superName or not SM_SUPER[superName] ) then return; end |
||
1018 | -- code can be "name", "texture", "body" |
||
1019 | local a={}; |
||
1020 | a.name,a.texture,a.body=unpack(SM_SUPER[superName]); |
||
1021 | if (not code) then |
||
1022 | return a.name,a.texture,a.body; |
||
1023 | else |
||
1024 | return a[code]; |
||
1025 | end |
||
1026 | end |
||
1027 | |||
1028 | function SortSuperMacroList() |
||
1029 | -- sort SM_SUPER into ordered list |
||
1030 | local a={}; |
||
1031 | for n in pairs(SM_SUPER) do |
||
1032 | table.insert(a, n); |
||
1033 | end |
||
1034 | table.sort(a, atoz); |
||
1035 | return a; |
||
1036 | end |
||
1037 | |||
1038 | function GetOrderedSuperMacroInfo( id ) |
||
1039 | if ( not SM_ORDERED ) then |
||
1040 | SM_ORDERED=SortSuperMacroList(); |
||
1041 | end |
||
1042 | if ( not SM_SUPER[SM_ORDERED[id] ] ) then |
||
1043 | return; |
||
1044 | end |
||
1045 | return unpack(SM_SUPER[SM_ORDERED[id] ]); |
||
1046 | end |
||
1047 | |||
1048 | function GetOrderedSuperMacro( name ) |
||
1049 | for i,v in SM_ORDERED do |
||
1050 | if ( v==name ) then |
||
1051 | return i; |
||
1052 | end |
||
1053 | end |
||
1054 | end |
||
1055 | |||
1056 | function CreateSuperMacro( name, texture, body ) |
||
1057 | if ( not SM_SUPER[name] ) then |
||
1058 | SM_SUPER[name]={name, texture, body or ''}; |
||
1059 | end |
||
1060 | SM_UpdateActionSpell( name, "super", body); |
||
1061 | SM_ORDERED=SortSuperMacroList(); |
||
1062 | return GetOrderedSuperMacro(name); |
||
1063 | end |
||
1064 | |||
1065 | function EditSuperMacro( id, name, texture) |
||
1066 | local oldMacro, oldTexture, oldBody=GetOrderedSuperMacroInfo(id); |
||
1067 | if ( oldMacro~=name ) then |
||
1068 | SM_SUPER[oldMacro]=nil; |
||
1069 | SM_UpdateActionSpell( oldMacro, "super", nil); |
||
1070 | end |
||
1071 | SM_SUPER[name]={ name, texture, oldBody}; |
||
1072 | SM_UpdateActionSpell( name, "super", oldBody); |
||
1073 | SM_ORDERED=SortSuperMacroList(); |
||
1074 | return GetOrderedSuperMacro(name); |
||
1075 | end |
||
1076 | |||
1077 | function DeleteSuperMacro( macro ) |
||
1078 | local id=macro; |
||
1079 | if ( type(macro)=="number" ) then |
||
1080 | macro=GetOrderedSuperMacroInfo(macro); |
||
1081 | else |
||
1082 | id=GetOrderedSuperMacro(macro); |
||
1083 | end |
||
1084 | SM_SUPER[macro]=nil; |
||
1085 | SM_ORDERED=SortSuperMacroList(); |
||
1086 | if ( GetNumSuperMacros()==0 ) then |
||
1087 | id=nil; |
||
1088 | else |
||
1089 | id=id>1 and id-1 or 1; |
||
1090 | end |
||
1091 | SuperMacroFrame_SelectSuperMacro(id); |
||
1092 | end |
||
1093 | |||
1094 | function SM_LoadMacroIcons() |
||
1095 | local icon={}; |
||
1096 | for i=1,GetNumMacroIcons() do |
||
1097 | local texture=GetMacroIconInfo(i); |
||
1098 | icon[texture]=i; |
||
1099 | end |
||
1100 | return icon; |
||
1101 | end |
||
1102 | |||
1103 | function SM_UpdateActionSpell( macroname, macrotype, body) |
||
1104 | -- SM_ACTION_SPELL={} |
||
1105 | -- SM_ACTION_SPELL.regular={} |
||
1106 | -- SM_ACTION_SPELL.super={} |
||
1107 | if ( not macroname ) then |
||
1108 | -- update all macros |
||
1109 | for i=1, 36 do |
||
1110 | local name,_,body=GetMacroInfo(i); |
||
1111 | if ( name ) then |
||
1112 | SM_UpdateActionSpell(name, "regular", body); |
||
1113 | end |
||
1114 | end |
||
1115 | for i=1, GetNumSuperMacros() do |
||
1116 | local name,_,body=GetOrderedSuperMacroInfo(i); |
||
1117 | SM_UpdateActionSpell(name, "super", body); |
||
1118 | end |
||
1119 | return; |
||
1120 | end |
||
1121 | --macrotype is "regular" or "super" |
||
1122 | if ( macrotype~="regular" and macrotype~="super" ) then |
||
1123 | macrotype="regular"; |
||
1124 | end |
||
1125 | SM_ACTION_SPELL[macrotype][macroname]={}; |
||
1126 | local id, book, texture, count, spell=FindFirstSpell(body); |
||
1127 | if ( id ) then |
||
1128 | SM_ACTION_SPELL[macrotype][macroname].type="spell"; |
||
1129 | spell=count; |
||
1130 | else |
||
1131 | id, book, texture, count, spell=FindFirstItem(body); |
||
1132 | if ( id ) then |
||
1133 | SM_ACTION_SPELL[macrotype][macroname].type="item"; |
||
1134 | end |
||
1135 | end |
||
1136 | if ( not id ) then |
||
1137 | SM_ACTION_SPELL[macrotype][macroname]=nil; |
||
1138 | return; |
||
1139 | end |
||
1140 | SM_ACTION_SPELL[macrotype][macroname].spell=spell; |
||
1141 | SM_ACTION_SPELL[macrotype][macroname].texture=texture; |
||
1142 | end |
||
1143 | |||
1144 | function SM_GetActionSpell(macroname, macrotype) |
||
1145 | if ( macrotype and macrotype~="regular" ) then |
||
1146 | macrotype="super"; |
||
1147 | else |
||
1148 | macrotype="regular"; |
||
1149 | end |
||
1150 | if ( not SM_ACTION_SPELL[macrotype][macroname] ) then |
||
1151 | return nil; |
||
1152 | end |
||
1153 | local actiontype=SM_ACTION_SPELL[macrotype][macroname].type; |
||
1154 | local spell=SM_ACTION_SPELL[macrotype][macroname].spell; |
||
1155 | local texture=SM_ACTION_SPELL[macrotype][macroname].texture; |
||
1156 | return actiontype, spell, texture; |
||
1157 | end |