This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AuctionatorShop.lua
executable file
·1180 lines (814 loc) · 28.9 KB
/
AuctionatorShop.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
local addonName, addonTable = ...;
local ZT = addonTable.ztt.ZT;
local zc = addonTable.zc;
local zz = zc.md
local _
-----------------------------------------
Atr_SList = {}
Atr_SList.__index = Atr_SList
local SLITEMS_NUM_LINES = 15
local WEAPON = 1
local ARMOR = 2
ATR_MAXNUM_ITEMS_ON_SHOPPING_LIST = 50
local gCurrentSList
local gTempShoppingList = nil
-----------------------------------------
function Atr_ShoppingListsInit ()
if (AUCTIONATOR_SHOPPING_LISTS == nil) then
AUCTIONATOR_SHOPPING_LISTS = {};
Atr_SList.create (ZT("Recent Searches"), true);
if (zc.IsEnglishLocale()) then
local slist = Atr_SList.create ("Sample Shopping List #1");
slist:AddItem ("Greater Cosmic Essence");
slist:AddItem ("Infinite Dust");
slist:AddItem ("Dream Shard");
slist:AddItem ("Abyss Crystal");
end
end
local num = #AUCTIONATOR_SHOPPING_LISTS;
local x;
for x = 1,num do
setmetatable (AUCTIONATOR_SHOPPING_LISTS[x], Atr_SList);
end
for x = 1,num do
local slist = AUCTIONATOR_SHOPPING_LISTS[x]
if (slist.name == nil) then
slist.name = "foo"
zz ("null named shopping list found")
end
end
end
-----------------------------------------
function Atr_SList.create (name, isRecents, isTemporary)
if (name == nil) then
return
end
local slist = {};
setmetatable (slist,Atr_SList);
slist.name = name;
slist.items = {};
if (isRecents) then
slist.isRecents = 1;
end
if (isTemporary) then
gTempShoppingList = slist
else
table.insert (AUCTIONATOR_SHOPPING_LISTS, slist)
end
local x
for x = 1,#AUCTIONATOR_SHOPPING_LISTS do
local slist = AUCTIONATOR_SHOPPING_LISTS[x]
if (slist.name == nil) then
slist.name = "foo"
zz ("null named shopping list found")
end
end
table.sort (AUCTIONATOR_SHOPPING_LISTS, Atr_SortSlists);
CloseDropDownMenus();
return slist;
end
-----------------------------------------
function Atr_SortSlists (x, y)
if (x.isRecents) then return true; end;
if (y.isRecents) then return false; end;
return (string.lower(x.name) < string.lower(y.name));
end
-----------------------------------------
function Atr_SList.FindByName (name, options)
local checkTempList = (options == nil or not options.skipTempList)
if (checkTempList and gTempShoppingList and zc.StringSame (gTempShoppingList.name, name)) then
return gTempShoppingList
end
local num = #AUCTIONATOR_SHOPPING_LISTS;
local x;
for x = 1,num do
if (zc.StringSame (AUCTIONATOR_SHOPPING_LISTS[x].name, name)) then
return AUCTIONATOR_SHOPPING_LISTS[x];
end
end
end
-----------------------------------------
function Atr_SList:AddItem (itemName)
if (itemName == "" or itemName == nil) then
return;
end
if (self.isRecents) then
table.insert (self.items, 1, itemName);
while (#self.items > 50) do -- max 50 items on recents list
table.remove (self.items);
end
else
table.insert (self.items, itemName);
self.isSorted = false;
end
end
-----------------------------------------
function Atr_SList:RemoveItem (itemName)
local num = #self.items;
local n;
for n = 1,num do
if (zc.StringSame (self.items[n], itemName)) then
table.remove (self.items, n);
return;
end
end
end
-----------------------------------------
function Atr_SList:Clear ()
self.items = {}
end
-----------------------------------------
function Atr_DisplaySlist ()
if (gCurrentSList) then
gCurrentSList:DisplayX ();
end
end
-----------------------------------------
function sortSlist (x, y)
return (string.lower(x) < string.lower(y));
end
-----------------------------------------
function Atr_SList:DisplayX ()
gCurrentSList = self;
local currentPane = Atr_GetCurrentPane();
if (not (self.isRecents or self.isSorted)) then
self.isSorted = true;
table.sort (self.items, sortSlist);
end
local numrows = #self.items;
local line; -- 1 through NN of our window to scroll
local dataOffset; -- an index into our data calculated from the scroll offset
FauxScrollFrame_Update (Atr_Hlist_ScrollFrame, numrows, SLITEMS_NUM_LINES, 16);
for line = 1,SLITEMS_NUM_LINES do
currentPane.hlistScrollOffset = FauxScrollFrame_GetOffset (Atr_Hlist_ScrollFrame);
dataOffset = line + currentPane.hlistScrollOffset;
local lineEntry = _G["AuctionatorHEntry"..line];
lineEntry:SetID(dataOffset);
local slItem = self.items[dataOffset];
if (dataOffset <= numrows and slItem) then
local lineEntry_text = _G["AuctionatorHEntry"..line.."_EntryText"];
lineEntry_text:SetText (Atr_AbbrevItemName (slItem));
if (Atr_IsShoppingListSearch (slItem)) then
lineEntry_text:SetTextColor (.7,.6,.5);
else
lineEntry_text:SetTextColor (.6,.6,.6);
end
if (currentPane.activeSearch.origSearchText ~= "" and zc.StringSame (slItem , currentPane.activeSearch.origSearchText)) then
lineEntry:SetButtonState ("PUSHED", true);
elseif (currentPane.activeSearch.searchText == "" and zc.StringSame (slItem , Atr_Search_Box:GetText())) then
lineEntry:SetButtonState ("PUSHED", true);
else
lineEntry:SetButtonState ("NORMAL", false);
end
lineEntry:Show();
else
lineEntry:Hide();
end
end
end
-----------------------------------------
function Atr_SList:FindItemIndex (itemName)
local num = #self.items;
local n;
for n = 1,num do
if (zc.StringSame (itemName, self.items[n])) then
return n;
end
end
return 0;
end
-----------------------------------------
function Atr_SList:GetNumItems ()
return #self.items
end
-----------------------------------------
function Atr_SList:GetNthItemName (n)
if (n <= #self.items) then
return self.items[n];
end
return nil;
end
-----------------------------------------
function Atr_SList:IsItemOnList (itemName)
return (self:FindItemIndex(itemName) > 0);
end
-----------------------------------------
local function IsExactChecked ()
return Atr_Exact_Search_Button:GetChecked()
end
-----------------------------------------
function Atr_Exact_Search_Onclick ()
local searchText = Atr_Search_Box:GetText();
local isQuoted = zc.IsTextQuoted (searchText);
local isExactChecked = IsExactChecked();
if (isExactChecked and not isQuoted) then
Atr_Search_Box:SetText ("\""..searchText.."\"");
end
if ((not isExactChecked) and isQuoted) then
Atr_Search_Box:SetText (zc.TrimQuotes (searchText))
end
end
-----------------------------------------
function Atr_SetExactChecked (b)
if (b == nil) then
zz ("Atr_SetExactChecked requires a value")
end
return Atr_Exact_Search_Button:SetChecked(b)
end
-----------------------------------------
function Atr_Search_Onclick ()
Auctionator.Debug.Message( 'Atr_Search_Onclick')
local currentPane = Atr_GetCurrentPane()
local searchText = Atr_Search_Box:GetText()
Atr_Search_Button:Disable()
Atr_Adv_Search_Button:Disable()
Atr_Exact_Search_Button:Disable()
Atr_Buy1_Button:Disable()
Atr_AddToSListButton:Disable()
Atr_RemFromSListButton:Disable()
Atr_ClearAll()
currentPane:DoSearch( searchText )
Atr_ClearHistory()
end
function Auctionator.SearchUI.Disable()
Atr_Search_Button:Disable();
Atr_Adv_Search_Button:Disable();
Atr_Exact_Search_Button:Disable();
Atr_Buy1_Button:Disable();
Atr_AddToSListButton:Disable();
Atr_RemFromSListButton:Disable();
Atr_ClearAll();
end
function Atr_Search_Onclick_2( search )
Auctionator.Debug.Message( 'Atr_Search_Onclick_2' )
Auctionator.SearchUI.Disable()
local currentPane = Atr_GetCurrentPane();
currentPane:DoSearch2( search )
Atr_ClearHistory()
end
-----------------------------------------
function Atr_AddToRecents (searchText)
Auctionator.Debug.Message( 'Atr_AddToRecents', searchText )
local recentsList = AUCTIONATOR_SHOPPING_LISTS[1];
-- Added check to ensure recentsList is an AtrList, per issue #1
-- Todo: Understand how lists are getting created without the Atr_SList metatable...
if (recentsList and getmetatable(recentsList) == Atr_SList) then
local isRecentsShown = (gCurrentSList == recentsList);
local n = recentsList:FindItemIndex(searchText);
if (n > 14 or (not isRecentsShown and n > 0)) then
table.remove (recentsList.items, n);
end
n = recentsList:FindItemIndex(searchText);
if (n == 0) then
recentsList:AddItem (searchText);
end
if (isRecentsShown) then
FauxScrollFrame_SetOffset (Atr_Hlist_ScrollFrame, 0);
Atr_Hlist_ScrollFrame:SetVerticalScroll(0);
end
end
end
-----------------------------------------
function Atr_SetSearchText (searchText)
Atr_Search_Box:SetText (searchText)
Atr_Search_Box:ClearFocus()
end
-----------------------------------------
function Atr_Shop_OnFinishScan ()
Auctionator.Debug.Message( 'Atr_Shop_OnFinishScan' )
local currentPane = Atr_GetCurrentPane();
local searchText = currentPane.activeSearch.origSearchText;
Atr_SetSearchText (searchText);
local shplist = Atr_GetShoppingListFromSearchText (searchText)
if (shplist and shplist == gTempShoppingList) then
return -- don't add to recents list
end
Atr_AddToRecents(searchText)
if (#currentPane.activeScan.sortedData > 0) then
currentPane.currIndex = 1;
end
currentPane.UINeedsUpdate = true;
Atr_Search_Button:Enable();
Atr_Adv_Search_Button:Enable();
Atr_Exact_Search_Button:Enable();
end
-----------------------------------------
function Atr_DropDownSL_OnShow (self)
local curIndex = 1;
if (gCurrentSList) then
local x;
for x = 1,#AUCTIONATOR_SHOPPING_LISTS do
if (gCurrentSList == AUCTIONATOR_SHOPPING_LISTS[x]) then
curIndex = x;
break;
end
end
end
UIDropDownMenu_Initialize (self, Atr_DropDownSL_Initialize);
UIDropDownMenu_SetSelectedValue (self, curIndex);
UIDropDownMenu_SetWidth (self, 150);
UIDropDownMenu_JustifyText (self, "CENTER");
end
-----------------------------------------
function Atr_DropDownSL_Initialize(self)
local num = #AUCTIONATOR_SHOPPING_LISTS;
local x;
for x = 1,num do
local slist = AUCTIONATOR_SHOPPING_LISTS[x];
Atr_Dropdown_AddPick (self, slist.name, x, Atr_DropDownSL_OnClick);
end
end
-----------------------------------------
function Atr_DropDownSL_OnClick(info)
UIDropDownMenu_SetSelectedValue (info.owner, info.value);
gCurrentSList = AUCTIONATOR_SHOPPING_LISTS[info.value];
Atr_SetUINeedsUpdate();
end
-----------------------------------------
function Atr_SEntryOnClick (self)
local entryIndex = self:GetID();
local itemName = gCurrentSList.items[entryIndex];
if (itemName) then
Atr_SetSearchText (itemName);
if (IsAltKeyDown()) then
Atr_GetCurrentPane():ClearSearch();
Atr_RemFromSListOnClick();
Atr_SetSearchText ("");
else
Atr_Search_Onclick ();
end
Atr_Shop_UpdateUI();
end
-- gCurrentSList:DisplayX(); -- for the highlight
end
-----------------------------------------
function Atr_RenameSList(index, newname)
if (newname == nil or newname == "") then
return
end
local oldname = AUCTIONATOR_SHOPPING_LISTS[index].name
AUCTIONATOR_SHOPPING_LISTS[index].name = newname
-- in case it's the currently selected one
-- local curIndex = UIDropDownMenu_GetSelectedValue(Atr_DropDownSL)
-- if (curIndex and curIndex > 0) then
-- UIDropDownMenu_SetText (Atr_DropDownSL, AUCTIONATOR_SHOPPING_LISTS[curIndex].name) -- needed to fix bug in UIDropDownMenu
-- end
-- run thru all the lists and fix up any lists that contain this list
local n
for n = 1, #AUCTIONATOR_SHOPPING_LISTS do
local slist = AUCTIONATOR_SHOPPING_LISTS[n]
local foundIndex = slist:FindItemIndex("{ "..oldname.." }")
if (foundIndex > 0) then
slist.items[foundIndex] = "{ "..newname.." }"
end
if (n == curIndex) then
slist:DisplayX()
Atr_SetUINeedsUpdate();
end
end
end
-----------------------------------------
StaticPopupDialogs["ATR_NEW_SHOPPING_LIST"] = {
text = "",
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = 1,
maxLetters = 32,
OnAccept = function(self)
local text = self.editBox:GetText();
Atr_SList.create( text )
end,
EditBoxOnEnterPressed = function(self)
local text = self:GetParent().editBox:GetText();
Atr_SList.create( text )
self:GetParent():Hide();
end,
OnShow = function(self)
self.editBox:SetText("");
self.editBox:SetFocus();
end,
timeout = 0,
exclusive = 1,
whileDead = 1,
hideOnEscape = 1
};
-----------------------------------------
function Atr_NewSlist_OnClick ()
StaticPopupDialogs["ATR_NEW_SHOPPING_LIST"].text = ZT("Name for your new shopping list");
StaticPopup_Show("ATR_NEW_SHOPPING_LIST");
end
-----------------------------------------
function Atr_MngSLists_OnClick ()
InterfaceOptionsFrame_OpenToCategory ("Shopping Lists");
local slist
local currentPane = Atr_GetCurrentPane()
if (gCurrentSList) then
if (not gCurrentSList.isRecents) then
slist = gCurrentSList
elseif (currentPane and currentPane.activeSearch) then
local searchText = strtrim (currentPane.activeSearch.searchText, "{}")
slist = Atr_SList.FindByName (strtrim (searchText))
end
end
if (slist) then
local n
for n=2,#AUCTIONATOR_SHOPPING_LISTS do
if (AUCTIONATOR_SHOPPING_LISTS[n] == slist) then
Atr_ShpListsEntry_Select(n)
Atr_ShpListsEntry_ScrollToShow(n)
return
end
end
end
end
-----------------------------------------
function Atr_AddToSListOnClick ()
local currentPane = Atr_GetCurrentPane();
if (gCurrentSList) then
if (#gCurrentSList.items >= ATR_MAXNUM_ITEMS_ON_SHOPPING_LIST) then
Atr_Error_Text:SetText (string.format (ZT("You may have no more than\n\n%d items on a shopping list."), ATR_MAXNUM_ITEMS_ON_SHOPPING_LIST));
Atr_Error_Frame.withMask = 1;
Atr_Error_Frame:Show ();
else
gCurrentSList:AddItem (Atr_Search_Box:GetText());
Atr_SetUINeedsUpdate();
end
end
end
-----------------------------------------
function Atr_RemFromSListOnClick ()
local currentPane = Atr_GetCurrentPane();
if (gCurrentSList) then
gCurrentSList:RemoveItem (Atr_Search_Box:GetText());
Atr_SetUINeedsUpdate();
end
end
-----------------------------------------
function Atr_SrchSList_OnClick ()
if (gCurrentSList) then
local searchText = "{ "..gCurrentSList.name.." }";
Atr_SetSearchText(searchText)
Atr_Search_Onclick()
end
end
-----------------------------------------
function Atr_ShpList_Validate ()
if (gCurrentSList and getmetatable (gCurrentSList) ~= Atr_SList) then
zc.msg_badErr ("gCurrentSList bad metatable; type gCurrentSList: ", type (gCurrentSList))
end
zz ("num shopping lists: ", #AUCTIONATOR_SHOPPING_LISTS)
local x, slist
for x = 1,#AUCTIONATOR_SHOPPING_LISTS do
slist = AUCTIONATOR_SHOPPING_LISTS[x]
if (slist == nil) then
zz ("slist["..x.."] is nil")
elseif (getmetatable (slist) ~= Atr_SList) then
zc.msg_badErr ("slist["..x.."] bad metatable; type: ", type (slist))
else
zz ("slist["..x.."] is valid")
end
end
end
-----------------------------------------
function Atr_Shop_Idle ()
local searchText = Atr_Search_Box:GetText();
local isQuoted = zc.IsTextQuoted (searchText);
Atr_SetExactChecked (isQuoted)
end
-----------------------------------------
function Atr_Shop_UpdateUI ()
local currentPane = Atr_GetCurrentPane();
Atr_AddToSListButton:Disable();
Atr_RemFromSListButton:Disable();
Atr_SrchSListButton:Disable();
if (gCurrentSList == nil) then
Atr_ShpList_SetToRecents()
end
if (getmetatable (gCurrentSList) ~= Atr_SList) then
Atr_ShpList_Validate()
end
if (gCurrentSList and getmetatable (gCurrentSList) == Atr_SList) then -- somehow gCurrentSList:DisplayX is sometimes nil - not sure why yet
gCurrentSList:DisplayX ();
local iName = Atr_Search_Box:GetText();
if (gCurrentSList:IsItemOnList (iName)) then
Atr_RemFromSListButton:Enable();
elseif (iName ~= "" and iName ~= nil and gCurrentSList ~= AUCTIONATOR_SHOPPING_LISTS[1]) then
Atr_AddToSListButton:Enable();
end
if (gCurrentSList ~= AUCTIONATOR_SHOPPING_LISTS[1]) then
Atr_SrchSListButton:Enable();
end
end
Atr_SaveThisList_Button:Hide()
Atr_Back_Button:Hide()
if (currentPane.activeSearch:NumScans() > 1 and not currentPane:IsScanNil()) then
Atr_Back_Button:Show()
elseif (gTempShoppingList) then
local listWithSameName = Atr_SList.FindByName (gTempShoppingList.name, { skipTempList=true } )
if (gTempShoppingList == currentPane.activeSearch.shplist and #gTempShoppingList.items > 1 and listWithSameName == nil) then
Atr_SaveThisList_Button:Show()
end
end
end
-----------------------------------------
function Atr_ShpList_SetToRecents()
gCurrentSList = AUCTIONATOR_SHOPPING_LISTS[1]
UIDropDownMenu_SetSelectedValue(Atr_DropDownSL, 1);
UIDropDownMenu_SetText (Atr_DropDownSL, gCurrentSList.name); -- needed to fix bug in UIDropDownMenu
end
-----------------------------------------
function Atr_Onclick_SaveTempList()
if (gTempShoppingList) then
table.insert (AUCTIONATOR_SHOPPING_LISTS, gTempShoppingList)
table.sort (AUCTIONATOR_SHOPPING_LISTS, Atr_SortSlists);
Atr_ShpList_SetToRecents()
Atr_AddToRecents("{ "..gTempShoppingList.name.." }") -- nice visual confirmation
gTempShoppingList = nil
Atr_SetUINeedsUpdate()
end
end
-----------------------------------------
function Atr_Adv_Search_Onclick()
Auctionator.Debug.Message( 'Atr_Adv_Search_Onclick' )
local searchText = Atr_Search_Box:GetText()
Atr_Adv_Search_Dialog:Show()
Atr_Adv_Search_Button:SetChecked( false )
if Atr_IsCompoundSearch( searchText ) then
local queryString, filter, minLevel, maxLevel, minItemLevel, maxItemLevel =
Atr_ParseCompoundSearch( searchText )
Atr_AS_Searchtext:SetText( queryString )
local parentFilter, subFilter = Auctionator.Filter.Find( filter.key )
Atr_Dropdown_Refresh( Atr_ASDD_Class )
UIDropDownMenu_SetSelectedValue( Atr_ASDD_Class, parentFilter.key )
Atr_Dropdown_Refresh( Atr_ASDD_Subclass )
UIDropDownMenu_SetSelectedValue( Atr_ASDD_Subclass, subFilter.key )
if minLevel == nil then
minLevel = ""
end
if maxLevel == nil then
maxLevel = ""
end
Atr_AS_Minlevel:SetText( minLevel )
Atr_AS_Maxlevel:SetText( maxLevel )
if minItemLevel == nil then
minItemLevel = ""
end
if maxItemLevel == nil then
maxItemLevel = ""
end
Atr_AS_MinItemlevel:SetText( minItemLevel )
Atr_AS_MaxItemlevel:SetText( maxItemLevel )
else
Atr_AS_Searchtext:SetText( searchText )
end
end
-----------------------------------------
function Atr_ASDD_Class_OnShow( self )
UIDropDownMenu_Initialize( self, Atr_ASDD_Class_Initialize )
UIDropDownMenu_SetSelectedValue( self, 0 )
end
-----------------------------------------
function Atr_ASDD_Class_Initialize( self )
Atr_Dropdown_AddPick( Atr_ASDD_Subclass, Auctionator.Constants.FilterDefault, 0 )
for index, filterEntry in ipairs( Auctionator.Filters ) do
Atr_Dropdown_AddPick( self, filterEntry.name, filterEntry.key, Atr_ASDD_Class_OnClick )
end
end
-----------------------------------------
function Atr_ASDD_Class_OnClick( info )
UIDropDownMenu_SetSelectedValue( info.owner, info.value )
Atr_Dropdown_Refresh( Atr_ASDD_Subclass )
end
-----------------------------------------
function Atr_ASDD_Subclass_OnShow (self)
UIDropDownMenu_Initialize( self, Atr_ASDD_Subclass_Initialize )
UIDropDownMenu_SetSelectedValue( self, 0 )
end
-----------------------------------------
function Atr_ASDD_Subclass_Initialize( self )
Atr_Dropdown_AddPick( Atr_ASDD_Subclass, Auctionator.Constants.FilterDefault, 0 )
local parentFilterKey = UIDropDownMenu_GetSelectedValue( Atr_ASDD_Class )
local parentFilter = Auctionator.FilterLookup[ parentFilterKey ]
Auctionator.Debug.Message( 'parent filter key is ', parentFilterKey )
Auctionator.Util.Print( parentFilter, parentFilterKey )
-- TODO not a fan of this special casing bullshit
if parentFilterKey == 0 then
return
end
for index, filterEntry in ipairs( parentFilter.subClasses ) do
Atr_Dropdown_AddPick( Atr_ASDD_Subclass, filterEntry.name, filterEntry.key )
end
if Atr_IsWeaponType( parentFilter.classID ) or Atr_IsArmorType( parentFilter.classID ) then
Atr_AS_ILevRange_Label:Show()
Atr_AS_ILevRange_Dash:Show()
Atr_AS_MinItemlevel:Show()
Atr_AS_MaxItemlevel:Show()
else
Atr_AS_ILevRange_Label:Hide()
Atr_AS_ILevRange_Dash:Hide()
Atr_AS_MinItemlevel:Hide()
Atr_AS_MaxItemlevel:Hide()
end
end
-----------------------------------------
function Atr_Adv_Search_Reset()
Atr_AS_Searchtext:SetText ("");
Atr_Dropdown_Refresh (Atr_ASDD_Class);
UIDropDownMenu_SetSelectedValue (Atr_ASDD_Class, 0);
Atr_Dropdown_Refresh (Atr_ASDD_Subclass);
UIDropDownMenu_SetSelectedValue (Atr_ASDD_Subclass, 0);
Atr_AS_Minlevel:SetText ("");
Atr_AS_Maxlevel:SetText ("");
Atr_AS_MinItemlevel:SetText ("");
Atr_AS_MaxItemlevel:SetText ("");
end
-----------------------------------------
function Atr_Adv_Search_Do()
local parentFilterKey = UIDropDownMenu_GetSelectedValue( Atr_ASDD_Class )
local subClassFilterKey = UIDropDownMenu_GetSelectedValue( Atr_ASDD_Subclass )
local filterKey = parentFilterKey
if subClassFilterKey ~= 0 then
filterKey = subClassFilterKey
end
if filterKey == 0 then
zc.msg_anm ("|cffff0000Error getting itemClass from menu|r. ", parentFilterKey, subClassFilterKey )
Atr_Adv_Search_Dialog:Hide()
return
end
Auctionator.Debug.Message( 'Search Text: ', filterKey )
local filter = Auctionator.FilterLookup[ filterKey ]
if filter.parentKey ~= nil then
filter = Auctionator.FilterLookup[ filter.parentKey ]
end
local minLevel = Atr_AS_Minlevel:GetNumber()
local maxLevel = Atr_AS_Maxlevel:GetNumber()
local text = Atr_AS_Searchtext:GetText()
local minItemLevel = 0
local maxItemLevel = 0
Auctionator.Debug.Message( 'filter.classID is ', filter.classID )
if Atr_IsWeaponType( filter.classID ) or Atr_IsArmorType( filter.classID ) then
minItemLevel = Atr_AS_MinItemlevel:GetNumber()
maxItemLevel = Atr_AS_MaxItemlevel:GetNumber()
end
local tokens = {}
table.insert( tokens, text )
table.insert( tokens, filterKey )
table.insert( tokens, minLevel )
table.insert( tokens, maxLevel )
table.insert( tokens, minItemLevel )
table.insert( tokens, maxItemLevel )
local tempSearchText = table.concat( tokens, Auctionator.Constants.AdvancedSearchDivider )
Atr_SetSearchText( tempSearchText )
Atr_Search_Onclick()
Atr_Adv_Search_Dialog:Hide()
end
-- function Atr_Adv_Search_Do()
-- Auctionator.Debug.Message( 'Atr_Adv_Search_Do' )
-- local parentKey = UIDropDownMenu_GetSelectedValue( Atr_ASDD_Class )
-- local subClassKey = UIDropDownMenu_GetSelectedValue( Atr_ASDD_Subclass )
-- local minLevel = Atr_AS_Minlevel:GetNumber()
-- local maxLevel = Atr_AS_Maxlevel:GetNumber()
-- local text = Atr_AS_Searchtext:GetText()
-- local search = Auctionator.SearchQuery:new({
-- text = text,
-- minLevel = minLevel,
-- maxLevel = maxLevel,
-- parentKey = parentKey,
-- subClassKey = subClassKey,
-- advanced = true
-- })
-- Atr_SetSearchText( search:ToString() )