vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | MAX_MEGAMACROS = 84; |
2 | NUM_MACRO_ICONS_SHOWN = 20; |
||
3 | NUM_ICONS_PER_ROW = 5; |
||
4 | NUM_ICON_ROWS = 4; |
||
5 | MACRO_ICON_ROW_HEIGHT = 36; |
||
6 | local menucheck = 0; |
||
7 | local loadcheck = 0; |
||
8 | |||
9 | BINDING_HEADER_MEGAMACROHEADER = "Megamacro"; |
||
10 | BINDING_NAME_MEGAMACRO = "MegaMacro Toggle"; |
||
11 | |||
12 | MegaMacroText = {}; |
||
13 | |||
14 | SLASH_MEGAMACRO1 = "/megamacro"; |
||
15 | SlashCmdList["MEGAMACRO"] = function(msg) |
||
16 | ShowMegaMacroFrame(); |
||
17 | end |
||
18 | SlashCmdList["MACRO"] = function(msg) |
||
19 | ShowMegaMacroFrame(); |
||
20 | end |
||
21 | UIPanelWindows["MegaMacroFrame"] = { area = "left", pushable = 5 }; |
||
22 | |||
23 | -- Hook the New MacroFrame Load to load MegaMacro LoadOnDemand Style :) |
||
24 | --MacroFrame_LoadUI = MegaMacroFrame_LoadUI; |
||
25 | |||
26 | function MegaMacroFrame_LoadUI() |
||
27 | -- Hmm :) do nothing for now.. |
||
28 | --UIParentLoadAddOn("MegaMacro"); |
||
29 | if ( not MegaMacroFrame:IsVisible() ) then |
||
30 | ShowUIPanel(MegaMacroFrame); |
||
31 | end |
||
32 | end |
||
33 | |||
34 | function ShowMegaMacroFrame() |
||
35 | ShowUIPanel(MegaMacroFrame); |
||
36 | end |
||
37 | |||
38 | function MegaMacro_SpellButton_OnClick(drag) |
||
39 | local id = SpellBook_GetSpellID(this:GetID()); |
||
40 | if ( id > MAX_SPELLS ) then |
||
41 | return; |
||
42 | end |
||
43 | this:SetChecked("false"); |
||
44 | if ( drag ) then |
||
45 | PickupSpell(id, SpellBookFrame.bookType); |
||
46 | elseif ( IsShiftKeyDown() ) then |
||
47 | if ( MegaMacroFrame and MegaMacroFrame:IsVisible() ) then |
||
48 | local spellName, subSpellName = GetSpellName(id, SpellBookFrame.bookType); |
||
49 | if ( spellName and not IsSpellPassive(id, SpellBookFrame.bookType) ) then |
||
50 | if ( subSpellName and (strlen(subSpellName) > 0) ) then |
||
51 | MegaMacroFrame_AddMacroLine(TEXT(SLASH_CAST1).." "..spellName.."("..subSpellName..")"); |
||
52 | else |
||
53 | MegaMacroFrame_AddMacroLine(TEXT(SLASH_CAST1).." "..spellName); |
||
54 | end |
||
55 | end |
||
56 | else |
||
57 | PickupSpell(id, SpellBookFrame.bookType ); |
||
58 | end |
||
59 | elseif ( arg1 ~= "LeftButton" and SpellBookFrame.bookType == BOOKTYPE_PET ) then |
||
60 | ToggleSpellAutocast(id, SpellBookFrame.bookType); |
||
61 | else |
||
62 | CastSpell(id, SpellBookFrame.bookType); |
||
63 | SpellButton_UpdateSelection(); |
||
64 | end |
||
65 | end |
||
66 | |||
67 | function MegaMacroFrame_OnLoad() |
||
68 | --Fix the load error hopefully |
||
69 | --this:RegisterEvent("VARIABLES_LOADED"); |
||
70 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
71 | |||
72 | -- Hook functions |
||
73 | MacroFrame_LoadUI = MegaMacroFrame_LoadUI; |
||
74 | ShowMacroFrame = ShowMegaMacroFrame; |
||
75 | |||
76 | -- Hook spellbook to allow shift clicking of spells |
||
77 | SpellButton_OnClick = MegaMacro_SpellButton_OnClick; |
||
78 | |||
79 | if ( GetNumMacros() > 0 ) then |
||
80 | MegaMacroFrame_SelectMacro(1); |
||
81 | MegaMacroFrameSelectedMacroButton:SetID(1); |
||
82 | else |
||
83 | MegaMacroFrame_SelectMacro(nil); |
||
84 | end |
||
85 | end |
||
86 | |||
87 | function DeleteMegaMacroFrame_OnLoad() |
||
88 | if ( GetNumMacros() > 0 ) then |
||
89 | MegaMacroFrame_SelectMacro(1); |
||
90 | MegaMacroFrameSelectedMacroButton:SetID(1); |
||
91 | else |
||
92 | MegaMacroFrame_SelectMacro(nil); |
||
93 | end |
||
94 | end |
||
95 | |||
96 | function MegaMacro_OnEvent() |
||
97 | if ( event == "PLAYER_ENTERING_WORLD" ) then |
||
98 | MegaMacro_Init(); |
||
99 | end |
||
100 | end |
||
101 | |||
102 | function MegaMacro_Init() |
||
103 | if ( loadcheck == 0 ) then |
||
104 | local numMacros = GetNumMacros(); |
||
105 | for i=1, MAX_MEGAMACROS do |
||
106 | if ( i <= numMacros ) then |
||
107 | macroName = GetMacroInfo(i); |
||
108 | if ( not MegaMacroText[macroName] ) then |
||
109 | MegaMacroText[macroName] = ""; |
||
110 | else |
||
111 | RunScript(MegaMacroText[macroName]); |
||
112 | end |
||
113 | end |
||
114 | end |
||
115 | loadcheck = 1; |
||
116 | end |
||
117 | end |
||
118 | |||
119 | function NewChatMenu_OnShow() |
||
120 | UIMenu_OnShow(); |
||
121 | EmoteMenu:Hide(); |
||
122 | if (menucheck ==0) then |
||
123 | --ChatMenuButton10:Hide(); |
||
124 | UIMenu_AddButton("MegaMacro", nil, ShowMegaMacroFrame); |
||
125 | menucheck = 1; |
||
126 | end |
||
127 | end |
||
128 | |||
129 | function MegaMacro_Execute() |
||
130 | MegaMacroText[macroName] = MegaMacroEditBox:GetText(); |
||
131 | RunScript(MegaMacroText[macroName]); |
||
132 | MegaMegaMacroNewButton:Disable(); |
||
133 | end |
||
134 | |||
135 | function MegaMacro_UpdateText(macroName) |
||
136 | |||
137 | --if ( not macroName ) then |
||
138 | -- Hmm |
||
139 | --else |
||
140 | --if ( not MegaMacroText[macroName] ) then |
||
141 | --MegaMacroText[macroName] = ""; |
||
142 | --end |
||
143 | MegaMacroText[macroName] = MegaMacroEditBox:GetText(); |
||
144 | --end |
||
145 | end |
||
146 | |||
147 | function MegaMacroFrame_OnShow() |
||
148 | MegaMacroFrame_Update(); |
||
149 | PlaySound("igCharacterInfoOpen"); |
||
150 | --MacroNewButton:SetText(NEW); |
||
151 | --Mega macro updates |
||
152 | MegaMegaMacroNewButton:Disable(); |
||
153 | MegaMacroID = MegaMacroFrame.selectedMacro; |
||
154 | if ( not MegaMacroID ) then |
||
155 | -- Hmm |
||
156 | else |
||
157 | macroName = GetMacroInfo(MegaMacroID); |
||
158 | MegaMacroEditBox:SetText(MegaMacroText[macroName]); |
||
159 | end |
||
160 | end |
||
161 | |||
162 | function MegaMacroFrame_OnHide() |
||
163 | MegaMacroPopupFrame:Hide(); |
||
164 | if ( MegaMacroFrame.textChanged and MegaMacroFrame.selectedMacro and GetNumMacros() > 0) then |
||
165 | EditMacro(MegaMacroFrame.selectedMacro, nil, nil, MegaMacroFrameText:GetText(), 1); |
||
166 | end |
||
167 | MegaMacroFrame.textChanged = nil; |
||
168 | --Dunno why but this is what blizzard did.. |
||
169 | --SaveMacros(); |
||
170 | PlaySound("igCharacterInfoClose"); |
||
171 | end |
||
172 | |||
173 | function MegaMacroFrame_Update() |
||
174 | local numMacros = GetNumMacros(); |
||
175 | local megamacroButton, macroIcon, macroName; |
||
176 | local name, texture, body, isLocal; |
||
177 | local selectedName, selectedBody, selectedIcon; |
||
178 | |||
179 | -- Macro List |
||
180 | for i=1, MAX_MEGAMACROS do |
||
181 | megamacroButton = getglobal("MegaMacroButton"..i); |
||
182 | macroIcon = getglobal("MegaMacroButton"..i.."Icon"); |
||
183 | macroName = getglobal("MegaMacroButton"..i.."Name"); |
||
184 | if ( i <= numMacros ) then |
||
185 | name, texture, body, isLocal = GetMacroInfo(i); |
||
186 | macroIcon:SetTexture(texture); |
||
187 | macroName:SetText(name); |
||
188 | megamacroButton:Enable(); |
||
189 | -- Highlight Selected Macro |
||
190 | if ( i == MegaMacroFrame.selectedMacro ) then |
||
191 | megamacroButton:SetChecked(1); |
||
192 | MegaMacroFrameSelectedMacroName:SetText(name); |
||
193 | MegaMacroFrameText:SetText(body); |
||
194 | MegaMacroFrameSelectedMacroButtonIcon:SetTexture(texture); |
||
195 | else |
||
196 | megamacroButton:SetChecked(0); |
||
197 | end |
||
198 | else |
||
199 | megamacroButton:SetChecked(0); |
||
200 | macroIcon:SetTexture(""); |
||
201 | macroName:SetText(""); |
||
202 | megamacroButton:Disable(); |
||
203 | end |
||
204 | end |
||
205 | |||
206 | --Mega Macro Updates |
||
207 | local numMacros = GetNumMacros(); |
||
208 | for i=1, MAX_MEGAMACROS do |
||
209 | if ( i <= numMacros ) then |
||
210 | macroName = GetMacroInfo(i); |
||
211 | if ( not MegaMacroText[macroName] ) then |
||
212 | MegaMacroText[macroName] = ""; |
||
213 | else |
||
214 | --RunScript on PLAYER_ENTERING_WORLD once |
||
215 | --RunScript(MegaMacroText[macroName]); |
||
216 | end |
||
217 | end |
||
218 | end |
||
219 | |||
220 | -- Macro Details |
||
221 | if ( MegaMacroFrame.selectedMacro ~= nil ) then |
||
222 | MegaMacroFrame_ShowDetails(); |
||
223 | MegaMacroDeleteButton:Enable(); |
||
224 | else |
||
225 | MegaMacroFrame_HideDetails(); |
||
226 | MegaMacroDeleteButton:Disable(); |
||
227 | end |
||
228 | |||
229 | if ( numMacros == MAX_MEGAMACROS or MegaMacroPopupFrame:IsVisible() ) then |
||
230 | MegaMacroNewButton:Disable(); |
||
231 | else |
||
232 | MegaMacroNewButton:Enable(); |
||
233 | end |
||
234 | |||
235 | -- Disable Buttons |
||
236 | if ( MegaMacroPopupFrame:IsVisible() ) then |
||
237 | MegaMacroEditButton:Disable(); |
||
238 | MegaMacroDeleteButton:Disable(); |
||
239 | else |
||
240 | MegaMacroEditButton:Enable(); |
||
241 | MegaMacroDeleteButton:Enable(); |
||
242 | end |
||
243 | |||
244 | if ( not MegaMacroFrame.selectedMacro ) then |
||
245 | MegaMacroDeleteButton:Disable(); |
||
246 | end |
||
247 | end |
||
248 | |||
249 | function MegaMacroFrame_AddMacroLine(line) |
||
250 | if ( MegaMacroFrameText:IsVisible() ) then |
||
251 | MegaMacroFrameText:SetText(MegaMacroFrameText:GetText()..line); |
||
252 | end |
||
253 | end |
||
254 | |||
255 | function MegaMacroButton_OnClick() |
||
256 | if ( MegaMacroFrame.textChanged and MegaMacroFrame.selectedMacro ) then |
||
257 | EditMacro(MegaMacroFrame.selectedMacro, nil, nil, MegaMacroFrameText:GetText(), 1); |
||
258 | end |
||
259 | MegaMacroFrame.textChanged = nil; |
||
260 | MegaMacroFrame_SelectMacro(this:GetID()); |
||
261 | MegaMacroFrameSelectedMacroButton:SetID(this:GetID()); |
||
262 | MegaMacroFrame_Update(); |
||
263 | MegaMacroPopupFrame:Hide(); |
||
264 | MegaMacroFrameText:ClearFocus(); |
||
265 | --Mega Macro Stuff |
||
266 | MegaMacroEditBox:ClearFocus(); |
||
267 | MegaMacroEditBox:SetTextColor(25,25,25); |
||
268 | MegaMacroID = MegaMacroFrame.selectedMacro; |
||
269 | macroName = GetMacroInfo(MegaMacroID); |
||
270 | --if ( not MegaMacroText[macroName] ) then |
||
271 | --MegaMacroText[macroName] = ""; |
||
272 | --end |
||
273 | MegaMacroEditBox:SetText(MegaMacroText[macroName]); |
||
274 | MegaMacro_UpdateText(macroName); |
||
275 | end |
||
276 | |||
277 | function MegaMacroFrame_SelectMacro(id) |
||
278 | MegaMacroFrame.selectedMacro = id; |
||
279 | end |
||
280 | |||
281 | function MegaMacroNewButton_OnClick() |
||
282 | if ( MegaMacroNewButton:GetText() == COMPLETE ) then |
||
283 | MegaMacroFrameText:ClearFocus(); |
||
284 | EditMacro(MegaMacroFrame.selectedMacro, nil, nil, MegaMacroFrameText:GetText(), 1); |
||
285 | --MegaMacroNewButton:SetText(NEW); |
||
286 | return; |
||
287 | end |
||
288 | |||
289 | MegaMacroPopupFrame.mode = "new"; |
||
290 | if ( MegaMacroFrame.textChanged and MegaMacroFrame.selectedMacro ) then |
||
291 | EditMacro(MegaMacroFrame.selectedMacro, nil, nil, MegaMacroFrameText:GetText(), 1); |
||
292 | end |
||
293 | MegaMacroFrameText:Hide(); |
||
294 | MegaMacroFrame.textChanged = nil; |
||
295 | MegaMacroFrameSelectedMacroButtonIcon:SetTexture(""); |
||
296 | MegaMacroPopupFrame.selectedIcon = nil; |
||
297 | MegaMacroPopupFrame:Show(); |
||
298 | --MegaMacroNewButton:SetText(COMPLETE); |
||
299 | MegaMegaMacroNewButton:Disable(); |
||
300 | end |
||
301 | |||
302 | function MegaMacroEditButton_OnClick() |
||
303 | MegaMacroPopupFrame.mode = "edit"; |
||
304 | if ( MegaMacroFrame.textChanged ) then |
||
305 | EditMacro(MegaMacroFrame.selectedMacro, nil, nil, MegaMacroFrameText:GetText(), 1); |
||
306 | end |
||
307 | MegaMacroFrame.textChanged = nil; |
||
308 | MegaMacroPopupOkayButton_Update(); |
||
309 | MegaMacroPopupFrame:Show(); |
||
310 | end |
||
311 | |||
312 | function MegaMacroFrame_HideDetails() |
||
313 | MegaMacroEditButton:Hide(); |
||
314 | MegaMacroFrameCharLimitText:Hide(); |
||
315 | MegaMacroFrameText:Hide(); |
||
316 | MegaMacroFrameSelectedMacroName:Hide(); |
||
317 | MegaMacroFrameSelectedMacroBackground:Hide(); |
||
318 | MegaMacroFrameSelectedMacroButton:Hide(); |
||
319 | end |
||
320 | |||
321 | function MegaMacroFrame_ShowDetails() |
||
322 | MegaMacroEditButton:Show(); |
||
323 | MegaMacroFrameCharLimitText:Show(); |
||
324 | MegaMacroFrameEnterMacroText:Show(); |
||
325 | MegaMacroFrameText:Show(); |
||
326 | MegaMacroFrameSelectedMacroName:Show(); |
||
327 | MegaMacroFrameSelectedMacroBackground:Show(); |
||
328 | MegaMacroFrameSelectedMacroButton:Show(); |
||
329 | end |
||
330 | |||
331 | function MegaMacroPopupFrame_OnShow() |
||
332 | MegaMacroPopupFrame_Update(); |
||
333 | PlaySound("igCharacterInfoOpen"); |
||
334 | MegaMacroFrameText:ClearFocus(); |
||
335 | MegaMacroPopupEditBox:SetFocus(); |
||
336 | MegaMacroPopupOkayButton_Update(); |
||
337 | |||
338 | -- Disable Buttons |
||
339 | MegaMacroEditButton:Disable(); |
||
340 | MegaMacroDeleteButton:Disable(); |
||
341 | MegaMacroNewButton:Disable(); |
||
342 | end |
||
343 | |||
344 | function MegaMacroPopupFrame_OnHide() |
||
345 | if ( this.mode == "new" ) then |
||
346 | MegaMacroFrameText:Show(); |
||
347 | MegaMacroFrameText:SetFocus(); |
||
348 | end |
||
349 | |||
350 | -- Enable Buttons |
||
351 | MegaMacroEditButton:Enable(); |
||
352 | MegaMacroDeleteButton:Enable(); |
||
353 | MegaMacroNewButton:Enable(); |
||
354 | end |
||
355 | |||
356 | function MegaMacroPopupFrame_Update() |
||
357 | local numMacroIcons = GetNumMacroIcons(); |
||
358 | local macroPopupIcon, macroPopupButton; |
||
359 | local macroPopupOffset = FauxScrollFrame_GetOffset(MegaMacroPopupScrollFrame); |
||
360 | local index; |
||
361 | |||
362 | -- Determine whether we're creating a new macro or editing an existing one |
||
363 | if ( this.mode == "new" ) then |
||
364 | MegaMacroPopupEditBox:SetText(""); |
||
365 | elseif ( this.mode == "edit" ) then |
||
366 | local name, texture, body, isLocal = GetMacroInfo(MegaMacroFrame.selectedMacro); |
||
367 | MegaMacroPopupEditBox:SetText(name); |
||
368 | end |
||
369 | |||
370 | -- Icon list |
||
371 | for i=1, NUM_MACRO_ICONS_SHOWN do |
||
372 | macroPopupIcon = getglobal("MegaMacroPopupButton"..i.."Icon"); |
||
373 | macroPopupButton = getglobal("MegaMacroPopupButton"..i); |
||
374 | index = (macroPopupOffset * NUM_ICONS_PER_ROW) + i; |
||
375 | if ( index <= numMacroIcons ) then |
||
376 | macroPopupIcon:SetTexture(GetMacroIconInfo(index)); |
||
377 | macroPopupButton:Show(); |
||
378 | else |
||
379 | macroPopupIcon:SetTexture(""); |
||
380 | macroPopupButton:Hide(); |
||
381 | end |
||
382 | if ( index == MegaMacroPopupFrame.selectedIcon ) then |
||
383 | macroPopupButton:SetChecked(1); |
||
384 | else |
||
385 | macroPopupButton:SetChecked(nil); |
||
386 | end |
||
387 | end |
||
388 | |||
389 | -- Scrollbar stuff |
||
390 | FauxScrollFrame_Update(MegaMacroPopupScrollFrame, ceil(numMacroIcons / NUM_ICONS_PER_ROW) , NUM_ICON_ROWS, MACRO_ICON_ROW_HEIGHT ); |
||
391 | end |
||
392 | |||
393 | function MegaMacroPopupOkayButton_Update() |
||
394 | if ( (strlen(MegaMacroPopupEditBox:GetText()) > 0) and MegaMacroPopupFrame.selectedIcon ) then |
||
395 | MegaMacroPopupOkayButton:Enable(); |
||
396 | else |
||
397 | MegaMacroPopupOkayButton:Disable(); |
||
398 | end |
||
399 | if ( MegaMacroPopupFrame.mode == "edit" and (strlen(MegaMacroPopupEditBox:GetText()) > 0) ) then |
||
400 | MegaMacroPopupOkayButton:Enable(); |
||
401 | end |
||
402 | end |
||
403 | |||
404 | function MegaMacroPopupButton_OnClick() |
||
405 | MegaMacroPopupFrame.selectedIcon = this:GetID() + (FauxScrollFrame_GetOffset(MegaMacroPopupScrollFrame) * NUM_ICONS_PER_ROW) |
||
406 | MegaMacroFrameSelectedMacroButtonIcon:SetTexture(GetMacroIconInfo(MegaMacroPopupFrame.selectedIcon)); |
||
407 | MegaMacroPopupOkayButton_Update(); |
||
408 | MegaMacroPopupFrame_Update(); |
||
409 | end |
||
410 | |||
411 | function MegaMacroPopupOkayButton_OnClick() |
||
412 | local index = 1 |
||
413 | if ( MegaMacroPopupFrame.mode == "new" ) then |
||
414 | index = CreateMacro(MegaMacroPopupEditBox:GetText(), MegaMacroPopupFrame.selectedIcon, nil, 1); |
||
415 | elseif ( MegaMacroPopupFrame.mode == "edit" ) then |
||
416 | local id = MegaMacroFrame.selectedMacro; |
||
417 | if ( not id ) then |
||
418 | -- Hmm |
||
419 | else |
||
420 | local idName = GetMacroInfo(id); |
||
421 | local newmacroName = MegaMacroPopupEditBox:GetText(); |
||
422 | if ( not MegaMacroText[newmacroName] ) then |
||
423 | MegaMacroText[newmacroName] = MegaMacroText[idName]; |
||
424 | end |
||
425 | MegaMacroText[idName] = nil; |
||
426 | end |
||
427 | index = EditMacro(MegaMacroFrame.selectedMacro, MegaMacroPopupEditBox:GetText(), MegaMacroPopupFrame.selectedIcon); |
||
428 | |||
429 | end |
||
430 | MegaMacroFrame_SelectMacro(index); |
||
431 | MegaMacroPopupFrame:Hide(); |
||
432 | MegaMacroFrame_Update(); |
||
433 | end |
||
434 | |||
435 | function MegaMacroFrame_EditMacro() |
||
436 | if ( MegaMacroFrameText:IsVisible() ) then |
||
437 | if ( MegaMacroFrame.textChanged ) then |
||
438 | EditMacro(MegaMacroFrame.selectedMacro, nil, nil, MegaMacroFrameText:GetText(), 1); |
||
439 | MegaMacroFrame.textChanged = nil; |
||
440 | end |
||
441 | end |
||
442 | end |
||
443 | |||
444 | function ToggleMegaMacroFrame() |
||
445 | if ( MegaMacroFrame:IsVisible() ) then |
||
446 | MegaMacroFrame:Hide(); |
||
447 | else |
||
448 | MegaMacroFrame:Show(); |
||
449 | end |
||
450 | end |