vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- |
2 | -- AutoBar |
||
3 | -- Copyright 2004, 2005, 2006 original author. |
||
4 | -- Copyright is expressly not transferred to Blizzard. |
||
5 | -- |
||
6 | -- Configurable set of 12 buttons that seeks out configured items |
||
7 | -- in your pack for use. Intended primarily for consumables. Not |
||
8 | -- for use with spells, skills, trinkets, or powers. |
||
9 | -- |
||
10 | -- Author: Marc aka Saien on Hyjal |
||
11 | -- WOWSaien@gmail.com |
||
12 | -- http://64.168.251.69/wow |
||
13 | -- |
||
14 | -- 2006.03.31 |
||
15 | -- Minor category changes |
||
16 | -- 2006.02.10 |
||
17 | -- Enriched Manna Biscuit/Alterac Manna Biscuit (which is usable everywhere) |
||
18 | -- moved to their own category("Food & Water Combo") - Update your buttons |
||
19 | -- Custom items can now appear on multiple buttons, as intended. |
||
20 | -- 2006.01.28 |
||
21 | -- Oils fixed. |
||
22 | -- Custom items got broken by selfcast config. Fixed. |
||
23 | -- 2006.01.20 |
||
24 | -- Will no longer fallback to zone-restricted items when all items in a button are ineligible. |
||
25 | -- Fixed bug where hitting keybinding for a button that has no items found will popup an error |
||
26 | -- Buttons will skip items too high in level for character |
||
27 | -- 2006.01.12 |
||
28 | -- Selfcast is back |
||
29 | -- AutoBar re-parented so it hides with an Alt-Z |
||
30 | -- Configuration checkbox to hide Keybind text |
||
31 | -- Configuration checkbox to hide Count text |
||
32 | -- Configuration checkbox to show empty buttons |
||
33 | -- Keybind text and count text scales with button width. |
||
34 | -- Can now open configuration while dead. |
||
35 | -- "Num Pad" key bindings are now shortened to just N in display. |
||
36 | -- Removed /ab as a shortcut for the depreciated slash commands. |
||
37 | -- Fixed Mana potion hp restriction - should be mana restriction |
||
38 | -- Minimum button width/height set to 9 pixels instead of 18. |
||
39 | -- 2006.01.06 |
||
40 | -- Release of complete re-write. |
||
41 | -- |
||
42 | |||
43 | AUTOBAR_VERSION = "2006.02.10" -- Notice the cleverly disguised date. |
||
44 | ------------------------------------ |
||
45 | BINDING_HEADER_AUTOBAR_SEP = "Auto Bar"; |
||
46 | BINDING_NAME_AUTOBAR_CONFIG = "Configuration Window"; |
||
47 | BINDING_NAME_AUTOBAR_BUTTON1 = "Button 1"; |
||
48 | BINDING_NAME_AUTOBAR_BUTTON2 = "Button 2"; |
||
49 | BINDING_NAME_AUTOBAR_BUTTON3 = "Button 3"; |
||
50 | BINDING_NAME_AUTOBAR_BUTTON4 = "Button 4"; |
||
51 | BINDING_NAME_AUTOBAR_BUTTON5 = "Button 5"; |
||
52 | BINDING_NAME_AUTOBAR_BUTTON6 = "Button 6"; |
||
53 | BINDING_NAME_AUTOBAR_BUTTON7 = "Button 7"; |
||
54 | BINDING_NAME_AUTOBAR_BUTTON8 = "Button 8"; |
||
55 | BINDING_NAME_AUTOBAR_BUTTON9 = "Button 9"; |
||
56 | BINDING_NAME_AUTOBAR_BUTTON10 = "Button 10"; |
||
57 | BINDING_NAME_AUTOBAR_BUTTON11 = "Button 11"; |
||
58 | BINDING_NAME_AUTOBAR_BUTTON12 = "Button 12"; |
||
59 | ------------------------------------ |
||
60 | AUTOBAR_MAXBUTTONS = 12; |
||
61 | ----------------------------------- |
||
62 | AutoBar_Debug = nil; |
||
63 | AutoBar_Player = nil; -- global |
||
64 | -- |
||
65 | local AutoBar_ConfigLoaded = nil; |
||
66 | AutoBar_SearchedForItems = {}; |
||
67 | local AutoBar_ButtonItemList = {}; |
||
68 | local AutoBar_ButtonItemList_Reversed = {}; |
||
69 | local AutoBar_Buttons_CurrentItems = {}; |
||
70 | -- |
||
71 | local AutoBar_InWorld = nil; |
||
72 | local AutoBar_InCombat = nil; -- For item use restrictions |
||
73 | ------------------------------------ |
||
74 | |||
75 | local function AutoBar_LinkDecode(link) |
||
76 | if (link) then |
||
77 | local _, _, id, name = string.find(link,"|Hitem:(%d+):%d+:%d+:%d+|h%[([^]]+)%]|h|r$"); |
||
78 | if (id and name) then |
||
79 | return name, tonumber(id); |
||
80 | end |
||
81 | end |
||
82 | end |
||
83 | |||
84 | local function AutoBar_ConfigInit() |
||
85 | if (not AutoBar_Config) then AutoBar_Config = {}; end |
||
86 | if (not AutoBar_Config[AutoBar_Player]) then AutoBar_Config[AutoBar_Player] = {}; end |
||
87 | --- |
||
88 | if (AutoBar_Config[AutoBar_Player].docked and AutoBar_Config[AutoBar_Player].scaling and |
||
89 | AutoBar_Config[AutoBar_Player].rows and AutoBar_Config[AutoBar_Player].columns) then |
||
90 | -- Config is from pre re-write. Not upgrading. |
||
91 | AutoBar_Config[AutoBar_Player] = {}; |
||
92 | AutoBar_Msg("Config for this character is old version. Clearing. No attempt to upgrade config is being done."); |
||
93 | end |
||
94 | --- |
||
95 | if (not AutoBar_Config[AutoBar_Player].buttons) then |
||
96 | local _,class = UnitClass("player"); |
||
97 | AutoBar_Config[AutoBar_Player].buttons = {}; |
||
98 | AutoBar_Config[AutoBar_Player].buttons[1] = { "BANDAGES", "ALTERAC_BANDAGES", "WARSONG_BANDAGES", "ARATHI_BANDAGES", "UNGORO_RESTORE"}; |
||
99 | AutoBar_Config[AutoBar_Player].buttons[2] = { "HEALPOTIONS", "REJUVENATION_POTIONS", "WHIPPER_ROOT", "NIGHT_DRAGONS_BREATH", "PVP_HEALPOTIONS", "ALTERAC_HEAL", "HEALTHSTONE" }; |
||
100 | if (class == "WARRIOR") then |
||
101 | AutoBar_Config[AutoBar_Player].buttons[3] = "RAGEPOTIONS"; |
||
102 | elseif (class == "ROGUE") then |
||
103 | AutoBar_Config[AutoBar_Player].buttons[3] = "ENERGYPOTIONS"; |
||
104 | elseif (class == "MAGE") then |
||
105 | AutoBar_Config[AutoBar_Player].buttons[3] = { "MANAPOTIONS", "REJUVENATION_POTIONS", "NIGHT_DRAGONS_BREATH", "PVP_MANAPOTIONS", "ALTERAC_MANA", "MANASTONE" }; |
||
106 | else |
||
107 | AutoBar_Config[AutoBar_Player].buttons[3] = { "MANAPOTIONS", "REJUVENATION_POTIONS", "NIGHT_DRAGONS_BREATH", "PVP_MANAPOTIONS", "ALTERAC_MANA" }; |
||
108 | end |
||
109 | if (class ~= "ROGUE" and class ~= "WARRIOR") then |
||
110 | AutoBar_Config[AutoBar_Player].buttons[4] = { "WATER", "WATER_CONJURED" }; |
||
111 | end |
||
112 | AutoBar_Config[AutoBar_Player].buttons[5] = { "FOOD", "FOOD_STAMINA", "FOOD_CONJURED" }; |
||
113 | AutoBar_Config[AutoBar_Player].buttons[AUTOBAR_MAXBUTTONS] = "HEARTHSTONE"; |
||
114 | end |
||
115 | if (not AutoBar_Config[AutoBar_Player].display) then |
||
116 | AutoBar_Config[AutoBar_Player].display = {}; |
||
117 | end |
||
118 | AutoBar_ConfigUpdated(); |
||
119 | end |
||
120 | |||
121 | local function AutoBar_BuildItemList() |
||
122 | local function AddItemInfo(identifier, buttonnum) |
||
123 | if (AutoBar_Category_Info[identifier] and AutoBar_Category_Info[identifier].items) then |
||
124 | local idx,j; |
||
125 | for idx, j in AutoBar_Category_Info[identifier].items do |
||
126 | if (AutoBar_SearchedForItems[j]) then |
||
127 | table.insert(AutoBar_SearchedForItems[j], buttonnum); |
||
128 | else |
||
129 | AutoBar_SearchedForItems[j] = { buttonnum, identifier, idx }; |
||
130 | end |
||
131 | table.insert(AutoBar_ButtonItemList[buttonnum], j); |
||
132 | end |
||
133 | else |
||
134 | if (AutoBar_SearchedForItems[identifier]) then |
||
135 | table.insert(AutoBar_SearchedForItems[identifier], buttonnum); |
||
136 | else |
||
137 | AutoBar_SearchedForItems[identifier] = { buttonnum, identifier, 0 }; |
||
138 | end |
||
139 | table.insert(AutoBar_ButtonItemList[buttonnum], identifier); |
||
140 | end |
||
141 | end |
||
142 | AutoBar_SearchedForItems = {}; |
||
143 | AutoBar_ButtonItemList_Reversed = {}; |
||
144 | local idx; |
||
145 | for idx = 1, AUTOBAR_MAXBUTTONS, 1 do |
||
146 | if (AutoBar_Config[AutoBar_Player].buttons[idx]) then |
||
147 | local i, j; |
||
148 | AutoBar_ButtonItemList[idx] = {}; |
||
149 | AutoBar_ButtonItemList_Reversed[idx] = {}; |
||
150 | if (type(AutoBar_Config[AutoBar_Player].buttons[idx]) == "table") then |
||
151 | for i, j in AutoBar_Config[AutoBar_Player].buttons[idx] do |
||
152 | AddItemInfo (j, idx); |
||
153 | end |
||
154 | else |
||
155 | AddItemInfo (AutoBar_Config[AutoBar_Player].buttons[idx], idx); |
||
156 | end |
||
157 | for i, j in AutoBar_ButtonItemList[idx] do |
||
158 | AutoBar_ButtonItemList_Reversed[idx][j] = i; |
||
159 | end |
||
160 | end |
||
161 | end |
||
162 | end |
||
163 | |||
164 | function AutoBar_Button_GetDisplayItem(buttonnum) |
||
165 | local idx, bag, slot, rank, itemid, category, categoryidx, acceptable, cooldowntime, level; |
||
166 | local cooldownidx, start, duration, enable, fallback; |
||
167 | if (AutoBar_Buttons_CurrentItems[buttonnum]) then |
||
168 | idx = table.getn(AutoBar_Buttons_CurrentItems[buttonnum]); |
||
169 | else |
||
170 | idx = 0; |
||
171 | end |
||
172 | while (idx > 0 and not acceptable) do |
||
173 | bag = AutoBar_Buttons_CurrentItems[buttonnum][idx].items[1][1]; |
||
174 | slot = AutoBar_Buttons_CurrentItems[buttonnum][idx].items[1][2]; |
||
175 | rank = AutoBar_Buttons_CurrentItems[buttonnum][idx].rank; |
||
176 | itemid = AutoBar_ButtonItemList[buttonnum][rank]; |
||
177 | if (type(itemid) == "number") then |
||
178 | _,_,_,level = GetItemInfo(itemid); |
||
179 | else |
||
180 | level = 0; |
||
181 | end |
||
182 | if (AutoBar_SearchedForItems[itemid]) then |
||
183 | category = AutoBar_SearchedForItems[itemid][2]; |
||
184 | categoryidx = AutoBar_SearchedForItems[itemid][3]; |
||
185 | else |
||
186 | category = nil; |
||
187 | categoryidx = nil; |
||
188 | end |
||
189 | -- |
||
190 | start, duration, enable = GetContainerItemCooldown(bag, slot); |
||
191 | if (start > 0 and duration > 0) then |
||
192 | local tmp = start - GetTime() + duration; |
||
193 | if (not cooldowntime or tmp < cooldowntime) then |
||
194 | cooldowntime = tmp; |
||
195 | cooldownidx = idx; |
||
196 | end |
||
197 | idx = idx - 1; |
||
198 | elseif (level > UnitLevel("player")) then |
||
199 | idx = idx - 1; |
||
200 | elseif (AutoBar_Category_Info[category] and AutoBar_Category_Info[category].location and AutoBar_Category_Info[category].location ~= GetZoneText()) then |
||
201 | idx = idx - 1; |
||
202 | elseif (AutoBar_Category_Info[category]) then |
||
203 | if (not fallback) then |
||
204 | fallback = idx; |
||
205 | end |
||
206 | if (AutoBar_Category_Info[category].combatonly and not AutoBar_InCombat) then |
||
207 | idx = idx - 1; |
||
208 | elseif (AutoBar_Category_Info[category].noncombat and AutoBar_InCombat) then |
||
209 | idx = idx - 1; |
||
210 | elseif (AutoBar_Category_Info[category].limit) then |
||
211 | local losthp = UnitHealthMax("player") - UnitHealth("player"); |
||
212 | local lostmana = UnitManaMax("player") - UnitMana("player"); |
||
213 | if (UnitPowerType("player") ~= 0 ) then |
||
214 | --if (UnitClass("player") == "Druid") then |
||
215 | -- Can't check mana in druid forms |
||
216 | -- lostmana = 0; |
||
217 | --else |
||
218 | -- Class doesn't have mana, don't limit |
||
219 | lostmana = 10000; |
||
220 | --end |
||
221 | end |
||
222 | if (AutoBar_Category_Info[category].limit.downhp and AutoBar_Category_Info[category].limit.downhp[categoryidx] > losthp) then |
||
223 | idx = idx - 1 |
||
224 | elseif (AutoBar_Category_Info[category].limit.downmana and AutoBar_Category_Info[category].limit.downmana[categoryidx] > lostmana) then |
||
225 | idx = idx - 1 |
||
226 | else |
||
227 | acceptable = true; |
||
228 | end |
||
229 | else |
||
230 | acceptable = true; |
||
231 | end |
||
232 | else |
||
233 | acceptable = true; |
||
234 | end |
||
235 | end |
||
236 | if (not acceptable) then |
||
237 | if (fallback) then |
||
238 | idx = fallback; |
||
239 | elseif (cooldownidx) then |
||
240 | idx = cooldownidx; |
||
241 | elseif (AutoBar_Buttons_CurrentItems[buttonnum]) then |
||
242 | idx = table.getn(AutoBar_Buttons_CurrentItems[buttonnum]); |
||
243 | else |
||
244 | idx = nil; |
||
245 | end |
||
246 | end |
||
247 | -- |
||
248 | if (idx) then |
||
249 | bag = AutoBar_Buttons_CurrentItems[buttonnum][idx].items[1][1]; |
||
250 | slot = AutoBar_Buttons_CurrentItems[buttonnum][idx].items[1][2]; |
||
251 | rank = AutoBar_Buttons_CurrentItems[buttonnum][idx].rank; |
||
252 | else |
||
253 | bag = nil; slot = nil; rank = nil; |
||
254 | end |
||
255 | if (AutoBar_ButtonItemList[buttonnum]) then |
||
256 | itemid = AutoBar_ButtonItemList[buttonnum][rank]; |
||
257 | if (AutoBar_SearchedForItems[itemid]) then |
||
258 | category = AutoBar_SearchedForItems[itemid][2]; |
||
259 | categoryidx = AutoBar_SearchedForItems[itemid][3]; |
||
260 | else |
||
261 | category = nil; |
||
262 | categoryidx = nil; |
||
263 | end |
||
264 | else |
||
265 | itemid = nil; category = nil; categoryidx = nil; |
||
266 | end |
||
267 | return bag, slot, rank, itemid, category, categoryidx, idx, acceptable, cooldowntime; |
||
268 | end |
||
269 | |||
270 | function AutoBar_Button_UpdateButtons() |
||
271 | local buttonnum, i, button, icon, normaltexture, counttxt, bag, slot, idx, items; |
||
272 | local hotkey, count, tmpcount, keyText, actioncommand; |
||
273 | for buttonnum = 1, AUTOBAR_MAXBUTTONS, 1 do |
||
274 | button = getglobal("AutoBar_Button"..buttonnum); |
||
275 | icon = getglobal("AutoBar_Button"..buttonnum.."Icon"); |
||
276 | normaltexture = getglobal("AutoBar_Button"..buttonnum.."NormalTexture"); |
||
277 | counttxt = getglobal("AutoBar_Button"..buttonnum.."Count"); |
||
278 | hotkey = getglobal("AutoBar_Button"..buttonnum.."HotKey"); |
||
279 | if (not button.forcehidden and button.effectiveButton) then |
||
280 | button:Show(); |
||
281 | bag, slot,_,_,_,_,idx,enabled = AutoBar_Button_GetDisplayItem(button.effectiveButton) |
||
282 | if (bag and slot) then |
||
283 | items = AutoBar_Buttons_CurrentItems[button.effectiveButton][idx].items |
||
284 | count = 0; |
||
285 | for i, bagslot in items do |
||
286 | _, tmpcount = GetContainerItemInfo(bagslot[1], bagslot[2]); |
||
287 | if (tmpcount) then |
||
288 | count = count + tmpcount; |
||
289 | end |
||
290 | end |
||
291 | icon:SetTexture(GetContainerItemInfo(bag,slot)); |
||
292 | if (count > 1) then |
||
293 | counttxt:SetText(count); |
||
294 | else |
||
295 | counttxt:SetText(""); |
||
296 | end |
||
297 | if (enabled) then |
||
298 | icon:SetVertexColor(1,1,1); |
||
299 | normaltexture:SetVertexColor(1,1,1); |
||
300 | else |
||
301 | icon:SetVertexColor(0.4,0.4,0.4); |
||
302 | normaltexture:SetVertexColor(1,1,1); |
||
303 | end |
||
304 | actioncommand = "AUTOBAR_BUTTON"..button.effectiveButton; |
||
305 | if (actioncommand) then |
||
306 | keyText = GetBindingKey(actioncommand); |
||
307 | if (keyText) then |
||
308 | keyText = string.gsub(keyText, "CTRL", "C"); |
||
309 | keyText = string.gsub(keyText, "ALT", "A"); |
||
310 | keyText = string.gsub(keyText, "SHIFT", "S"); |
||
311 | keyText = string.gsub(keyText, "NUMPAD", "N"); |
||
312 | hotkey:SetText(keyText); |
||
313 | else |
||
314 | hotkey:SetText(""); |
||
315 | end |
||
316 | end |
||
317 | else |
||
318 | icon:SetTexture(""); |
||
319 | counttxt:SetText(""); |
||
320 | hotkey:SetText(""); |
||
321 | end |
||
322 | else |
||
323 | button:Hide(); |
||
324 | end |
||
325 | end |
||
326 | end |
||
327 | |||
328 | local function AutoBar_AssignButtons() |
||
329 | local displayButton = 0; |
||
330 | local buttonidx, buttoninfo, rankidx, items; |
||
331 | for buttonidx = 1, AUTOBAR_MAXBUTTONS, 1 do |
||
332 | if (AutoBar_Config[AutoBar_Player].display.showemptybuttons or AutoBar_Buttons_CurrentItems[buttonidx]) then |
||
333 | displayButton = displayButton + 1; |
||
334 | local button = getglobal("AutoBar_Button"..displayButton); |
||
335 | button.effectiveButton = buttonidx; |
||
336 | end |
||
337 | end |
||
338 | for buttonidx = displayButton+1, AUTOBAR_MAXBUTTONS, 1 do |
||
339 | local button = getglobal("AutoBar_Button"..buttonidx); |
||
340 | button.effectiveButton = nil; |
||
341 | end |
||
342 | AutoBar_Button_UpdateButtons(); |
||
343 | end |
||
344 | |||
345 | local function AutoBar_UpdateCategoryNameToID(name,id) |
||
346 | local buttonnum, idx; |
||
347 | for buttonnum = 1, AUTOBAR_MAXBUTTONS, 1 do |
||
348 | if (AutoBar_Config[AutoBar_Player].buttons[buttonnum]) then |
||
349 | if (type(AutoBar_Config[AutoBar_Player].buttons[buttonnum]) == "table") then |
||
350 | for idx in AutoBar_Config[AutoBar_Player].buttons[buttonnum] do |
||
351 | if (AutoBar_Config[AutoBar_Player].buttons[buttonnum][idx] == name) then |
||
352 | AutoBar_Config[AutoBar_Player].buttons[buttonnum][idx] = id; |
||
353 | AutoBar_Msg("Updating multi item button #",buttonnum," item #",idx," to use itemid instead of item name."); |
||
354 | end |
||
355 | end |
||
356 | elseif (AutoBar_Config[AutoBar_Player].buttons[buttonnum] == name) then |
||
357 | AutoBar_Config[AutoBar_Player].buttons[buttonnum] = id; |
||
358 | AutoBar_Msg("Updating single item button #",buttonnum," to use itemid instead of item name."); |
||
359 | end |
||
360 | end |
||
361 | end |
||
362 | end |
||
363 | |||
364 | function AutoBar_ScanBags(specificbag) |
||
365 | local function ClearOutBag(bag) |
||
366 | local buttonnum, idx, i, bagslot, newitemlist, newranks; |
||
367 | for buttonnum = 1, AUTOBAR_MAXBUTTONS, 1 do |
||
368 | if (AutoBar_Buttons_CurrentItems[buttonnum]) then |
||
369 | newranks = {}; |
||
370 | for idx in AutoBar_Buttons_CurrentItems[buttonnum] do |
||
371 | newitemlist = {}; |
||
372 | for i, bagslot in AutoBar_Buttons_CurrentItems[buttonnum][idx].items do |
||
373 | if (bag ~= bagslot[1]) then |
||
374 | table.insert(newitemlist,bagslot); |
||
375 | end |
||
376 | end |
||
377 | if (table.getn(newitemlist) > 0) then |
||
378 | AutoBar_Buttons_CurrentItems[buttonnum][idx].items = newitemlist; |
||
379 | table.insert(newranks,AutoBar_Buttons_CurrentItems[buttonnum][idx]); |
||
380 | end |
||
381 | end |
||
382 | if (table.getn(newranks) == 0) then |
||
383 | AutoBar_Buttons_CurrentItems[buttonnum] = nil; |
||
384 | else |
||
385 | AutoBar_Buttons_CurrentItems[buttonnum] = newranks; |
||
386 | end |
||
387 | end |
||
388 | end |
||
389 | end |
||
390 | local function AddItem(buttonnum, rank, bag, slot) |
||
391 | if (AutoBar_Buttons_CurrentItems[buttonnum]) then |
||
392 | local idx, rec, findRank; |
||
393 | for idx, rec in AutoBar_Buttons_CurrentItems[buttonnum] do |
||
394 | if (rec.rank == rank) then |
||
395 | findRank = idx; |
||
396 | end |
||
397 | end |
||
398 | if (findRank) then |
||
399 | table.insert(AutoBar_Buttons_CurrentItems[buttonnum][findRank].items, { bag, slot } ); |
||
400 | else |
||
401 | table.insert(AutoBar_Buttons_CurrentItems[buttonnum], |
||
402 | { |
||
403 | ["rank"] = rank, |
||
404 | ["items"] = { { bag, slot } } |
||
405 | } |
||
406 | ); |
||
407 | end |
||
408 | else |
||
409 | AutoBar_Buttons_CurrentItems[buttonnum] = { |
||
410 | [1] = { |
||
411 | ["rank"] = rank, |
||
412 | ["items"] = { { bag, slot } } |
||
413 | }, |
||
414 | }; |
||
415 | end |
||
416 | end |
||
417 | local function SortByRank(a,b) |
||
418 | if (a and b and a.rank and b.rank) then |
||
419 | return a.rank < b.rank; |
||
420 | else |
||
421 | return true; |
||
422 | end |
||
423 | end |
||
424 | |||
425 | local bag, slot, name, id, i; |
||
426 | local minbag,maxbag = 0, 4; |
||
427 | if (specificbag) then |
||
428 | minbag = specificbag; |
||
429 | maxbag = specificbag; |
||
430 | ClearOutBag(specificbag); |
||
431 | else |
||
432 | AutoBar_Buttons_CurrentItems = {}; |
||
433 | end |
||
434 | -- AutoBar_Buttons_CurrentItems = { |
||
435 | -- buttonnum = { |
||
436 | -- idx = { |
||
437 | -- "rank" = ranknum, |
||
438 | -- "items" = { {bag,slot}, {bag,slot}, {bag, slot} } |
||
439 | -- }, |
||
440 | -- }, |
||
441 | --}; |
||
442 | for bag = minbag, maxbag, 1 do |
||
443 | for slot = 1, GetContainerNumSlots(bag), 1 do |
||
444 | name, id = AutoBar_LinkDecode(GetContainerItemLink(bag,slot)); |
||
445 | if (name and AutoBar_SearchedForItems[name] and id) then |
||
446 | if (not AutoBar_SearchedForItems[id]) then |
||
447 | AutoBar_SearchedForItems[id] = { AutoBar_SearchedForItems[name][1], AutoBar_SearchedForItems[name][2], AutoBar_SearchedForItems[name][3] }; |
||
448 | end |
||
449 | AutoBar_UpdateCategoryNameToID(name,id); |
||
450 | AutoBar_SearchedForItems[name] = nil; |
||
451 | end |
||
452 | if (id and AutoBar_SearchedForItems[id]) then |
||
453 | local button = AutoBar_SearchedForItems[id][1]; |
||
454 | local rank = AutoBar_ButtonItemList_Reversed[button][id]; |
||
455 | AddItem(button, rank, bag, slot) |
||
456 | if (AutoBar_SearchedForItems[id][4]) then |
||
457 | for i = 4, table.getn(AutoBar_SearchedForItems[id]), 1 do |
||
458 | button = AutoBar_SearchedForItems[id][i]; |
||
459 | rank = AutoBar_ButtonItemList_Reversed[button][id]; |
||
460 | AddItem(button, rank, bag, slot) |
||
461 | end |
||
462 | end |
||
463 | end |
||
464 | end |
||
465 | end |
||
466 | local buttonnum; |
||
467 | for buttonnum = 1, AUTOBAR_MAXBUTTONS, 1 do |
||
468 | if (AutoBar_Buttons_CurrentItems[buttonnum]) then |
||
469 | table.sort(AutoBar_Buttons_CurrentItems[buttonnum], SortByRank); |
||
470 | end |
||
471 | end |
||
472 | AutoBar_AssignButtons(); |
||
473 | end |
||
474 | |||
475 | ------------------------------------ |
||
476 | |||
477 | function AutoBar_OnLoad() |
||
478 | AutoBar_Player = UnitName("player").." - "..GetCVar("realmName"); |
||
479 | |||
480 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
481 | this:RegisterEvent("PLAYER_LEAVING_WORLD"); |
||
482 | -- |
||
483 | this:RegisterEvent("BAG_UPDATE"); |
||
484 | this:RegisterEvent("UPDATE_BINDINGS"); |
||
485 | -- |
||
486 | -- For item use restrictions |
||
487 | this:RegisterEvent("ZONE_CHANGED_NEW_AREA"); |
||
488 | this:RegisterEvent("PLAYER_REGEN_ENABLED"); |
||
489 | this:RegisterEvent("PLAYER_REGEN_DISABLED"); |
||
490 | this:RegisterEvent("UNIT_MANA"); |
||
491 | this:RegisterEvent("UNIT_HEALTH"); |
||
492 | this:RegisterEvent("PLAYER_ALIVE"); |
||
493 | this:RegisterEvent("BAG_UPDATE_COOLDOWN"); |
||
494 | -- |
||
495 | end |
||
496 | |||
497 | function AutoBar_OnEvent(event) |
||
498 | if (event == "PLAYER_ENTERING_WORLD") then |
||
499 | AutoBar_InCombat = nil; |
||
500 | if (not AutoBar_ConfigLoaded) then |
||
501 | AutoBar_ConfigInit(); |
||
502 | AutoBar_ConfigLoaded = 1; |
||
503 | AutoBar_ScanBags(); |
||
504 | end |
||
505 | if (not AutoBar_InWorld) then |
||
506 | AutoBar_InWorld = 1; |
||
507 | AutoBar_ScanBags(); |
||
508 | AutoBar_Button_UpdateButtons(); |
||
509 | end |
||
510 | elseif (event == "PLAYER_LEAVING_WORLD") then |
||
511 | AutoBar_InWorld = nil; |
||
512 | elseif (AutoBar_InWorld) then |
||
513 | if (event == "BAG_UPDATE") then |
||
514 | if (arg1 < 5) then |
||
515 | AutoBar_ScanBags(arg1); |
||
516 | end |
||
517 | elseif (event == "UPDATE_BINDINGS") then |
||
518 | AutoBar_Button_UpdateButtons(); |
||
519 | elseif (event == "PLAYER_ALIVE") then |
||
520 | AutoBar_Button_UpdateButtons(); |
||
521 | elseif ((event == "UNIT_MANA" or event == "UNIT_HEALTH") and arg1=="player") then |
||
522 | AutoBar_Button_UpdateButtons(); |
||
523 | elseif (event == "PLAYER_REGEN_ENABLED") then |
||
524 | AutoBar_InCombat = nil; |
||
525 | AutoBar_Button_UpdateButtons(); |
||
526 | elseif (event == "PLAYER_REGEN_DISABLED") then |
||
527 | AutoBar_InCombat = 1; |
||
528 | AutoBar_Button_UpdateButtons(); |
||
529 | elseif (event == "ZONE_CHANGED_NEW_AREA") then |
||
530 | AutoBar_Button_UpdateButtons(); |
||
531 | elseif (event == "BAG_UPDATE_COOLDOWN") then |
||
532 | AutoBar_Button_UpdateButtons(); |
||
533 | end |
||
534 | end |
||
535 | end |
||
536 | |||
537 | ------------------------------------ |
||
538 | |||
539 | function AutoBar_UseButton(num) |
||
540 | local bag, slot, rank, itemid, category, categoryidx, idx, acceptable = AutoBar_Button_GetDisplayItem(num); |
||
541 | if (bag and slot) then |
||
542 | UseContainerItem(bag,slot); |
||
543 | if (AutoBar_Category_Info[category] and AutoBar_Category_Info[category].targetted == "WEAPON" and SpellIsTargeting()) then |
||
544 | PickupInventoryItem(GetInventorySlotInfo("MainHandSlot")); |
||
545 | elseif (AutoBar_Category_Info[category] and AutoBar_Category_Info[category].targetted and AutoBar_Config[AutoBar_Player].smartselfcast and AutoBar_Config[AutoBar_Player].smartselfcast[category] and SpellIsTargeting()) then |
||
546 | SpellTargetUnit("player"); |
||
547 | end |
||
548 | end |
||
549 | end |
||
550 | |||
551 | |||
552 | function AutoBar_Button_OnClick(mousebutton, updown, override) |
||
553 | local button; |
||
554 | if (override) then |
||
555 | button = getglobal("AutoBar_Button"..override); |
||
556 | else |
||
557 | button = this; |
||
558 | end |
||
559 | button:SetChecked(0); |
||
560 | if (AutoBar.moving) then |
||
561 | if (updown == "CLICK") then |
||
562 | AutoBar.moving = nil; |
||
563 | AutoBar:StopMovingOrSizing(); |
||
564 | AutoBar_Config[AutoBar_Player].display.position = {}; |
||
565 | AutoBar_Config[AutoBar_Player].display.position.x, |
||
566 | AutoBar_Config[AutoBar_Player].display.position.y = AutoBar:GetCenter(); |
||
567 | AutoBar:SetMovable(0); |
||
568 | end |
||
569 | elseif (updown == "CLICK") then |
||
570 | local bag, slot, rank, itemid, category, categoryidx, idx, acceptable = AutoBar_Button_GetDisplayItem(button.effectiveButton); |
||
571 | if (bag and slot) then |
||
572 | UseContainerItem(bag,slot); |
||
573 | if (AutoBar_Category_Info[category] and AutoBar_Category_Info[category].targetted == "WEAPON" and SpellIsTargeting()) then |
||
574 | if (mousebutton == "LeftButton") then |
||
575 | PickupInventoryItem(GetInventorySlotInfo("MainHandSlot")); |
||
576 | elseif (mousebutton == "RightButton") then |
||
577 | PickupInventoryItem(GetInventorySlotInfo("SecondaryHandSlot")); |
||
578 | end |
||
579 | elseif (AutoBar_Category_Info[category] and AutoBar_Category_Info[category].targetted and AutoBar_Config[AutoBar_Player].smartselfcast and AutoBar_Config[AutoBar_Player].smartselfcast[category] and SpellIsTargeting()) then |
||
580 | SpellTargetUnit("player"); |
||
581 | end |
||
582 | end |
||
583 | elseif (mousebutton == "RightButton" and updown == "DOWN" and IsControlKeyDown()) then |
||
584 | if (not AutoBar_Config[AutoBar_Player].display.docking) then |
||
585 | AutoBar.moving = true; |
||
586 | AutoBar:SetMovable(1); |
||
587 | AutoBar:StartMoving(); |
||
588 | end |
||
589 | end |
||
590 | end |
||
591 | |||
592 | function AutoBar_Button_SetTooltip(button, elapsed) |
||
593 | if (not button) then button = this; end |
||
594 | if (button:GetParent().updateTooltip and elapsed) then |
||
595 | button.updateTooltip = button.updateTooltip - elapsed; |
||
596 | if (button.updateTooltip > 0) then return; end |
||
597 | end |
||
598 | |||
599 | if (button.effectiveButton) then |
||
600 | if (GetCVar("UberTooltips") == "1") then |
||
601 | GameTooltip_SetDefaultAnchor(GameTooltip, button); |
||
602 | else |
||
603 | GameTooltip:SetOwner(button, "ANCHOR_RIGHT"); |
||
604 | end |
||
605 | button.updateTooltip = nil; |
||
606 | |||
607 | local bag, slot, rank, itemid, category, categoryidx = AutoBar_Button_GetDisplayItem(button.effectiveButton) |
||
608 | if (bag and slot) then |
||
609 | GameTooltip:SetBagItem(bag, slot); |
||
610 | if (AutoBar_Debug) then |
||
611 | if (rank) then |
||
612 | GameTooltip:AddLine("DISPLAYED RANK: "..rank); |
||
613 | end |
||
614 | if (itemid) then |
||
615 | GameTooltip:AddLine("DISPLAYED ITEMID: "..itemid); |
||
616 | end |
||
617 | if (category) then |
||
618 | GameTooltip:AddLine("DISPLAYED CATEGORY: "..category); |
||
619 | end |
||
620 | if (categoryidx) then |
||
621 | GameTooltip:AddLine("DISPLAYED CATEGORYIDX: "..categoryidx); |
||
622 | end |
||
623 | end |
||
624 | local start, duration, enable = GetContainerItemCooldown(bag, slot); |
||
625 | if (start > 0 and duration > 0) then |
||
626 | button.updateTooltip = TOOLTIP_UPDATE_TIME; |
||
627 | end |
||
628 | |||
629 | GameTooltip:AddLine(""); |
||
630 | local rankidx, idx, itemident, bagslot, count, tmpcount, name, itemid, msg; |
||
631 | local start, duration, enable; |
||
632 | for rankidx, itemident in AutoBar_Buttons_CurrentItems[button.effectiveButton] do |
||
633 | count = 0; |
||
634 | for idx, bagslot in itemident.items do |
||
635 | _, tmpcount = GetContainerItemInfo(bagslot[1], bagslot[2]); |
||
636 | count = count + tmpcount; |
||
637 | end |
||
638 | name,itemid = AutoBar_LinkDecode(GetContainerItemLink(itemident.items[1][1], itemident.items[1][2])); |
||
639 | category = AutoBar_SearchedForItems[itemid][2]; |
||
640 | start, duration, enable = GetContainerItemCooldown(itemident.items[1][1], itemident.items[1][2]); |
||
641 | msg = name.." (Count: "..count..")"; |
||
642 | if (AutoBar_Debug) then |
||
643 | msg = msg.." ["..itemident.items[1][1]..","..itemident.items[1][2].."]"; |
||
644 | if (rank) then |
||
645 | msg = msg.." rank="..itemident.rank; |
||
646 | end |
||
647 | if (cat) then |
||
648 | msg = msg.." cat="..category; |
||
649 | end |
||
650 | end |
||
651 | if (category == itemid and categoryidx == 0) then |
||
652 | msg = msg.." [Custom Item]" |
||
653 | end |
||
654 | if (AutoBar_Category_Info[category]) then |
||
655 | if (AutoBar_Category_Info[category].combatonly) then |
||
656 | msg=msg.." [In Combat Only]"; |
||
657 | end |
||
658 | if (AutoBar_Category_Info[category].noncombat) then |
||
659 | msg=msg.." [Non Combat Only]"; |
||
660 | end |
||
661 | if (AutoBar_Category_Info[category].limit) then |
||
662 | msg=msg.." [Limited Usage]"; |
||
663 | end |
||
664 | end |
||
665 | if (start > 0 and duration > 0) then |
||
666 | msg = msg.." [Cooldown]"; |
||
667 | end |
||
668 | GameTooltip:AddLine(msg); |
||
669 | if (category and AutoBar_Category_Info[category] and AutoBar_Category_Info[category].targetted == "WEAPON") then |
||
670 | GameTooltip:AddLine("\n(Left Click to apply to Main Hand weapon\nRight Click to apply to OffHand weapon)"); |
||
671 | end |
||
672 | end |
||
673 | GameTooltip:Show(); |
||
674 | end |
||
675 | end |
||
676 | end |
||
677 | |||
678 | ------------------------------------ |
||
679 | |||
680 | function AutoBar_GetTexture(id) |
||
681 | if (not id) then return ""; end |
||
682 | if (type(id) == "table" and id[1]) then id = id[1]; end |
||
683 | if (id and AutoBar_Category_Info[id]) then |
||
684 | if (AutoBar_Category_Info[id].texture) then |
||
685 | return "Interface\\Icons\\"..AutoBar_Category_Info[id].texture; |
||
686 | else |
||
687 | id = AutoBar_Category_Info[id].items[1]; |
||
688 | end |
||
689 | end |
||
690 | if (type(id)=="number" and id > 0) then |
||
691 | local _,_,_,_,_,_,_,_,texture = GetItemInfo(tonumber(id)); |
||
692 | if (texture) then return texture; end |
||
693 | end |
||
694 | return "Interface\\Icons\\INV_Misc_Gift_01"; |
||
695 | end |
||
696 | |||
697 | function AutoBar_Msg(...) |
||
698 | local message = ""; |
||
699 | for i = 1, arg.n, 1 do |
||
700 | if (type(arg[i]) == "string" or type(arg[i]) == "number") then |
||
701 | message = message..arg[i]; |
||
702 | else |
||
703 | message = message..string.upper(type(arg[i])); |
||
704 | end |
||
705 | end |
||
706 | ChatFrame1:AddMessage("AutoBar: "..message); |
||
707 | end |
||
708 | |||
709 | function AutoBar_ConfigUpdated() |
||
710 | AutoBar_BuildItemList(); |
||
711 | AutoBar_ScanBags(); |
||
712 | AutoBar_SetupVisual(); |
||
713 | end |
||
714 | |||
715 | function AutoBar_SetupVisual() |
||
716 | local rows = AutoBar_Config[AutoBar_Player].display.rows; |
||
717 | local columns = AutoBar_Config[AutoBar_Player].display.columns; |
||
718 | local gapping = AutoBar_Config[AutoBar_Player].display.gapping; |
||
719 | local alpha = AutoBar_Config[AutoBar_Player].display.alpha; |
||
720 | local buttonwidth = AutoBar_Config[AutoBar_Player].display.buttonwidth; |
||
721 | local buttonheight = AutoBar_Config[AutoBar_Player].display.buttonheight; |
||
722 | local dockshiftx = AutoBar_Config[AutoBar_Player].display.dockshiftx; |
||
723 | local dockshifty = AutoBar_Config[AutoBar_Player].display.dockshifty; |
||
724 | -- |
||
725 | if (not rows) then rows = 1; end |
||
726 | if (not columns) then columns = 6; end |
||
727 | if (not gapping) then gapping = 6; end |
||
728 | if (not alpha) then alpha = 1; end |
||
729 | if (not buttonwidth) then buttonwidth = 36 end |
||
730 | if (not buttonheight) then buttonheight = 36; end |
||
731 | if (not dockshiftx) then dockshiftx = 0; end |
||
732 | if (not dockshifty) then dockshifty = 0; end |
||
733 | -- |
||
734 | AutoBar:Show(); |
||
735 | AutoBar:ClearAllPoints(); |
||
736 | if (AutoBar_Config[AutoBar_Player].display.framestrata) then |
||
737 | AutoBar:SetFrameStrata(AutoBar_Config[AutoBar_Player].display.framestrata); |
||
738 | else |
||
739 | if (AutoBar_Config[AutoBar_Player].display.docking == "MAINMENU") then |
||
740 | AutoBar:SetFrameStrata("HIGH"); |
||
741 | else |
||
742 | AutoBar:SetFrameStrata("LOW"); |
||
743 | end |
||
744 | end |
||
745 | if (AutoBar_Config[AutoBar_Player].display.docking) then |
||
746 | if (AutoBar_Config[AutoBar_Player].display.docking == "MAINMENU") then |
||
747 | AutoBar:SetPoint("BOTTOMLEFT","MainMenuBarArtFrame","BOTTOMLEFT",546+dockshiftx,38+dockshifty); |
||
748 | else |
||
749 | AutoBar_Config[AutoBar_Player].display.docking = nil; |
||
750 | end |
||
751 | elseif (AutoBar_Config[AutoBar_Player].display.position) then |
||
752 | AutoBar:SetPoint("CENTER","UIParent","BOTTOMLEFT", |
||
753 | AutoBar_Config[AutoBar_Player].display.position.x, |
||
754 | AutoBar_Config[AutoBar_Player].display.position.y); |
||
755 | else |
||
756 | AutoBar:SetPoint("CENTER","UIParent","CENTER",0,0); |
||
757 | end |
||
758 | local i, texture, counttxt, hotkey, fonttext, fontsize, fontoptions, percent; |
||
759 | percent = buttonwidth / 36; |
||
760 | if (percent > 1) then percent = 1; end |
||
761 | for i = 1, AUTOBAR_MAXBUTTONS, 1 do |
||
762 | local button = getglobal("AutoBar_Button"..i); |
||
763 | if (i > (rows*columns)) then |
||
764 | button:Hide(); |
||
765 | button.forcehidden = 1; |
||
766 | else |
||
767 | texture = getglobal("AutoBar_Button"..i.."NormalTexture"); |
||
768 | counttxt = getglobal("AutoBar_Button"..i.."Count"); |
||
769 | hotkey = getglobal("AutoBar_Button"..i.."HotKey"); |
||
770 | button.forcehidden = nil; |
||
771 | button:SetAlpha(alpha); |
||
772 | texture:SetAlpha(alpha); |
||
773 | button:SetWidth(buttonwidth); |
||
774 | texture:SetWidth(buttonwidth*1.833); |
||
775 | button:SetHeight(buttonheight); |
||
776 | texture:SetHeight(buttonheight*1.833); |
||
777 | if (AutoBar_Config[AutoBar_Player].display.hidekeytext) then |
||
778 | hotkey:Hide(); |
||
779 | else |
||
780 | hotkey:Show(); |
||
781 | fonttext, fontsize, fontoptions = hotkey:GetFont(); |
||
782 | hotkey:SetFont(fonttext, 12*percent, fontoptions); |
||
783 | hotkey:SetPoint("TOPLEFT","AutoBar_Button"..i,"TOPLEFT",-10,-2); |
||
784 | end |
||
785 | if (AutoBar_Config[AutoBar_Player].display.hidecount) then |
||
786 | counttxt:Hide(); |
||
787 | else |
||
788 | counttxt:Show(); |
||
789 | fonttext, fontsize, fontoptions = counttxt:GetFont(); |
||
790 | counttxt:SetFont(fonttext, 14*percent, fontoptions); |
||
791 | end |
||
792 | button:ClearAllPoints(); |
||
793 | if (i == 1) then |
||
794 | button:SetPoint("TOPLEFT","AutoBar","TOPLEFT",0,0); |
||
795 | elseif (columns == 1) then |
||
796 | if (AutoBar_Config[AutoBar_Player].display.reversebuttons) then |
||
797 | button:SetPoint("BOTTOM","AutoBar_Button"..(i-1),"TOP",0,gapping); |
||
798 | else |
||
799 | button:SetPoint("TOP","AutoBar_Button"..(i-1),"BOTTOM",0,gapping*-1); |
||
800 | end |
||
801 | elseif (math.mod(i,columns) == 1) then |
||
802 | local row = math.floor(i/columns); |
||
803 | if (AutoBar_Config[AutoBar_Player].display.reversebuttons) then |
||
804 | button:SetPoint("BOTTOM","AutoBar_Button"..(i-columns),"TOP",0,gapping); |
||
805 | else |
||
806 | button:SetPoint("TOP","AutoBar_Button"..(i-columns),"BOTTOM",0,gapping*-1); |
||
807 | end |
||
808 | else |
||
809 | if (AutoBar_Config[AutoBar_Player].display.reversebuttons) then |
||
810 | button:SetPoint("RIGHT","AutoBar_Button"..(i-1),"LEFT",gapping*-1,0); |
||
811 | else |
||
812 | button:SetPoint("LEFT","AutoBar_Button"..(i-1),"RIGHT",gapping,0); |
||
813 | end |
||
814 | end |
||
815 | end |
||
816 | end |
||
817 | AutoBar_AssignButtons(); |
||
818 | AutoBar_Button_UpdateButtons(); |
||
819 | end |
||
820 |