⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gathererinfo.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
		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 Gather_DB_TypeIndex 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 = Gather_DB_TypeIndex[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 = Gather_DB_TypeIndex[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 = Gather_DB_TypeIndex[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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -