This repository has been archived by the owner on Jan 24, 2020. It is now read-only.
forked from laytya/AdvancedTradeSkillWindow-vanilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atsw.lua
executable file
·3018 lines (2798 loc) · 96.8 KB
/
atsw.lua
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
-- Advanced Trade Skill Window v0.5.5b for Classic
-- copyright 2006 by Rene Schneider (Slarti on EU-Blackhand), 2017 by laytya
-- main script file
ATSW_TRADE_SKILLS_DISPLAYED = 23;
ATSW_MAX_TRADE_SKILL_REAGENTS = 8;
ATSW_TRADE_SKILL_HEIGHT = 16;
ATSW_MAX_DELAY = 4.0;
ATSW_MAX_RETRIES = 5;
ATSWTypeColor = { };
ATSWTypeColor["optimal"] = { r = 1.00, g = 0.50, b = 0.25 };
ATSWTypeColor["medium"] = { r = 1.00, g = 1.00, b = 0.00 };
ATSWTypeColor["easy"] = { r = 0.25, g = 0.75, b = 0.25 };
ATSWTypeColor["trivial"] = { r = 0.50, g = 0.50, b = 0.50 };
ATSWTypeColor["header"] = { r = 1.00, g = 0.82, b = 0 };
ATSWRarityColor={};
ATSWRarityColor[5] = { r = 0.64, g = 0.21, b = 0.93 };
ATSWRarityColor[4] = { r = 0, g = 0.44, b = 0.87 };
ATSWRarityColor[3] = { r = 0.12, g = 1, b = 0 };
ATSWRarityColor[2] = { r = 1, g = 1, b = 1 };
ATSWRarityColor[1] = { r = 0.62, g = 0.62, b = 0.62 };
ATSWRarityNames={};
ATSWRarityNames["purple"]=5;
ATSWRarityNames["blue"]=4;
ATSWRarityNames["green"]=3;
ATSWRarityNames["white"]=2;
ATSWRarityNames["grey"]=1;
atsw_tradeskilllist={};
atsw_tradeskillheaders={};
atsw_skilllisting={};
atsw_tradeskillcounter={};
atsw_selectedskill="";
atsw_craftskillclick=nil;
atsw_displayedgroup="";
atsw_retries=0;
atsw_retrydelay=0;
atsw_retry=false;
atsw_delay=0;
atsw_working=false;
atsw_processingtimeout=0;
atsw_scans=0;
atsw_updatedelay=0;
atsw_uncategorizedexpanded=true;
atsw_tradeskillid={};
atsw_orderby={};
atsw_updating=false;
atsw_incombat=false;
atsw_bankopened=false;
atsw_oldmode=false;
atsw_disabled={};
atsw_savedqueue={};
atsw_savednecessaryitems={};
atsw_is_sorted=false;
local previousRecipies = {}
function printTable(t)
for k, v in pairs(t) do
print(k, v)
end
end
function setn(t,n)
setmetatable(t,{__len=function() return n end})
end
function ATSW_OnLoad(self)
SLASH_ATSW1 = "/atsw";
SlashCmdList["ATSW"] = ATSW_Command;
self:RegisterEvent("TRADE_SKILL_UPDATE");
self:RegisterEvent("TRADE_SKILL_CLOSE");
self:RegisterEvent("TRADE_SKILL_SHOW");
self:RegisterEvent("UNIT_PORTRAIT_UPDATE");
self:RegisterEvent("UPDATE_TRADESKILL_RECAST");
self:RegisterEvent("BANKFRAME_OPENED");
self:RegisterEvent("BANKFRAME_CLOSED");
self:RegisterEvent("PLAYERBANKSLOTS_CHANGED");
self:RegisterEvent("PLAYERBANKBAGSLOTS_CHANGED");
self:RegisterEvent("MERCHANT_SHOW");
self:RegisterEvent("MERCHANT_UPDATE");
self:RegisterEvent("MERCHANT_CLOSED");
self:RegisterEvent("BAG_UPDATE");
self:RegisterEvent("TRAINER_CLOSED");
self:RegisterEvent("PLAYER_REGEN_DISABLED");
self:RegisterEvent("PLAYER_REGEN_ENABLED");
self:RegisterEvent("AUCTION_HOUSE_CLOSED");
self:RegisterEvent("AUCTION_HOUSE_SHOW");
self:RegisterEvent("CRAFT_SHOW");
self:RegisterEvent("CRAFT_CLOSE");
self:RegisterEvent("PLAYER_LOGOUT");
self:RegisterEvent("UI_ERROR_MESSAGE");
end
function ATSW_ShowWindow(self)
if(type(atsw_orderby)~="table") then atsw_orderby={}; end
if(not atsw_orderby[UnitName("player")]) then atsw_orderby[UnitName("player")]={}; end
if(not atsw_orderby[UnitName("player")][atsw_selectedskill]) then atsw_orderby[UnitName("player")][atsw_selectedskill]="nothing"; end
if(atsw_oldmode and atsw_orderby[UnitName("player")][atsw_selectedskill]=="nothing") then
atsw_orderby[UnitName("player")][atsw_selectedskill]="name";
end
atsw_oldtradeskillcount=0;
atsw_is_sorted=false;
if(atsw_subclassfiltered[atsw_selectedskill]==nil) then atsw_subclassfiltered[atsw_selectedskill]={}; end
if(atsw_invslotfiltered[atsw_selectedskill]==nil) then atsw_invslotfiltered[atsw_selectedskill]={}; end
ShowUIPanel(ATSWCheckerFrame);
SetPortraitTexture(ATSWFramePortrait, "player");
-- pullreq#1
if(atsw_oldmode) then
if atsw_craftskillclick ~= nil then
ATSWFrame_SetSelection(atsw_craftskillclick)
end
if(ATSW_GetTradeSkillSelectionIndex()>1) then
ATSWFrame_SetSelection(ATSW_GetTradeSkillSelectionIndex());
else
if(ATSW_GetNumTradeSkills()>0) then
ATSWFrame_SetSelection(ATSW_GetFirstTradeSkill());
FauxScrollFrame_SetOffset(ATSWListScrollFrame, 0);
end
ATSWListScrollFrameScrollBar:SetValue(0);
end
end
-- /pullreq#1
if(not atsw_oldmode) then
ExpandTradeSkillSubClass(0);
if(ATSW_GetTradeSkillSelectionIndex()>1) then
ATSWFrame_SetSelection(ATSW_GetTradeSkillSelectionIndex());
else
if(ATSW_GetNumTradeSkills()>0) then
ATSWFrame_SetSelection(ATSW_GetFirstTradeSkill());
FauxScrollFrame_SetOffset(ATSWListScrollFrame, 0);
end
ATSWListScrollFrameScrollBar:SetValue(0);
end
end
ATSWFrameTitleText:SetText(format(TRADE_SKILL_TITLE, ATSW_GetTradeSkillLine()).." - "..ATSW_VERSION);
ATSW_AdjustFrame();
ATSW_ResetPossibleItemCounts(self);
ATSW_CreateTradeSkillList(self);
ATSW_CreateSkillListing(self);
ATSWInv_UpdateItemList(self);
ShowUIPanel(ATSWFrame);
ATSWFrame_UpdateQueue(self);
ATSWInv_UpdateQueuedItemList(self);
ATSWFrame_Update(self);
ATSWInputBox:SetText("1");
atsw_updatedelay=0.5;
ATSWQueueStartStopButton:Enable();
ATSWQueueStartStopButton:SetText(ATSW_STARTQUEUE);
ATSWQueueDeleteButton:Enable();
end
function ATSW_HideWindow(self)
ATSW_SaveQueue(false);
HideUIPanel(ATSWFrame);
end
function ATSW_GetSelectedSkill(self)
atsw_selectedskill=ATSW_GetTradeSkillLine();
if(not atsw_disabled[UnitName("player")]) then
atsw_disabled[UnitName("player")]={};
end
if(not atsw_disabled[UnitName("player")][atsw_selectedskill]) then
atsw_disabled[UnitName("player")][atsw_selectedskill]=0;
end
end
function ATSW_CheckForRescan(self)
atsw_scans=0;
skillname=ATSW_GetTradeSkillLine();
if(skillname) then
if(skillname~=atsw_displayedgroup) then
if(atsw_displayedgroup~="") then
ATSW_SaveQueue(false);
end
atsw_displayedgroup=skillname;
atsw_selectedskill=skillname;
ATSW_RestoreQueue();
ATSW_CreateTradeSkillList(self);
ATSW_NoteNecessaryItemsForQueue();
end
end
if(ls3dci_guiTradeButton and ls3dci_guiTradeButton:IsVisible() and ls3dci_guiTradeButton:GetParent()~=ATSWFrame) then -- for LS3D craft info
ls3dci_guiTradeButton:SetParent(ATSWFrame);
ls3dci_guiTradePostButton:SetParent(ATSWFrame);
ls3dci_guiTradeWatchButton:SetParent(ATSWFrame);
ls3dci_guiTradeButton:SetPoint("BOTTOM", "ATSWFrame", "TOP", ls3dci_optVars.buttonPos[1]+50, ls3dci_optVars.buttonPos[2]-554);
ls3dci_guiTradePostButton:SetPoint("BOTTOM", "ATSWFrame", "TOP", ls3dci_optVars.buttonPos[1]+156, ls3dci_optVars.buttonPos[2]-554);
ls3dci_guiTradeWatchButton:SetPoint("BOTTOM", "ATSWFrame", "TOP", ls3dci_optVars.buttonPos[1]+262, ls3dci_optVars.buttonPos[2]-554);
ls3dci_guiTradeButton:SetAlpha(1.0);
ls3dci_guiTradePostButton:SetAlpha(1.0);
ls3dci_guiTradeWatchButton:SetAlpha(1.0);
end
if(AC_Craft and AC_Craft:GetParent()~=ATSWFrame) then -- for ArmorCraft
AC_Craft:SetParent(ATSWFrame);
AC_Craft:SetPoint("TOPLEFT","ATSWFrame","TOPRIGHT",-40,0);
AC_Craft:SetFrameLevel(0);
AC_ToggleButton:SetParent(ATSWFrame);
AC_ToggleButton:SetFrameLevel(ATSWFrame:GetFrameLevel()+3);
AC_ToggleButton:SetPoint("RIGHT","ATSWFrameCloseButton","LEFT")
AC_UseButton:SetFrameLevel(ATSWFrame:GetFrameLevel()+3);
AC_UseButton:SetPoint("RIGHT","AC_ToggleButton","LEFT");
AC_Craft:SetAlpha(1.0);
AC_ToggleButton:SetAlpha(1.0);
AC_UseButton:SetAlpha(1.0);
end
end
function ATSW_OnHide(self)
if(not atsw_oldmode) then
TradeSkillFrame_Hide();
else
CraftFrame_Hide();
end
HideUIPanel(ATSWCheckerFrame);
HideUIPanel(ATSWReagentFrame);
HideUIPanel(ATSWCSFrame);
atsw_displayedgroup="";
atsw_selectedskill="";
end
function ATSW_Command(cmd)
if(cmd=="show") then
ATSW_ShowWindow();
elseif(cmd=="disable") then
ATSW_DisableForActiveTradeskill();
elseif(cmd=="enable") then
ATSW_EnableForActiveTradeskill();
elseif(cmd=="reagents") then
ShowUIPanel(ATSWAllReagentListFrame);
end
end
function ATSW_DisableForActiveTradeskill(self)
if(atsw_oldmode) then
if(CraftFrame and CraftFrame:IsVisible()) then
atsw_disabled[UnitName("player")][atsw_selectedskill]=1;
HideUIPanel(ATSWFrame);
CraftFrame:SetAlpha(1);
CraftFrame:SetScale(1);
ATSW_DisplayMessage(ATSW_ACTIVATIONMESSAGE.." "..ATSW_DEACTIVATED);
end
else
if(TradeSkillFrame and TradeSkillFrame:IsVisible()) then
atsw_disabled[UnitName("player")][atsw_selectedskill]=1;
HideUIPanel(ATSWFrame);
TradeSkillFrame:SetAlpha(1);
TradeSkillFrame:SetScale(1);
ATSW_DisplayMessage(ATSW_ACTIVATIONMESSAGE.." "..ATSW_DEACTIVATED);
end
end
if(AC_Craft and AC_Craft:GetParent()==ATSWFrame) then -- for ArmorCraft
AC_Craft:SetParent(TradeSkillFrame);
AC_Craft:SetPoint("TOPLEFT","TradeSkillFrame","TOPRIGHT",-40,100);
AC_Craft:SetFrameLevel(0);
AC_ToggleButton:SetParent(TradeSkillFrame);
AC_ToggleButton:SetFrameLevel(TradeSkillFrame:GetFrameLevel()+3);
AC_UseButton:SetPoint("RIGHT","AC_ToggleButton","LEFT");
end
end
function ATSW_EnableForActiveTradeskill(self)
if(atsw_oldmode) then
if(CraftFrame and CraftFrame:IsVisible()) then
atsw_disabled[UnitName("player")][atsw_selectedskill]=0;
ATSW_ShowWindow();
CraftFrame:SetAlpha(0);
CraftFrame:SetScale(0.001);
ATSW_DisplayMessage(ATSW_ACTIVATIONMESSAGE.." "..ATSW_ACTIVATED);
end
else
if(TradeSkillFrame and TradeSkillFrame:IsVisible()) then
-- ATSW_DisplayMessage("atsw_selectedskill is '"..atsw_selectedskill.."'");
atsw_disabled[UnitName("player")][atsw_selectedskill]=0;
ATSW_ShowWindow();
TradeSkillFrame:SetAlpha(0);
TradeSkillFrame:SetScale(0.001);
ATSW_DisplayMessage(ATSW_ACTIVATIONMESSAGE.." "..ATSW_ACTIVATED);
end
end
end
function ATSWFrame_Show(self)
ATSW_ShowWindow();
end
function ATSW_CheckForTradeSkillWindow(self, arg1)
-- if arg1 is nil then arg1 = 0 end -- ROB FIX
if(ATSWFrame:IsVisible()) then
if(atsw_updatedelay>0) then
atsw_updatedelay=atsw_updatedelay-arg1;
if(atsw_updatedelay<=0) then
ATSWFrame_Update(self);
atsw_updatedelay=0;
end
end
ATSW_CheckForRescan();
end
if(atsw_processnext==true) then
atsw_processnext=false;
ATSW_ProcessNextQueueItem(self);
end
if(atsw_processing==true) then
if(atsw_processingtimeout~=0) then
if(atsw_processingtimeout>0) then
atsw_processingtimeout=atsw_processingtimeout-arg1;
else
atsw_processingtimeout=0;
ATSWQueueStartStopButton:Enable();
ATSWQueueDeleteButton:Enable();
ATSWQueueStartStopButton:SetText(ATSW_STARTQUEUE);
atsw_processing=false;
ATSWFrame:UnregisterEvent("UNIT_SPELLCAST_STOP");
ATSWFrame:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_STOP");
ATSWFrame:UnregisterEvent("UNIT_SPELLCAST_START");
ATSWFrame:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED");
end
end
if(atsw_retry==true) then
if(atsw_retrydelay<ATSW_MAX_DELAY) then
atsw_retrydelay=atsw_retrydelay+arg1;
else
atsw_retrydelay=0;
ATSW_ProcessNextQueueItem(self);
end
end
end
end
function ATSWFrame_OnEvent(self, event, ...)
local arg1 = ...
if(event=="TRADE_SKILL_SHOW") then
if(CraftFrame and CraftFrame:IsVisible()) then ATSW_HideWindow(); end
atsw_oldmode=false;
ATSW_GetSelectedSkill();
if(atsw_disabled[UnitName("player")][atsw_selectedskill]==0) then
ATSW_ShowWindow();
else
TradeSkillFrame:SetAlpha(1);
TradeSkillFrame:SetScale(1);
--HideUIPanel(ATSWFrame);
end
elseif(event=="TRADE_SKILL_CLOSE") then
ATSW_HideWindow();
elseif(event=="CRAFT_SHOW") then
if(TradeSkillFrame and TradeSkillFrame:IsVisible()) then ATSW_HideWindow(); end
atsw_oldmode=true;
local name=GetCraftDisplaySkillLine();
if(name) then
ATSW_GetSelectedSkill();
if(atsw_disabled[UnitName("player")][atsw_selectedskill]==0) then
ATSW_ShowWindow();
else
CraftFrame:SetAlpha(1);
CraftFrame:SetScale(1);
--HideUIPanel(ATSWFrame);
end
end
elseif(event=="CRAFT_CLOSE") then
ATSW_HideWindow();
elseif(event=="BANKFRAME_OPENED") then
atsw_bankopened=true;
ATSWBank_UpdateBankList();
elseif(event=="BANKFRAME_CLOSED") then
atsw_bankopened=false;
elseif(event=="PLAYERBANKSLOTS_CHANGED") then
ATSWBank_UpdateBankList();
elseif(event=="PLAYERBANKBAGSLOTS_CHANGED") then
ATSWBank_UpdateBankList();
elseif(event=="MERCHANT_SHOW") then
ATSWMerchant_InsertAutoBuyButton();
ATSWMerchant_UpdateMerchantList();
ATSWMerchant_AutoBuy();
elseif(event=="MERCHANT_CLOSED") then
ATSWMerchant_RemoveAutoBuyButton();
elseif(event=="MERCHANT_UPDATE") then
ATSWMerchant_UpdateMerchantList();
elseif(event=="AUCTION_HOUSE_SHOW") then
ATSWAuction_ShowShoppingList();
elseif(event=="AUCTION_HOUSE_CLOSED") then
ATSWAuction_HideShoppingList();
elseif(event=="BAG_UPDATE") then
if(ATSWFrame:IsVisible()) then
if(atsw_processing==true) then
if(table.getn(atsw_queue)==0) then
atsw_processingtimeout=-1;
end
end
atsw_retries=0;
atsw_retrydelay=ATSW_MAX_DELAY;
end
ATSW_ResetPossibleItemCounts(self);
ATSWInv_UpdateItemList(self);
ATSWBank_UpdateBankList();
if(ATSW_GetTradeSkillSelectionIndex()>0 and ATSWFrame:IsVisible()) then
ATSWFrame_SetSelection(ATSW_GetTradeSkillSelectionIndex()); --069
end
end
if(not ATSWFrame:IsVisible()) then
return;
end
if(TradeSkillFrame and TradeSkillFrame:IsVisible() and atsw_disabled[UnitName("player")][atsw_selectedskill]==0) then
TradeSkillFrame:SetAlpha(0);
TradeSkillFrame:SetScale(0.001);
end
if(CraftFrame and CraftFrame:IsVisible() and atsw_disabled[UnitName("player")][atsw_selectedskill]==0 and GetCraftDisplaySkillLine()) then
CraftFrame:SetAlpha(0);
CraftFrame:SetScale(0.001);
end
if(event=="TRADE_SKILL_UPDATE") then
if(atsw_scans<2) then
atsw_scans=atsw_scans+1;
ATSW_CreateTradeSkillList(self);
ATSWCreateButton:Disable();
ATSWQueueButton:Disable();
ATSWCreateAllButton:Disable();
ATSWQueueAllButton:Disable();
ATSWHighlightFrame:Hide();
if(ATSW_GetTradeSkillSelectionIndex()>1) then
ATSWFrame_SetSelection(ATSW_GetTradeSkillSelectionIndex());
else
if(ATSW_GetNumTradeSkills()>0) then
ATSWFrame_SetSelection(ATSW_GetFirstTradeSkill());
FauxScrollFrame_SetOffset(ATSWListScrollFrame, 0);
end
ATSWListScrollFrameScrollBar:SetValue(0);
end
if(atsw_updating==false) then
ATSW_ResetPossibleItemCounts(self);
ATSW_CreateSkillListing(self);
ATSWFrame_Update(self);
end
end
elseif(event=="UNIT_PORTRAIT_UPDATE") then
if(arg1=="player") then
SetPortraitTexture(TradeSkillFramePortrait, "player");
end
elseif(event=="UPDATE_TRADESKILL_RECAST") then
ATSWInputBox:SetNumber(GetTradeskillRepeatCount());
elseif(event=="UNIT_SPELLCAST_STOP" or event=="UNIT_SPELLCAST_CHANNEL_STOP") then
ATSW_SpellcastStop(self);
elseif(event=="UNIT_SPELLCAST_START") then
ATSW_SpellcastStart(self);
elseif(event=="UNIT_SPELLCAST_INTERRUPTED") then
ATSW_SpellcastInterrupted(self);
elseif(event=="TRAINER_CLOSED") then
ATSW_ResetPossibleItemCounts(self);
ATSW_CreateSkillListing(self);
if(ATSWFrame:IsVisible()) then ATSWFrame_Update(self); end
elseif(event=="PLAYER_REGEN_ENABLED") then
atsw_incombat=false;
elseif(event=="PLAYER_REGEN_DISABLED") then
atsw_incombat=true;
elseif(event=="PLAYER_LOGOUT") then
ATSW_SaveQueue(false);
elseif(event=="UI_ERROR_MESSAGE") then
if atsw_working and arg1 == "Interrupted" then
ATSW_SpellcastStop(self);
ATSW_SpellcastInterrupted(self);
end
-- Sea.io.printTable({arg1 or "nil",event})
if(ATSWFrame:IsVisible()) then
if(arg1==INVENTORY_FULL) then
ATSW_SpellcastStop(self);
ATSW_SpellcastInterrupted(self);
end
if(string.find(arg1,string.sub(SPELL_FAILED_REAGENTS,1,string.len(SPELL_FAILED_REAGENTS)-2),1,true)~=nil) then
ATSW_SpellcastStop(self); --069
ATSW_SpellcastInterrupted(self);
end
if(string.find(arg1,string.sub(SPELL_FAILED_REQUIRES_SPELL_FOCUS,1,string.len(SPELL_FAILED_REQUIRES_SPELL_FOCUS)-4),1,true)~=nil) then
ATSW_SpellcastStop(self);
ATSW_SpellcastInterrupted(self);
end
end
end
end
function ATSW_AdjustFrame(self)
if(atsw_oldmode) then
ATSWHeaderSortButton:Hide();
ATSWInvSlotDropDown:Hide();
ATSWSubClassDropDown:Hide();
ATSWExpandButtonFrame:Hide();
ATSWCreateButton:Hide();
ATSWQueueButton:Hide();
ATSWCreateAllButton:Hide();
ATSWQueueAllButton:Hide();
ATSWDecrementButton:Hide();
ATSWInputBox:Hide();
ATSWIncrementButton:Hide();
ATSWQueueStartStopButton:Hide();
ATSWQueueDeleteButton:Hide();
ATSWReagentsButton:Hide();
ATSWHorizontalBarLeft:Hide();
ATSWHorizontalBarLeft2:Hide();
ATSWHorizontalBarLeftAddon:Hide();
ATSWHorizontalBarLeft2Addon:Hide();
ATSWEnchantButton:Show();
ATSWReagentLabel:SetPoint("TOPLEFT", "ATSWFrame", "TOPLEFT" , 380, -180);
ATSWCraftDescription:Show();
else
ATSWHeaderSortButton:Show();
ATSWInvSlotDropDown:Show();
ATSWSubClassDropDown:Show();
ATSWExpandButtonFrame:Show();
ATSWCreateButton:Show();
ATSWQueueButton:Show();
ATSWCreateAllButton:Show();
ATSWQueueAllButton:Show();
ATSWDecrementButton:Show();
ATSWInputBox:Show();
ATSWIncrementButton:Show();
ATSWQueueStartStopButton:Show();
ATSWQueueDeleteButton:Show();
ATSWReagentsButton:Show();
ATSWHorizontalBarLeft:Show();
ATSWHorizontalBarLeft2:Show();
ATSWHorizontalBarLeftAddon:Show();
ATSWHorizontalBarLeft2Addon:Show();
ATSWEnchantButton:Hide();
ATSWReagentLabel:SetPoint("TOPLEFT", "ATSWFrame", "TOPLEFT" , 380, -136);
ATSWCraftDescription:Hide();
end
end
function ATSW_SortTradeSkills(self)
local tradeskills={};
ExpandTradeSkillSubClass(0);
local numTradeSkills=ATSW_GetNumTradeSkills();
for i=1,numTradeSkills,1 do
local skillName, skillType, numAvailable, isExpanded = ATSW_GetTradeSkillInfo(i);
if(skillType~="header") then
local skillTypeNumber=0;
if(skillType=="easy") then skillTypeNumber=1; end
if(skillType=="medium") then skillTypeNumber=2; end
if(skillType=="optimal") then skillTypeNumber=3; end
table.insert(tradeskills,{name=skillName,id=i,skilltype=skillTypeNumber});
end
end
atsw_tradeskillid={};
setn(atsw_tradeskillid,0);
if(atsw_orderby[UnitName("player")][atsw_selectedskill]=="name") then
table.sort(tradeskills,ATSW_CompareName);
for i=1,table.getn(tradeskills),1 do
table.insert(atsw_tradeskillid,tradeskills[i].id);
end
end
if(atsw_orderby[UnitName("player")][atsw_selectedskill]=="difficulty") then
table.sort(tradeskills,ATSW_CompareDifficulty);
for i=1,table.getn(tradeskills),1 do
table.insert(atsw_tradeskillid,tradeskills[i].id);
end
end
atsw_is_sorted=true;
end
function ATSW_CompareName(i,j)
return string.lower(i.name) < string.lower(j.name);
end
function ATSW_CompareDifficulty(i,j)
return string.lower(i.skilltype) > string.lower(j.skilltype);
end
function ATSW_OrderBy(self, order)
atsw_orderby[UnitName("player")][atsw_selectedskill]=order;
atsw_is_sorted=false;
ATSW_CreateSkillListing(self);
ATSWFrame_Update(self);
end
function ATSWFrame_Update(self)
if(not ATSWFrame:IsVisible()) then return; end
if(type(atsw_orderby)~="table") then atsw_orderby={}; end
if(not atsw_orderby[UnitName("player")]) then atsw_orderby[UnitName("player")]={}; end
if(not atsw_orderby[UnitName("player")][atsw_selectedskill]) then atsw_orderby[UnitName("player")][atsw_selectedskill]="nothing"; end
if(atsw_oldmode and atsw_orderby[UnitName("player")][atsw_selectedskill]=="nothing") then
atsw_orderby[UnitName("player")][atsw_selectedskill]="name";
end
if(atsw_orderby[UnitName("player")][atsw_selectedskill]=="name") then
ATSWHeaderSortButton:SetChecked(false);
ATSWNameSortButton:SetChecked(true);
ATSWDifficultySortButton:SetChecked(false);
ATSWCustomSortButton:SetChecked(false);
elseif(atsw_orderby[UnitName("player")][atsw_selectedskill]=="difficulty") then
ATSWHeaderSortButton:SetChecked(false);
ATSWNameSortButton:SetChecked(false);
ATSWDifficultySortButton:SetChecked(true);
ATSWCustomSortButton:SetChecked(false);
elseif(atsw_orderby[UnitName("player")][atsw_selectedskill]=="custom") then
ATSWHeaderSortButton:SetChecked(false);
ATSWNameSortButton:SetChecked(false);
ATSWDifficultySortButton:SetChecked(false);
ATSWCustomSortButton:SetChecked(true);
else
ATSWHeaderSortButton:SetChecked(true);
ATSWNameSortButton:SetChecked(false);
ATSWDifficultySortButton:SetChecked(false);
ATSWCustomSortButton:SetChecked(false);
end
for i=1,ATSW_TRADE_SKILLS_DISPLAYED,1 do
getglobal("ATSWSkill"..i):Hide();
end
if table.getn(previousRecipies) > 0 then
ATSWPreviousItemButton:Show()
else
ATSWPreviousItemButton:Hide()
end
if(atsw_orderby[UnitName("player")][atsw_selectedskill]=="nothing" or atsw_orderby[UnitName("player")][atsw_selectedskill]=="custom") then
ATSWExpandButtonFrame:Show();
local numTradeSkills=table.getn(atsw_skilllisting);
local skillOffset=FauxScrollFrame_GetOffset(ATSWListScrollFrame);
if(numTradeSkills==0) then
ATSWFrameTitleText:SetText(format(TRADE_SKILL_TITLE, ATSW_GetTradeSkillLine()).." - "..ATSW_VERSION);
ATSWSkillName:Hide();
ATSWSkillIcon:Hide();
ATSWRequirementLabel:Hide();
ATSWCollapseAllButton:Disable();
for i=1, ATSW_MAX_TRADE_SKILL_REAGENTS, 1 do
getglobal("ATSWReagent"..i):Hide();
end
else
ATSWSkillName:Show();
ATSWSkillIcon:Show();
ATSWCollapseAllButton:Enable();
end
FauxScrollFrame_Update(ATSWListScrollFrame, numTradeSkills, ATSW_TRADE_SKILLS_DISPLAYED, ATSW_TRADE_SKILL_HEIGHT, nil, nil, nil, ATSWHighlightFrame, 293, 316);
ATSWHighlightFrame:Hide();
local jumped=1;
for i=1,ATSW_TRADE_SKILLS_DISPLAYED,1 do
local skillName, skillType, numAvailable, isExpanded;
local skillIndex;
repeat
skillIndex=skillOffset+jumped;
if(skillIndex>numTradeSkills) then
skillName=nil;
else
skillName = atsw_skilllisting[skillIndex].name;
skillType = atsw_skilllisting[skillIndex].type;
isExpanded = atsw_skilllisting[skillIndex].expanded;
end
jumped=jumped+1;
until ((skillName and ATSW_Filter(skillName)==true and ATSW_FilterInvSlot(skillName) and ATSW_FilterSubClass(skillName)) or skillIndex>numTradeSkills or skillType=="header");
if(skillName) then numAvailable=ATSW_GetNumItemsPossible(skillName); end
local skillButton=getglobal("ATSWSkill"..i);
if(skillIndex<=numTradeSkills) then
if(ATSWListScrollFrame:IsVisible()) then
skillButton:SetWidth(293);
else
skillButton:SetWidth(323);
end
local color=ATSWTypeColor[skillType];
if(color) then
-- skillButton:SetTextColor(color.r, color.g, color.b);-- ROB FIX
end
if(atsw_skilllisting[skillIndex] and atsw_skilllisting[skillIndex].id) then
skillButton:SetID(atsw_skilllisting[skillIndex].id);
else
return;
end
skillButton:Show();
if(skillType=="header") then
skillButton:SetText(skillName);
if(isExpanded) then
skillButton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
else
skillButton:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
end
getglobal("ATSWSkill"..i.."Highlight"):SetTexture("Interface\\Buttons\\UI-PlusButton-Hilight");
getglobal("ATSWSkill"..i):UnlockHighlight();
else
if(not skillName)then
return;
end
skillButton:SetNormalTexture("");
getglobal("ATSWSkill"..i.."Highlight"):SetTexture("");
if(atsw_multicount==true) then
if ( numAvailable == 0 ) then
skillButton:SetText(" "..skillName);
else
skillButton:SetText(" "..skillName.." ["..numAvailable.."]");
end
else
local numAvailableString=ATSW_GetNumItemsPossibleWithInventory(skillName).."/"..numAvailable;
if ( numAvailableString == "0/0" ) then
skillButton:SetText(" "..skillName);
else
skillButton:SetText(" "..skillName.." ["..numAvailableString.."]");
end
end
if(ATSW_GetTradeSkillSelectionIndex()==atsw_skilllisting[skillIndex].id) then
ATSWHighlightFrame:SetPoint("TOPLEFT", "ATSWSkill"..i, "TOPLEFT", 0, 0);
ATSWHighlightFrame:Show();
ATSWFrame.numAvailable = numAvailable;
getglobal("ATSWSkill"..i):LockHighlight();
else
getglobal("ATSWSkill"..i):UnlockHighlight();
end
end
else
skillButton:Hide();
end
end
end
if(atsw_orderby[UnitName("player")][atsw_selectedskill]=="name" or atsw_orderby[UnitName("player")][atsw_selectedskill]=="difficulty") then
ATSWExpandButtonFrame:Hide();
atsw_updating=true;
if(atsw_is_sorted==false) then ATSW_SortTradeSkills(); end
local numTradeSkills=table.getn(atsw_tradeskillid);
local skillOffset=FauxScrollFrame_GetOffset(ATSWListScrollFrame);
if(numTradeSkills==0) then
ATSWFrameTitleText:SetText(format(TRADE_SKILL_TITLE, ATSW_GetTradeSkillLine()).." - "..ATSW_VERSION);
ATSWSkillName:Hide();
ATSWSkillIcon:Hide();
ATSWRequirementLabel:Hide();
ATSWCollapseAllButton:Disable();
for i=1, ATSW_MAX_TRADE_SKILL_REAGENTS, 1 do
getglobal("ATSWReagent"..i):Hide();
end
else
ATSWSkillName:Show();
ATSWSkillIcon:Show();
ATSWCollapseAllButton:Enable();
end
FauxScrollFrame_Update(ATSWListScrollFrame, numTradeSkills, ATSW_TRADE_SKILLS_DISPLAYED, ATSW_TRADE_SKILL_HEIGHT, nil, nil, nil, ATSWHighlightFrame, 293, 316);
ATSWHighlightFrame:Hide();
local jumped=1;
for i=1,ATSW_TRADE_SKILLS_DISPLAYED,1 do
local skillName, skillType, numAvailable, isExpanded, craftSubSpellName;
local skillIndex;
repeat
skillIndex=atsw_tradeskillid[skillOffset+jumped];
if(skillIndex==nil) then
skillName=nil;
else
skillName, skillType, numAvailable, isExpanded = ATSW_GetTradeSkillInfo(skillIndex);
end
jumped=jumped+1;
until (((skillName and ATSW_Filter(skillName)==true and ATSW_FilterInvSlot(skillName) and ATSW_FilterSubClass(skillName)) or skillIndex==nil) and skillType~="header");
if(skillIndex) then
skillName, skillType, numAvailable, isExpanded = ATSW_GetTradeSkillInfo(skillIndex);
if(skillName) then numAvailable=ATSW_GetNumItemsPossible(skillName); end
local skillButton=getglobal("ATSWSkill"..i);
if(ATSWListScrollFrame:IsVisible()) then
skillButton:SetWidth(293);
else
skillButton:SetWidth(323);
end
local color=ATSWTypeColor[skillType];
if(color) then
-- skillButton:SetTextColor(color.r, color.g, color.b);-- ROB FIX
end
skillButton:SetID(skillIndex);
skillButton:Show();
if(skillType=="header") then
skillButton:SetText(skillName);
if(isExpanded) then
skillButton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
else
skillButton:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
end
getglobal("ATSWSkill"..i.."Highlight"):SetTexture("Interface\\Buttons\\UI-PlusButton-Hilight");
getglobal("ATSWSkill"..i):UnlockHighlight();
else
if(not skillName)then
return;
end
skillButton:SetNormalTexture("");
getglobal("ATSWSkill"..i.."Highlight"):SetTexture("");
if(atsw_multicount==true) then
if ( numAvailable == 0 ) then
skillButton:SetText(" "..skillName);
else
skillButton:SetText(" "..skillName.." ["..numAvailable.."]");
end
else
local numAvailableString=ATSW_GetNumItemsPossibleWithInventory(skillName).."/"..numAvailable;
if ( numAvailableString == "0/0" ) then
skillButton:SetText(" "..skillName);
else
skillButton:SetText(" "..skillName.." ["..numAvailableString.."]");
end
end
if(ATSW_GetTradeSkillSelectionIndex()==skillIndex) then
ATSWHighlightFrame:SetPoint("TOPLEFT", "ATSWSkill"..i, "TOPLEFT", 0, 0);
ATSWHighlightFrame:Show();
ATSWFrame.numAvailable = numAvailable;
getglobal("ATSWSkill"..i):LockHighlight();
else
getglobal("ATSWSkill"..i):UnlockHighlight();
end
end
end
end
atsw_updating=false;
end
end
function ATSWSkillButton_OnClick(self, button)
if(button=="LeftButton") then
ATSWFrame_SetSelection(self:GetID(),true);
ATSWFrame_Update(self);
end
end
function ATSWFrame_SetSelection(id,wasClicked)
local skillName, skillType, numAvailable;
local listpos=ATSW_GetSkillListingPos(id);
if(atsw_skilllisting[listpos]) then
skillName = atsw_skilllisting[listpos].name;
skillType = atsw_skilllisting[listpos].type;
else
skillName=nil;
end
if(skillName) then numAvailable=ATSW_GetNumItemsPossible(skillName); end
if(IsShiftKeyDown() and skillName~=nil and wasClicked~=nil) then
if(arg1=="LeftButton" and (ChatFrameEditBox:IsVisible() or WIM_EditBoxInFocus~=nil)) then
ATSW_AddTradeSkillReagentLinksToChatFrame(skillName);
end
end
ATSWHighlightFrame:Show();
if(skillType=="header") then
ATSWHighlightFrame:Hide();
if(atsw_skilllisting[listpos].expanded) then
ATSW_SetHeaderExpanded(id,false);
else
ATSW_SetHeaderExpanded(id,true);
end
ATSWFrame_Update(self);
return;
end
-- pullreq#1
if atsw_oldmode then
skillName, craftSubSpellName, skillType, numAvailable = GetCraftInfo(id)
ATSWSkillName:SetText();
else
skillName, skillType, numAvailable = GetTradeSkillInfo(id)
ATSWSkillName:SetText();
end
-- /pullreq#1
local skillOffset = FauxScrollFrame_GetOffset(ATSWListScrollFrame);
local numTradeSkills = ATSW_GetNumTradeSkills()
if (numTradeSkills > ATSW_TRADE_SKILLS_DISPLAYED) then
local idpos = atsw_is_sorted and ATSW_TradeSkillIdPos(id) or id
idpos = atsw_orderby[UnitName("player")][atsw_selectedskill] == "custom" and (listpos > 0 and listpos or 0) or idpos
--[[
if (idpos - skillOffset > ATSW_TRADE_SKILLS_DISPLAYED) or (idpos - skillOffset < 0) then
if (idpos < numTradeSkills - ATSW_TRADE_SKILLS_DISPLAYED) then
FauxScrollFrame_SetOffset(ATSWListScrollFrame, idpos - 1);
ATSWListScrollFrameScrollBar:SetValue((idpos - 1) * ATSW_TRADE_SKILL_HEIGHT);
else
FauxScrollFrame_SetOffset(ATSWListScrollFrame, numTradeSkills - ATSW_TRADE_SKILLS_DISPLAYED);
ATSWListScrollFrameScrollBar:SetValue((numTradeSkills - ATSW_TRADE_SKILLS_DISPLAYED) * ATSW_TRADE_SKILL_HEIGHT);
end
end
]]
if (idpos - skillOffset > ATSW_TRADE_SKILLS_DISPLAYED) or (idpos - skillOffset < 0) then
skillOffset = math.floor( idpos / ATSW_TRADE_SKILLS_DISPLAYED) * ATSW_TRADE_SKILLS_DISPLAYED
FauxScrollFrame_SetOffset(ATSWListScrollFrame, skillOffset);
ATSWListScrollFrameScrollBar:SetValue(skillOffset * ATSW_TRADE_SKILL_HEIGHT);
end
end
ATSWFrame.selectedSkillName=skillName;
ATSWFrame.selectedSkill = id;
ATSW_SelectTradeSkill(id);
if(ATSW_GetTradeSkillSelectionIndex()>ATSW_GetNumTradeSkills())then
return;
end
local color=ATSWTypeColor[skillType];
if(color) then
ATSWHighlight:SetVertexColor(color.r, color.g, color.b);
end
-- General Info
local skillLineName, skillLineRank, skillLineMaxRank = ATSW_GetTradeSkillLine();
ATSWFrameTitleText:SetText(format(TRADE_SKILL_TITLE, skillLineName).." - "..ATSW_VERSION);
-- Set statusbar info
ATSWRankFrameSkillName:SetText(skillLineName);
ATSWRankFrame:SetStatusBarColor( 0.0, 0.0, 1.0, 0.5);
ATSWRankFrameBackground:SetVertexColor(0.0, 0.0, 0.75, 0.5);
ATSWRankFrame:SetMinMaxValues(0, skillLineMaxRank);
ATSWRankFrame:SetValue(skillLineRank);
ATSWRankFrameSkillRank:SetText(skillLineRank.."/"..skillLineMaxRank);
ATSWSkillName:SetText(skillName);
if(atsw_oldmode and GetCraftDescription(id)) then
ATSWCraftDescription:SetText(GetCraftDescription(id));
end
if(ATSW_GetTradeSkillCooldown(id)) then
ATSWSkillCooldown:SetText(COOLDOWN_REMAINING.." "..SecondsToTime(ATSW_GetTradeSkillCooldown(id)));
else
ATSWSkillCooldown:SetText("");
end
ATSWSkillIcon:SetNormalTexture(ATSW_GetTradeSkillIcon(id));
local minMade,maxMade = ATSW_GetTradeSkillNumMade(id);
if(maxMade>1) then
if(minMade==maxMade) then
ATSWSkillIconCount:SetText(minMade);
else
ATSWSkillIconCount:SetText(minMade.."-"..maxMade);
end
if(ATSWSkillIconCount:GetWidth()>39) then
ATSWSkillIconCount:SetText("~"..floor((minMade + maxMade)/2));
end
else
ATSWSkillIconCount:SetText("");
end
local creatable = 1;
local numReagents = ATSW_GetTradeSkillNumReagents(id);
for i=1, numReagents, 1 do
local reagentName, reagentTexture, reagentCount, playerReagentCount = ATSW_GetTradeSkillReagentInfo(id, i);
local reagent = getglobal("ATSWReagent"..i);
local name = getglobal("ATSWReagent"..i.."Name");
local count = getglobal("ATSWReagent"..i.."Count");
if(not reagentName or not reagentTexture) then
reagent:Hide();
else
reagent:Show();
SetItemButtonTexture(reagent, reagentTexture);
name:SetText(reagentName);
-- Grayout items
if(playerReagentCount<reagentCount) then
SetItemButtonTextureVertexColor(reagent, 0.5, 0.5, 0.5);
-- name:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b); -- ROB FIX
else
SetItemButtonTextureVertexColor(reagent, 1.0, 1.0, 1.0);
-- name:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);-- ROB FIX
end
if(playerReagentCount>=100) then
playerReagentCount = "*";
end
count:SetText(playerReagentCount.." /"..reagentCount);
end
end
local reagentToAnchorTo = numReagents;
if((numReagents > 0) and (mod(numReagents, 2)==0)) then
reagentToAnchorTo = reagentToAnchorTo - 1;
end
for i=numReagents+1, ATSW_MAX_TRADE_SKILL_REAGENTS, 1 do
getglobal("ATSWReagent"..i):Hide();
end
local spellFocus=BuildColoredListString(ATSW_GetTradeSkillTools(id));
if(spellFocus) then
ATSWRequirementLabel:Show();
ATSWRequirementText:SetText(spellFocus);
else
ATSWRequirementLabel:Hide();
ATSWRequirementText:SetText("");
end
if(creatable) then
ATSWCreateButton:Enable();
ATSWQueueButton:Enable();
ATSWCreateAllButton:Enable();
ATSWQueueAllButton:Enable();
else
ATSWCreateButton:Disable();
ATSWQueueButton:Disable();
ATSWCreateAllButton:Disable();
ATSWQueueAllButton:Disable();
end
if(FRC_CraftFrame_SetSelection and FRC_TradeSkillFrame_SetSelection) then -- for Fizzwidgets ReagentCost
if(atsw_oldmode==false) then
local ATSW_Orig_TradeSkillFrame_SetSelection=FRC_Orig_TradeSkillFrame_SetSelection;
FRC_Orig_TradeSkillFrame_SetSelection=ATSW_NOP;