vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Gatherer Report/Search UI
3 ]]--
4  
5 -- Scrolling variables
6 GATHERERINFO_TO_DISPLAY=15;
7 GATHERERINFO_FRAME_HEIGHT=15;
8 GATHERERINFO_SUBFRAMES = { "GathererInfo_ReportFrame", "GathererInfo_SearchFrame" };
9  
10 -- Defaults
11 currentNode = "";
12 GathererInfo_LastSortType = "gtype";
13 GathererInfo_LastSearchSortType= "Cname";
14 GathererInfo_AutoRegion = true;
15 GathererInfo_LastSortReverse = false;
16  
17 GathererInfoContinents = {};
18 GathererInfoZones = {};
19  
20 numGathererInfo = 0;
21 GI_totalCount = 0;
22  
23  
24 -- show display frame
25 function showGathererInfo(tab)
26 local myTab = 1;
27 if ( tab ) then myTab = tab; end;
28  
29 if ( not GathererInfo_DialogFrame:IsShown() ) then
30 GathererInfo_DialogFrame:Show();
31 PanelTemplates_SetTab(GathererInfo_DialogFrame, myTab);
32 ToggleGathererInfo_Dialog(GATHERERINFO_SUBFRAMES[myTab]);
33 else
34 GathererInfo_DialogFrame:Hide();
35 end
36 end
37  
38 function GathererInfo_LoadContinents(...)
39 for c=1, arg.n, 1 do
40 GathererInfoContinents[c] = {}
41 GathererInfoContinents[c] = arg[c];
42 GathererInfoContinents[arg[c]] = c;
43 GathererInfo_LoadZones(c, GetMapZones(c));
44 end
45 end
46  
47 function GathererInfo_LoadZones(c, ...)
48 for z=1, arg.n, 1 do
49 local zname = arg[z];
50 if ( not GathererInfoZones[c] ) then GathererInfoZones[c] = {}; end
51 GathererInfoZones[c][zname] = { continent=c, zone=z };
52 GathererInfoZones[c][z] = { continent=c, zone=zname };
53 end
54 end
55 -- ********************************************************************
56 -- dropdown menu functions
57 -- Continent
58 function GathererInfo_LocContinentDropDown_Initialize()
59 local index;
60 local info = {};
61  
62 for index in GatherItems do
63 -- grab zone text from table initiated by Gatherer Main
64 info.text = GathererInfoContinents[index];
65 info.checked = nil;
66 info.func = GathererInfo_LocContinentDropDown_OnClick;
67 UIDropDownMenu_AddButton(info);
68 end
69 end
70  
71 function GathererInfo_LocContinentDropDown_OnClick()
72 UIDropDownMenu_SetSelectedID(GathererInfo_LocContinentDropDown, this:GetID());
73 UIDropDownMenu_SetSelectedID(GathererInfo_LocZoneDropDown, 0);
74  
75 UIDropDownMenu_SetText("", GathererInfo_LocZoneDropDown);
76  
77 UIDropDownMenu_ClearAll(GathererInfo_LocZoneDropDown);
78 UIDropDownMenu_Initialize(GathererInfo_LocZoneDropDown, GathererInfo_LocZoneDropDown_Initialize);
79  
80 local j=1;
81 while (j < GATHERERINFO_TO_DISPLAY+1) do
82 getglobal("GathererInfo_FrameButton"..j):Hide();
83 j = j+1;
84 end
85  
86 end
87  
88 -- Zone
89 function GathererInfo_LocZoneDropDown_Initialize()
90 local index;
91 local info = {};
92 local gi_cont, gi_t_cont;
93  
94 gi_t_cont = UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown);
95 if ( gi_t_cont and gi_t_cont ~= nil and gi_t_cont ~= "") then
96 gi_cont = GathererInfoContinents[gi_t_cont];
97  
98 for index in GatherItems[gi_cont] do
99 -- grab zone text from table initiated by Gatherer Main
100 info.text = GathererInfoZones[gi_cont][index].zone;
101 info.checked = nil;
102 info.func = GathererInfo_LocZoneDropDown_OnClick;
103 UIDropDownMenu_AddButton(info);
104 end
105 end
106 end
107  
108 function GathererInfo_LocZoneDropDown_OnClick()
109 local gi_cont, gi_zone;
110 local l_zone, node_idx, index;
111  
112 UIDropDownMenu_SetSelectedID(GathererInfo_LocZoneDropDown, this:GetID());
113  
114 GathererInfo_AutoRegion = false;
115  
116 gi_cont = GathererInfoContinents[UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown)];
117 gi_zone = GathererInfoZones[gi_cont][UIDropDownMenu_GetText(GathererInfo_LocZoneDropDown)].zone;
118  
119 for l_zone in GatherItems[gi_cont] do
120 GI_totalCount = 0;
121 numGathererInfo=0;
122  
123 for node_idx in GatherItems[gi_cont][gi_zone] do
124 for index in GatherItems[gi_cont][gi_zone][node_idx] do
125 GI_totalCount = GI_totalCount + GatherItems[gi_cont][gi_zone][node_idx][index].count;
126 numGathererInfo = numGathererInfo + 1;
127 end
128 end
129 end
130  
131 GathererInfo_Update();
132 end
133  
134 -- ********************************************************************
135 -- Display frame initialization
136 function GathererInfo_SetDefaultLocation()
137 local gi_t_cont = GathererInfoContinents[GetCurrentMapContinent()];
138 local gi_t_zone = GetRealZoneText();
139 local gi_cont = GetCurrentMapContinent();
140 local gi_zone = nil;
141 local l_cnt, l_zone;
142 local node_idx, index;
143 local found = 0;
144  
145 if ( GetRealZoneText() and GathererInfoZones[gi_cont] and GathererInfoZones[gi_cont][GetRealZoneText()] ) then
146 gi_zone = GathererInfoZones[gi_cont][GetRealZoneText()].zone;
147 else
148 gi_zone = "unknown";
149 end
150  
151 for l_cnt in GatherItems do
152 if( l_cnt == gi_cont ) then
153 UIDropDownMenu_SetSelectedName(GathererInfo_LocContinentDropDown, gi_t_cont);
154 UIDropDownMenu_SetText(gi_t_cont, GathererInfo_LocContinentDropDown);
155  
156 for l_zone in GatherItems[gi_cont] do
157 if ( l_zone == gi_zone and GathererInfo_AutoRegion == true) then
158 UIDropDownMenu_SetSelectedName(GathererInfo_LocZoneDropDown, gi_t_zone);
159 UIDropDownMenu_SetText(gi_t_zone, GathererInfo_LocZoneDropDown);
160  
161 GI_totalCount = 0;
162 numGathererInfo=0;
163 found = 1;
164  
165 for node_idx in GatherItems[gi_cont][gi_zone] do
166 for index in GatherItems[gi_cont][gi_zone][node_idx] do
167 GI_totalCount = GI_totalCount + GatherItems[gi_cont][gi_zone][node_idx][index].count;
168 numGathererInfo = numGathererInfo + 1;
169 end
170 end
171  
172 GathererInfo_Update();
173 end
174 end
175 end
176 end
177 end
178  
179 -- update display frame relative to scrollbar
180 function GathererInfo_Update()
181 local node_idx, index;
182 local gatherInfoOffset = FauxScrollFrame_GetOffset(GathererInfo_ListScrollFrame);
183 local gi_cont, gi_zone, gi_loc;
184 local gatherInfoIndex;
185 local showScrollBar = nil;
186 local button;
187 local i = 1;
188 GITT = {};
189  
190 -- Get continent, zone
191 if ( UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown) and
192 UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown) ~= "")
193 then
194 gi_cont = GathererInfoContinents[UIDropDownMenu_GetText(GathererInfo_LocContinentDropDown)];
195 else
196 gi_cont = GetCurrentMapContinent();
197 end
198  
199 if ( UIDropDownMenu_GetText(GathererInfo_LocZoneDropDown) and
200 UIDropDownMenu_GetText(GathererInfo_LocZoneDropDown) ~= "")
201 then
202 gi_zone = GathererInfoZones[gi_cont][UIDropDownMenu_GetText(GathererInfo_LocZoneDropDown)].zone;
203 else
204 if ( GetRealZoneText() and GathererInfoZones[gi_cont] and GathererInfoZones[gi_cont][GetRealZoneText()] ) then
205 gi_zone = GathererInfoZones[gi_cont][GetRealZoneText()].zone;
206 else
207 gi_zone = nil;
208 end
209 end
210 -- if loc exists in stored base
211 if ( GatherItems and gi_cont and gi_zone and GatherItems[gi_cont] and
212 GatherItems[gi_cont][gi_zone] )
213 then
214 if ( GatherItems and GatherItems[gi_cont] and GatherItems[gi_cont][gi_zone] )
215 then
216 local typeNodeCount = {};
217 typeNodeCount[0]=0;
218 typeNodeCount[1]=0;
219 typeNodeCount[2]=0;
220 typeNodeCount[3]=0;
221  
222 for node_idx in GatherItems[gi_cont][gi_zone] do
223 for index in GatherItems[gi_cont][gi_zone][node_idx] do
224 local gtype;
225 if ( type(GatherItems[gi_cont][gi_zone][node_idx][index].gtype) =="number" )
226 then
227 gtype = GatherItems[gi_cont][gi_zone][node_idx][index].gtype;
228 else
229 gtype = Gatherer_EGatherType[GatherItems[gi_cont][gi_zone][node_idx][index].gtype]
230 end
231  
232 typeNodeCount[gtype] = typeNodeCount[gtype] + GatherItems[gi_cont][gi_zone][node_idx][index].count;
233 end
234 end
235  
236 -- assign values
237 for node_idx in GatherItems[gi_cont][gi_zone] do
238 local nodeCount;
239 for index in GatherItems[gi_cont][gi_zone][node_idx] do
240 local amount = GatherItems[gi_cont][gi_zone][node_idx][index].count;
241 local gtype;
242 if ( type(GatherItems[gi_cont][gi_zone][node_idx][index].gtype) == "number" )
243 then
244 gtype = GatherItems[gi_cont][gi_zone][node_idx][index].gtype;
245 else
246 gtype = Gatherer_EGatherType[GatherItems[gi_cont][gi_zone][node_idx][index].gtype]
247 end
248  
249 nodeCount = typeNodeCount[gtype];
250  
251 local found=0;
252 local findex;
253 for findex in GITT do
254 if ( GITT[findex].name == node_idx ) then
255 found = findex;
256 end
257 end
258  
259 if ( found == 0 ) then
260 GITT[i] = {};
261 GITT[i].name = node_idx;
262  
263 if ( type(GatherItems[gi_cont][gi_zone][node_idx][index].gtype) == "number" ) then
264 GITT[i].gatherType = Gatherer_EGatherType[GatherItems[gi_cont][gi_zone][node_idx][index].gtype];
265 else
266 GITT[i].gatherType = GatherItems[gi_cont][gi_zone][node_idx][index].gtype;
267 end
268  
269 GITT[i].typePercent = tonumber(format("%.1f",( amount / nodeCount ) * 100));
270 GITT[i].densityPercent = tonumber(format("%.1f",( amount / GI_totalCount ) * 100));
271  
272 -- divide by zero check
273 if ( GITT[i].typePercent == nil ) then GITT[i].typePercent = 0; end
274 if ( GITT[i].densityPercent == nil ) then GITT[i].densityPercent = 0; end
275  
276 GITT[i].amount = tonumber(amount);
277  
278 if ( type(GatherItems[gi_cont][gi_zone][node_idx][index].icon) == "number" ) then
279 GITT[i].texture = Gather_IconSet["iconic"][GITT[i].gatherType][Gatherer_GetDB_IconIndex(GatherItems[gi_cont][gi_zone][node_idx][index].icon, GITT[i].gatherType)];
280 else
281 GITT[i].texture = Gather_IconSet["iconic"][GITT[i].gatherType][GatherItems[gi_cont][gi_zone][node_idx][index].icon];
282 end
283  
284 GITT[i].nodeCount = nodeCount;
285 GITT[i].gi = gatherInfoOffset + i;
286  
287 i = i + 1;
288 else
289 GITT[found].amount = GITT[found].amount + tonumber(amount);
290 GITT[found].typePercent = tonumber(format("%.1f",( GITT[found].amount / GITT[found].nodeCount ) * 100));
291 GITT[found].densityPercent = tonumber(format("%.1f",( GITT[found].amount / GI_totalCount ) * 100));
292  
293 -- divide by zero check
294 if ( GITT[found].typePercent == nil ) then GITT[found].typePercent = 0; end
295 if ( GITT[found].densityPercent == nil ) then GITT[found].densityPercent = 0; end
296 found = 0;
297 end
298 end
299 end
300 end
301 SortGathererInfo(GathererInfo_LastSortType, false);
302 GathererInfo_totalcount:SetText(string.gsub(string.gsub(GATHERER_REPORT_SUMMARY, "#", GI_totalCount), "&", numGathererInfo));
303 end
304 end
305  
306 -- Add items in display frame
307 function GathererInfo_additem_table(gatherName, gatherNumber, gatherTexture, gatherType, typePercent, densityPercent, GIlocation, GIIndex)
308  
309 if ( GIlocation < GATHERERINFO_TO_DISPLAY +1) then
310 getglobal("GathererInfo_FrameButton"..GIlocation).gatherIndex = GIIndex;
311 getglobal("GathererInfo_FrameButton"..GIlocation.."Icon"):SetTexture(gatherTexture);
312 getglobal("GathererInfo_FrameButton"..GIlocation.."Type"):SetText(gatherType);
313 getglobal("GathererInfo_FrameButton"..GIlocation.."Gatherable"):SetText(gatherName);
314 getglobal("GathererInfo_FrameButton"..GIlocation.."Number"):SetText(gatherNumber);
315 getglobal("GathererInfo_FrameButton"..GIlocation.."TypePercent"):SetText(typePercent);
316 getglobal("GathererInfo_FrameButton"..GIlocation.."DensityPercent"):SetText(densityPercent);
317 getglobal("GathererInfo_FrameButton"..GIlocation):Show();
318 end
319  
320 end
321  
322 -- **************************************************************************
323 -- Sort functions (common to Report and Search)
324 function SortGathererInfo(sortType, reverse, search)
325 local compstr = {};
326 local ref_ind = 0;
327 local ind, newind;
328 local displayed=1;
329 local offSet = FauxScrollFrame_GetOffset(GathererInfo_ListScrollFrame);
330 local key1, key2, key3;
331 local indexToShow=0;
332 local search_stub;
333  
334 if (search) then
335 search_stub = search;
336 else
337 search_stub = "";
338 end
339  
340 for ind in GITT do
341 indexToShow = indexToShow + 1;
342 compstr[ind]= {}
343  
344 -- report sort types
345 if ( sortType == "gtype" ) then -- keys: type, % per type, name (default sort)
346 key1 = GITT[ind].gatherType;
347 key2 = format("%.6f", GITT[ind].typePercent / 10000);
348 key3 = GITT[ind].name;
349 elseif ( sortType == "percent") then -- keys: % per type, type, name
350 key1 = format("%.6f", GITT[ind].typePercent / 10000);
351 key2 = GITT[ind].gatherType;
352 key3 = GITT[ind].name;
353 elseif ( sortType == "density" ) then -- keys: % density, type, name
354 key1 = format("%.6f", GITT[ind].densityPercent / 10000);
355 key2 = GITT[ind].gatherType;
356 key3 = GITT[ind].name;
357 elseif ( sortType == "name" ) then -- keys: name, type, % type
358 key1 = GITT[ind].name;
359 key2 = GITT[ind].gatherType;
360 key3 = format("%.6f", GITT[ind].typePercent / 10000);
361 elseif ( sortType == "amount" ) then -- keys: amount, type, name
362 key1 = format("%.6f", GITT[ind].amount / 10000);
363 key2 = GITT[ind].gatherType;
364 key3 = GITT[ind].name;
365 elseif ( search_stub and search_stub ~= "" ) then
366 offSet = FauxScrollFrame_GetOffset(GathererInfo_SearchListScrollFrame)
367 -- handle Search sort types
368 if ( sortType == "Cname" ) then
369 key1 = GITT[ind].contName;
370 key2 = GITT[ind].zoneName;
371 key3 = format("%.6f", GITT[ind].amount / 10000);
372 elseif ( sortType == "Zname" ) then
373 key1 = GITT[ind].zoneName;
374 key2 = GITT[ind].contName;
375 key3 = format("%.6f", GITT[ind].amount / 10000);
376 elseif ( sortType == "Namount" ) then
377 key1 = format("%.6f", GITT[ind].amount / 10000);
378 key2 = GITT[ind].contName;
379 key3 = GITT[ind].zoneName;
380 elseif ( sortType == "Npercent" ) then
381 key1 = format("%.6f", GITT[ind].typePercent / 10000);
382 key2 = GITT[ind].contName;
383 key3 = GITT[ind].zoneName;
384 elseif ( sortType == "Ndensity" ) then
385 key1 = format("%.6f", GITT[ind].densityPercent / 10000);
386 key2 = GITT[ind].contName;
387 key3 = GITT[ind].zoneName;
388 end
389 end
390  
391 -- build sort string
392 compstr[ind] = key1.."/"..key2.."/"..key3.."#"..ind
393 end
394  
395 -- call sort function
396 if ( reverse and not GathererInfo_LastSortReverse) then
397 sort(compstr, GI_reverse_sort);
398 GathererInfo_LastSortReverse = true;
399 else
400 sort(compstr);
401 GathererInfo_LastSortReverse = false;
402 end
403  
404 -- display sorted items
405 for newind, data in compstr do
406 recup = tonumber(strsub(data, string.find(data, "#")+1));
407  
408 if (newind == 1) then
409 ref_ind = GITT[1].gi
410 else
411 ref_ind= ref_ind + 1;
412 end
413  
414 if ( newind > offSet and displayed < GATHERERINFO_TO_DISPLAY+1) then
415 if ( search_stub == "" ) then
416 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);
417 elseif ( search_stub == "Search" ) then
418 GathererInfo_additem_searchtable(GITT[recup].contName, GITT[recup].amount,
419 GITT[recup].zoneName, GITT[recup].typePercent,
420 GITT[recup].densityPercent, newind - offSet, ref_ind)
421 end
422 displayed=displayed+1;
423 end
424 end
425  
426 local j=displayed;
427 while (j < GATHERERINFO_TO_DISPLAY+1) do
428 getglobal("GathererInfo_"..search_stub.."FrameButton"..j):Hide();
429 j = j+1;
430 end
431  
432 FauxScrollFrame_Update(getglobal("GathererInfo_"..search_stub.."ListScrollFrame"), indexToShow, GATHERERINFO_TO_DISPLAY, GATHERERINFO_FRAME_HEIGHT);
433  
434 if( search_stub == "") then
435 GathererInfo_LastSortType = sortType;
436 elseif ( search_stub == "Search" ) then
437 GathererInfo_LastSearchSortType = sortType;
438 end
439 end
440  
441 function GI_reverse_sort(token1, token2)
442 return token1 > token2;
443 end
444  
445 -- ***********************************************************
446 -- Search UI functions
447 function GathererInfo_GatherTypeDropDown_Initialize()
448 local index;
449 local info = {};
450  
451 for index in Gatherer_EGatherType do
452 if ( index ~= "Default" and type(index) == "string" ) then
453 info.text = index;
454 info.checked = nil;
455 info.func = GathererInfo_GatherType_OnClick;
456 UIDropDownMenu_AddButton(info);
457 end
458 end
459 end
460  
461 function GathererInfo_GatherType_OnClick()
462 UIDropDownMenu_SetSelectedID(GathererInfo_GatherTypeDropDown, this:GetID());
463 UIDropDownMenu_SetSelectedID(GathererInfo_GatherItemDropDown, 0);
464  
465 UIDropDownMenu_SetText("", GathererInfo_GatherItemDropDown);
466  
467 UIDropDownMenu_ClearAll(GathererInfo_GatherItemDropDown);
468 UIDropDownMenu_Initialize(GathererInfo_GatherItemDropDown, GathererInfo_GatherItemDropDown_Initialize);
469  
470 local j=1;
471 while (j < GATHERERINFO_TO_DISPLAY+1) do
472 getglobal("GathererInfo_SearchFrameButton"..j):Hide();
473 j = j+1;
474 end
475 end
476  
477 function GathererInfo_GatherItemDropDown_Initialize()
478 local index;
479 local info = {};
480 local selectedGatherTypeText = UIDropDownMenu_GetText(GathererInfo_GatherTypeDropDown);
481 local selectedGatherType
482  
483 if ( selectedGatherTypeText ) then
484 selectedGatherType = Gatherer_EGatherType[selectedGatherTypeText];
485  
486 for index in Gather_DB_IconIndex[selectedGatherType] do
487 if (index ~= "default" ) then
488 info.text = index;
489 info.checked = nil;
490 info.func = GathererInfo_GatherItem_OnClick;
491 UIDropDownMenu_AddButton(info);
492 end
493 end
494 end
495 end
496  
497 function GathererInfo_GatherItem_OnClick()
498 local item_to_search, search_item;
499 local gi_cont, gi_zone, gi_node, gi_index;
500  
501 UIDropDownMenu_SetSelectedID(GathererInfo_GatherItemDropDown, this:GetID());
502  
503 item_to_search = UIDropDownMenu_GetText(GathererInfo_GatherItemDropDown)
504 _, _, search_item = string.find(item_to_search, "^([^ ]+)");
505 GI_totalCount = 0;
506  
507 for gi_cont in GatherItems do
508 for gi_zone in GatherItems[gi_cont] do
509 for gi_node in GatherItems[gi_cont][gi_zone] do
510 if ( string.find(gi_node, search_item, 1, true) ) then
511 local skip_node=-1;
512 for gi_index in GatherItems[gi_cont][gi_zone][gi_node] do
513 if ( skip_node == -1 ) then
514 local locIcon, locGtype;
515  
516 -- check gather type
517 locGtype = GatherItems[gi_cont][gi_zone][gi_node][gi_index].gtype;
518 if ( locGtype and type(locGtype) == "string" ) then
519 locGtype = Gatherer_EGatherType[locGtype];
520 end
521 locIcon = GatherItems[gi_cont][gi_zone][gi_node][gi_index].icon;
522 if ( (type(locIcon) == "string" and locIcon == search_item) or
523 (type(locIcon) == "number" and locIcon == Gather_DB_IconIndex[locGtype][item_to_search] )) then
524 skip_node=0
525 GI_totalCount = GI_totalCount +1;
526 else
527 skip_node=1
528 end
529 elseif ( skip_node == 0 ) then
530 GI_totalCount = GI_totalCount +1;
531 else
532 break;
533 end
534 end
535 end
536 end
537 end
538 end
539  
540 GathererInfo_SearchUpdate();
541 end
542  
543 function GathererInfo_SearchUpdate()
544 local node_idx, index;
545 local gatherInfoOffset = FauxScrollFrame_GetOffset(GathererInfo_SearchListScrollFrame);
546 local item_to_search = UIDropDownMenu_GetText(GathererInfo_GatherItemDropDown);
547 local search_item;
548 local gi_cont, gi_zone, gi_loc;
549 local gatherInfoIndex;
550 local showScrollBar = nil;
551 local button;
552 local i = 1;
553 GITT = {};
554  
555 -- if database exists
556 if ( GatherItems and item_to_search ) then
557 _, _, search_item = string.find(item_to_search, "([^ ]+)");
558 for gi_cont in GatherItems do
559 if ( gi_cont == 0 or not GathererInfoZones[gi_cont] ) then
560 Gatherer_ChatPrint("Gatherer: Warning invalid continent index ("..gi_cont..") found in data.");
561 else
562 for gi_zone in GatherItems[gi_cont] do
563 if ( gi_zone == 0 or not GathererInfoZones[gi_cont][gi_zone] ) then
564 Gatherer_ChatPrint("Gatherer: Warning invalid zone index ("..gi_zone..") found in "..gi_cont.." continent data.");
565 else
566 local nodeCount = 0;
567 for node_idx in GatherItems[gi_cont][gi_zone] do
568 for index in GatherItems[gi_cont][gi_zone][node_idx] do
569 nodeCount = nodeCount + 1;
570 end
571 end
572 -- assign values
573 for node_idx in GatherItems[gi_cont][gi_zone] do
574 local skip_node = -1;
575 if ( string.find(node_idx, search_item, 1, true) ) then
576 local amount = 0;
577 for index in GatherItems[gi_cont][gi_zone][node_idx] do
578 if ( skip_node == -1 ) then
579 local locIcon, locGtype;
580  
581 -- check gather type
582 locGtype = GatherItems[gi_cont][gi_zone][node_idx][index].gtype;
583 if ( type(locGtype) == "string" ) then
584 locGtype = Gatherer_EGatherType[locGtype];
585 end
586 locIcon = GatherItems[gi_cont][gi_zone][node_idx][index].icon;
587 if ( (type(locIcon) == "string" and locIcon == search_item) or
588 (type(locIcon) == "number" and locIcon == Gather_DB_IconIndex[locGtype][item_to_search] )) then
589 skip_node=0
590 amount = amount + 1;
591 else
592 skip_node=1
593 end
594 elseif ( skip_node == 0 ) then
595 amount = amount + 1;
596 else
597 break;
598 end
599 end
600  
601 if ( skip_node ~= 1 ) then
602 local found=0;
603 local findex;
604 for findex in GITT do
605 if ( GITT[findex].zoneName and GathererInfoZones[gi_cont][gi_zone].zone and
606 GITT[findex].zoneName == GathererInfoZones[gi_cont][gi_zone].zone ) then
607 found = findex;
608 end
609 end
610  
611 if ( found == 0 ) then
612 GITT[i] = {};
613 GITT[i].contName = GathererInfoContinents[gi_cont];
614 GITT[i].zoneName = GathererInfoZones[gi_cont][gi_zone].zone;
615 GITT[i].typePercent = tonumber(format("%.1f",( amount / nodeCount ) * 100));
616 GITT[i].densityPercent = tonumber(format("%.1f",( amount / GI_totalCount ) * 100));
617  
618 -- divide by zero check
619 if ( GITT[i].typePercent == nil ) then GITT[i].typePercent = 0; end
620 if ( GITT[i].densityPercent == nil ) then GITT[i].densityPercent = 0; end
621  
622 GITT[i].amount = tonumber(amount);
623 GITT[i].nodeCount = nodeCount;
624 GITT[i].gi = gatherInfoOffset + i;
625 i = i + 1;
626 else
627 GITT[found].amount = GITT[found].amount + tonumber(amount);
628 GITT[found].typePercent = tonumber(format("%.1f",( GITT[found].amount / GITT[found].nodeCount ) * 100));
629 GITT[found].densityPercent = tonumber(format("%.1f",( GITT[found].amount / GI_totalCount ) * 100));
630  
631 -- divide by zero check
632 if ( GITT[found].typePercent == nil ) then GITT[found].typePercent = 0; end
633 if ( GITT[found].densityPercent == nil ) then GITT[found].densityPercent = 0; end
634  
635 found = 0;
636 end
637 end
638 end
639 end
640 end
641 end
642 end
643 end
644 local lastGITTindex = i - 1;
645 SortGathererInfo(GathererInfo_LastSearchSortType, false, "Search");
646 GathererInfo_Searchtotalcount:SetText(string.gsub(string.gsub(GATHERER_SEARCH_SUMMARY, "#", GI_totalCount), "&", lastGITTindex));
647 end
648 end
649  
650 -- Add items in display frame
651 function GathererInfo_additem_searchtable(contName, gatherNumber, zoneName, typePercent, densityPercent, GIlocation, GIIndex)
652  
653 if ( GIlocation < GATHERERINFO_TO_DISPLAY +1) then
654 getglobal("GathererInfo_SearchFrameButton"..GIlocation).gatherIndex = GIIndex;
655 getglobal("GathererInfo_SearchFrameButton"..GIlocation.."Type"):SetText(contName);
656 getglobal("GathererInfo_SearchFrameButton"..GIlocation.."Gatherable"):SetText(zoneName);
657 getglobal("GathererInfo_SearchFrameButton"..GIlocation.."Number"):SetText(gatherNumber);
658 getglobal("GathererInfo_SearchFrameButton"..GIlocation.."TypePercent"):SetText(typePercent);
659 getglobal("GathererInfo_SearchFrameButton"..GIlocation.."DensityPercent"):SetText(densityPercent);
660 getglobal("GathererInfo_SearchFrameButton"..GIlocation):Show();
661 end
662  
663 end
664 -- ***********************************************************
665 -- Tab selection code
666 function ToggleGathererInfo_Dialog(tab)
667 local subFrame = getglobal(tab);
668 if ( subFrame ) then
669 PanelTemplates_SetTab(GathererInfo_DialogFrame, subFrame:GetID());
670 if ( GathererInfo_DialogFrame:IsVisible() ) then
671 PlaySound("igCharacterInfoTab");
672 GathererInfo_DialogFrame_ShowSubFrame(tab);
673 else
674 ShowUIPanel(GathererInfo_DialogFrame);
675 GathererInfo_DialogFrame_ShowSubFrame(tab);
676 end
677 end
678 end
679  
680 function GathererInfo_DialogFrame_ShowSubFrame(frameName)
681 for index, value in GATHERERINFO_SUBFRAMES do
682 if ( value == frameName ) then
683 getglobal(value):Show()
684 else
685 getglobal(value):Hide();
686 end
687 end
688 end
689 function GathererInfoFrameTab_OnClick()
690 if ( this:GetName() == "GathererInfo_DialogFrameTab1" ) then
691 ToggleGathererInfo_Dialog("GathererInfo_ReportFrame");
692 elseif ( this:GetName() == "GathererInfo_DialogFrameTab2" ) then
693 ToggleGathererInfo_Dialog("GathererInfo_SearchFrame");
694 end
695 PlaySound("igCharacterInfoTab");
696 end