-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCore.lua
More file actions
1715 lines (1512 loc) · 57.3 KB
/
Core.lua
File metadata and controls
1715 lines (1512 loc) · 57.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- AutoBar
-- Copyright 2004, 2005, 2006 original author.
-- New Stuff Copyright 2006 Toadkiller of Proudmoore.
-- Configurable set of 24 buttons that seeks out configured items
-- in your pack for use. Intended primarily for consumables. Not
-- for use with spells, skills, trinkets, or powers.
--
-- Maintained by Azethoth / Toadkiller of Proudmoore. Original author Saien of Hyjal
-- http://www.curse-gaming.com/en/wow/addons-4430-1-autobar-toadkiller.html
-- Coming Attractions:
-- Don't show buff items if buffed already
-- On click bring config to front.
-- Set operations / calculated categories.
-- Multible bars or individually draggable buttons?
-- Exchange profiles
-- Hide Microbuttons option
-- Indication of when an object being edited is obscured by a higher layer.
-- Named Custom Categories, Named button ranges.
-- Next Up:
-- ItemClasses-2.0, UseItem-2.0, CursorItem-2.0, Tablet-2.0, Ace Locale
-- Bartender support?
-- Named Slots
-- 1.12.06.12 beta
-- Tooltip little fix
-- 1.12.06.11 beta
-- added Rumsey Rum Black Label and other analogues
-- 1.12.06.10 beta
-- Make Drag Handle hideable again
-- Dock to bottom right action bar, left or right side of it.
-- 1.12.06.09
-- Switch to Ace Event for timers
-- Upgrade align buttons option to have any combination of vertical and horizontal alignment (9 options).
-- Fix toc for Ace svn
-- 1.12.06.08
-- Korean + some more incremental ACE Locale changes for all languages.
-- 1.12.06.07
-- Renamed files ACE Locale style + some incremental ACE Locale changes for all languages.
-- Deleted obsolete dependencies and files.
-- Toc changes to support ace & ace wiki.
-- 1.12.06.06
-- Actually separate display editing from slots editing for Character vs Shared.
-- This clears up a crasher & some non-obvious behavior after a reset.
-- 1.12.06.05
-- Lock all bars option for drag handle + 30 second timeout on the unlock. No more accidentally dragging action bar items around!
-- Cleared up a case of algorithm necrosis
-- Looks like Character layout got broken. Will be fixed next version. Use Shared layout for now.
-- 1.12.06.04
-- Fixed some Compost library issues.
-- Fixed a couple of spots where non tables were fed into the slots list again.
-- 1.12.06.03
-- Remove single item slot option. Its pretty pointless & prevents all kinds of options.
-- Compost-2.0
-- oSkin support checkbox on profile tab. Random results on choose category / view category dialog though.
-- 1.12.06.02
-- Fix embedded library issue
-- 1.12.06.01
-- Ace 2
-- Dewdrop-2.0
-- Boiled clams moved to bonus category
-- Do not flash the popup when using keybinding
-- Harvest festival foods
-- Korean, tx Sayclub!
-- 1.12.05
-- Ok, here it is: the release version of the profiling system.
-- Changed defaults so profile is Single for people with existing Character layer buttons, and Standard profile if not.
-- Dense Dynamite
-- Default noPopup for mount changed to arrangeOnUse. A better way to go now that mounts are cheap.
-- 1.12.04.12
-- Korean
-- Label Combined Layer View & Layer Edit Sections.
-- Hide edit layer buttons that are not enabled.
-- Config Tooltips.
-- 1.12.04.11
-- View Slot now has a red background and appropriate title and the errant button is now properly hidden.
-- Added some text directing you to the Slots tab for editing as well.
-- Edit Slot dialog has a slightly green background to indicate editing is possible.
-- 1.12.04.10
-- Winterfall Firewater
-- Removed some duplicates in the pet food meat section
-- Revert Button for config so you can undo unintended changes & experiment more freely
-- Basic and Class layers now editable as well
-- Quick Setup & Reset buttons: Single, Shared, Custom as well as blank slate button.
-- 1.12.04.09
-- Chinese & Korean courtesy of the usual suspects
-- Runes added to potion slot
-- 1.12.04.08
-- Fixed dragging slots around on the slots tab.
-- Can now drag from the slot view at the top to the slots being edited at the bottom as well.
-- Fixed slot view not updating when selecting profile layers in the profile
-- 1.12.04.07
-- Added a zeroing out category called "Clear Slot" as well as a button for it on the edit slot dialog.
-- 1.12.04.06
-- Simplified profile interface
-- Now has 4 shared profiles, selectable under profile tab
-- Fixed Smart Self Cast bug.
-- Added Smart Self Cast to defaults
-- Smart Self Cast remains partly broken in its current implementation until it gets a rewrite
-- You can turn the individual ones on but not necessarily off if they are part of the defaults etc.
-- 1.12.04.05
-- Added Clear Slot category.
-- 1.12.04.04
-- Fixed warrior rage potion slot conflicting with heal potions
-- 1.12.04.03
-- Class default bug fix
-- Arathi Basin Food upgrade, tx Ghoschdi
-- Korean, tx Sayclub
-- Expanded slot list to 16. Removed the clunky movement buttons. Use drag & drop to reorder instead.
-- Split out more code for the various frames
-- Fixed autoselfcast for now. Needs a better implementation.
-- Slot View area has tooltips again & clicking them brings up a non-editable Slot View.
-- 1.12.04.01
-- Profile Tab: 4 layers, current edit layer picked at top of dialog. Class & Basic defaults (not editable)
-- Display settings are either character specific or shared. No layering.
-- Fixed frame strata for bar & popup
-- Seperated code for ChooseCategory and ConfigSlot.
-- Some lua changes for 2.0
-- Hourglass Sand
-- Casting Cursor used for button interaction
-- Removed custom item insertion. Cumbersome and not needed if u can drag & drop.
-- Align center button is not functional. Renamed from "reverse buttons"
-- Slots tab for editing character or shared slots. Old slots section is now display only, still needs work.
-- 1.12.03
-- Korean thanks to Sayclub
-- Disabled code that hid character buttons when docking to main menu. These have unintended side effects.
-- 1.12.02.05
-- Chinese Simplified & Traditional (Thanks PDI175)
-- Fixed some typos in localization.
-- 1.12.02.04
-- Pet feed on right click should now work. Tx Kerrang. Still need to upgrade the pet food category handling itself.
-- 1.12.02.03
-- Fixed onload issue that broke slash commands
-- AutoBar now dismisses with the escape key as it should
-- Added click for config show / hide
-- 1.12.02.02
-- New 1.12 function ClearCursor() called after drag & drop.
-- Juju
-- First cut of tabbed interface for config
-- 24 buttons
-- Arathi Basin Field Ration
-- Config dialog is now draggable
-- Hunter Pet Food & Feeding
-- First cut at blizzard style dialog. A frustrating thing as texcoords don't act as expected.
-- 1.12.02
-- Dock to is now list based with a drop down. I will make the drop down pretty some other time. Needs settings for various bars.
-- Empty Slot button added.
-- Popup Z order increased so its in front of other mods
-- 1.12.01
-- Chinese Simplified & Traditional (Thanks PDI175)
-- TOC updated.
-- Fixed plain buttons bug
-- Improved config layout for Korean.
-- 1.11.16.01
-- Fixed popup click bug. Apparently mouseup events do not allow casting like click events. Strange.
-- Disabled some config checkboxes for single category slots. Fixes crash.
-- Fixed keybinding screwup.
-- Some more hunter pet foods added. meats aren't done yet.
-- Added a drag handle for the bar. Left click to lock right click to bring up options. Handle can be hidden.
-- Slot specific option to disable popup.
-- Slot specific option to rearrange category priority on use.
-- Increased max popup buttons to 12.
-- 1.11.15.04
-- Done button on config panel to avoid confusion.
-- Option to show Category Icon for slots with 0 item count. Displayed dark & with -- to distinguish them from regular slots.
-- Scale item count, hotKey and Cooldown Clock text beyond size 36 and up to size 72
-- First cut at a popup list for slots with 2 or more available items
-- Added some unsorted items to pet foods. These will be broken till sorted.
-- Config for popup direction
-- Fixed popup button scaling
-- Popup on modifier key
-- Popup disable
-- Tooltip for popup buttons
-- Added Jungle Remedy
-- Popup hit rect overlap fixed
-- 1.11.14.03
-- New User / deleted wtf config file bug fix. tx Xavior for finding it.
-- Ahn Qirajh translation for Chinese. Thanks PDI175.
-- Typo fixed
-- Working Korean I think. Thanks to Sayclub
-- 1.11.13
-- Deutch! Ser gut Teodred!
-- 1.11.12
-- Korean thanks to Sayclub!
-- 1.11.11
-- Ooh, Traditional Chinese thanks to PDI175
-- Roasted Quail added to pet meats
-- Use the highest priority item for the icon. (ie. the bottom one in the category list).
-- 1.11.10
-- More Drag & Drop: rearrange button categories now as well
-- Drag from inventory into a button's items (or click on an item then click on category button)
-- Potions: Holy Protection, Agility, Strength, Fortitude, Intellect, Wisdom, Defense, Troll Blood
-- 1.11.09
-- Anti-Venom
-- Global smart self cast checkbox
-- Scrolls of Agility, Intellect, Protection, Stamina, Strength, Spirit
-- Food categories for no bonus food so hunters can feed themselves
-- 1.11.08
-- Drag & Drop to rearrange slot category order in the config dialog.
-- Close button added to config
-- Updated some category icons.
-- 1.11.07
-- Row & column sliders in the config panel are now freely slideable.
-- 1.11.06
-- Fixed glitch at 6 columns
-- 1.11.05
-- Friendship Bread, Freshly Squeezed Lemonade, Wildvine Potion, Sagefish Delight, Smoked Sagefish
-- Dirge's Kickin' Chimaerok Chops,
-- Fixed: Essence Mango,
-- 1.11.04
-- Reset to default button for the buttons
-- Hide tooltips option
-- Demonic and Dark Runes, Battle Standards, Invulnerability Potions
-- 1.11.03.01
-- Deathcharger's Reins, Qiraji Mounts
-- Reworked defaults a bit.
-- 1.11.02
-- Mojos of Zanza & essence mangos; arcane, fire, frost, nature, shadow, spell Protection Potions.
-- Dreamless sleep
-- First cut of cooldown.
-- 1.11.01
-- Added new AD oil & sharpening stone.
-- Expand up to 18 buttons.
-- Rolled in the nurfed version's changes for pvp potions
-- Chocolate Square
-- 2006.03.31
-- Minor category changes
-- Last version by Saien
local L = AceLibrary("AceLocale-2.1"):GetInstance("AutoBar", true);
BINDING_HEADER_AUTOBAR_SEP = L["AUTOBAR"];
BINDING_NAME_AUTOBAR_CONFIG = L["CONFIG_WINDOW"];
BINDING_NAME_AUTOBAR_BUTTON1 = L["BUTTON"] .. " 1";
BINDING_NAME_AUTOBAR_BUTTON2 = L["BUTTON"] .. " 2";
BINDING_NAME_AUTOBAR_BUTTON3 = L["BUTTON"] .. " 3";
BINDING_NAME_AUTOBAR_BUTTON4 = L["BUTTON"] .. " 4";
BINDING_NAME_AUTOBAR_BUTTON5 = L["BUTTON"] .. " 5";
BINDING_NAME_AUTOBAR_BUTTON6 = L["BUTTON"] .. " 6";
BINDING_NAME_AUTOBAR_BUTTON7 = L["BUTTON"] .. " 7";
BINDING_NAME_AUTOBAR_BUTTON8 = L["BUTTON"] .. " 8";
BINDING_NAME_AUTOBAR_BUTTON9 = L["BUTTON"] .. " 9";
BINDING_NAME_AUTOBAR_BUTTON10 = L["BUTTON"] .. " 10";
BINDING_NAME_AUTOBAR_BUTTON11 = L["BUTTON"] .. " 11";
BINDING_NAME_AUTOBAR_BUTTON12 = L["BUTTON"] .. " 12";
BINDING_NAME_AUTOBAR_BUTTON13 = L["BUTTON"] .. " 13";
BINDING_NAME_AUTOBAR_BUTTON14 = L["BUTTON"] .. " 14";
BINDING_NAME_AUTOBAR_BUTTON15 = L["BUTTON"] .. " 15";
BINDING_NAME_AUTOBAR_BUTTON16 = L["BUTTON"] .. " 16";
BINDING_NAME_AUTOBAR_BUTTON17 = L["BUTTON"] .. " 17";
BINDING_NAME_AUTOBAR_BUTTON18 = L["BUTTON"] .. " 18";
BINDING_NAME_AUTOBAR_BUTTON19 = L["BUTTON"] .. " 19";
BINDING_NAME_AUTOBAR_BUTTON20 = L["BUTTON"] .. " 20";
BINDING_NAME_AUTOBAR_BUTTON21 = L["BUTTON"] .. " 21";
BINDING_NAME_AUTOBAR_BUTTON22 = L["BUTTON"] .. " 22";
BINDING_NAME_AUTOBAR_BUTTON23 = L["BUTTON"] .. " 23";
BINDING_NAME_AUTOBAR_BUTTON24 = L["BUTTON"] .. " 24";
local options = {
type = 'execute',
desc = "Toggle the config panel",
func = function()
getglobal("AutoBarConfig_Toggle")();
end
}
-- If the Debug library is available then use it
if AceLibrary:HasInstance("AceDebug-2.0") then
AutoBar = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceEvent-2.0", "AceDebug-2.0");
else
AutoBar = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceEvent-2.0");
end
AutoBar:RegisterChatCommand({L["SLASHCMD_SHORT"], L["SLASHCMD_LONG"]}, options)
AUTOBAR_MAXBUTTONS = 24;
AUTOBAR_MAXPOPUPBUTTONS = 12;
AUTOBAR_MAXSLOTCATEGORIES = 16;
AutoBar_Debug = nil;
AutoBar_SearchedForItems = {};
local AutoBar_ButtonItemList = {};
local AutoBar_ButtonItemList_Reversed = {};
local AutoBar_Buttons_CurrentItems = {};
function AutoBar:OnInitialize()
AutoBar.currentPlayer = UnitName("player") .. " - " .. GetCVar("realmName");
AutoBar.inWorld = false;
AutoBar.inCombat = false; -- For item use restrictions
AutoBar.inBG = false; -- For battleground only items
AutoBarItemList:OnInitialize();
end
function AutoBar:OnEnable()
-- Called when the addon is enabled
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_LEAVING_WORLD")
self:RegisterEvent("BAG_UPDATE")
self:RegisterEvent("UPDATE_BINDINGS")
-- For item use restrictions
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("UNIT_MANA")
self:RegisterEvent("UNIT_HEALTH")
self:RegisterEvent("PLAYER_ALIVE")
self:RegisterEvent("BAG_UPDATE_COOLDOWN")
self:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
end
function AutoBar:OnDisable()
-- Called when the addon is disabled
end
function AutoBar:PLAYER_ENTERING_WORLD()
AutoBar.inCombat = false;
local scanned = false;
if (not AutoBar.initialized) then
AutoBarProfile.Initialize();
AutoBar.ConfigChanged();
profileLoaded = true;
AutoBar_ScanBags();
scanned = true;
AutoBarConfig:TabButtonInitialize();
AutoBar.initialized = true;
end
if (not AutoBar.inWorld) then
AutoBar.inWorld = true;
if (not scanned) then
AutoBar_ScanBags();
end
AutoBar:ButtonsUpdate();
end
end
function AutoBar:PLAYER_LEAVING_WORLD()
AutoBar.inWorld = false;
end
function AutoBar:BAG_UPDATE()
if (AutoBar.inWorld and arg1 < 5) then
AutoBar_ScanBags(arg1);
end
end
function AutoBar:UPDATE_BINDINGS()
AutoBar:ButtonsUpdate();
end
function AutoBar:ZONE_CHANGED_NEW_AREA()
AutoBar:ButtonsUpdate();
end
function AutoBar:PLAYER_REGEN_ENABLED()
AutoBar.inCombat = false;
AutoBar:ButtonsUpdate();
end
function AutoBar:PLAYER_REGEN_DISABLED()
AutoBar.inCombat = true;
AutoBar:ButtonsUpdate();
end
function AutoBar:UNIT_MANA()
if (arg1 == "player") then
AutoBar:ButtonsUpdate();
end
end
function AutoBar:UNIT_HEALTH()
if (arg1 == "player") then
AutoBar:ButtonsUpdate();
end
end
function AutoBar:PLAYER_ALIVE()
AutoBar:ButtonsUpdate();
end
function AutoBar:BAG_UPDATE_COOLDOWN()
AutoBar:ButtonsUpdate();
end
function AutoBar:UPDATE_BATTLEFIELD_STATUS()
if (AutoBar.inWorld) then
for i = 1, MAX_BATTLEFIELD_QUEUES do
local status, mapName, instanceID = GetBattlefieldStatus(i);
if (instanceID ~= 0) then
AutoBar.inBG = true;
return;
else
AutoBar.inBG = false;
end
end
end
end
-- When dragging, contains { frameName, index }, otherwise nil
AutoBar.dragging = nil;
local draggingData = {};
function AutoBar.GetDraggingIndex(frameName)
if (AutoBar.dragging and AutoBar.dragging.frameName == frameName) then
return AutoBar.dragging.index;
end
return nil;
end
function AutoBar.SetDraggingIndex(frameName, index)
draggingData.frameName = frameName;
draggingData.index = index;
AutoBar.dragging = draggingData;
end
function AutoBar.LinkDecode(link)
if (link) then
local _, _, id, name = string.find(link,"|Hitem:(%d+):%d+:%d+:%d+|h%[([^]]+)%]|h|r$");
if (id and name) then
return name, tonumber(id);
end
end
end
local function AutoBar_BuildItemList()
local function AddItemInfo(identifier, buttonnum)
if (AutoBar_Category_Info[identifier] and AutoBar_Category_Info[identifier].items) then
local index, j;
for index, j in pairs(AutoBar_Category_Info[identifier].items) do
if (AutoBar_SearchedForItems[j]) then
table.insert(AutoBar_SearchedForItems[j], buttonnum);
else
AutoBar_SearchedForItems[j] = { buttonnum, identifier, index };
end
table.insert(AutoBar_ButtonItemList[buttonnum], j);
end
else
if (AutoBar_SearchedForItems[identifier]) then
table.insert(AutoBar_SearchedForItems[identifier], buttonnum);
else
AutoBar_SearchedForItems[identifier] = { buttonnum, identifier, 0 };
end
table.insert(AutoBar_ButtonItemList[buttonnum], identifier);
end
end
AutoBar_SearchedForItems = {};
AutoBar_ButtonItemList_Reversed = {};
local index;
for index = 1, AUTOBAR_MAXBUTTONS, 1 do
if (AutoBar.buttons[index]) then
local i, j;
AutoBar_ButtonItemList[index] = {};
AutoBar_ButtonItemList_Reversed[index] = {};
if (type(AutoBar.buttons[index]) == "table") then
for i, j in pairs(AutoBar.buttons[index]) do
AddItemInfo (j, index);
end
else
AddItemInfo (AutoBar.buttons[index], index);
end
for i, j in pairs(AutoBar_ButtonItemList[index]) do
AutoBar_ButtonItemList_Reversed[index][j] = i;
end
end
end
end
function AutoBar_Button_GetDisplayItem(buttonnum)
local index, bag, slot, rank, itemId, category, categoryIndex, acceptable, cooldowntime, level;
local cooldownIndex, start, duration, enable, fallback;
if (AutoBar_Buttons_CurrentItems[buttonnum]) then
index = table.getn(AutoBar_Buttons_CurrentItems[buttonnum]);
else
index = 0;
end
while (index > 0 and not acceptable) do
bag = AutoBar_Buttons_CurrentItems[buttonnum][index].items[1][1];
slot = AutoBar_Buttons_CurrentItems[buttonnum][index].items[1][2];
rank = AutoBar_Buttons_CurrentItems[buttonnum][index].rank;
itemId = AutoBar_ButtonItemList[buttonnum][rank];
if (type(itemId) == "number") then
_,_,_,level = GetItemInfo(itemId);
else
level = 0;
end
if (AutoBar_SearchedForItems[itemId]) then
category = AutoBar_SearchedForItems[itemId][2];
categoryIndex = AutoBar_SearchedForItems[itemId][3];
else
category = nil;
categoryIndex = nil;
end
--
start, duration, enable = GetContainerItemCooldown(bag, slot);
if (start > 0 and duration > 0) then
local tmp = start - GetTime() + duration;
if (not cooldowntime or tmp < cooldowntime) then
cooldowntime = tmp;
cooldownIndex = index;
end
index = index - 1;
elseif (level > UnitLevel("player")) then
index = index - 1;
elseif (AutoBar_Category_Info[category] and AutoBar_Category_Info[category].location and AutoBar_Category_Info[category].location ~= GetRealZoneText()) then
index = index - 1;
elseif (AutoBar_Category_Info[category] and AutoBar_Category_Info[category].battleground and not AutoBar.inBG) then
index = index - 1;
elseif (AutoBar_Category_Info[category]) then
if (not fallback) then
fallback = index;
end
if (AutoBar_Category_Info[category].combatonly and not AutoBar.inCombat) then
index = index - 1;
elseif (AutoBar_Category_Info[category].noncombat and AutoBar.inCombat) then
index = index - 1;
elseif (AutoBar_Category_Info[category].limit) then
local losthp = UnitHealthMax("player") - UnitHealth("player");
local lostmana = UnitManaMax("player") - UnitMana("player");
if (UnitPowerType("player") ~= 0 ) then
--if (UnitClass("player") == "Druid") then
-- Can't check mana in druid forms
-- lostmana = 0;
--else
-- Class doesn't have mana, don't limit
lostmana = 10000;
--end
end
if (AutoBar_Category_Info[category].limit.downhp and AutoBar_Category_Info[category].limit.downhp[categoryIndex] > losthp) then
index = index - 1
elseif (AutoBar_Category_Info[category].limit.downmana and AutoBar_Category_Info[category].limit.downmana[categoryIndex] > lostmana) then
index = index - 1
else
acceptable = true;
end
else
acceptable = true;
end
else
acceptable = true;
end
end
if (not acceptable) then
if (fallback) then
index = fallback;
elseif (cooldownIndex) then
index = cooldownIndex;
elseif (AutoBar_Buttons_CurrentItems[buttonnum]) then
index = table.getn(AutoBar_Buttons_CurrentItems[buttonnum]);
else
index = nil;
end
end
--
if (index) then
bag = AutoBar_Buttons_CurrentItems[buttonnum][index].items[1][1];
slot = AutoBar_Buttons_CurrentItems[buttonnum][index].items[1][2];
rank = AutoBar_Buttons_CurrentItems[buttonnum][index].rank;
else
bag = nil; slot = nil; rank = nil;
end
if (AutoBar_ButtonItemList[buttonnum]) then
itemId = AutoBar_ButtonItemList[buttonnum][rank];
if (AutoBar_SearchedForItems[itemId]) then
category = AutoBar_SearchedForItems[itemId][2];
categoryIndex = AutoBar_SearchedForItems[itemId][3];
else
category = nil;
categoryIndex = nil;
end
else
itemId = nil; category = nil; categoryIndex = nil;
end
return bag, slot, rank, itemId, category, categoryIndex, index, acceptable, cooldowntime;
end
function AutoBar:ButtonsUpdate()
if (not AutoBar.inWorld) then
return
end
local buttonnum, i, button, icon, normalTexture, countText, bag, slot, index, items;
local hotKey, count, itemCount, keyText, actioncommand, cooldown;
for buttonnum = 1, AUTOBAR_MAXBUTTONS, 1 do
button = getglobal("AutoBarFrameButton"..buttonnum);
icon = getglobal("AutoBarFrameButton"..buttonnum.."Icon");
normalTexture = getglobal("AutoBarFrameButton"..buttonnum.."NormalTexture");
countText = getglobal("AutoBarFrameButton"..buttonnum.."Count");
hotKey = getglobal("AutoBarFrameButton"..buttonnum.."HotKey");
cooldown = getglobal("AutoBarFrameButton"..buttonnum.."Cooldown");
if (not button.forceHidden and button.effectiveButton) then
button:Show();
bag, slot,_,_,_,_,index,enabled = AutoBar_Button_GetDisplayItem(button.effectiveButton)
if (bag and slot) then
local start, duration, enable = GetContainerItemCooldown(bag, slot);
CooldownFrame_SetTimer(cooldown, start, duration, enable);
items = AutoBar_Buttons_CurrentItems[button.effectiveButton][index].items
count = 0;
for i, bagSlot in pairs(items) do
_, itemCount = GetContainerItemInfo(bagSlot[1], bagSlot[2]);
if (itemCount) then
count = count + itemCount;
end
end
icon:SetTexture(GetContainerItemInfo(bag, slot));
if (AutoBar.display.plainButtons) then
icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
else
icon:SetTexCoord(0, 1, 0, 1)
end
if (count > 1) then
countText:SetText(count);
else
countText:SetText("");
end
if (enabled) then
icon:SetVertexColor(1, 1, 1);
normalTexture:SetVertexColor(1, 1, 1);
elseif (start > 0 and duration > 0) then
icon:SetVertexColor(1, 1, 1);
normalTexture:SetVertexColor(1, 1, 1);
else
icon:SetVertexColor(0.4, 0.4, 0.4);
normalTexture:SetVertexColor(1, 1, 1);
end
actioncommand = "AUTOBAR_BUTTON"..button.effectiveButton;
if (actioncommand) then
keyText = GetBindingKey(actioncommand);
if (keyText) then
keyText = string.gsub(keyText, "CTRL", "C");
keyText = string.gsub(keyText, "ALT", "A");
keyText = string.gsub(keyText, "SHIFT", "S");
keyText = string.gsub(keyText, "NUMPAD", "N");
hotKey:SetText(keyText);
else
hotKey:SetText("");
end
end
else
CooldownFrame_SetTimer(cooldown, 0, 0, 0);
if (AutoBar.display.showCategoryIcon and AutoBar.buttons[button.effectiveButton]) then
-- Button is empty so show Category Icon
local buttonInfo = AutoBar.buttons[button.effectiveButton];
icon:SetTexture(AutoBar_GetTexture(buttonInfo));
countText:SetText("--");
hotKey:SetText("");
icon:SetVertexColor(0.2, 0.2, 0.2);
normalTexture:SetVertexColor(1, 1, 1);
else
-- Button is empty
icon:SetTexture("");
countText:SetText("");
hotKey:SetText("");
end
end
else
button:Hide();
end
end
end
-- Assign display buttons to active slots and return the number of displayed buttons
function AutoBar:AssignButtons()
local displayButton = 0;
local buttonIndex, buttonInfo, rankIndex, items;
for buttonIndex = 1, AUTOBAR_MAXBUTTONS, 1 do
if (AutoBar.display.showEmptyButtons or AutoBar_Buttons_CurrentItems[buttonIndex]) then
displayButton = displayButton + 1;
local button = getglobal("AutoBarFrameButton"..displayButton);
button.effectiveButton = buttonIndex;
elseif (AutoBar.display.showCategoryIcon and AutoBar.buttons[buttonIndex]) then
displayButton = displayButton + 1;
local button = getglobal("AutoBarFrameButton"..displayButton);
button.effectiveButton = buttonIndex;
end
end
for buttonIndex = displayButton+1, AUTOBAR_MAXBUTTONS, 1 do
local button = getglobal("AutoBarFrameButton"..buttonIndex);
button.effectiveButton = nil;
end
return displayButton;
end
local function AutoBar_UpdateCategoryNameToID(name,id)
local buttonnum, index;
for buttonnum = 1, AUTOBAR_MAXBUTTONS, 1 do
if (AutoBar.buttons[buttonnum]) then
if (type(AutoBar.buttons[buttonnum]) == "table") then
for index in pairs(AutoBar.buttons[buttonnum]) do
if (AutoBar.buttons[buttonnum][index] == name) then
AutoBar.buttons[buttonnum][index] = id;
AutoBar_Msg(string.format(AUTOBAR_CHAT_MESSAGE2,buttonnum,idx));
end
end
elseif (AutoBar.buttons[buttonnum] == name) then
AutoBar.buttons[buttonnum] = id;
AutoBar_Msg(string.format(AUTOBAR_CHAT_MESSAGE3,buttonnum));
end
end
end
end
function AutoBar_ScanBags(specificbag)
local function ClearOutBag(bag)
local buttonnum, index, i, bagSlot, newitemlist, newranks;
for buttonnum = 1, AUTOBAR_MAXBUTTONS, 1 do
if (AutoBar_Buttons_CurrentItems[buttonnum]) then
newranks = {};
for index in pairs(AutoBar_Buttons_CurrentItems[buttonnum]) do
newitemlist = {};
for i, bagSlot in pairs(AutoBar_Buttons_CurrentItems[buttonnum][index].items) do
if (bag ~= bagSlot[1]) then
table.insert(newitemlist,bagSlot);
end
end
if (table.getn(newitemlist) > 0) then
AutoBar_Buttons_CurrentItems[buttonnum][index].items = newitemlist;
table.insert(newranks,AutoBar_Buttons_CurrentItems[buttonnum][index]);
end
end
if (table.getn(newranks) == 0) then
AutoBar_Buttons_CurrentItems[buttonnum] = nil;
else
AutoBar_Buttons_CurrentItems[buttonnum] = newranks;
end
end
end
end
local function AddItem(buttonnum, rank, bag, slot)
if (AutoBar_Buttons_CurrentItems[buttonnum]) then
local index, rec, findRank;
for index, rec in pairs(AutoBar_Buttons_CurrentItems[buttonnum]) do
if (rec.rank == rank) then
findRank = index;
end
end
if (findRank) then
table.insert(AutoBar_Buttons_CurrentItems[buttonnum][findRank].items, { bag, slot } );
else
table.insert(AutoBar_Buttons_CurrentItems[buttonnum],
{
["rank"] = rank,
["items"] = { { bag, slot } }
}
);
end
else
AutoBar_Buttons_CurrentItems[buttonnum] = {
[1] = {
["rank"] = rank,
["items"] = { { bag, slot } }
},
};
end
end
local function SortByRank(a,b)
if (a and b and a.rank and b.rank) then
return a.rank < b.rank;
else
return true;
end
end
local bag, slot, name, id, i;
local minbag,maxbag = 0, 4;
if (specificbag) then
minbag = specificbag;
maxbag = specificbag;
ClearOutBag(specificbag);
else
AutoBar_Buttons_CurrentItems = {};
end
-- AutoBar_Buttons_CurrentItems = {
-- buttonnum = {
-- index = {
-- "rank" = ranknum,
-- "items" = { {bag,slot}, {bag,slot}, {bag, slot} }
-- },
-- },
--};
for bag = minbag, maxbag, 1 do
for slot = 1, GetContainerNumSlots(bag), 1 do
name, id = AutoBar.LinkDecode(GetContainerItemLink(bag,slot));
if (name and AutoBar_SearchedForItems[name] and id) then
if (not AutoBar_SearchedForItems[id]) then
AutoBar_SearchedForItems[id] = { AutoBar_SearchedForItems[name][1], AutoBar_SearchedForItems[name][2], AutoBar_SearchedForItems[name][3] };
end
AutoBar_UpdateCategoryNameToID(name,id);
AutoBar_SearchedForItems[name] = nil;
end
if (id and AutoBar_SearchedForItems[id]) then
local button = AutoBar_SearchedForItems[id][1];
local rank = AutoBar_ButtonItemList_Reversed[button][id];
AddItem(button, rank, bag, slot)
if (AutoBar_SearchedForItems[id][4]) then
for i = 4, table.getn(AutoBar_SearchedForItems[id]), 1 do
button = AutoBar_SearchedForItems[id][i];
rank = AutoBar_ButtonItemList_Reversed[button][id];
AddItem(button, rank, bag, slot)
end
end
end
end
end
local buttonnum;
for buttonnum = 1, AUTOBAR_MAXBUTTONS, 1 do
if (AutoBar_Buttons_CurrentItems[buttonnum]) then
table.sort(AutoBar_Buttons_CurrentItems[buttonnum], SortByRank);
end
end
AutoBar:AssignButtons();
AutoBar:ButtonsUpdate();
end
function AutoBar_OnEvent(event)
if (event == "PLAYER_ENTERING_WORLD") then
elseif (event == "PLAYER_LEAVING_WORLD") then
AutoBar.inWorld = nil;
elseif (AutoBar.inWorld) then
if (event == "BAG_UPDATE") then
if (arg1 < 5) then
AutoBar_ScanBags(arg1);
end
elseif (event == "UPDATE_BINDINGS") then
AutoBar:ButtonsUpdate();
elseif (event == "PLAYER_ALIVE") then
AutoBar:ButtonsUpdate();
elseif ((event == "UNIT_MANA" or event == "UNIT_HEALTH") and arg1=="player") then
AutoBar:ButtonsUpdate();
elseif (event == "PLAYER_REGEN_ENABLED") then
AutoBar.inCombat = false;
AutoBar:ButtonsUpdate();
elseif (event == "PLAYER_REGEN_DISABLED") then
AutoBar.inCombat = true;
AutoBar:ButtonsUpdate();
elseif (event == "ZONE_CHANGED_NEW_AREA") then
AutoBar:ButtonsUpdate();
elseif (event == "BAG_UPDATE_COOLDOWN") then
AutoBar:ButtonsUpdate();
elseif (event == "UPDATE_BATTLEFIELD_STATUS") then
for i = 1, MAX_BATTLEFIELD_QUEUES do
local status, mapName, instanceID = GetBattlefieldStatus(i);
if (instanceID ~= 0) then
AutoBar.inBG = true;
return;
else
AutoBar.inBG = false;
end
end
end
end
end
function AutoBar:SlotUse(slotIndex)
AutoBar_Button_OnClick("LeftButton", "CLICK", slotIndex);
end
function AutoBar_Button_OnClick(mousebutton, updown, override)
local button, effectiveButton;
if (override) then
button = getglobal("AutoBarFrameButton"..override);
effectiveButton = override;
else
button = this;
effectiveButton = button.effectiveButton;
end
button:SetChecked(0);
if (AutoBarFrame.moving) then
if (updown == "CLICK") then
AutoBarFrame.moving = nil;
AutoBarFrame:StopMovingOrSizing();
AutoBar.display.position = {};
AutoBar.display.position.x,
AutoBar.display.position.y = AutoBarFrame:GetCenter();
end
elseif (updown == "CLICK") then
local bag, slot, rank, itemId, category, categoryIndex, index, acceptable = AutoBar_Button_GetDisplayItem(effectiveButton);
if (bag and slot) then
local buttonInfo = AutoBar.buttons[effectiveButton];
if (mousebutton == "RightButton" and type(buttonInfo) == "table" and buttonInfo.rightClickTargetsPet and UnitExists("pet")) then
PickupContainerItem(bag, slot);
DropItemOnUnit("pet");
else
UseContainerItem(bag, slot);
end
if (AutoBar_Category_Info[category] and AutoBar_Category_Info[category].targetted == "WEAPON" and SpellIsTargeting()) then
if (mousebutton == "LeftButton") then
PickupInventoryItem(GetInventorySlotInfo("MainHandSlot"));
elseif (mousebutton == "RightButton") then
PickupInventoryItem(GetInventorySlotInfo("SecondaryHandSlot"));
end
elseif (AutoBar_Category_Info[category] and AutoBar_Category_Info[category].targetted and (AutoBar.display.autoSmartSelfCast or AutoBar.smartSelfcast and AutoBar.smartSelfcast[category]) and SpellIsTargeting()) then
SpellTargetUnit("player");
elseif (type(AutoBar.buttons[effectiveButton]) == "table" and AutoBar.buttons[effectiveButton].rightClickTargetsPet and SpellIsTargeting()) then
SpellTargetUnit("pet");
end
AutoBarPopupFrame:Hide();
if (not override) then
AutoBar:SetPopupButton(button);
end
end
elseif (mousebutton == "RightButton" and updown == "DOWN" and IsControlKeyDown()) then
if (not AutoBar.display.docking) then
AutoBarFrame.moving = true;
AutoBarFrame:StartMoving();
end
end
end
-- Add tooltip info about the other categories in a slot to the current GameTooltip
function AutoBar_ButtonSetTooltipCategories(currentItems, categoryIndex)
local count = 0;
local itemCount;
for index, bagSlot in pairs(currentItems.items) do
_, itemCount = GetContainerItemInfo(bagSlot[1], bagSlot[2]);
if (not itemCount) then
itemCount = 0;