-
Notifications
You must be signed in to change notification settings - Fork 1
/
GathererInfo.lua
696 lines (603 loc) · 23.2 KB
/
GathererInfo.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
--[[
Gatherer Report/Search UI
]]--
-- Scrolling variables
GATHERERINFO_TO_DISPLAY=15;
GATHERERINFO_FRAME_HEIGHT=15;
GATHERERINFO_SUBFRAMES = { "GathererInfo_ReportFrame", "GathererInfo_SearchFrame" };
-- Defaults
currentNode = "";
GathererInfo_LastSortType = "gtype";
GathererInfo_LastSearchSortType= "Cname";
GathererInfo_AutoRegion = true;
GathererInfo_LastSortReverse = false;
GathererInfoContinents = {};
GathererInfoZones = {};
numGathererInfo = 0;
GI_totalCount = 0;
-- show display frame
function showGathererInfo(tab)
local myTab = 1;
if ( tab ) then myTab = tab; end;
if ( not GathererInfo_DialogFrame:IsShown() ) then
GathererInfo_DialogFrame:Show();
PanelTemplates_SetTab(GathererInfo_DialogFrame, myTab);
ToggleGathererInfo_Dialog(GATHERERINFO_SUBFRAMES[myTab]);
else
GathererInfo_DialogFrame:Hide();
end
end
function GathererInfo_LoadContinents(...)
for c=1, arg.n, 1 do
GathererInfoContinents[c] = {}
GathererInfoContinents[c] = arg[c];
GathererInfoContinents[arg[c]] = c;
GathererInfo_LoadZones(c, GetMapZones(c));
end
end
function GathererInfo_LoadZones(c, ...)
for z=1, arg.n, 1 do
local zname = arg[z];
if ( not GathererInfoZones[c] ) then GathererInfoZones[c] = {}; end
GathererInfoZones[c][zname] = { continent=c, zone=z };
GathererInfoZones[c][z] = { continent=c, zone=zname };
end
end
-- ********************************************************************
-- dropdown menu functions
-- Continent
function GathererInfo_LocContinentDropDown_Initialize()
local index;
local info = {};
for index in GatherItems do
-- grab zone text from table initiated by Gatherer Main
info.text = GathererInfoContinents[index];
info.checked = nil;
info.func = GathererInfo_LocContinentDropDown_OnClick;
UIDropDownMenu_AddButton(info);
end
end
function GathererInfo_LocContinentDropDown_OnClick()
UIDropDownMenu_SetSelectedID(GathererInfo_LocContinentDropDown, this:GetID());
UIDropDownMenu_SetSelectedID(GathererInfo_LocZoneDropDown, 0);
UIDropDownMenu_SetText("", GathererInfo_LocZoneDropDown);
UIDropDownMenu_ClearAll(GathererInfo_LocZoneDropDown);
UIDropDownMenu_Initialize(GathererInfo_LocZoneDropDown, GathererInfo_LocZoneDropDown_Initialize);
local j=1;
while (j < GATHERERINFO_TO_DISPLAY+1) do
getglobal("GathererInfo_FrameButton"..j):Hide();
j = j+1;
end
end
-- Zone
function GathererInfo_LocZoneDropDown_Initialize()
local index;
local info = {};
local gi_cont, gi_t_cont;
gi_t_cont = UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown);
if ( gi_t_cont and gi_t_cont ~= nil and gi_t_cont ~= "") then
gi_cont = GathererInfoContinents[gi_t_cont];
for index in GatherItems[gi_cont] do
-- grab zone text from table initiated by Gatherer Main
info.text = GathererInfoZones[gi_cont][index].zone;
info.checked = nil;
info.func = GathererInfo_LocZoneDropDown_OnClick;
UIDropDownMenu_AddButton(info);
end
end
end
function GathererInfo_LocZoneDropDown_OnClick()
local gi_cont, gi_zone;
local l_zone, node_idx, index;
UIDropDownMenu_SetSelectedID(GathererInfo_LocZoneDropDown, this:GetID());
GathererInfo_AutoRegion = false;
gi_cont = GathererInfoContinents[UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown)];
gi_zone = GathererInfoZones[gi_cont][UIDropDownMenu_GetText(GathererInfo_LocZoneDropDown)].zone;
for l_zone in GatherItems[gi_cont] do
GI_totalCount = 0;
numGathererInfo=0;
for node_idx in GatherItems[gi_cont][gi_zone] do
for index in GatherItems[gi_cont][gi_zone][node_idx] do
GI_totalCount = GI_totalCount + GatherItems[gi_cont][gi_zone][node_idx][index].count;
numGathererInfo = numGathererInfo + 1;
end
end
end
GathererInfo_Update();
end
-- ********************************************************************
-- Display frame initialization
function GathererInfo_SetDefaultLocation()
local gi_t_cont = GathererInfoContinents[GetCurrentMapContinent()];
local gi_t_zone = GetRealZoneText();
local gi_cont = GetCurrentMapContinent();
local gi_zone = nil;
local l_cnt, l_zone;
local node_idx, index;
local found = 0;
if ( GetRealZoneText() and GathererInfoZones[gi_cont] and GathererInfoZones[gi_cont][GetRealZoneText()] ) then
gi_zone = GathererInfoZones[gi_cont][GetRealZoneText()].zone;
else
gi_zone = "unknown";
end
for l_cnt in GatherItems do
if( l_cnt == gi_cont ) then
UIDropDownMenu_SetSelectedName(GathererInfo_LocContinentDropDown, gi_t_cont);
UIDropDownMenu_SetText(gi_t_cont, GathererInfo_LocContinentDropDown);
for l_zone in GatherItems[gi_cont] do
if ( l_zone == gi_zone and GathererInfo_AutoRegion == true) then
UIDropDownMenu_SetSelectedName(GathererInfo_LocZoneDropDown, gi_t_zone);
UIDropDownMenu_SetText(gi_t_zone, GathererInfo_LocZoneDropDown);
GI_totalCount = 0;
numGathererInfo=0;
found = 1;
for node_idx in GatherItems[gi_cont][gi_zone] do
for index in GatherItems[gi_cont][gi_zone][node_idx] do
GI_totalCount = GI_totalCount + GatherItems[gi_cont][gi_zone][node_idx][index].count;
numGathererInfo = numGathererInfo + 1;
end
end
GathererInfo_Update();
end
end
end
end
end
-- update display frame relative to scrollbar
function GathererInfo_Update()
local node_idx, index;
local gatherInfoOffset = FauxScrollFrame_GetOffset(GathererInfo_ListScrollFrame);
local gi_cont, gi_zone, gi_loc;
local gatherInfoIndex;
local showScrollBar = nil;
local button;
local i = 1;
GITT = {};
-- Get continent, zone
if ( UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown) and
UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown) ~= "")
then
gi_cont = GathererInfoContinents[UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown)];
else
gi_cont = GetCurrentMapContinent();
end
if ( UIDropDownMenu_GetText(GathererInfo_LocZoneDropDown) and
UIDropDownMenu_GetText(GathererInfo_LocZoneDropDown) ~= "")
then
gi_zone = GathererInfoZones[gi_cont][UIDropDownMenu_GetText(GathererInfo_LocZoneDropDown)].zone;
else
if ( GetRealZoneText() and GathererInfoZones[gi_cont] and GathererInfoZones[gi_cont][GetRealZoneText()] ) then
gi_zone = GathererInfoZones[gi_cont][GetRealZoneText()].zone;
else
gi_zone = nil;
end
end
-- if loc exists in stored base
if ( GatherItems and gi_cont and gi_zone and GatherItems[gi_cont] and
GatherItems[gi_cont][gi_zone] )
then
if ( GatherItems and GatherItems[gi_cont] and GatherItems[gi_cont][gi_zone] )
then
local typeNodeCount = {};
typeNodeCount[0]=0;
typeNodeCount[1]=0;
typeNodeCount[2]=0;
typeNodeCount[3]=0;
for node_idx in GatherItems[gi_cont][gi_zone] do
for index in GatherItems[gi_cont][gi_zone][node_idx] do
local gtype;
if ( type(GatherItems[gi_cont][gi_zone][node_idx][index].gtype) =="number" )
then
gtype = GatherItems[gi_cont][gi_zone][node_idx][index].gtype;
else
gtype = Gatherer_EGatherType[GatherItems[gi_cont][gi_zone][node_idx][index].gtype]
end
typeNodeCount[gtype] = typeNodeCount[gtype] + GatherItems[gi_cont][gi_zone][node_idx][index].count;
end
end
-- assign values
for node_idx in GatherItems[gi_cont][gi_zone] do
local nodeCount;
for index in GatherItems[gi_cont][gi_zone][node_idx] do
local amount = GatherItems[gi_cont][gi_zone][node_idx][index].count;
local gtype;
if ( type(GatherItems[gi_cont][gi_zone][node_idx][index].gtype) == "number" )
then
gtype = GatherItems[gi_cont][gi_zone][node_idx][index].gtype;
else
gtype = Gatherer_EGatherType[GatherItems[gi_cont][gi_zone][node_idx][index].gtype]
end
nodeCount = typeNodeCount[gtype];
local found=0;
local findex;
for findex in GITT do
if ( GITT[findex].name == node_idx ) then
found = findex;
end
end
if ( found == 0 ) then
GITT[i] = {};
GITT[i].name = node_idx;
if ( type(GatherItems[gi_cont][gi_zone][node_idx][index].gtype) == "number" ) then
GITT[i].gatherType = Gatherer_EGatherType[GatherItems[gi_cont][gi_zone][node_idx][index].gtype];
else
GITT[i].gatherType = GatherItems[gi_cont][gi_zone][node_idx][index].gtype;
end
GITT[i].typePercent = tonumber(format("%.1f",( amount / nodeCount ) * 100));
GITT[i].densityPercent = tonumber(format("%.1f",( amount / GI_totalCount ) * 100));
-- divide by zero check
if ( GITT[i].typePercent == nil ) then GITT[i].typePercent = 0; end
if ( GITT[i].densityPercent == nil ) then GITT[i].densityPercent = 0; end
GITT[i].amount = tonumber(amount);
if ( type(GatherItems[gi_cont][gi_zone][node_idx][index].icon) == "number" ) then
GITT[i].texture = Gather_IconSet["iconic"][GITT[i].gatherType][Gatherer_GetDB_IconIndex(GatherItems[gi_cont][gi_zone][node_idx][index].icon, GITT[i].gatherType)];
else
GITT[i].texture = Gather_IconSet["iconic"][GITT[i].gatherType][GatherItems[gi_cont][gi_zone][node_idx][index].icon];
end
GITT[i].nodeCount = nodeCount;
GITT[i].gi = gatherInfoOffset + i;
i = i + 1;
else
GITT[found].amount = GITT[found].amount + tonumber(amount);
GITT[found].typePercent = tonumber(format("%.1f",( GITT[found].amount / GITT[found].nodeCount ) * 100));
GITT[found].densityPercent = tonumber(format("%.1f",( GITT[found].amount / GI_totalCount ) * 100));
-- divide by zero check
if ( GITT[found].typePercent == nil ) then GITT[found].typePercent = 0; end
if ( GITT[found].densityPercent == nil ) then GITT[found].densityPercent = 0; end
found = 0;
end
end
end
end
SortGathererInfo(GathererInfo_LastSortType, false);
GathererInfo_totalcount:SetText(string.gsub(string.gsub(GATHERER_REPORT_SUMMARY, "#", GI_totalCount), "&", numGathererInfo));
end
end
-- Add items in display frame
function GathererInfo_additem_table(gatherName, gatherNumber, gatherTexture, gatherType, typePercent, densityPercent, GIlocation, GIIndex)
if ( GIlocation < GATHERERINFO_TO_DISPLAY +1) then
getglobal("GathererInfo_FrameButton"..GIlocation).gatherIndex = GIIndex;
getglobal("GathererInfo_FrameButton"..GIlocation.."Icon"):SetTexture(gatherTexture);
getglobal("GathererInfo_FrameButton"..GIlocation.."Type"):SetText(gatherType);
getglobal("GathererInfo_FrameButton"..GIlocation.."Gatherable"):SetText(gatherName);
getglobal("GathererInfo_FrameButton"..GIlocation.."Number"):SetText(gatherNumber);
getglobal("GathererInfo_FrameButton"..GIlocation.."TypePercent"):SetText(typePercent);
getglobal("GathererInfo_FrameButton"..GIlocation.."DensityPercent"):SetText(densityPercent);
getglobal("GathererInfo_FrameButton"..GIlocation):Show();
end
end
-- **************************************************************************
-- Sort functions (common to Report and Search)
function SortGathererInfo(sortType, reverse, search)
local compstr = {};
local ref_ind = 0;
local ind, newind;
local displayed=1;
local offSet = FauxScrollFrame_GetOffset(GathererInfo_ListScrollFrame);
local key1, key2, key3;
local indexToShow=0;
local search_stub;
if (search) then
search_stub = search;
else
search_stub = "";
end
for ind in GITT do
indexToShow = indexToShow + 1;
compstr[ind]= {}
-- report sort types
if ( sortType == "gtype" ) then -- keys: type, % per type, name (default sort)
key1 = GITT[ind].gatherType;
key2 = format("%.6f", GITT[ind].typePercent / 10000);
key3 = GITT[ind].name;
elseif ( sortType == "percent") then -- keys: % per type, type, name
key1 = format("%.6f", GITT[ind].typePercent / 10000);
key2 = GITT[ind].gatherType;
key3 = GITT[ind].name;
elseif ( sortType == "density" ) then -- keys: % density, type, name
key1 = format("%.6f", GITT[ind].densityPercent / 10000);
key2 = GITT[ind].gatherType;
key3 = GITT[ind].name;
elseif ( sortType == "name" ) then -- keys: name, type, % type
key1 = GITT[ind].name;
key2 = GITT[ind].gatherType;
key3 = format("%.6f", GITT[ind].typePercent / 10000);
elseif ( sortType == "amount" ) then -- keys: amount, type, name
key1 = format("%.6f", GITT[ind].amount / 10000);
key2 = GITT[ind].gatherType;
key3 = GITT[ind].name;
elseif ( search_stub and search_stub ~= "" ) then
offSet = FauxScrollFrame_GetOffset(GathererInfo_SearchListScrollFrame)
-- handle Search sort types
if ( sortType == "Cname" ) then
key1 = GITT[ind].contName;
key2 = GITT[ind].zoneName;
key3 = format("%.6f", GITT[ind].amount / 10000);
elseif ( sortType == "Zname" ) then
key1 = GITT[ind].zoneName;
key2 = GITT[ind].contName;
key3 = format("%.6f", GITT[ind].amount / 10000);
elseif ( sortType == "Namount" ) then
key1 = format("%.6f", GITT[ind].amount / 10000);
key2 = GITT[ind].contName;
key3 = GITT[ind].zoneName;
elseif ( sortType == "Npercent" ) then
key1 = format("%.6f", GITT[ind].typePercent / 10000);
key2 = GITT[ind].contName;
key3 = GITT[ind].zoneName;
elseif ( sortType == "Ndensity" ) then
key1 = format("%.6f", GITT[ind].densityPercent / 10000);
key2 = GITT[ind].contName;
key3 = GITT[ind].zoneName;
end
end
-- build sort string
compstr[ind] = key1.."/"..key2.."/"..key3.."#"..ind
end
-- call sort function
if ( reverse and not GathererInfo_LastSortReverse) then
sort(compstr, GI_reverse_sort);
GathererInfo_LastSortReverse = true;
else
sort(compstr);
GathererInfo_LastSortReverse = false;
end
-- display sorted items
for newind, data in compstr do
recup = tonumber(strsub(data, string.find(data, "#")+1));
if (newind == 1) then
ref_ind = GITT[1].gi
else
ref_ind= ref_ind + 1;
end
if ( newind > offSet and displayed < GATHERERINFO_TO_DISPLAY+1) then
if ( search_stub == "" ) then
GathererInfo_additem_table(GITT[recup].name, GITT[recup].amount, GITT[recup].texture, GITT[recup].gatherType, GITT[recup].typePercent, GITT[recup].densityPercent, newind - offSet, ref_ind);
elseif ( search_stub == "Search" ) then
GathererInfo_additem_searchtable(GITT[recup].contName, GITT[recup].amount,
GITT[recup].zoneName, GITT[recup].typePercent,
GITT[recup].densityPercent, newind - offSet, ref_ind)
end
displayed=displayed+1;
end
end
local j=displayed;
while (j < GATHERERINFO_TO_DISPLAY+1) do
getglobal("GathererInfo_"..search_stub.."FrameButton"..j):Hide();
j = j+1;
end
FauxScrollFrame_Update(getglobal("GathererInfo_"..search_stub.."ListScrollFrame"), indexToShow, GATHERERINFO_TO_DISPLAY, GATHERERINFO_FRAME_HEIGHT);
if( search_stub == "") then
GathererInfo_LastSortType = sortType;
elseif ( search_stub == "Search" ) then
GathererInfo_LastSearchSortType = sortType;
end
end
function GI_reverse_sort(token1, token2)
return token1 > token2;
end
-- ***********************************************************
-- Search UI functions
function GathererInfo_GatherTypeDropDown_Initialize()
local index;
local info = {};
for index in Gatherer_EGatherType do
if ( index ~= "Default" and type(index) == "string" ) then
info.text = index;
info.checked = nil;
info.func = GathererInfo_GatherType_OnClick;
UIDropDownMenu_AddButton(info);
end
end
end
function GathererInfo_GatherType_OnClick()
UIDropDownMenu_SetSelectedID(GathererInfo_GatherTypeDropDown, this:GetID());
UIDropDownMenu_SetSelectedID(GathererInfo_GatherItemDropDown, 0);
UIDropDownMenu_SetText("", GathererInfo_GatherItemDropDown);
UIDropDownMenu_ClearAll(GathererInfo_GatherItemDropDown);
UIDropDownMenu_Initialize(GathererInfo_GatherItemDropDown, GathererInfo_GatherItemDropDown_Initialize);
local j=1;
while (j < GATHERERINFO_TO_DISPLAY+1) do
getglobal("GathererInfo_SearchFrameButton"..j):Hide();
j = j+1;
end
end
function GathererInfo_GatherItemDropDown_Initialize()
local index;
local info = {};
local selectedGatherTypeText = UIDropDownMenu_GetText(GathererInfo_GatherTypeDropDown);
local selectedGatherType
if ( selectedGatherTypeText ) then
selectedGatherType = Gatherer_EGatherType[selectedGatherTypeText];
for index in Gather_DB_IconIndex[selectedGatherType] do
if (index ~= "default" ) then
info.text = index;
info.checked = nil;
info.func = GathererInfo_GatherItem_OnClick;
UIDropDownMenu_AddButton(info);
end
end
end
end
function GathererInfo_GatherItem_OnClick()
local item_to_search, search_item;
local gi_cont, gi_zone, gi_node, gi_index;
UIDropDownMenu_SetSelectedID(GathererInfo_GatherItemDropDown, this:GetID());
item_to_search = UIDropDownMenu_GetText(GathererInfo_GatherItemDropDown)
_, _, search_item = string.find(item_to_search, "^([^ ]+)");
GI_totalCount = 0;
for gi_cont in GatherItems do
for gi_zone in GatherItems[gi_cont] do
for gi_node in GatherItems[gi_cont][gi_zone] do
if ( string.find(gi_node, search_item, 1, true) ) then
local skip_node=-1;
for gi_index in GatherItems[gi_cont][gi_zone][gi_node] do
if ( skip_node == -1 ) then
local locIcon, locGtype;
-- check gather type
locGtype = GatherItems[gi_cont][gi_zone][gi_node][gi_index].gtype;
if ( locGtype and type(locGtype) == "string" ) then
locGtype = Gatherer_EGatherType[locGtype];
end
locIcon = GatherItems[gi_cont][gi_zone][gi_node][gi_index].icon;
if ( (type(locIcon) == "string" and locIcon == search_item) or
(type(locIcon) == "number" and locIcon == Gather_DB_IconIndex[locGtype][item_to_search] )) then
skip_node=0
GI_totalCount = GI_totalCount +1;
else
skip_node=1
end
elseif ( skip_node == 0 ) then
GI_totalCount = GI_totalCount +1;
else
break;
end
end
end
end
end
end
GathererInfo_SearchUpdate();
end
function GathererInfo_SearchUpdate()
local node_idx, index;
local gatherInfoOffset = FauxScrollFrame_GetOffset(GathererInfo_SearchListScrollFrame);
local item_to_search = UIDropDownMenu_GetText(GathererInfo_GatherItemDropDown);
local search_item;
local gi_cont, gi_zone, gi_loc;
local gatherInfoIndex;
local showScrollBar = nil;
local button;
local i = 1;
GITT = {};
-- if database exists
if ( GatherItems and item_to_search ) then
_, _, search_item = string.find(item_to_search, "([^ ]+)");
for gi_cont in GatherItems do
if ( gi_cont == 0 or not GathererInfoZones[gi_cont] ) then
Gatherer_ChatPrint("Gatherer: Warning invalid continent index ("..gi_cont..") found in data.");
else
for gi_zone in GatherItems[gi_cont] do
if ( gi_zone == 0 or not GathererInfoZones[gi_cont][gi_zone] ) then
Gatherer_ChatPrint("Gatherer: Warning invalid zone index ("..gi_zone..") found in "..gi_cont.." continent data.");
else
local nodeCount = 0;
for node_idx in GatherItems[gi_cont][gi_zone] do
for index in GatherItems[gi_cont][gi_zone][node_idx] do
nodeCount = nodeCount + 1;
end
end
-- assign values
for node_idx in GatherItems[gi_cont][gi_zone] do
local skip_node = -1;
if ( string.find(node_idx, search_item, 1, true) ) then
local amount = 0;
for index in GatherItems[gi_cont][gi_zone][node_idx] do
if ( skip_node == -1 ) then
local locIcon, locGtype;
-- check gather type
locGtype = GatherItems[gi_cont][gi_zone][node_idx][index].gtype;
if ( type(locGtype) == "string" ) then
locGtype = Gatherer_EGatherType[locGtype];
end
locIcon = GatherItems[gi_cont][gi_zone][node_idx][index].icon;
if ( (type(locIcon) == "string" and locIcon == search_item) or
(type(locIcon) == "number" and locIcon == Gather_DB_IconIndex[locGtype][item_to_search] )) then
skip_node=0
amount = amount + 1;
else
skip_node=1
end
elseif ( skip_node == 0 ) then
amount = amount + 1;
else
break;
end
end
if ( skip_node ~= 1 ) then
local found=0;
local findex;
for findex in GITT do
if ( GITT[findex].zoneName and GathererInfoZones[gi_cont][gi_zone].zone and
GITT[findex].zoneName == GathererInfoZones[gi_cont][gi_zone].zone ) then
found = findex;
end
end
if ( found == 0 ) then
GITT[i] = {};
GITT[i].contName = GathererInfoContinents[gi_cont];
GITT[i].zoneName = GathererInfoZones[gi_cont][gi_zone].zone;
GITT[i].typePercent = tonumber(format("%.1f",( amount / nodeCount ) * 100));
GITT[i].densityPercent = tonumber(format("%.1f",( amount / GI_totalCount ) * 100));
-- divide by zero check
if ( GITT[i].typePercent == nil ) then GITT[i].typePercent = 0; end
if ( GITT[i].densityPercent == nil ) then GITT[i].densityPercent = 0; end
GITT[i].amount = tonumber(amount);
GITT[i].nodeCount = nodeCount;
GITT[i].gi = gatherInfoOffset + i;
i = i + 1;
else
GITT[found].amount = GITT[found].amount + tonumber(amount);
GITT[found].typePercent = tonumber(format("%.1f",( GITT[found].amount / GITT[found].nodeCount ) * 100));
GITT[found].densityPercent = tonumber(format("%.1f",( GITT[found].amount / GI_totalCount ) * 100));
-- divide by zero check
if ( GITT[found].typePercent == nil ) then GITT[found].typePercent = 0; end
if ( GITT[found].densityPercent == nil ) then GITT[found].densityPercent = 0; end
found = 0;
end
end
end
end
end
end
end
end
local lastGITTindex = i - 1;
SortGathererInfo(GathererInfo_LastSearchSortType, false, "Search");
GathererInfo_Searchtotalcount:SetText(string.gsub(string.gsub(GATHERER_SEARCH_SUMMARY, "#", GI_totalCount), "&", lastGITTindex));
end
end
-- Add items in display frame
function GathererInfo_additem_searchtable(contName, gatherNumber, zoneName, typePercent, densityPercent, GIlocation, GIIndex)
if ( GIlocation < GATHERERINFO_TO_DISPLAY +1) then
getglobal("GathererInfo_SearchFrameButton"..GIlocation).gatherIndex = GIIndex;
getglobal("GathererInfo_SearchFrameButton"..GIlocation.."Type"):SetText(contName);
getglobal("GathererInfo_SearchFrameButton"..GIlocation.."Gatherable"):SetText(zoneName);
getglobal("GathererInfo_SearchFrameButton"..GIlocation.."Number"):SetText(gatherNumber);
getglobal("GathererInfo_SearchFrameButton"..GIlocation.."TypePercent"):SetText(typePercent);
getglobal("GathererInfo_SearchFrameButton"..GIlocation.."DensityPercent"):SetText(densityPercent);
getglobal("GathererInfo_SearchFrameButton"..GIlocation):Show();
end
end
-- ***********************************************************
-- Tab selection code
function ToggleGathererInfo_Dialog(tab)
local subFrame = getglobal(tab);
if ( subFrame ) then
PanelTemplates_SetTab(GathererInfo_DialogFrame, subFrame:GetID());
if ( GathererInfo_DialogFrame:IsVisible() ) then
PlaySound("igCharacterInfoTab");
GathererInfo_DialogFrame_ShowSubFrame(tab);
else
ShowUIPanel(GathererInfo_DialogFrame);
GathererInfo_DialogFrame_ShowSubFrame(tab);
end
end
end
function GathererInfo_DialogFrame_ShowSubFrame(frameName)
for index, value in GATHERERINFO_SUBFRAMES do
if ( value == frameName ) then
getglobal(value):Show()
else
getglobal(value):Hide();
end
end
end
function GathererInfoFrameTab_OnClick()
if ( this:GetName() == "GathererInfo_DialogFrameTab1" ) then
ToggleGathererInfo_Dialog("GathererInfo_ReportFrame");
elseif ( this:GetName() == "GathererInfo_DialogFrameTab2" ) then
ToggleGathererInfo_Dialog("GathererInfo_SearchFrame");
end
PlaySound("igCharacterInfoTab");
end