vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | ---------------------------------------------------------- |
2 | ---------------------------------------------------------- |
||
3 | -- Simple Action Sets Beta 0.4 -- |
||
4 | -- -- |
||
5 | -- Allows all 120 action buttons to be saved to action -- |
||
6 | -- sets. Sets can then be swapped to on the fly. -- |
||
7 | -- -- |
||
8 | -- Thanks to Cide, Ts, and Gello for some excellent -- |
||
9 | -- mods to "borrow" from. -- |
||
10 | ---------------------------------------------------------- |
||
11 | ---------------------------------------------------------- |
||
12 | |||
13 | SAS_POS = 270; |
||
14 | SAS_OFFSET = 0 |
||
15 | |||
16 | SAS_POS_DEFAULT = 270; |
||
17 | SAS_OFFSET_DEFAULT = 0; |
||
18 | |||
19 | SAS_POS_TEMP = nil; |
||
20 | SAS_OFFSET_TEMP = nil; |
||
21 | |||
22 | --SAS_DEBUG = nil; |
||
23 | |||
24 | local PlrName; |
||
25 | local PlrClass; -- not used yet |
||
26 | |||
27 | -- Fix for barmods that badly hook PickupAction instead of doing it in external functions or xml |
||
28 | local barmods = { ctmod = {"CT_HotbarButtons_Locked"}, nurfed = {"NURFED_LOCKALL", 0} }; |
||
29 | |||
30 | -- Path name for all icons in the game |
||
31 | local IconPath = "Interface\\Icons\\"; |
||
32 | |||
33 | -- Table used to track what's on the cursor |
||
34 | SAS_SavedPickup = {}; -- name, rank, macro, link, texture |
||
35 | |||
36 | |||
37 | ------------------------------ |
||
38 | -- SAS Main Frame functions -- |
||
39 | ------------------------------ |
||
40 | |||
41 | function SASMain_UpdateDisplay() |
||
42 | local tab = SASMain.selectedTab; |
||
43 | if ( tab == 1 ) then |
||
44 | SASActions:SetHeight(280); |
||
45 | SASMainBottomDivider:SetPoint("TOPLEFT", SASMainTopDivider, "BOTTOMLEFT", 0, -270); |
||
46 | SASSets:Show() |
||
47 | SASOptions:Hide(); |
||
48 | SASHelp:Hide(); |
||
49 | elseif ( tab == 2 ) then |
||
50 | SASActions:SetHeight(185); |
||
51 | SASMainBottomDivider:SetPoint("TOPLEFT", SASMainTopDivider, "BOTTOMLEFT", 0, -175); |
||
52 | SASSets:Hide(); |
||
53 | SASOptions:Show(); |
||
54 | SASHelp:Hide(); |
||
55 | elseif ( tab == 3 ) then |
||
56 | SASActions:SetHeight(185); |
||
57 | SASMainBottomDivider:SetPoint("TOPLEFT", SASMainTopDivider, "BOTTOMLEFT", 0, -175); |
||
58 | SASSets:Hide(); |
||
59 | SASOptions:Hide(); |
||
60 | SASHelp:Show(); |
||
61 | end |
||
62 | end |
||
63 | |||
64 | function SASMain_Toggle() |
||
65 | if ( SASMain:IsVisible() ) then |
||
66 | HideUIPanel(SASMain); |
||
67 | else |
||
68 | ShowUIPanel(SASMain); |
||
69 | end |
||
70 | end |
||
71 | |||
72 | |||
73 | ----------------------------- |
||
74 | -- Actions Frame functions -- |
||
75 | ----------------------------- |
||
76 | function SASActions_OnShow() |
||
77 | SASActions_Load( SAS_GetCurrentSet() ); |
||
78 | end |
||
79 | |||
80 | function SASActions_OnHide() |
||
81 | SAS_Temp = nil; |
||
82 | end |
||
83 | |||
84 | function SASActions_Load( set, plr ) |
||
85 | SAS_Temp = {}; |
||
86 | |||
87 | if ( not plr ) then |
||
88 | plr = PlrName; |
||
89 | end |
||
90 | |||
91 | if ( not set or set == SAS_TEXT_CURRENT ) then |
||
92 | set = nil; |
||
93 | SAS_Temp = SAS_IterateActions(); |
||
94 | SASDebug( "Loading current actions" ); |
||
95 | UIDropDownMenu_Initialize(SASActionSetsDropDown, SASActions_DropDown_Initialize); |
||
96 | UIDropDownMenu_SetSelectedID( SASActionSetsDropDown, 0 ); |
||
97 | SASActionSetsDropDownButton:Disable(); |
||
98 | SASActionSetsDropDownText:SetText( "|c00999999"..SAS_TEXT_CURRENT ); |
||
99 | SASActionsDelete:Disable(); |
||
100 | elseif ( plr ~= PlrName ) then |
||
101 | SAS_Temp = SAS_CopyTable(SAS_Saved[plr]["s"][set]); |
||
102 | SASDebug( "Loading set "..set.." from "..plr ); |
||
103 | UIDropDownMenu_Initialize(SASActionSetsDropDown, SASActions_DropDown_Initialize); |
||
104 | UIDropDownMenu_SetSelectedID( SASActionSetsDropDown, 0 ); |
||
105 | SASActionSetsDropDownText:SetText( "|c00999999"..SAS_TEXT_CURRENT ); |
||
106 | SASActionsDelete:Disable(); |
||
107 | else |
||
108 | SAS_Temp = SAS_CopyTable(SAS_Saved[plr]["s"][set]); |
||
109 | SASDebug( "Loading set "..set ); |
||
110 | UIDropDownMenu_Initialize(SASActionSetsDropDown, SASActions_DropDown_Initialize); |
||
111 | UIDropDownMenu_SetSelectedName( SASActionSetsDropDown, set ); |
||
112 | SASActionsDelete:Enable(); |
||
113 | end |
||
114 | |||
115 | for k, v in SAS_Saved[PlrName]["s"] do |
||
116 | SASActionSetsDropDownButton:Enable(); |
||
117 | break; |
||
118 | end |
||
119 | |||
120 | SASActions_Display(); |
||
121 | SASActionsSave:Disable(); |
||
122 | --SAS_CurrentSet = set; |
||
123 | TitanPanelSAS_Update(); |
||
124 | end |
||
125 | |||
126 | function SASActions_Bar_CheckAll() |
||
127 | -- Check all bars enabled or disabled |
||
128 | local check = this:GetChecked(); |
||
129 | for i = 0, 9 do |
||
130 | getglobal( "SASActionBar"..i.."Enable"):SetChecked(check); |
||
131 | --SASActions_Bar_Toggle( i, check ); |
||
132 | if ( SAS_Temp[i] ) then |
||
133 | if ( check ) then |
||
134 | SAS_Temp[i][0] = nil; |
||
135 | else |
||
136 | SAS_Temp[i][0] = 1; |
||
137 | end |
||
138 | end |
||
139 | end |
||
140 | SASActions_Display(); |
||
141 | end |
||
142 | |||
143 | function SASActions_BarEnable_OnClick( bar, enable ) |
||
144 | -- Enable or disable a bar |
||
145 | if ( SAS_Temp[bar] ) then |
||
146 | if ( enable ) then |
||
147 | SAS_Temp[bar][0] = nil; |
||
148 | else |
||
149 | SAS_Temp[bar][0] = 1; |
||
150 | end |
||
151 | end |
||
152 | SASActions_UpdateBar( bar ) |
||
153 | SASActionsCheckAll:SetChecked(1); |
||
154 | |||
155 | SASActions_SaveEnable(); |
||
156 | end |
||
157 | |||
158 | function SASActionBarButton_OnClick() |
||
159 | local bar = this:GetParent():GetID(); |
||
160 | local enable = SAS_BarEnabled(bar) |
||
161 | local LocalSavedBar = SAS_CopyTable(SAS_Temp[bar]); |
||
162 | local returnbar = SAS_DraggingBar; |
||
163 | |||
164 | if ( SASFakeDragFrame.Bar and not IsShiftKeyDown() and not IsControlKeyDown() ) then |
||
165 | SAS_Temp[bar] = SASFakeDrag_Drop(1); |
||
166 | --SAS_Temp[bar]["enable"] = enable; |
||
167 | if ( returnbar ) then |
||
168 | SAS_DraggingBar = nil; |
||
169 | --enable = SAS_Temp[returnbar]["enable"]; |
||
170 | SAS_Temp[returnbar] = SAS_CopyTable(LocalSavedBar); |
||
171 | --SAS_Temp[returnbar]["enable"] = enable; |
||
172 | SASActions_UpdateBar(returnbar); |
||
173 | end |
||
174 | LocalSavedBar = nil; |
||
175 | elseif ( IsControlKeyDown() and not IsShiftKeyDown() ) then |
||
176 | SAS_Temp[bar] = {}; |
||
177 | --SAS_Temp[bar]["enable"] = enable; |
||
178 | end |
||
179 | |||
180 | if ( SAS_BarHasActions(bar) and LocalSavedBar ) then |
||
181 | SASFakeDrag_PickupBar(LocalSavedBar); |
||
182 | if ( not IsShiftKeyDown() ) then |
||
183 | SAS_DraggingBar = bar; |
||
184 | end |
||
185 | end |
||
186 | SASActions_UpdateBar(bar); |
||
187 | SASActions_SaveEnable(); |
||
188 | end |
||
189 | |||
190 | function SASActionBarButton_OnReceiveDrag() |
||
191 | SASActionBarButton_OnClick(); |
||
192 | end |
||
193 | |||
194 | function SASActionBarButton_OnDragStart() |
||
195 | local bar = this:GetParent():GetID(); |
||
196 | if ( SAS_BarHasActions(bar) ) then |
||
197 | SASDebug("Picking up bar "..bar ); |
||
198 | SASFakeDrag_PickupBar( SAS_Temp[bar] ); |
||
199 | SAS_DraggingBar = bar; |
||
200 | SASActions_UpdateBar(bar); |
||
201 | else |
||
202 | SASFakeDrag_PickupBar(); |
||
203 | SAS_DraggingBar = nil; |
||
204 | end |
||
205 | end |
||
206 | |||
207 | function SASActionBarButton_OnEnter() |
||
208 | this:SetScript("OnUpdate", SASActionBarButton_OnUpdate); |
||
209 | GameTooltip:SetOwner(this, "ANCHOR_RIGHT"); |
||
210 | GameTooltip:SetText( getglobal("SAS_TEXT_BARS_"..this:GetParent():GetID()) ); |
||
211 | GameTooltip:Show(); |
||
212 | end |
||
213 | |||
214 | function SASActionBarButton_OnLeave() |
||
215 | this:SetScript("OnUpdate", nil); |
||
216 | |||
217 | for i=1, 12 do |
||
218 | local button = getglobal( this:GetParent():GetName().."Action"..i ):GetName(); |
||
219 | getglobal( button.."Delete" ):Hide(); |
||
220 | getglobal( button.."Copy" ):Hide(); |
||
221 | end |
||
222 | |||
223 | GameTooltip:Hide(); |
||
224 | end |
||
225 | |||
226 | function SASActionBarButton_OnUpdate() |
||
227 | if ( not SAS_Temp ) then return; end |
||
228 | |||
229 | local BarFrame = this:GetParent(); |
||
230 | local barName = BarFrame:GetName(); |
||
231 | |||
232 | for i=1, 12 do |
||
233 | local button = getglobal( barName.."Action"..i ):GetName(); |
||
234 | if ( IsControlKeyDown() and not IsShiftKeyDown() and getglobal( button.."Icon" ):IsVisible() ) then |
||
235 | getglobal( button.."Delete" ):Show(); |
||
236 | getglobal( button.."Copy" ):Hide(); |
||
237 | elseif ( IsShiftKeyDown() and not IsControlKeyDown() and SAS_BarHasActions(BarFrame:GetID()) ) then |
||
238 | getglobal( button.."Copy" ):Show(); |
||
239 | getglobal( button.."Delete" ):Hide(); |
||
240 | else |
||
241 | getglobal( button.."Delete" ):Hide(); |
||
242 | getglobal( button.."Copy" ):Hide(); |
||
243 | end |
||
244 | end |
||
245 | end |
||
246 | |||
247 | function SASActionBarButton_OnDragStop() |
||
248 | SASFakeDrag_Drop(); |
||
249 | end |
||
250 | |||
251 | function SASActions_DropDown_OnLoad() |
||
252 | UIDropDownMenu_Initialize(this, SASActions_DropDown_Initialize); |
||
253 | UIDropDownMenu_SetWidth(135); |
||
254 | UIDropDownMenu_SetButtonWidth(24); |
||
255 | UIDropDownMenu_JustifyText("LEFT", SASActionSetsDropDown); |
||
256 | if ( SAS_GetCurrentSet() ) then |
||
257 | UIDropDownMenu_SetSelectedName(SASActionSetsDropDown, SAS_GetCurrentSet()); |
||
258 | else |
||
259 | UIDropDownMenu_SetText( "|c00999999"..SAS_TEXT_CURRENT, SASActionSetsDropDown ); |
||
260 | end |
||
261 | end |
||
262 | |||
263 | function SASActions_DropDown_Initialize() |
||
264 | if ( not SAS_Saved or not SAS_Saved[PlrName] or not SAS_Saved[PlrName]["s"] ) then return; end |
||
265 | local list = {}; |
||
266 | for k, v in SAS_Saved[PlrName].s do |
||
267 | tinsert(list, k); |
||
268 | end |
||
269 | table.sort(list); |
||
270 | local info; |
||
271 | for k, v in list do |
||
272 | info = {}; |
||
273 | info.text = v; |
||
274 | info.value = v; |
||
275 | info.justifyH = "LEFT"; |
||
276 | info.func = SASActions_DropDown_OnClick; |
||
277 | UIDropDownMenu_AddButton(info); |
||
278 | end |
||
279 | end |
||
280 | |||
281 | function SASActions_DropDown_OnClick() |
||
282 | UIDropDownMenu_SetSelectedID( SASActionSetsDropDown, this:GetID() ); |
||
283 | SASActions_Load(this:GetText()); |
||
284 | end |
||
285 | |||
286 | function SASActions_Display() |
||
287 | -- Update the display of all bars. |
||
288 | if ( SAS_Temp ) then |
||
289 | for i=0, 9 do |
||
290 | SASActions_UpdateBar( i ); |
||
291 | end |
||
292 | end |
||
293 | SASActions_SaveEnable(); |
||
294 | end |
||
295 | |||
296 | function SASActions_UpdateBar( bar ) |
||
297 | -- Update the display of a bar |
||
298 | local BarFrame = getglobal( "SASActionBar"..bar ); |
||
299 | if ( SAS_Temp[bar] ) then |
||
300 | getglobal( BarFrame:GetName().."Enable"):SetChecked(not SAS_Temp[bar][0]); |
||
301 | end |
||
302 | if ( bar ) then |
||
303 | for i=1, 12 do |
||
304 | SASActions_UpdateAction( bar, i ); |
||
305 | end |
||
306 | end |
||
307 | |||
308 | if ( SAS_DraggingBar == bar and SASFakeDragFrame:IsVisible() ) then |
||
309 | BarFrame:SetAlpha(0.5); |
||
310 | else |
||
311 | BarFrame:SetAlpha(1.0); |
||
312 | end |
||
313 | end |
||
314 | |||
315 | function SAS_BarEnabled( bar, set ) |
||
316 | if ( not set ) then set = SAS_Temp; end |
||
317 | if ( set and set[bar] ) then |
||
318 | return not set[bar][0]; |
||
319 | end |
||
320 | end |
||
321 | |||
322 | function SASActions_UpdateAction(bar, id) |
||
323 | -- Update the display of an action. |
||
324 | local button = getglobal( "SASActionBar"..bar.."Action"..id ):GetName(); |
||
325 | local icon = getglobal( button.."Icon" ); |
||
326 | local buttonName = getglobal( button.."Name" ); |
||
327 | local normalTexture = getglobal( button.."NormalTexture" ); |
||
328 | local border = getglobal( button.."Border" ); |
||
329 | local hotkey = getglobal( button.."HotKey" ); |
||
330 | local enable = SAS_BarEnabled(bar); |
||
331 | |||
332 | if ( SAS_Saved[PlrName]["NoEmptyButtons"] and (not SAS_Temp[bar] or not SAS_Temp[bar][id]) ) then |
||
333 | enable = nil; |
||
334 | elseif ( not SAS_Saved[PlrName]["EmptyBars"] and not SAS_BarHasActions(bar) ) then |
||
335 | enable = nil; |
||
336 | end |
||
337 | SetDesaturation( getglobal( "SASActionBar"..bar.."Action"..id.."Icon" ), not enable ); |
||
338 | border:Hide(); |
||
339 | normalTexture:SetVertexColor(1.0, 1.0, 1.0, 1.0); |
||
340 | |||
341 | if ( enable ) then |
||
342 | getglobal(button):SetAlpha(1.0); |
||
343 | else |
||
344 | getglobal(button):SetAlpha(0.5); |
||
345 | end |
||
346 | |||
347 | hotkey:SetTextColor(0.25,0.25,0.25); |
||
348 | |||
349 | if ( not SAS_Temp ) then |
||
350 | getglobal( button ):Disable(); |
||
351 | else |
||
352 | getglobal( button ):Enable(); |
||
353 | |||
354 | icon:Hide() |
||
355 | buttonName:Hide(); |
||
356 | icon:SetVertexColor(1.0, 1.0, 1.0); |
||
357 | |||
358 | if ( SAS_Temp[bar] and SAS_Temp[bar][id] ) then |
||
359 | local name, texture, rank, link, macro = SAS_ParseActionInfo( SAS_Temp[bar][id] ); --SAS_Temp[bar][id][1], SAS_Temp[bar][id][2], SAS_Temp[bar][id][3], SAS_Temp[bar][id][4], SAS_Temp[bar][id][5]; |
||
360 | texture = SAS_FullPath(texture); |
||
361 | icon:SetTexture( texture ); |
||
362 | icon:Show(); |
||
363 | normalTexture:SetTexture("Interface\\Buttons\\UI-Quickslot2"); |
||
364 | hotkey:SetTextColor(0.6,0.6,0.6); |
||
365 | |||
366 | if ( macro ) then |
||
367 | buttonName:SetText( name ); |
||
368 | buttonName:Show(); |
||
369 | buttonName:SetTextColor(1.0, 1.0, 1.0); |
||
370 | if ( not SAS_FindMacro( name, texture, macro ) ) then |
||
371 | border:SetVertexColor(1.0, 0.0, 0.0, 0.35); |
||
372 | buttonName:SetTextColor(0.4, 0.4, 0.4); |
||
373 | border:Show(); |
||
374 | normalTexture:SetVertexColor(0.9, 0.0, 0.0, 1.0); |
||
375 | icon:SetVertexColor(0.4, 0.4, 0.4); |
||
376 | end |
||
377 | elseif ( link ) then |
||
378 | border:SetVertexColor(0, 1.0, 0, 0.35); |
||
379 | border:Show(); |
||
380 | local itemLink; |
||
381 | if ( link == "?" or link == "1" ) then |
||
382 | itemLink = SAS_CheckItem( name, bar*12+id, SASActions_GetLoaded() ); |
||
383 | else |
||
384 | itemLink = SAS_FindItem( link ); |
||
385 | end |
||
386 | if ( not itemLink or itemLink == "?" ) then |
||
387 | border:SetVertexColor(1.0, 0.0, 0.0, 0.35); |
||
388 | normalTexture:SetVertexColor(0.9, 0.0, 0.0, 1.0); |
||
389 | icon:SetVertexColor(0.4, 0.4, 0.4); |
||
390 | elseif ( link == "?" ) then |
||
391 | SAS_Temp[bar][id] = SAS_IncActionInfo( SAS_Temp[bar][id], itemLink, 4 ); |
||
392 | end |
||
393 | else |
||
394 | local spellNum, highest = SAS_FindSpell( name, rank ); |
||
395 | if ( not spellNum ) then |
||
396 | if ( highest ) then |
||
397 | border:SetVertexColor(0.0, 0.0, 1.0, 0.7); |
||
398 | else |
||
399 | icon:SetVertexColor(0.4, 0.4, 0.4); |
||
400 | border:SetVertexColor(1.0, 0.0, 0.0, 0.35); |
||
401 | end |
||
402 | border:Show(); |
||
403 | elseif ( not rank ) then |
||
404 | local checktexture = GetSpellTexture( spellNum, BOOKTYPE_SPELL ); |
||
405 | if ( texture ~= checktexture ) then |
||
406 | icon:SetTexture( checktexture ); |
||
407 | local set = SASActions_GetLoaded(); |
||
408 | if ( set ) then |
||
409 | SAS_Temp[bar][id] = SAS_IncActionInfo( SAS_Temp[bar][id], checktexture, 2 ); |
||
410 | SAS_Saved[PlrName]["s"][set][bar][id] = SAS_IncActionInfo( SAS_Saved[PlrName]["s"][set][bar][id], checktexture, 2 ); |
||
411 | end |
||
412 | end |
||
413 | end |
||
414 | end |
||
415 | elseif ( SAS_Temp[bar] ) then |
||
416 | if ( enable ) then |
||
417 | normalTexture:SetTexture("Interface\\Buttons\\UI-Quickslot"); |
||
418 | else |
||
419 | normalTexture:SetTexture("Interface\\Buttons\\UI-Quickslot2"); |
||
420 | end |
||
421 | end |
||
422 | end |
||
423 | end |
||
424 | |||
425 | function SASActions_SaveNew( set ) |
||
426 | SASSaveMenuNameEB:SetText(""); |
||
427 | ShowUIPanel(SASSaveMenu); |
||
428 | if ( set ) then |
||
429 | SASSaveMenuNameEB:SetText( set ); |
||
430 | SASSaveMenu_Save( set ); |
||
431 | end |
||
432 | end |
||
433 | |||
434 | function SASActions_ClearTemp() |
||
435 | -- Clear the temp set |
||
436 | for i=0, 9 do |
||
437 | SAS_Temp[i] = {}; |
||
438 | end |
||
439 | SASActions_Display(); |
||
440 | end |
||
441 | |||
442 | function SASActions_LoadCurrent() |
||
443 | if ( SASActionsSave:GetButtonState() == "DISABLED" ) then |
||
444 | SASActions_Load(); |
||
445 | else |
||
446 | SAS_Warning("UNSAVED_LOAD", SASActions_Load); |
||
447 | end |
||
448 | end |
||
449 | |||
450 | function SASActions_SwapSet() |
||
451 | if ( SASActionsSave:GetButtonState() == "NORMAL" ) then |
||
452 | SAS_Warning("SWAPPINGSAVE", SASActions_SwapSave, SASActions_GetLoaded()); |
||
453 | else |
||
454 | SAS_Warning("SWAPPING", SAS_SwapSet, SASActions_GetLoaded()); |
||
455 | end |
||
456 | end |
||
457 | |||
458 | function SASActions_SwapSave( set ) |
||
459 | SAS_SaveSet( set ); |
||
460 | SAS_SwapSet( set ); |
||
461 | end |
||
462 | |||
463 | function SASActions_Delete() |
||
464 | SAS_Warning("DELETE", SAS_Delete, SASActions_GetLoaded()); |
||
465 | end |
||
466 | |||
467 | function SASActions_Save() |
||
468 | SAS_Warning("SAVE", SAS_SaveSet, SASActions_GetLoaded()); |
||
469 | end |
||
470 | |||
471 | function SASActions_SaveEnable() |
||
472 | local set = SASActions_GetLoaded(); |
||
473 | if ( set and SAS_CompareSet(SAS_Temp, SAS_Saved[PlrName]["s"][set], 2) ) then |
||
474 | SASActionsSave:Enable(); |
||
475 | else |
||
476 | SASActionsSave:Disable(); |
||
477 | end |
||
478 | end |
||
479 | |||
480 | function SASActions_Cancel() |
||
481 | if ( SASActionsSave:GetButtonState() == "DISABLED" ) then |
||
482 | HideUIPanel(this:GetParent()); |
||
483 | else |
||
484 | SAS_Warning("UNSAVED_CANCEL", SASMain_Toggle); |
||
485 | end |
||
486 | end |
||
487 | |||
488 | function SASActions_GetLoaded() |
||
489 | local set = UIDropDownMenu_GetSelectedName( SASActionSetsDropDown ); |
||
490 | if ( set ~= SAS_TEXT_CURRENT ) then |
||
491 | return set; |
||
492 | end |
||
493 | end |
||
494 | |||
495 | function SASActionsSave_Enable() |
||
496 | SASActionsSaveLeft:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up"); |
||
497 | SASActionsSaveMiddle:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up"); |
||
498 | SASActionsSaveRight:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up"); |
||
499 | SASActionsSave:oldEnable(); |
||
500 | SASActionsSave:EnableMouse(1); |
||
501 | end |
||
502 | |||
503 | function SASActionsSave_Disable() |
||
504 | SASActionsSaveLeft:SetTexture("Interface\\Buttons\\UI-Panel-Button-Disabled"); |
||
505 | SASActionsSaveMiddle:SetTexture("Interface\\Buttons\\UI-Panel-Button-Disabled"); |
||
506 | SASActionsSaveRight:SetTexture("Interface\\Buttons\\UI-Panel-Button-Disabled"); |
||
507 | SASActionsSave:oldDisable(); |
||
508 | SASActionsSave:EnableMouse(); |
||
509 | end |
||
510 | |||
511 | function SASSets_Character_DropDown_OnLoad() |
||
512 | UIDropDownMenu_Initialize(this, SASSets_Character_DropDown_Initialize); |
||
513 | UIDropDownMenu_SetWidth(160); |
||
514 | UIDropDownMenu_SetButtonWidth(24); |
||
515 | UIDropDownMenu_JustifyText("LEFT", SASSets_Character_DropDown); |
||
516 | UIDropDownMenu_SetSelectedID( SASSets_Character_DropDown, 1 ); |
||
517 | end |
||
518 | |||
519 | function SASSets_Character_DropDown_Initialize() |
||
520 | local info; |
||
521 | local list = {}; |
||
522 | for k, v in SAS_Saved do |
||
523 | if ( k ~= "debug" and k ~= "BackUp" and k ~= PlrName and v.s ) then |
||
524 | for j, z in v.s do |
||
525 | tinsert(list,k); |
||
526 | break; |
||
527 | end |
||
528 | end |
||
529 | end |
||
530 | table.sort(list); |
||
531 | if ( SAS_Saved["BackUp"] ) then |
||
532 | tinsert(list,"BackUp"); |
||
533 | end |
||
534 | for i=1, getn(list) do |
||
535 | info = {}; |
||
536 | info.text = list[i]; |
||
537 | info.value = list[i]; |
||
538 | info.justifyH = "LEFT"; |
||
539 | info.func = SASSets_Character_DropDown_OnClick; |
||
540 | UIDropDownMenu_AddButton(info); |
||
541 | end |
||
542 | end |
||
543 | |||
544 | function SASSets_Character_DropDown_OnClick() |
||
545 | UIDropDownMenu_SetSelectedName( SASSets_Character_DropDown, this:GetText() ); |
||
546 | UIDropDownMenu_Initialize(SASSets_CharacterSets_DropDown, SASSets_CharacterSets_DropDown_Initialize); |
||
547 | UIDropDownMenu_SetSelectedID( SASSets_CharacterSets_DropDown, 1 ); |
||
548 | end |
||
549 | |||
550 | function SASSets_CharacterSets_DropDown_OnLoad() |
||
551 | UIDropDownMenu_Initialize(this, SASSets_CharacterSets_DropDown_Initialize); |
||
552 | UIDropDownMenu_SetWidth(160); |
||
553 | UIDropDownMenu_SetButtonWidth(24); |
||
554 | UIDropDownMenu_JustifyText("LEFT", SASSets_CharacterSets_DropDown); |
||
555 | UIDropDownMenu_SetSelectedID( SASSets_CharacterSets_DropDown, 1 ); |
||
556 | end |
||
557 | |||
558 | function SASSets_CharacterSets_DropDown_Initialize() |
||
559 | local info; |
||
560 | local list = {}; |
||
561 | local char = SASSets_Character_DropDownText:GetText(); |
||
562 | if ( SAS_Saved[char] and SAS_Saved[char]["s"] ) then |
||
563 | for k, v in SAS_Saved[char]["s"] do |
||
564 | tinsert(list,k); |
||
565 | end |
||
566 | end |
||
567 | table.sort(list); |
||
568 | for i=1, getn(list) do |
||
569 | info = {}; |
||
570 | info.text = list[i]; |
||
571 | info.value = list[i]; |
||
572 | info.justifyH = "LEFT"; |
||
573 | info.func = SASSets_CharacterSets_DropDown_OnClick; |
||
574 | UIDropDownMenu_AddButton(info); |
||
575 | end |
||
576 | end |
||
577 | |||
578 | function SASSets_CharacterSets_DropDown_OnClick() |
||
579 | UIDropDownMenu_SetSelectedID( SASSets_CharacterSets_DropDown, this:GetID() ); |
||
580 | end |
||
581 | |||
582 | function SASActions_LoadOtherSet() |
||
583 | local char = SASSets_Character_DropDownText:GetText(); |
||
584 | local set = SASSets_CharacterSets_DropDownText:GetText(); |
||
585 | SASActions_Load( set, char ); |
||
586 | end |
||
587 | |||
588 | ------------------------------- |
||
589 | -- SASActionButton functions -- |
||
590 | ------------------------------- |
||
591 | function SASActionButton_OnClick( button ) |
||
592 | -- Pick up action, and replace with held action (if there is one) |
||
593 | local bar = this:GetParent():GetID(); |
||
594 | local id = this:GetID(); |
||
595 | --local i = id + bar * 12; |
||
596 | local LocalSavedAction; |
||
597 | if ( button == "RightButton" and SASFakeDragFrame.Action ) then |
||
598 | SASFakeDrag_Drop(1); |
||
599 | elseif ( IsShiftKeyDown() and not IsControlKeyDown() ) then |
||
600 | LocalSavedAction = SAS_Temp[bar][id]; |
||
601 | SAS_ClearCursor(); |
||
602 | else |
||
603 | if ( SAS_IsValidAction ) then |
||
604 | -- Cursor has an item / action / macro that can be placed on the action bar |
||
605 | SASDebug("SASActionButton_OnClick getting action "..SAS_ParseActionInfo(SAS_SavedPickup, 1).." from cursor"); |
||
606 | if ( SAS_ParseActionInfo(SAS_SavedPickup, 6) ) then |
||
607 | -- Spell is passive, don't add to set |
||
608 | UIErrorsFrame:AddMessage(ERR_PASSIVE_ABILITY, 1.0, 0.1, 0.1, 1.0, UIERRORS_HOLD_TIME); |
||
609 | else |
||
610 | if ( SAS_Temp[bar] and not SAS_Temp[bar][id] == SAS_SavedPickup ) then |
||
611 | LocalSavedAction = SAS_Temp[bar][id]; |
||
612 | end |
||
613 | SAS_Temp[bar][id] = SAS_SavedPickup; |
||
614 | SASActions_UpdateAction( bar, id ); |
||
615 | |||
616 | if ( SAS_ReturnAction ) then |
||
617 | PlaceAction( SAS_ReturnAction ); |
||
618 | else |
||
619 | SAS_ClearCursor(); |
||
620 | end |
||
621 | end |
||
622 | elseif ( SASFakeDragFrame.Action ) then |
||
623 | -- Cursor fake drag is holding an action |
||
624 | SASDebug("SASActionButton_OnClick getting fake drag action "..SAS_ParseActionInfo(SASFakeDragFrame.Action, 1)); |
||
625 | if ( SAS_Temp[bar] and SAS_Temp[bar][id] ) then |
||
626 | LocalSavedAction = SAS_CopyTable(SAS_Temp[bar][id]); |
||
627 | end |
||
628 | SAS_Temp[bar][id] = SASFakeDrag_Drop(1) |
||
629 | SASActions_UpdateAction( bar, id ); |
||
630 | elseif ( SAS_Temp[bar][id] ) then |
||
631 | SASDebug("SASActionButton_OnClick putting action "..SAS_ParseActionInfo(SAS_Temp[bar][id], 1).." on fake drag"); |
||
632 | -- This slot already has an action, pick it up |
||
633 | LocalSavedAction = SAS_Temp[bar][id]; |
||
634 | SAS_Temp[bar][id] = nil; |
||
635 | SASActions_UpdateAction( bar, id ); |
||
636 | if ( IsControlKeyDown() and not IsShiftKeyDown() ) then |
||
637 | LocalSavedAction = nil; |
||
638 | end |
||
639 | getglobal( this:GetName().."Delete" ):Hide(); |
||
640 | getglobal( this:GetName().."Copy" ):Hide(); |
||
641 | end |
||
642 | end |
||
643 | |||
644 | if ( LocalSavedAction ) then |
||
645 | SASFakeDrag_PickupAction( LocalSavedAction ); |
||
646 | end |
||
647 | SASActions_SaveEnable(); |
||
648 | end |
||
649 | |||
650 | function SASActionButton_OnDragStart() |
||
651 | local bar = this:GetParent():GetID(); |
||
652 | local id = this:GetID(); |
||
653 | SASFakeDrag_PickupAction( SAS_Temp[bar][id] ); |
||
654 | if ( not IsShiftKeyDown() ) then |
||
655 | SAS_Temp[bar][id] = nil; |
||
656 | SASActions_UpdateAction( bar, id ); |
||
657 | SASActions_SaveEnable(); |
||
658 | end |
||
659 | end |
||
660 | |||
661 | function SASActionButton_OnDragStop() |
||
662 | SASFakeDrag_Drop(); |
||
663 | end |
||
664 | |||
665 | function SASActionButton_OnReceiveDrag() |
||
666 | SASDebug("Drag Receive"); |
||
667 | SASActionButton_OnClick(); |
||
668 | end |
||
669 | |||
670 | function SASActionButton_OnEnter() |
||
671 | -- Make Tooltip to display for this button |
||
672 | this:SetScript("OnUpdate", SASActionButton_OnUpdate); --this.hasfocus = 1; |
||
673 | |||
674 | local bar = this:GetParent():GetID(); |
||
675 | local id = this:GetID(); |
||
676 | local enabled = getglobal( "SASActionBar"..bar.."Enable" ):GetChecked(); |
||
677 | |||
678 | if ( not enabled ) then |
||
679 | SetDesaturation( getglobal(this:GetName().."Icon"), 0 ); |
||
680 | this:SetAlpha(1.0); |
||
681 | this:SetNormalTexture("Interface\\Buttons\\UI-Quickslot"); |
||
682 | end |
||
683 | |||
684 | if ( getglobal( this:GetName().."Icon" ):IsVisible() and SAS_Temp ) then |
||
685 | GameTooltip:SetOwner(this, "ANCHOR_RIGHT"); |
||
686 | SAS_SetTooltip( bar, id ); |
||
687 | end |
||
688 | end |
||
689 | |||
690 | function SASActionButton_OnLeave() |
||
691 | -- Hide the tooltip, reset desaturated on disabled bars |
||
692 | local enabled = getglobal( "SASActionBar"..this:GetParent():GetID().."Enable" ):GetChecked(); |
||
693 | local bar = this:GetParent():GetID(); |
||
694 | local id = this:GetID(); |
||
695 | SASActions_UpdateAction( bar, id ); |
||
696 | this:SetScript("OnUpdate", nil); --this.hasfocus = nil; |
||
697 | getglobal( this:GetName().."Delete" ):Hide(); |
||
698 | getglobal( this:GetName().."Copy" ):Hide(); |
||
699 | GameTooltip:Hide(); |
||
700 | end |
||
701 | |||
702 | function SASActionButton_OnUpdate() |
||
703 | if ( not getglobal( this:GetName().."Icon" ):IsVisible() or not SAS_Temp ) then return; end |
||
704 | |||
705 | if ( IsControlKeyDown() and not IsShiftKeyDown() ) then |
||
706 | getglobal( this:GetName().."Delete" ):Show(); |
||
707 | else |
||
708 | getglobal( this:GetName().."Delete" ):Hide(); |
||
709 | end |
||
710 | if ( IsShiftKeyDown() and not IsControlKeyDown() ) then |
||
711 | getglobal( this:GetName().."Copy" ):Show(); |
||
712 | else |
||
713 | getglobal( this:GetName().."Copy" ):Hide(); |
||
714 | end |
||
715 | end |
||
716 | |||
717 | |||
718 | ---------------------------- |
||
719 | -- Options Menu Functions -- |
||
720 | ---------------------------- |
||
721 | function SASOptions_OnShow() |
||
722 | SASOptions_Update(); |
||
723 | SASOptionsMinimapShow:SetChecked( not SAS_Saved[PlrName]["HideMinimapButton"] ); |
||
724 | SASOptionsMinimapShowText:SetText( SAS_TEXT_OPTIONS_MINIMAP_SHOW ); |
||
725 | SASOptionsMinimapDrag:SetChecked( SAS_Saved[PlrName]["LockMinimapButton"] ); |
||
726 | SASOptionsMinimapDragText:SetText( SAS_TEXT_OPTIONS_MINIMAP_DRAG ); |
||
727 | SASOptionsMinimapPositionUndo:Disable(); |
||
728 | SASOptionsGeneralWarnings:SetChecked( not SAS_Saved[PlrName]["NoUIWarnings"] ); |
||
729 | SASOptionsGeneralWarningsText:SetText( SAS_TEXT_OPTIONS_GENERAL_WARNINGS ); |
||
730 | SASOptionsGeneralWarnings.tooltipText = SAS_TEXT_OPTIONS_GENERAL_WARNINGS_TOOLTIP; |
||
731 | SASOptionsGeneralEmptyBars:SetChecked( not SAS_Saved[PlrName]["EmptyBars"] ); |
||
732 | SASOptionsGeneralEmptyBarsText:SetText( SAS_TEXT_OPTIONS_GENERAL_EMPTYBARS ); |
||
733 | SASOptionsGeneralEmptyBars.tooltipText = SAS_TEXT_OPTIONS_GENERAL_EMPTYBARS_TOOLTIP; |
||
734 | SASOptionsGeneralEmptyButtons:SetChecked( SAS_Saved[PlrName]["NoEmptyButtons"] ); |
||
735 | SASOptionsGeneralEmptyButtonsText:SetText( SAS_TEXT_OPTIONS_GENERAL_EMPTYBUTTONS ); |
||
736 | SASOptionsGeneralEmptyButtons.tooltipText = SAS_TEXT_OPTIONS_GENERAL_EMPTYBUTTONS_TOOLTIP; |
||
737 | SASOptionsGeneralFakeItemTooltips:SetChecked( not SAS_Saved[PlrName]["HideFakeItemTooltips"] ); |
||
738 | SASOptionsGeneralFakeItemTooltipsText:SetText( SAS_TEXT_OPTIONS_GENERAL_FAKEITEMTOOLTIPS ); |
||
739 | SASOptionsGeneralFakeItemTooltips.tooltipText = SAS_TEXT_OPTIONS_GENERAL_FAKEITEMTOOLTIPS_TOOLTIP; |
||
740 | SASOptionsGeneralAutoRestore:SetChecked( not SAS_Saved[PlrName]["AutoRestore"] ); |
||
741 | SASOptionsGeneralAutoRestoreText:SetText( SAS_TEXT_OPTIONS_GENERAL_AUTORESTORE ); |
||
742 | SASOptionsGeneralAutoRestore.tooltipText = SAS_TEXT_OPTIONS_GENERAL_AUTORESTORE_TOOLTIP; |
||
743 | SASOptionsGeneralAutoRestoreWarning:SetChecked( not SAS_Saved[PlrName]["NoAutoRestoreWarnings"] ); |
||
744 | SASOptionsGeneralAutoRestoreWarningText:SetText( SAS_TEXT_OPTIONS_GENERAL_AUTORESTOREWARN ); |
||
745 | SASOptionsGeneralAutoRestoreWarning.tooltipText = SAS_TEXT_OPTIONS_GENERAL_AUTORESTOREWARN_TOOLTIP; |
||
746 | SAS_POS_TEMP = SAS_POS; |
||
747 | SAS_OFFSET_TEMP = SAS_OFFSET; |
||
748 | end |
||
749 | |||
750 | function SASOptions_General_Warnings() |
||
751 | SAS_Saved[PlrName]["NoUIWarnings"] = not this:GetChecked(); |
||
752 | end |
||
753 | |||
754 | function SASOptions_General_EmptyBars() |
||
755 | SAS_Saved[PlrName]["EmptyBars"] = not this:GetChecked(); |
||
756 | SASActions_Display(); |
||
757 | end |
||
758 | |||
759 | function SASOptions_General_EmptyButtons() |
||
760 | SAS_Saved[PlrName]["NoEmptyButtons"] = this:GetChecked(); |
||
761 | SASActions_Display(); |
||
762 | end |
||
763 | |||
764 | function SASOptions_General_FakeItemTooltips() |
||
765 | SAS_Saved[PlrName]["HideFakeItemTooltips"] = not this:GetChecked(); |
||
766 | end |
||
767 | |||
768 | function SASOptions_General_AutoRestore() |
||
769 | SAS_Saved[PlrName]["AutoRestore"] = not this:GetChecked(); |
||
770 | end |
||
771 | |||
772 | function SASOptions_General_AutoRestoreWarnings() |
||
773 | SAS_Saved[PlrName]["NoAutoRestoreWarnings"] = not this:GetChecked(); |
||
774 | end |
||
775 | |||
776 | function SASOptions_Minimap_Show() |
||
777 | SAS_Saved[PlrName]["HideMinimapButton"] = not this:GetChecked(); |
||
778 | if ( this:GetChecked() ) then |
||
779 | SASMinimapFrame:Show(); |
||
780 | else |
||
781 | SASMinimapFrame:Hide(); |
||
782 | end |
||
783 | end |
||
784 | |||
785 | function SASOptions_Minimap_Drag() |
||
786 | SAS_Saved[PlrName]["LockMinimapButton"] = this:GetChecked(); |
||
787 | end |
||
788 | |||
789 | function SASOptions_Minimap_Defaults() |
||
790 | SAS_POS = SAS_POS_DEFAULT; |
||
791 | SAS_OFFSET = SAS_POS_DEFAULT; |
||
792 | SASMinimap_PosUpdate(); |
||
793 | end |
||
794 | |||
795 | function SASOptions_Minimap_Undo() |
||
796 | SAS_POS = SAS_POS_TEMP; |
||
797 | SAS_OFFSET = SAS_OFFSET_TEMP; |
||
798 | SASMinimap_PosUpdate(); |
||
799 | SASOptions_Update(); |
||
800 | end |
||
801 | |||
802 | function SASOptions_Update() |
||
803 | if ( SAS_POS < 0 ) then SAS_POS = SAS_POS + 360; end |
||
804 | SASButtonPos:SetValue(SAS_POS); |
||
805 | SASButtonOffset:SetValue(SAS_OFFSET); |
||
806 | end |
||
807 | |||
808 | |||
809 | -------------------------------------- |
||
810 | -- Warning and Save Frame Functions -- |
||
811 | -------------------------------------- |
||
812 | function SAS_Warning( type, func, value, force ) |
||
813 | if ( SAS_Saved[PlrName]["NoUIWarnings"] and ( not force or SAS_Saved[PlrName]["NoAutoRestoreWarnings"] ) ) then |
||
814 | func(value); |
||
815 | else |
||
816 | if ( value ) then |
||
817 | SASWarningFrameText:SetText( string.gsub(getglobal("SAS_TEXT_WARNING_"..type), "%%s", value) ); |
||
818 | else |
||
819 | SASWarningFrameText:SetText( getglobal("SAS_TEXT_WARNING_"..type ) ); |
||
820 | end |
||
821 | SASWarningFrame.func = func; |
||
822 | SASWarningFrame.value = value |
||
823 | ShowUIPanel(SASWarningFrame); |
||
824 | end |
||
825 | end |
||
826 | |||
827 | function SASWarning_Okay() |
||
828 | SASWarningFrame.func(SASWarningFrame.value) |
||
829 | SASWarningFrame.func = nil; |
||
830 | SASWarningFrame.value = nil; |
||
831 | HideUIPanel(this:GetParent()); |
||
832 | end |
||
833 | |||
834 | function SASSaveMenu_Save( set ) |
||
835 | SASSaveMenuHelp.warned = nil |
||
836 | SASSaveMenuHelp:Hide(); |
||
837 | SAS_SaveSet( set ); |
||
838 | HideUIPanel( SASSaveMenu ); |
||
839 | end |
||
840 | |||
841 | |||
842 | --------------------------------- |
||
843 | -- Minimap Button functions -- |
||
844 | --------------------------------- |
||
845 | function SASMinimap_OnLoad() |
||
846 | -- Load and initialize Simple Action Sets |
||
847 | this:RegisterEvent("VARIABLES_LOADED"); |
||
848 | this:RegisterForClicks("LeftButtonUp", "RightButtonUp"); |
||
849 | this:RegisterForDrag("LeftButton", "RightButton"); |
||
850 | |||
851 | tinsert(UISpecialFrames,"SASMain"); |
||
852 | |||
853 | SlashCmdList["SAS"] = SAS_Console; |
||
854 | SLASH_SAS1 = "/sas"; |
||
855 | end |
||
856 | |||
857 | function SASMinimap_OnEvent() |
||
858 | if( event == "VARIABLES_LOADED" ) then |
||
859 | this:RegisterEvent("ACTIONBAR_SHOWGRID"); |
||
860 | this:RegisterEvent("ACTIONBAR_HIDEGRID"); |
||
861 | this:RegisterEvent("UNIT_INVENTORY_CHANGED"); |
||
862 | this:RegisterEvent("BAG_UPDATE"); |
||
863 | this:RegisterEvent("PLAYER_LOGOUT"); |
||
864 | |||
865 | SASMinimap_PosUpdate(); |
||
866 | |||
867 | PlrName = UnitName("player").." - "..GetCVar("realmName"); |
||
868 | |||
869 | SASFrame.PlrName = PlrName; |
||
870 | |||
871 | PlrClass, PlrClass = UnitClass("player"); |
||
872 | |||
873 | if ( not SAS_Saved ) then |
||
874 | SAS_Saved = {}; |
||
875 | end |
||
876 | if ( not SAS_Saved[PlrName] ) then |
||
877 | SAS_Saved[PlrName] = {}; |
||
878 | SAS_Saved[PlrName]["s"] = {}; |
||
879 | end |
||
880 | |||
881 | if ( SAS_Saved[PlrName]["sets"] ) then |
||
882 | SAS_UpgradeSets(); |
||
883 | end |
||
884 | |||
885 | if ( SAS_Saved[PlrName]["HideMinimapButton"] ) then |
||
886 | SASMinimapFrame:Hide(); |
||
887 | end |
||
888 | |||
889 | local currentset = SAS_GetCurrentSet(); |
||
890 | local liveactions = SAS_IterateActions(1); |
||
891 | |||
892 | if ( SAS_Saved[PlrName]["AutoRestore"] and SAS_Saved["BackUp"] and SAS_Saved["BackUp"]["s"][PlrName] ) then |
||
893 | if ( SAS_CompareSet( liveactions, SAS_Saved["BackUp"]["s"][PlrName] ) ) then |
||
894 | SAS_Warning( "CHANGEDSINCELAST", SAS_RestoreBackUp, nil, 1 ); |
||
895 | return; |
||
896 | end |
||
897 | end |
||
898 | if ( currentset ) then |
||
899 | if ( SAS_CompareSet( liveactions, SAS_Saved[PlrName]["s"][currentset] ) ) then |
||
900 | SASDebug( currentset.." does not appear to be loaded." ); |
||
901 | SAS_SetCurrentSet(); |
||
902 | else |
||
903 | SASDebug( currentset.." appears to be loaded, keeping as current set." ); |
||
904 | end |
||
905 | end |
||
906 | elseif( event == "ACTIONBAR_SHOWGRID" ) then |
||
907 | if ( not SAS_SwappingSet ) then |
||
908 | SAS_IsValidAction = 1; |
||
909 | --SASDebug("Valid Item on Cursor"); |
||
910 | end |
||
911 | elseif( event == "ACTIONBAR_HIDEGRID" ) then |
||
912 | if ( not SAS_SwappingSet ) then |
||
913 | SAS_IsValidAction = nil; |
||
914 | --SASDebug("No Valid Item on Cursor"); |
||
915 | end |
||
916 | elseif ( event == "UNIT_INVENTORY_CHANGED" or event == "BAG_UPDATE" ) then |
||
917 | if ( arg1 == "player" or tonumber(arg1) ) then |
||
918 | SAS_FindMissingItems(); |
||
919 | SASActions_Display(); |
||
920 | end |
||
921 | elseif ( event == "PLAYER_LOGOUT" ) then |
||
922 | if ( not SAS_Saved["BackUp"] ) then |
||
923 | SAS_Saved["BackUp"] = {}; |
||
924 | SAS_Saved["BackUp"]["s"] = {}; |
||
925 | end |
||
926 | SAS_Saved["BackUp"]["s"][PlrName] = SAS_IterateActions(); |
||
927 | end |
||
928 | end |
||
929 | |||
930 | function SASMinimap_OnClick( button ) |
||
931 | -- Open up the main menu |
||
932 | SAS_SetsDropDown:Hide(); |
||
933 | if ( button == "LeftButton" ) then |
||
934 | if ( this:GetScript("OnUpdate") ) then |
||
935 | SASMinimap_DragStop() |
||
936 | else |
||
937 | SASMain_Toggle(); |
||
938 | end |
||
939 | else |
||
940 | if ( this:GetScript("OnUpdate")) then |
||
941 | SASMinimap_DragStop(); |
||
942 | SAS_POS = SAS_POS_TEMP; |
||
943 | SASMinimap_PosUpdate(); |
||
944 | else |
||
945 | SAS_SetsDropDown.point = "TOPRIGHT"; |
||
946 | SAS_SetsDropDown.relativePoint = "BOTTOMLEFT"; |
||
947 | ToggleDropDownMenu(1, nil, SAS_SetsDropDown, "SASMinimapButton", 0, 0); |
||
948 | end |
||
949 | end |
||
950 | end |
||
951 | |||
952 | -- Dragging functions for the minimap button position |
||
953 | function SASMinimap_DragStart() |
||
954 | if ( not SAS_Saved[PlrName]["LockMinimapButton"] ) then |
||
955 | SAS_POS_TEMP = SAS_POS; |
||
956 | this:SetScript("OnUpdate", SASMinimap_DragUpdate); --SASMinimapFrame.BeingDragged = true; |
||
957 | end |
||
958 | end |
||
959 | function SASMinimap_DragStop() |
||
960 | SASMinimapButton:UnlockHighlight() |
||
961 | this:SetScript("OnUpdate", nil); --SASMinimapFrame.BeingDragged = nil; |
||
962 | end |
||
963 | function SASMinimap_DragUpdate() |
||
964 | -- Thanks to Gello for making this a ton shorter |
||
965 | SASMinimapButton:LockHighlight(); |
||
966 | local curX, curY = GetCursorPosition(); |
||
967 | local mapX, mapY = Minimap:GetCenter(); |
||
968 | SAS_POS = math.deg(math.atan2( curY - mapY * Minimap:GetEffectiveScale(), mapX * Minimap:GetEffectiveScale() - curX )); |
||
969 | SASMinimap_PosUpdate(); |
||
970 | end |
||
971 | |||
972 | function SASMinimap_OnEnter() |
||
973 | if ( SAS_SetsDropDown:IsVisible() ) then return; end |
||
974 | GameTooltip:SetOwner(this, "ANCHOR_LEFT"); |
||
975 | GameTooltip:AddLine("Simple Action Sets"); |
||
976 | if ( SAS_Saved[PlrName]["LockMinimapButton"] ) then |
||
977 | GameTooltip:AddLine(" Minimap button is locked", 0.6, 0.6, 0.6); |
||
978 | elseif ( SASMinimapFrame.BeingDragged ) then |
||
979 | GameTooltip:AddLine(" Right click SAS button to reset", 0.7, 0.7, 0.7); |
||
980 | else |
||
981 | GameTooltip:AddLine(" Drag to reposition minimap button", 0.7, 0.7, 0.7); |
||
982 | end |
||
983 | GameTooltip:Show(); |
||
984 | end |
||
985 | |||
986 | function SASMinimap_PosUpdate() |
||
987 | SASMinimapFrame:SetPoint("TOPLEFT","Minimap","TOPLEFT",53-((80+SAS_OFFSET)*cos(SAS_POS or 0)),((80+SAS_OFFSET)*sin(SAS_POS or 0))-55); |
||
988 | SASOptions_Update(); |
||
989 | end |
||
990 | |||
991 | function SASMinimap_SetsDropDown_Initialize() |
||
992 | -- Setup the minimap dropdown menu |
||
993 | local info = {}; |
||
994 | local hasSets; |
||
995 | |||
996 | info.text = SAS_TEXT_DROPDOWN_TITLE; |
||
997 | info.isTitle = 1; |
||
998 | info.justifyH = "CENTER"; |
||
999 | info.notCheckable = 1; |
||
1000 | UIDropDownMenu_AddButton(info); |
||
1001 | |||
1002 | SAS_SetsDropDown_Initialize(); |
||
1003 | end |
||
1004 | |||
1005 | function SAS_SetsDropDown_Initialize() |
||
1006 | local hasSets; |
||
1007 | |||
1008 | local info = {}; |
||
1009 | info.text = SAS_TEXT_DROPDOWN_OPEN; |
||
1010 | info.notCheckable = 1; |
||
1011 | info.func = SASMinimap_SetsDropDown_OnClick; |
||
1012 | UIDropDownMenu_AddButton(info); |
||
1013 | |||
1014 | info = {}; |
||
1015 | info.text = SAS_TEXT_DROPDOWN_SAVENEW; |
||
1016 | info.notCheckable = 1; |
||
1017 | info.func = SASMinimap_SetsDropDown_OnClick; |
||
1018 | UIDropDownMenu_AddButton(info); |
||
1019 | |||
1020 | info = {}; |
||
1021 | info.text = SAS_TEXT_DROPDOWN_SAVECURRENT; |
||
1022 | info.notCheckable = 1; |
||
1023 | if ( not SAS_GetCurrentSet() ) then |
||
1024 | info.disabled = 1; |
||
1025 | end |
||
1026 | info.func = SASMinimap_SetsDropDown_OnClick; |
||
1027 | UIDropDownMenu_AddButton(info); |
||
1028 | |||
1029 | info = {}; |
||
1030 | info.text = SAS_TEXT_DROPDOWN_SETS; |
||
1031 | info.isTitle = 1; |
||
1032 | info.justifyH = "CENTER"; |
||
1033 | info.notCheckable = 1; |
||
1034 | UIDropDownMenu_AddButton(info); |
||
1035 | if ( SAS_Saved and SAS_Saved[PlrName]["s"] ) then |
||
1036 | local list = {}; |
||
1037 | for k, v in SAS_Saved[PlrName]["s"] do |
||
1038 | tinsert(list,k); |
||
1039 | end |
||
1040 | table.sort(list); |
||
1041 | for k, v in list do |
||
1042 | info = { }; |
||
1043 | info.text = v; |
||
1044 | info.isTitle = nil; |
||
1045 | if ( SAS_GetCurrentSet() == v ) then |
||
1046 | info.checked = 1; |
||
1047 | end |
||
1048 | info.func = SASMinimap_SetsDropDown_OnClick; |
||
1049 | UIDropDownMenu_AddButton(info); |
||
1050 | hasSets = 1; |
||
1051 | end |
||
1052 | end |
||
1053 | if ( not hasSets ) then |
||
1054 | info = { }; |
||
1055 | info.text = SAS_TEXT_DROPDOWN_NONE; |
||
1056 | info.disabled = 1; |
||
1057 | UIDropDownMenu_AddButton(info); |
||
1058 | end |
||
1059 | end |
||
1060 | |||
1061 | function SASMinimap_SetsDropDown_OnClick() |
||
1062 | -- minimap dropdown menu handler |
||
1063 | local id = this:GetID(); |
||
1064 | if ( id == 2 ) then |
||
1065 | ShowUIPanel(SASMain); |
||
1066 | elseif ( id == 3 ) then |
||
1067 | SASActions_SaveNew(); |
||
1068 | elseif ( id == 4 ) then |
||
1069 | SAS_Warning("SAVE", SAS_SaveSet, SAS_GetCurrentSet()); |
||
1070 | elseif ( id > 5 ) then |
||
1071 | SASDebug( this:GetText() ); |
||
1072 | SAS_SwapSet( this:GetText() ); |
||
1073 | end |
||
1074 | end |
||
1075 | |||
1076 | function SASMinimap_SetsDropDown_OnLoad() |
||
1077 | UIDropDownMenu_Initialize(this, SASMinimap_SetsDropDown_Initialize, "MENU"); |
||
1078 | end |
||
1079 | |||
1080 | |||
1081 | ------------------------- |
||
1082 | -- Fake Drag functions -- |
||
1083 | ------------------------- |
||
1084 | function SASFakeDrag_Drop(clear) |
||
1085 | -- Pick up sas item |
||
1086 | SASFakeDragFrame:Hide(); |
||
1087 | local focus = GetMouseFocus(); |
||
1088 | local action = SASFakeDragFrame.Action; |
||
1089 | local bar = SASFakeDragFrame.Bar; |
||
1090 | if ( focus and not (focus.IsSASAction or focus.IsSASBar) or clear ) then |
||
1091 | if ( SASFakeDragFrame.Action ) then |
||
1092 | PlaySoundFile("Sound\\Interface\\uSpellIconDrop.wav"); |
||
1093 | SASDebug("Dumping FakeDrag Action "..SAS_ParseActionInfo(SASFakeDragFrame.Action, 1)); |
||
1094 | elseif ( SASFakeDragFrame.Bar ) then |
||
1095 | PlaySoundFile("Sound\\Interface\\uSpellIconDrop.wav"); |
||
1096 | SASDebug("Dumping FakeDrag Bar"); |
||
1097 | else |
||
1098 | --SASDebug("Dumping FakeDrag Action, no action"); |
||
1099 | end |
||
1100 | SASFakeDragFrame.Action = nil; |
||
1101 | SASFakeDragFrame.Bar = nil; |
||
1102 | SASFakeDragFrame:SetScript("OnUpdate", nil); |
||
1103 | if ( SAS_DraggingBar ) then |
||
1104 | if ( SASActions:IsVisible() ) then |
||
1105 | SASActions_UpdateBar(SAS_DraggingBar); |
||
1106 | else |
||
1107 | SAS_DraggingBar = nil; |
||
1108 | end |
||
1109 | end |
||
1110 | end |
||
1111 | return action or bar; |
||
1112 | end |
||
1113 | |||
1114 | function SASFakeDrag_PickupAction(action) |
||
1115 | SASFakeDragFrame.Action = action; |
||
1116 | SASFakeDragFrame.Bar = nil; |
||
1117 | if ( action ) then |
||
1118 | local name, texture = SAS_ParseActionInfo( action ); |
||
1119 | for i=1, 12 do |
||
1120 | getglobal( "SASFakeDragFrameIcon"..i ):SetTexture(); |
||
1121 | end |
||
1122 | SASDebug("FakeDrag Pickup Action "..name); |
||
1123 | SASFakeDragFrame:Show(); |
||
1124 | SASFakeDragFrameIcon:SetTexture( SAS_FullPath(texture) ); |
||
1125 | SASFakeDragFrameIcon:SetAlpha( 0.5 ); |
||
1126 | PlaySoundFile("Sound\\Interface\\uSpellIconPickup.wav"); |
||
1127 | SASFakeDragFrame:SetScript("OnUpdate", SASFakeDrag_OnUpdate); |
||
1128 | else |
||
1129 | SASFakeDragFrame:Hide(); |
||
1130 | SASFakeDragFrame:SetScript("OnUpdate", nil); |
||
1131 | end |
||
1132 | end |
||
1133 | |||
1134 | function SASFakeDrag_PickupBar(bar) |
||
1135 | SASFakeDragFrame.Bar = SAS_CopyTable(bar); |
||
1136 | SASFakeDragFrame.Action = nil; |
||
1137 | if ( bar ) then |
||
1138 | SASFakeDragFrameIcon:SetTexture(); |
||
1139 | for i=1, 12 do |
||
1140 | local icon = getglobal( "SASFakeDragFrameIcon"..i ); |
||
1141 | if ( bar[i] ) then |
||
1142 | local texture = SAS_ParseActionInfo( bar[i], 2 ); |
||
1143 | icon:SetTexture( SAS_FullPath(texture) ); |
||
1144 | icon:SetTexCoord( 0, 1, 0, 1 ); |
||
1145 | else |
||
1146 | icon:SetTexture("Interface\\Buttons\\UI-Quickslot"); |
||
1147 | icon:SetTexCoord( 0.1875, 0.8125, 0.1875, 0.8125 ); |
||
1148 | end |
||
1149 | icon:SetAlpha( 0.5 ); |
||
1150 | SASFakeDragFrame:Show(); |
||
1151 | SASFakeDragFrame:SetScript("OnUpdate", SASFakeDrag_OnUpdate); |
||
1152 | end |
||
1153 | PlaySoundFile("Sound\\Interface\\uSpellIconPickup.wav"); |
||
1154 | else |
||
1155 | SASFakeDragFrame:Hide(); |
||
1156 | SASFakeDragFrame:SetScript("OnUpdate", nil); |
||
1157 | end |
||
1158 | end |
||
1159 | |||
1160 | function SASFakeDrag_OnUpdate() |
||
1161 | -- Update the position of the FakeDrag frame to under the cursor |
||
1162 | if ( (this.Action or this.Bar) and this:IsVisible() ) then |
||
1163 | if ( SASActions:IsVisible() ) then |
||
1164 | local curX, curY = GetCursorPosition(); |
||
1165 | local scale = UIParent:GetScale(); |
||
1166 | this:SetPoint("CENTER", "UIParent", "BOTTOMLEFT", curX/scale, curY/scale ); |
||
1167 | else |
||
1168 | SASFakeDrag_Drop(1); |
||
1169 | this:SetScript("OnUpdate", nil); |
||
1170 | end |
||
1171 | else |
||
1172 | this:SetScript("OnUpdate", nil); |
||
1173 | end |
||
1174 | end |
||
1175 | |||
1176 | |||
1177 | ------------------------- |
||
1178 | -- Titan Panel Support -- |
||
1179 | ------------------------- |
||
1180 | function TitanPanelSASButton_OnLoad() |
||
1181 | this.registry = { |
||
1182 | id = SAS_TITAN_ID, |
||
1183 | menuText = "Simple Action Sets", |
||
1184 | buttonTextFunction = "TitanPanelSASButton_GetButtonText", |
||
1185 | tooltipTitle = SAS_TITLE, |
||
1186 | tooltipTextFunction = "TitanPanelSASButton_GetTooltipText", |
||
1187 | icon = "Interface\\AddOns\\SimpleActionSets\\sas", |
||
1188 | iconWidth = 16, |
||
1189 | savedVariables = { |
||
1190 | ShowLabelText = 1, -- Default to 1 |
||
1191 | ShowIcon = 1; |
||
1192 | ShowColoredText = 1, |
||
1193 | } |
||
1194 | }; |
||
1195 | end |
||
1196 | |||
1197 | function TitanPanelSASButton_GetButtonText(id) |
||
1198 | -- If id not nil, return corresponding plugin button |
||
1199 | -- Otherwise return this button and derive the real id |
||
1200 | local button, id = TitanUtils_GetButton(id, true); |
||
1201 | |||
1202 | if ( SAS_GetCurrentSet() ) then |
||
1203 | if ( TitanGetVar(SAS_TITAN_ID, "ShowColoredText") ) then |
||
1204 | return SAS_TITAN_LABEL, TitanUtils_GetGreenText( SAS_GetCurrentSet() ); |
||
1205 | else |
||
1206 | return SAS_TITAN_LABEL, TitanUtils_GetHighlightText( SAS_GetCurrentSet() ); |
||
1207 | end |
||
1208 | else |
||
1209 | return SAS_TITAN_LABEL, TitanUtils_GetHighlightText( SAS_TITAN_NA ); |
||
1210 | end |
||
1211 | end |
||
1212 | |||
1213 | function TitanPanelSASButton_GetTooltipText() |
||
1214 | return TitanUtils_GetGreenText(SAS_TITAN_HINT); |
||
1215 | end |
||
1216 | |||
1217 | function TitanPanelSAS_OnClick(button) |
||
1218 | if ( button == "LeftButton" ) then |
||
1219 | SASMain_Toggle(); |
||
1220 | end |
||
1221 | end |
||
1222 | |||
1223 | function TitanPanelRightClickMenu_PrepareSASMenu() |
||
1224 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[SAS_TITAN_ID].menuText); |
||
1225 | |||
1226 | SAS_SetsDropDown_Initialize(); |
||
1227 | |||
1228 | TitanPanelRightClickMenu_AddSpacer(); |
||
1229 | TitanPanelRightClickMenu_AddToggleIcon(SAS_TITAN_ID); |
||
1230 | TitanPanelRightClickMenu_AddToggleLabelText(SAS_TITAN_ID); |
||
1231 | TitanPanelRightClickMenu_AddToggleColoredText(SAS_TITAN_ID); |
||
1232 | |||
1233 | TitanPanelRightClickMenu_AddSpacer(); |
||
1234 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, SAS_TITAN_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
1235 | end |
||
1236 | |||
1237 | function TitanPanelSAS_Update() |
||
1238 | if ( TitanPanelSASButton and TitanPanelButton_UpdateButton ) then |
||
1239 | TitanPanelButton_UpdateButton(SAS_TITAN_ID); |
||
1240 | end |
||
1241 | end |
||
1242 | |||
1243 | |||
1244 | ------------------------ |
||
1245 | -- Reusable functions -- |
||
1246 | ------------------------ |
||
1247 | |||
1248 | function SASPrint(msg) |
||
1249 | -- Basic print function |
||
1250 | if ( not msg ) then |
||
1251 | msg = "|wnil"; |
||
1252 | end |
||
1253 | msg = string.gsub( msg, "%|w", "|cffff0000" ); |
||
1254 | msg = string.gsub( msg, "%|i", "|cffe6e6fA" ); |
||
1255 | DEFAULT_CHAT_FRAME:AddMessage( "<|cff40E0D0SAS|r> "..msg, 0.012, 0.658, 0.62 ); |
||
1256 | --local cols = "|cff03A98E"; |
||
1257 | end |
||
1258 | |||
1259 | function SASDebug(msg) |
||
1260 | -- Print when debug is turned on |
||
1261 | if ( SAS_Saved["debug"] ) then SASPrint("<|wDEBUG|r> "..msg); end |
||
1262 | end |
||
1263 | |||
1264 | function SASTooltipAddLine(msg) |
||
1265 | -- Adds a colored line to the tooltip |
||
1266 | GameTooltip:AddLine( msg, 0.012, 0.658, 0.62, 1, 1 ); |
||
1267 | GameTooltip:Show(); |
||
1268 | end |
||
1269 | |||
1270 | function SAS_ClearCursor() |
||
1271 | -- Clear the cursor of anything |
||
1272 | local i = 500 |
||
1273 | while GetSpellName( i, BOOKTYPE_SPELL ) do |
||
1274 | i = i+1; |
||
1275 | end |
||
1276 | PickupSpell( i+1, BOOKTYPE_SPELL ); |
||
1277 | end |
||
1278 | |||
1279 | function SAS_BuildActionInfo(...) -- name, texture, rank, link, macro, ? |
||
1280 | if ( arg[2] ) then arg[2] = tPath(arg[2]); end |
||
1281 | if ( arg[3] ) then arg[3] = tRank(arg[3]); end |
||
1282 | if ( arg[4] ) then arg[4] = tLink(arg[4]); end |
||
1283 | while not arg[arg.n] and arg.n > 1 do arg.n = arg.n - 1; end |
||
1284 | if ( arg.n < 2 ) then return; end |
||
1285 | local string = ""; |
||
1286 | for i=1, arg.n do |
||
1287 | string = string..(arg[i] or "").."·"; |
||
1288 | end |
||
1289 | return string; |
||
1290 | end |
||
1291 | |||
1292 | function SAS_IncActionInfo( action, val, part ) |
||
1293 | if ( not val ) then return; |
||
1294 | elseif ( not part ) then part = 1; end |
||
1295 | local a = {SAS_ParseActionInfo(action)}; |
||
1296 | a[part] = val; |
||
1297 | |||
1298 | return SAS_BuildActionInfo( a[1], a[2], a[3], a[4], a[5], a[6] ); |
||
1299 | end |
||
1300 | |||
1301 | function SAS_ParseActionInfo( action, ... ) |
||
1302 | if not action then return; end |
||
1303 | if type(action)~="string" then return action; end |
||
1304 | local a = {}; |
||
1305 | for val in string.gfind( action, "(.-)·" ) do |
||
1306 | tinsert( a, val ); |
||
1307 | end |
||
1308 | for k, v in a do if v == "" then v = nil; end end |
||
1309 | if ( arg.n > 0 ) then |
||
1310 | local b = {}; |
||
1311 | for i=1, arg.n do |
||
1312 | tinsert( b, a[arg[i]] ); |
||
1313 | end |
||
1314 | return unpack(b); |
||
1315 | else |
||
1316 | return a[1], a[2], tonumber(a[3]), a[4], tonumber(a[5]), a[6]; --name, texture, rank, link, macro, ?; |
||
1317 | end |
||
1318 | end |
||
1319 | |||
1320 | function SAS_ItemLink( item ) |
||
1321 | -- Return an item's link |
||
1322 | local itemLink = SAS_FindItem( item ); |
||
1323 | if ( itemLink ) then |
||
1324 | return SAS_FindLink( itemLink ); |
||
1325 | end |
||
1326 | end |
||
1327 | function SAS_FindLink( item ) |
||
1328 | -- Find an item's link number from it's item link |
||
1329 | if ( item ) then |
||
1330 | for link in string.gfind( item, "(%d+:%d+:%d+:%d+)" ) do |
||
1331 | return tLink(link); |
||
1332 | end |
||
1333 | end |
||
1334 | end |
||
1335 | |||
1336 | function SAS_ItemName( item ) |
||
1337 | -- Return an item's name |
||
1338 | local itemName = SAS_FindItem( item ); |
||
1339 | if ( itemName ) then |
||
1340 | return SAS_FindName( itemName ); |
||
1341 | end |
||
1342 | end |
||
1343 | function SAS_FindName( item ) |
||
1344 | -- Find an item's name from it's item link |
||
1345 | if ( item ) then |
||
1346 | for name in string.gfind( item, "%[(.+)%]") do |
||
1347 | return name; |
||
1348 | end |
||
1349 | end |
||
1350 | end |
||
1351 | |||
1352 | function SAS_FindItem( item ) |
||
1353 | -- Iterate over items the player has and return it's link and location -- |
||
1354 | if ( not item ) then return; end |
||
1355 | |||
1356 | item = tostring(item); |
||
1357 | |||
1358 | -- Iterate over bags |
||
1359 | for i=0, 4 do |
||
1360 | local bagSlots = GetContainerNumSlots(i); |
||
1361 | if ( bagSlots ) then |
||
1362 | for j=1, bagSlots do |
||
1363 | --SASDebug("Doing GetContainerItemLink() on "..i.." "..j); |
||
1364 | local itemLink = GetContainerItemLink(i,j); |
||
1365 | if ( itemLink ) then |
||
1366 | if ( item == SAS_FindLink( itemLink ) or item == SAS_FindName( itemLink ) ) then |
||
1367 | return itemLink, i, j; |
||
1368 | end |
||
1369 | end |
||
1370 | end |
||
1371 | end |
||
1372 | end |
||
1373 | |||
1374 | -- Iterate over paper doll |
||
1375 | for i=0, 23 do |
||
1376 | --SASDebug("Doing GetInventoryItemLink() on "..i); |
||
1377 | local itemLink = GetInventoryItemLink("player",i); |
||
1378 | if ( itemLink ) then |
||
1379 | if ( itemLink ) then |
||
1380 | if ( item == SAS_FindLink( itemLink ) or item == SAS_FindName( itemLink ) ) then |
||
1381 | return itemLink, nil, nil, i; |
||
1382 | end |
||
1383 | end |
||
1384 | end |
||
1385 | end |
||
1386 | end |
||
1387 | |||
1388 | function SAS_FindSpell( spell, rank ) |
||
1389 | -- Iterate over spells the player has and return location |
||
1390 | if ( not spell ) then return; end |
||
1391 | local i = 1; |
||
1392 | local highest; |
||
1393 | local spellName, spellRank = GetSpellName( i, BOOKTYPE_SPELL ); |
||
1394 | --if ( any and PlrClass == "WARRIOR" and PlrClass == "ROGUE" ) then |
||
1395 | -- rank = nil; |
||
1396 | --end |
||
1397 | local name, texture, offset, numSpells = nil, nil, 0, 0; |
||
1398 | --if ( not strict and PlrClass == "DRUID" and GetNumSpellTabs() == 4 ) then |
||
1399 | -- name, texture, offset, numSpells = GetSpellTabInfo(3) |
||
1400 | -- numSpells = numSpells+offset; |
||
1401 | --end |
||
1402 | while spellName do |
||
1403 | if ( spellName == spell ) then |
||
1404 | highest = i; |
||
1405 | if ( rank ) then |
||
1406 | if ( tRank(spellRank) == tonumber(rank) ) then |
||
1407 | return i; |
||
1408 | end |
||
1409 | else |
||
1410 | return i; |
||
1411 | end |
||
1412 | end |
||
1413 | i = i+1; |
||
1414 | spellName, spellRank = GetSpellName( i, BOOKTYPE_SPELL ); |
||
1415 | end |
||
1416 | |||
1417 | return nil, highest; |
||
1418 | end |
||
1419 | |||
1420 | function SAS_FindMacro( name, texture, macro ) |
||
1421 | -- Check saved macro id |
||
1422 | local macroName, macroTexture, bestguess; |
||
1423 | if ( macro ) then |
||
1424 | macroName, macroTexture = GetMacroInfo(macro); |
||
1425 | if ( macroName == name ) then |
||
1426 | if ( texture and macroTexture == texture ) then |
||
1427 | return macro; |
||
1428 | end |
||
1429 | bestguess = macro; |
||
1430 | end |
||
1431 | end |
||
1432 | |||
1433 | -- If no direct match, iterate over macros and return matching index |
||
1434 | local numAccountMacros, numCharacterMacros = GetNumMacros(); |
||
1435 | numCharacterMacros = numCharacterMacros + 18; |
||
1436 | for i=1, 36 do |
||
1437 | if ( i > numAccountMacros and i < 19 ) then |
||
1438 | -- no more global macros, skip to local |
||
1439 | i = 19; |
||
1440 | end |
||
1441 | if ( i > numCharacterMacros ) then |
||
1442 | -- no more macros |
||
1443 | break; |
||
1444 | end |
||
1445 | macroName, macroTexture = GetMacroInfo(i) |
||
1446 | if ( macroName and macroName == name ) then |
||
1447 | if ( texture and macroTexture == texture ) then |
||
1448 | return i; |
||
1449 | end |
||
1450 | bestguess = i; |
||
1451 | end |
||
1452 | end |
||
1453 | |||
1454 | return bestguess; |
||
1455 | end |
||
1456 | |||
1457 | function SAS_GetActionInfo( id, quick ) |
||
1458 | -- Scans an action button to attempt to determine if it's a spell, macro, or item |
||
1459 | if ( HasAction(id) ) then |
||
1460 | SASToolTip:SetAction(id); |
||
1461 | local name = SASToolTipTextLeft1:GetText(); |
||
1462 | local rank, macro, link; |
||
1463 | local texture = GetActionTexture(id); |
||
1464 | |||
1465 | local count = GetActionCount(id); |
||
1466 | |||
1467 | if ( name and name ~= "" ) then |
||
1468 | if ( SASToolTipTextRight1:IsShown() ) then |
||
1469 | rank = tRank(SASToolTipTextRight1:GetText()) |
||
1470 | end |
||
1471 | |||
1472 | local spellNum = SAS_FindSpell( name, rank ); |
||
1473 | if ( spellNum ) then |
||
1474 | -- is ActionButton a spell |
||
1475 | texture = GetSpellTexture( spellNum, BOOKTYPE_SPELL ); -- auras don't have correct texture on action bar |
||
1476 | elseif ( GetActionText(id) ) then |
||
1477 | -- is ActionButton a macro |
||
1478 | macro = GetMacroIndexByName(name); -- will find first macro with name by creation date |
||
1479 | else |
||
1480 | -- is ActionButton an item |
||
1481 | if ( quick ) then -- avoid slow item check |
||
1482 | link = "?"; |
||
1483 | else |
||
1484 | if ( count > 0 ) then |
||
1485 | link = SAS_ItemLink( name ); |
||
1486 | if ( not link ) then SASDebug("|wItem "..name.." on action button "..id.." not found."); end |
||
1487 | else |
||
1488 | SASDebug("|wItem "..name.." on action button "..id.." is an item not on this character."); |
||
1489 | link = SAS_CheckItemDBs( name ); |
||
1490 | end |
||
1491 | end |
||
1492 | end |
||
1493 | |||
1494 | return name, texture, rank, link, macro; --{ name, rank, macro, link, texture }; |
||
1495 | |||
1496 | elseif ( SAS_Saved[PlrName]["MissingItems"] and SAS_Saved[PlrName]["MissingItems"][id] ) then |
||
1497 | name, texture, rank, link = SAS_ParseActionInfo(SAS_Saved[PlrName]["MissingItems"][id]); |
||
1498 | if ( link == "?" ) then |
||
1499 | link = SAS_CheckItemDBs(name); |
||
1500 | end |
||
1501 | return name, texture, rank, link, macro; |
||
1502 | else |
||
1503 | SASDebug("|wAction "..id.." HasAction() but doesn't have anything in it."); |
||
1504 | end |
||
1505 | end |
||
1506 | end |
||
1507 | |||
1508 | function SAS_IterateActions( quick ) |
||
1509 | -- Iterate over all current actions |
||
1510 | local actionlist = {}; |
||
1511 | for i=0, 9 do |
||
1512 | actionlist[i] = {}; |
||
1513 | for j=1, 12 do |
||
1514 | actionlist[i][j] = SAS_BuildActionInfo( SAS_GetActionInfo( j+(i*12), quick ) ); --action[1], action[2], action[3], action[4], action[5] ); |
||
1515 | end |
||
1516 | end |
||
1517 | |||
1518 | return actionlist; |
||
1519 | end |
||
1520 | |||
1521 | function SAS_SetTooltip( bar, id ) |
||
1522 | -- Sets the Tooltip for the found action |
||
1523 | if ( not bar or not id ) then return; end |
||
1524 | |||
1525 | if ( SAS_Temp[bar][id] ) then |
||
1526 | local name, texture, rank, link, macro = SAS_ParseActionInfo( SAS_Temp[bar][id] ); --SAS_Temp[bar][id][1], SAS_Temp[bar][id][2], SAS_Temp[bar][id][3], SAS_Temp[bar][id][4], SAS_Temp[bar][id][5]; |
||
1527 | texture = SAS_FullPath(texture); |
||
1528 | local TooltipReturn; |
||
1529 | -- is a macro |
||
1530 | if ( macro ) then |
||
1531 | TooltipReturn = GameTooltip:SetText( name, 1, 1, 1 ); |
||
1532 | local macroName,macroTexture,macroText = GetMacroInfo( SAS_FindMacro(name, texture, macro) ); |
||
1533 | if ( macroText ) then |
||
1534 | GameTooltip:AddLine( macroText, 0.75, 0.75, 0.75, 1, 1 ); |
||
1535 | GameTooltip:Show(); |
||
1536 | else |
||
1537 | SASTooltipAddLine( SAS_TEXT_TOOLTIP_NOMACRO ); |
||
1538 | end |
||
1539 | -- is an item |
||
1540 | elseif ( link ) then |
||
1541 | local itemLink; |
||
1542 | SASDebug("SAS_SetTooltip - link = "..link); |
||
1543 | if ( link == "?" or link == "1" ) then |
||
1544 | itemLink = SAS_FindItem( name ); |
||
1545 | if ( itemLink ) then |
||
1546 | link = SAS_FindLink(itemLink); |
||
1547 | else |
||
1548 | link = nil; |
||
1549 | end |
||
1550 | else |
||
1551 | itemLink = SAS_FindItem( link ); |
||
1552 | end |
||
1553 | if ( link and GetItemInfo("item:"..link) ) then |
||
1554 | TooltipReturn = GameTooltip:SetHyperlink("item:"..link); |
||
1555 | if ( not itemLink ) then |
||
1556 | SASTooltipAddLine( SAS_TEXT_TOOLTIP_NOTHAVE ); |
||
1557 | end |
||
1558 | else |
||
1559 | TooltipReturn = GameTooltip:SetText( name, 1, 1, 1 ); |
||
1560 | SASTooltipAddLine( SAS_TEXT_TOOLTIP_NOTVALID ); |
||
1561 | end |
||
1562 | -- is a spell |
||
1563 | else |
||
1564 | local spellNum, highest = SAS_FindSpell( name, rank ); |
||
1565 | if ( spellNum ) then |
||
1566 | TooltipReturn = GameTooltip:SetSpell( spellNum, BOOKTYPE_SPELL ); |
||
1567 | if ( rank ) then |
||
1568 | local spellName, spellRank = GetSpellName( spellNum, BOOKTYPE_SPELL ); |
||
1569 | GameTooltipTextRight1:SetText( spellRank ); |
||
1570 | GameTooltipTextRight1:SetTextColor( 0.5, 0.5, 0.5 ); |
||
1571 | GameTooltipTextRight1:Show(); |
||
1572 | GameTooltip:Show(); |
||
1573 | end |
||
1574 | elseif ( highest ) then |
||
1575 | local spellName, spellRank = GetSpellName( highest, BOOKTYPE_SPELL ); |
||
1576 | local string = string.gsub( SAS_TEXT_TOOLTIP_NOSPELLRANK, "%%r", rank ); |
||
1577 | TooltipReturn = GameTooltip:SetSpell( highest, BOOKTYPE_SPELL ); |
||
1578 | if ( spellRank ) then |
||
1579 | GameTooltipTextRight1:SetText( spellRank ); |
||
1580 | GameTooltipTextRight1:SetTextColor( 0.5, 0.5, 0.5 ); |
||
1581 | GameTooltipTextRight1:Show(); |
||
1582 | GameTooltip:Show(); |
||
1583 | end |
||
1584 | SASTooltipAddLine( string ); |
||
1585 | else |
||
1586 | TooltipReturn = GameTooltip:SetText( name, 1, 1, 1 ); |
||
1587 | if ( rank ) then |
||
1588 | GameTooltipTextRight1:SetText( RANK.." "..rank ); |
||
1589 | GameTooltipTextRight1:SetTextColor( 0.5, 0.5, 0.5 ); |
||
1590 | GameTooltipTextRight1:Show(); |
||
1591 | GameTooltip:Show(); |
||
1592 | end |
||
1593 | SASTooltipAddLine( SAS_TEXT_TOOLTIP_NOSPELL ); |
||
1594 | end |
||
1595 | end |
||
1596 | |||
1597 | if ( TooltipReturn ) then |
||
1598 | this.updateTooltip = TOOLTIP_UPDATE_TIME; |
||
1599 | else |
||
1600 | this.updateTooltip = nil; |
||
1601 | end |
||
1602 | end |
||
1603 | end |
||
1604 | |||
1605 | function SAS_BarHasActions(bar, set) |
||
1606 | if ( not set ) then |
||
1607 | set = SAS_Temp; |
||
1608 | end |
||
1609 | if ( bar and set[bar] ) then |
||
1610 | for i=1, 12 do |
||
1611 | if ( set[bar][i] ) then |
||
1612 | return 1; |
||
1613 | end |
||
1614 | end |
||
1615 | end |
||
1616 | end |
||
1617 | |||
1618 | function SAS_ClearSlot(id) |
||
1619 | -- Clear an action slot |
||
1620 | if ( HasAction(id) and not SAS_Saved[PlrName]["NoEmptyButtons"] ) then |
||
1621 | PickupAction(id); |
||
1622 | SAS_ClearCursor(); |
||
1623 | end |
||
1624 | end |
||
1625 | |||
1626 | function SAS_MissingItem( id, itemInfo ) |
||
1627 | -- Add to list of items to place on the bar when available. |
||
1628 | if ( id and itemInfo ) then |
||
1629 | if ( not SAS_Saved[PlrName]["MissingItems"] ) then |
||
1630 | SAS_Saved[PlrName]["MissingItems"] = {}; |
||
1631 | end |
||
1632 | local missing = SAS_Saved[PlrName]["MissingItems"] |
||
1633 | if ( not missing[id] or SAS_ParseActionInfo(missing[id], 3) ~= itemInfo[3] ) then |
||
1634 | if ( not SAS_original_HasAction( id ) ) then |
||
1635 | i = 1; |
||
1636 | local passive = IsSpellPassive( i, BOOKTYPE_SPELL ); |
||
1637 | while passive do |
||
1638 | i = i + 1; |
||
1639 | passive = IsSpellPassive( i, BOOKTYPE_SPELL ); |
||
1640 | end |
||
1641 | PickupSpell( i, BOOKTYPE_SPELL ); |
||
1642 | SAS_original_PickupAction( id ); |
||
1643 | end |
||
1644 | SAS_Saved[PlrName]["MissingItems"][id] = SAS_BuildActionInfo(itemInfo[1], itemInfo[2], nil, itemInfo[3], nil, nil, itemInfo[4]); |
||
1645 | SAS_original_PickupAction( id ); |
||
1646 | SAS_ClearCursor(); |
||
1647 | SASDebug( itemInfo[1] ); |
||
1648 | end |
||
1649 | end |
||
1650 | end |
||
1651 | |||
1652 | function SAS_ForceUpdate( id ) |
||
1653 | if ( id and not SAS_original_HasAction( id ) ) then |
||
1654 | SASDebug( "force update on "..id ); |
||
1655 | SAS_ToggleBarLocks(); |
||
1656 | i = 1; |
||
1657 | --if ( not SAS_original_HasAction( id ) ) then |
||
1658 | local passive = IsSpellPassive( i, BOOKTYPE_SPELL ); |
||
1659 | while passive do |
||
1660 | i = i + 1; |
||
1661 | passive = IsSpellPassive( i, BOOKTYPE_SPELL ); |
||
1662 | end |
||
1663 | PickupSpell( i, BOOKTYPE_SPELL ); |
||
1664 | SAS_original_PickupAction( id ); |
||
1665 | --end |
||
1666 | SAS_original_PickupAction( id ); |
||
1667 | SAS_ToggleBarLocks(1); |
||
1668 | SAS_ClearCursor(); |
||
1669 | end |
||
1670 | end |
||
1671 | |||
1672 | function SAS_FindMissingItems() |
||
1673 | -- Readd missing items to action bar |
||
1674 | if ( not SAS_Saved[PlrName]["MissingItems"] ) then return; end |
||
1675 | SAS_ToggleBarLocks(); |
||
1676 | for id, itemInfo in SAS_Saved[PlrName]["MissingItems"] do |
||
1677 | SAS_PlaceItem( id, SAS_ParseActionInfo( itemInfo, 4, 1, 6 ) ); |
||
1678 | end |
||
1679 | SAS_ToggleBarLocks(1); |
||
1680 | end |
||
1681 | |||
1682 | function SAS_GetMissingItemInfo( id ) |
||
1683 | if ( id ) then |
||
1684 | if ( SAS_Saved and PlrName ) then |
||
1685 | if ( SAS_Saved[PlrName]["MissingItems"] and SAS_Saved[PlrName]["MissingItems"][id] ) then |
||
1686 | return SAS_Saved[PlrName]["MissingItems"][id]; |
||
1687 | end |
||
1688 | end |
||
1689 | end |
||
1690 | end |
||
1691 | |||
1692 | function SAS_CheckItemDBs( name ) |
||
1693 | -- check if there are any item db mods, get item link from that |
||
1694 | if ( ItemLinks ) then |
||
1695 | if ( ItemLinks[name] and ItemLinks[name]["i"] ) then |
||
1696 | SASDebug( "found "..name.." in LootLink db" ); |
||
1697 | return tLink(ItemLinks[name]["i"]); |
||
1698 | end |
||
1699 | elseif ( IMDB ) then |
||
1700 | local realm = GetCVar("realmName"); |
||
1701 | if ( IMDB[realm] and IMDB[realm][name] ) then |
||
1702 | for itemLink in string.gfind( IMDB[realm][name], "item(%d:%d:%d:%d)" ) do |
||
1703 | SASDebug( "found "..name.." in ItemSync db" ); |
||
1704 | return tLink(itemLink); |
||
1705 | end |
||
1706 | elseif ( IMDB[name] ) then |
||
1707 | for itemLink in string.gfind( IMDB[name], "item(%d:%d:%d:%d)" ) do |
||
1708 | SASDebug( "found "..name.." in ItemSync db" ); |
||
1709 | return tLink(itemLink); |
||
1710 | end |
||
1711 | end |
||
1712 | end |
||
1713 | |||
1714 | SASDebug( "could not find "..name.." in either item dbs." ); |
||
1715 | |||
1716 | return "?"; |
||
1717 | end |
||
1718 | |||
1719 | function SAS_PlaceItem( id, link, name, set ) |
||
1720 | -- Place an item, update set link id if found |
||
1721 | local itemLink, bag, slot, inv; |
||
1722 | if ( link == "?" or link == "1" ) then |
||
1723 | itemLink, bag, slot, inv = SAS_CheckItem( name, id, set ); |
||
1724 | else |
||
1725 | itemLink, bag, slot, inv = SAS_FindItem( link ); |
||
1726 | end |
||
1727 | if ( bag ) then |
||
1728 | PickupContainerItem( bag, slot ); |
||
1729 | PlaceAction(id); |
||
1730 | return 1; |
||
1731 | elseif ( inv ) then |
||
1732 | PickupInventoryItem( inv ); |
||
1733 | PlaceAction(id); |
||
1734 | return 1; |
||
1735 | end |
||
1736 | end |
||
1737 | |||
1738 | function SAS_CheckItem( name, id, set ) |
||
1739 | if ( name ) then |
||
1740 | itemLink, bag, slot, inv = SAS_FindItem( name ); |
||
1741 | itemLink = SAS_FindLink(itemLink) |
||
1742 | if ( not itemLink ) then |
||
1743 | itemLink = SAS_CheckItemDBs( name ); |
||
1744 | end |
||
1745 | if ( itemLink and itemLink ~= "?" and itemLink ~= "1" ) then |
||
1746 | local slot = math.mod( id, 12 ); |
||
1747 | local bar = (id-slot) / 12; |
||
1748 | if ( SAS_Saved[PlrName]["s"][set] ) then |
||
1749 | local action = SAS_Saved[PlrName]["s"][set][bar][slot]; |
||
1750 | local iname, ilink = SAS_ParseActionInfo(action, 1, 4); |
||
1751 | if ( iname ) then |
||
1752 | if ( iname == name and ilink and ilink == "?" ) then |
||
1753 | SASDebug( "Updating item in action #"..id.." in set "..set.." with itemLink." ); |
||
1754 | SAS_Saved[PlrName]["s"][set][bar][slot] = SAS_IncActionInfo(action, itemLink, 4); |
||
1755 | else |
||
1756 | SASDebug( "|wAttempted to update itemLink in action #"..id.." but names are wrong?" ); |
||
1757 | end |
||
1758 | end |
||
1759 | end |
||
1760 | end |
||
1761 | end |
||
1762 | return itemLink, bag, slot, inv; |
||
1763 | end |
||
1764 | |||
1765 | function SAS_ToggleBarLocks( on ) |
||
1766 | -- disable locking on bar mods that hook PickupAction() |
||
1767 | for k, v in barmods do |
||
1768 | if ( getglobal(v[1]) ) then |
||
1769 | if ( on ) then |
||
1770 | setglobal(v[1], v[3]) |
||
1771 | else |
||
1772 | v[3] = getglobal(v[1]); |
||
1773 | setglobal(v[1], v[2]); |
||
1774 | end |
||
1775 | end |
||
1776 | end |
||
1777 | end |
||
1778 | |||
1779 | function SAS_SwapSet( set, player ) |
||
1780 | -- Swaps a saved set to the player's real action bars. |
||
1781 | if ( not player ) then |
||
1782 | SASDebug( "SAS_SwapSet - No player name specified, using "..PlrName ); |
||
1783 | player = PlrName; |
||
1784 | end |
||
1785 | |||
1786 | local actions; |
||
1787 | if ( set ) then |
||
1788 | SASDebug(" SAS_SwapSet - about to do copy table on SAS_Saved["..player.."][sets]["..set.."]" ); |
||
1789 | actions = SAS_CopyTable( SAS_Saved[player]["s"][set] ); |
||
1790 | elseif ( SASMain:IsVisible() ) then |
||
1791 | SASDebug(" SAS_SwapSet - about to do copy table on SAS_Temp" ); |
||
1792 | actions = SAS_CopyTable( SAS_Temp ); |
||
1793 | else |
||
1794 | return; |
||
1795 | end |
||
1796 | |||
1797 | if ( not actions ) then |
||
1798 | SASDebug("|wNo actions to change to."); |
||
1799 | return; |
||
1800 | end |
||
1801 | |||
1802 | SAS_SwappingSet = true; |
||
1803 | if ( player == PlrName ) then |
||
1804 | SAS_SetCurrentSet( set ); |
||
1805 | end |
||
1806 | SAS_ToggleBarLocks(); |
||
1807 | SAS_ClearCursor(); |
||
1808 | for i = 0, 9 do |
||
1809 | if ( SAS_BarEnabled(i,actions) and not ( not SAS_BarHasActions(i, actions) and not SAS_Saved[PlrName]["EmptyBars"] ) ) then |
||
1810 | SASDebug("Bar "..(i+1).." is enabled"); |
||
1811 | for j = 1, 12 do |
||
1812 | local id = j + i*12; |
||
1813 | local msg = "Action "..id; |
||
1814 | if ( actions[i][j] ) then |
||
1815 | local ename, etexture, erank, elink, emacro = SAS_GetActionInfo(id, 1); |
||
1816 | local name, texture, rank, link, macro = SAS_ParseActionInfo( actions[i][j] ); --actions[i][j][1], actions[i][j][2], actions[i][j][3], actions[i][j][4], actions[i][j][5]; |
||
1817 | if ( (name == ename and (( rank == erank ) or ( macro and emacro ) or ( link and elink ))) ) then |
||
1818 | msg = msg.." is the same as the one trying to be swapped."; |
||
1819 | else |
||
1820 | if ( macro ) then |
||
1821 | msg = msg.." is a macro."; |
||
1822 | local macroID = SAS_FindMacro( name, texture, macro ) |
||
1823 | if ( macroID ) then |
||
1824 | PickupMacro( macroID ); |
||
1825 | PlaceAction(id); |
||
1826 | else |
||
1827 | msg = msg.." |wCouldn't find macro." |
||
1828 | SAS_ClearSlot(id); |
||
1829 | end |
||
1830 | elseif ( link ) then |
||
1831 | msg = msg.." is an item."; |
||
1832 | if ( not SAS_PlaceItem( id, link, name, set ) ) then |
||
1833 | msg = msg.." |wCouldn't find item." |
||
1834 | SAS_MissingItem( id, {name, texture, link, set} ); |
||
1835 | end |
||
1836 | elseif ( name ) then |
||
1837 | msg = msg.." is a spell."; |
||
1838 | local spellNum, highest = SAS_FindSpell( name, rank ); |
||
1839 | if ( spellNum ) then |
||
1840 | PickupSpell( spellNum, BOOKTYPE_SPELL ); |
||
1841 | PlaceAction(id); |
||
1842 | elseif ( highest ) then |
||
1843 | local spellName, spellRank = GetSpellName( highest, BOOKTYPE_SPELL ); |
||
1844 | if ( rank ~= spellRank ) then |
||
1845 | msg = msg.." Can't find rank, using highest found instead."; |
||
1846 | PickupSpell( highest, BOOKTYPE_SPELL ); |
||
1847 | PlaceAction(id); |
||
1848 | else |
||
1849 | msg = msg.." Action is highest rank found, won't swap."; |
||
1850 | end |
||
1851 | else |
||
1852 | msg = msg.." |wCoulnd't find spell." |
||
1853 | SAS_ClearSlot(id); |
||
1854 | end |
||
1855 | else |
||
1856 | msg = msg.." is has no name, link, macro?"; |
||
1857 | end |
||
1858 | end |
||
1859 | |||
1860 | SAS_ClearCursor(); |
||
1861 | elseif ( not SAS_Saved[PlrName]["NoEmptyButtons"] ) then |
||
1862 | msg = msg.." is empty."; |
||
1863 | SAS_ClearSlot(id); |
||
1864 | end |
||
1865 | SASDebug(msg); |
||
1866 | end |
||
1867 | elseif ( not SAS_BarEnabled(i,actions) ) then |
||
1868 | SASDebug("Bar "..(i+1).." not enabled, skipping"); |
||
1869 | else |
||
1870 | SASDebug("Bar "..(i+1).." has no actions, skipping"); |
||
1871 | end |
||
1872 | end |
||
1873 | SAS_ClearCursor(); |
||
1874 | SAS_ToggleBarLocks(1); |
||
1875 | |||
1876 | SAS_SwappingSet = nil; |
||
1877 | TitanPanelSAS_Update(); |
||
1878 | end |
||
1879 | |||
1880 | function SAS_CopyTable(copyTable) |
||
1881 | -- properly copies a table instead of referencing the same table, thanks Sallust. |
||
1882 | if ( not copyTable ) then return; end |
||
1883 | local returnTable = {}; |
||
1884 | for k, v in copyTable do |
||
1885 | if type(v) == "table" then |
||
1886 | returnTable[k] = SAS_CopyTable(v); |
||
1887 | else |
||
1888 | returnTable[k] = v; |
||
1889 | end |
||
1890 | end |
||
1891 | return returnTable; |
||
1892 | end |
||
1893 | |||
1894 | function SAS_SetExists( set ) |
||
1895 | -- Check to see if the set already exists |
||
1896 | if SAS_Saved[PlrName]["s"][set] then |
||
1897 | return true; |
||
1898 | end |
||
1899 | end |
||
1900 | |||
1901 | function SAS_SaveSet(set) |
||
1902 | -- Save a set |
||
1903 | if ( not set ) then |
||
1904 | if ( SAS_GetCurrentSet() ) then |
||
1905 | set = SAS_GetCurrentSet(); |
||
1906 | else |
||
1907 | return; |
||
1908 | end |
||
1909 | end |
||
1910 | local actions; |
||
1911 | if ( SASMain:IsVisible() and SAS_Temp ) then |
||
1912 | actions = SAS_CopyTable(SAS_Temp); |
||
1913 | else |
||
1914 | actions = SAS_IterateActions(); |
||
1915 | end |
||
1916 | SASPrint(SAS_TEXT_SAVING..set); |
||
1917 | SAS_Saved[PlrName]["s"][set] = SAS_CopyTable(actions); |
||
1918 | SASActions_Load( set ); |
||
1919 | end |
||
1920 | |||
1921 | function SAS_Delete(set) |
||
1922 | -- Delete a set |
||
1923 | SASDebug(SAS_TEXT_DELETING..set); |
||
1924 | SAS_Saved[PlrName]["s"][set] = nil; |
||
1925 | if ( SAS_GetCurrentSet() == set ) then |
||
1926 | SAS_SetCurrentSet(); |
||
1927 | end |
||
1928 | SASActions_Load(); |
||
1929 | end |
||
1930 | |||
1931 | function SAS_SetCurrentSet( set ) |
||
1932 | SAS_Saved[PlrName]["CurrentSet"] = set; |
||
1933 | end |
||
1934 | |||
1935 | function SAS_GetCurrentSet() |
||
1936 | if ( SAS_Saved and PlrName ) then |
||
1937 | return SAS_Saved[PlrName]["CurrentSet"]; |
||
1938 | end |
||
1939 | end |
||
1940 | |||
1941 | function SASBackUp() |
||
1942 | SAS_BackUp = SAS_IterateActions(); |
||
1943 | end |
||
1944 | |||
1945 | function SAS_RestoreBackUp() |
||
1946 | SAS_SwapSet( PlrName, "BackUp" ); |
||
1947 | end |
||
1948 | |||
1949 | function SAS_Console( msg ) |
||
1950 | if ( strlower(string.sub( msg, 1, 4 )) == "swap" ) then |
||
1951 | local set = string.sub( msg, 6 ); |
||
1952 | if ( set and SAS_SetExists( set ) ) then |
||
1953 | SAS_SwapSet( set ); |
||
1954 | else |
||
1955 | SASPrint( string.gsub(SAS_TEXT_CONSOLE_NOVALID, "%%s", set) ); |
||
1956 | end |
||
1957 | elseif ( strlower(string.sub( msg, 1, 4 )) == "save" ) then |
||
1958 | local set = string.sub( msg, 6 ); |
||
1959 | if ( set ) then |
||
1960 | if ( SAS_SetExists( set ) ) then |
||
1961 | else |
||
1962 | SAS_SaveSet( set ); |
||
1963 | end |
||
1964 | end |
||
1965 | elseif ( strlower(string.sub( msg, 1, 5 )) == "debug" ) then |
||
1966 | SAS_Saved["debug"] = not SAS_Saved["debug"]; |
||
1967 | elseif ( strlower(string.sub( msg, 1, 4 )) == "show" or msg == "" ) then |
||
1968 | SASMain_Toggle(); |
||
1969 | else |
||
1970 | SASPrint( SAS_TEXT_CONSOLE_HELP ); |
||
1971 | end |
||
1972 | end |
||
1973 | function tPath( texture ) |
||
1974 | -- truncate icon's file path |
||
1975 | return string.gsub( texture, IconPath, "" ); |
||
1976 | end |
||
1977 | |||
1978 | function SAS_FullPath( texture ) |
||
1979 | -- add icon's file path back in |
||
1980 | if ( texture ) then return IconPath..texture; end |
||
1981 | end |
||
1982 | |||
1983 | function tRank( rank ) |
||
1984 | -- truncate ranks to just numerical data |
||
1985 | if ( not rank ) then return; end |
||
1986 | for i in string.gfind( rank, "%d+" ) do return tonumber(i); end |
||
1987 | end |
||
1988 | |||
1989 | function tLink( itemLink ) |
||
1990 | -- truncate item links to item ids |
||
1991 | if ( not itemLink ) then return; end |
||
1992 | for num in string.gfind( itemLink, "(%d+):0:0:0" ) do return num; end |
||
1993 | return itemLink; |
||
1994 | end |
||
1995 | |||
1996 | function SAS_TableNil(a) |
||
1997 | if a then |
||
1998 | for k, v in a do |
||
1999 | return a; |
||
2000 | end |
||
2001 | end |
||
2002 | end |
||
2003 | |||
2004 | local function actionComp( a, b ) |
||
2005 | if a and b then |
||
2006 | local A = { SAS_ParseActionInfo( a ) }; |
||
2007 | local B = { SAS_ParseActionInfo( b ) }; |
||
2008 | for k, v in A do |
||
2009 | if ( k ~= 4 and (not B[k] or v ~= B[k]) ) then |
||
2010 | SASDebug( k.." "..v.." does not == "..B[k] ); |
||
2011 | return 1; |
||
2012 | end |
||
2013 | end |
||
2014 | else |
||
2015 | if ( a ) then |
||
2016 | SASDebug( "no b" ); |
||
2017 | elseif ( b ) then |
||
2018 | SASDebug( "no a" ); |
||
2019 | else |
||
2020 | SASDebug( "no a or b" ); |
||
2021 | end |
||
2022 | return 1; |
||
2023 | end |
||
2024 | end |
||
2025 | |||
2026 | function SAS_CompareSet( set1, set2, strict ) |
||
2027 | -- Compare two sets to see if they're similar |
||
2028 | if ( not set1 or not set2 ) then |
||
2029 | if ( not set1 ) then |
||
2030 | SASDebug( "no set1" ); |
||
2031 | elseif ( not set2 ) then |
||
2032 | SASDebug( "no set2" ); |
||
2033 | else |
||
2034 | SASDebug( "no set1 or set2" ); |
||
2035 | end |
||
2036 | return 1; |
||
2037 | end |
||
2038 | |||
2039 | for i=0, 9 do |
||
2040 | if ( set1[i] ) then |
||
2041 | if ( strict == 2 ) then |
||
2042 | if ( set1[i][0] ~= set2[i][0] ) then |
||
2043 | return 1; |
||
2044 | end |
||
2045 | end |
||
2046 | for j=1, 12 do |
||
2047 | if ( set1[i][j] ) then |
||
2048 | if ( actionComp( set1[i][j], set2[i][j] ) ) then |
||
2049 | SASDebug( "returning at "..i.." "..j ); |
||
2050 | return 1; |
||
2051 | end |
||
2052 | elseif ( strict and set2[i][j] ) then |
||
2053 | SASDebug( "strict returning at "..i.." "..j.." no set1 but set2" ); |
||
2054 | return 1; |
||
2055 | end |
||
2056 | end |
||
2057 | elseif ( strict and set2[i] ) then |
||
2058 | SASDebug( "strict returning at "..i.." no set1 but set2" ); |
||
2059 | return 1; |
||
2060 | end |
||
2061 | end |
||
2062 | end |
||
2063 | |||
2064 | function SAS_UpgradeSets() |
||
2065 | -- Move action set data from 0.373 and prior versions to 0.4+ |
||
2066 | for p, v in SAS_Saved do |
||
2067 | if ( v["sets"] ) then |
||
2068 | SASPrint( "Doing upgrade on "..p.."'s sets" ); |
||
2069 | v["s"] = {}; |
||
2070 | for s, k in v["sets"] do |
||
2071 | v["s"][s] = {}; |
||
2072 | for i=0, 9 do |
||
2073 | v["s"][s][i] = {}; |
||
2074 | if ( not k[i]["enable"] ) then |
||
2075 | v["s"][s][i] = {[0] = 1}; |
||
2076 | end |
||
2077 | for j=1, 12 do |
||
2078 | local a = SAS_TableNil(SAS_CopyTable(k[i][j])); |
||
2079 | if ( a ) then |
||
2080 | v["s"][s][i][j] = SAS_BuildActionInfo(a[1],a[5],a[2],a[4],a[3]); |
||
2081 | end |
||
2082 | end |
||
2083 | end |
||
2084 | end |
||
2085 | v["sets"] = nil; -- delete old set data!! |
||
2086 | end |
||
2087 | end |
||
2088 | end |
||
2089 | |||
2090 | |||
2091 | -- Unused code |
||
2092 | |||
2093 | --[[ unneeded delay code - save for later |
||
2094 | function SAS_MissingItem( id, itemInfo ) |
||
2095 | -- Add to list of items to place on the bar when available. |
||
2096 | if ( id ) then |
||
2097 | if ( not SAS_Saved[PlrName]["MissingItems"] ) then |
||
2098 | SAS_Saved[PlrName]["MissingItems"] = {}; |
||
2099 | end |
||
2100 | SAS_Saved[PlrName]["MissingItems"][id] = itemInfo; |
||
2101 | SAS_ForceUpdate( id ); |
||
2102 | end |
||
2103 | end]] |
||
2104 | |||
2105 | --[[function SAS_ForceUpdate( id ) |
||
2106 | -- Force an update event for an action |
||
2107 | tinsert( SAS_ForceUpdateList, id ); |
||
2108 | SASFrame:SetScript( "OnUpdate", SAS_Delayed_OnUpdate ); |
||
2109 | end |
||
2110 | |||
2111 | function SAS_Delayed_OnUpdate() |
||
2112 | local id = SAS_ForceUpdateList[1]; |
||
2113 | if ( id and not SAS_original_HasAction( id ) ) then |
||
2114 | local itemInfo = SAS_GetMissingItemInfo( id ); |
||
2115 | i = 1; |
||
2116 | local passive = IsSpellPassive( i, BOOKTYPE_SPELL ); |
||
2117 | while passive do |
||
2118 | i = i + 1; |
||
2119 | passive = IsSpellPassive( i, BOOKTYPE_SPELL ); |
||
2120 | end |
||
2121 | PickupSpell( i, BOOKTYPE_SPELL ); |
||
2122 | SAS_original_PickupAction( id ); |
||
2123 | SAS_Saved[PlrName]["MissingItems"][id] = itemInfo; |
||
2124 | SAS_original_PickupAction( id ); |
||
2125 | SAS_ClearCursor(); |
||
2126 | tremove( SAS_ForceUpdateList, 1 ); |
||
2127 | else |
||
2128 | SASFrame:SetScript( "OnUpdate", nil ); |
||
2129 | end |
||
2130 | end]] |
||
2131 | |||
2132 | --[[ attempt to unquely identify macros |
||
2133 | function SAS_CreateUniqueMacros() |
||
2134 | local function iterateMacros() |
||
2135 | local all, numglobal, numlocal = {}, GetNumMacros(); |
||
2136 | numlocal = numlocal + 18; |
||
2137 | for i=1, 36 do |
||
2138 | if ( i > numglobal and i < 19 ) then |
||
2139 | -- no more global macros, skip to local |
||
2140 | i = 19; |
||
2141 | end |
||
2142 | if ( i > numlocal ) then |
||
2143 | -- no more macros |
||
2144 | return; |
||
2145 | end |
||
2146 | local name = GetMacroInfo(i); |
||
2147 | if ( name ) then |
||
2148 | if ( all[name] ) then |
||
2149 | all[name] = all[name] + 1; |
||
2150 | EditMacro(i, name.."·"); |
||
2151 | return iterateMacros(); |
||
2152 | else |
||
2153 | all[name] = 0; |
||
2154 | end |
||
2155 | end |
||
2156 | end |
||
2157 | end |
||
2158 | iterateMacros(); |
||
2159 | end |
||
2160 | |||
2161 | function SAS_StripUniqueMacros() |
||
2162 | for i=1, 36 do |
||
2163 | local name = GetMacroInfo(i); |
||
2164 | if ( name ) then |
||
2165 | EditMacro(i, SAS_StripUniqueMacroName(name)); |
||
2166 | end |
||
2167 | end |
||
2168 | end |
||
2169 | |||
2170 | function SAS_StripUniqueMacroName(name) |
||
2171 | return string.gsub(name, "(.-)·+", "%1"); |
||
2172 | end]] |