欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

informant.lua

时间太紧了
LUA
第 1 页 / 共 2 页
字号:
		end	end	if (getFilter('show-stack')) then		if (stacks > 1) then			EnhTooltip.AddLine(string.format(_INFM('FrmtInfoStx'), stacks), nil, embedded)		end	end	if (getFilter('show-merchant')) then		if (itemInfo.vendors) then			local merchantCount = table.getn(itemInfo.vendors)			if (merchantCount > 0) then				EnhTooltip.AddLine(string.format(_INFM('FrmtInfoMerchants'), merchantCount), nil, embedded)				EnhTooltip.LineColor(0.5, 0.8, 0.5)			end		end	end	if (getFilter('show-usage')) then		local reagentInfo = ""		if (itemInfo.classText) then			reagentInfo = string.format(_INFM('FrmtInfoClass'), itemInfo.classText)			EnhTooltip.AddLine(reagentInfo, nil, embedded)			EnhTooltip.LineColor(0.6, 0.4, 0.8)		end		if (itemInfo.usedList and itemInfo.usageText) then			if (table.getn(itemInfo.usedList) > 2) then				local currentUseLine = nilSafeString(itemInfo.usedList[1])..", "..nilSafeString(itemInfo.usedList[2])..","				reagentInfo = string.format(_INFM('FrmtInfoUse'), currentUseLine)				EnhTooltip.AddLine(reagentInfo, nil, embedded)				EnhTooltip.LineColor(0.6, 0.4, 0.8)				for index = 3, table.getn(itemInfo.usedList), 2 do					if (itemInfo.usedList[index+1]) then						reagentInfo = whitespace(string.len(_INFM('FrmtInfoUse')) + 3)..nilSafeString(itemInfo.usedList[index])..", "..nilSafeString(itemInfo.usedList[index+1])..","						EnhTooltip.AddLine(reagentInfo, nil, embedded)						EnhTooltip.LineColor(0.6, 0.4, 0.8)					else						reagentInfo = whitespace(string.len(_INFM('FrmtInfoUse')) + 3)..nilSafeString(itemInfo.usedList[index])						EnhTooltip.AddLine(reagentInfo, nil, embedded)						EnhTooltip.LineColor(0.6, 0.4, 0.8)					end				end			else				reagentInfo = string.format(_INFM('FrmtInfoUse'), itemInfo.usageText)				EnhTooltip.AddLine(reagentInfo, nil, embedded)				EnhTooltip.LineColor(0.6, 0.4, 0.8)			end		end	end	if (getFilter('show-quest')) then		if (itemInfo.quests) then			local questCount = itemInfo.questCount			if (questCount > 0) then				EnhTooltip.AddLine(string.format(_INFM('FrmtInfoQuest'), questCount), nil, embedded)				EnhTooltip.LineColor(0.5, 0.5, 0.8)			end		end	endendfunction nilSafeString(str)	if (not str) then str = "" end	return str;endfunction whitespace(length)	local spaces = ""	while length ~= 0 do		spaces = spaces.." "		length = length - 1	end	return spacesendfunction showHideInfo()	if (InformantFrame:IsVisible()) then		InformantFrame:Hide()	elseif (itemInfo) then		InformantFrameTitle:SetText(_INFM('FrameTitle'))		-- Woohoo! We need to provide any information we can from the item currently in itemInfo		local quality = itemInfo.itemQuality or itemInfo.quality or 0		local color = "ffffff"		if (quality == 4) then color = "a335ee"		elseif (quality == 3) then color = "0070dd"		elseif (quality == 2) then color = "1eff00"		elseif (quality == 0) then color = "9d9d9d"		end		clear()		addLine(string.format(_INFM('InfoHeader'), color, itemInfo.itemName))		local buy = itemInfo.itemBuy or itemInfo.buy or 0		local sell = itemInfo.itemSell or itemInfo.sell or 0		local quant = itemInfo.itemQuant or itemInfo.quantity or 0		local count = itemInfo.itemCount or 1		if ((buy > 0) or (sell > 0)) then			local bgsc = EnhTooltip.GetTextGSC(buy, true)			local sgsc = EnhTooltip.GetTextGSC(sell, true)			if (count and (count > 1)) then				local bqgsc = EnhTooltip.GetTextGSC(buy*count, true)				local sqgsc = EnhTooltip.GetTextGSC(sell*count, true)				addLine(string.format(_INFM('FrmtInfoBuymult'), count, bgsc)..": "..bqgsc, "ee8822")				addLine(string.format(_INFM('FrmtInfoSellmult'), count, sgsc)..": "..sqgsc, "ee8822")			else				addLine(string.format(_INFM('FrmtInfoBuy'))..": "..bgsc, "ee8822")				addLine(string.format(_INFM('FrmtInfoSell'))..": "..sgsc, "ee8822")			end		end		if (itemInfo.stack > 1) then			addLine(string.format(_INFM('FrmtInfoStx'), itemInfo.stack))		end		local reagentInfo = ""		if (itemInfo.classText) then			reagentInfo = string.format(_INFM('FrmtInfoClass'), itemInfo.classText)			addLine(reagentInfo, "aa66ee")		end		if (itemInfo.usageText) then			reagentInfo = string.format(_INFM('FrmtInfoUse'), itemInfo.usageText)			addLine(reagentInfo, "aa66ee")		end		if (itemInfo.isPlayerMade) then			addLine(string.format(_INFM('InfoPlayerMade'), itemInfo.reqLevel, itemInfo.reqSkillName), "5060ff")		end		if (itemInfo.quests) then			local questCount = itemInfo.questCount			if (questCount > 0) then				addLine("")				addLine(string.format(_INFM('FrmtInfoQuest'), questCount), nil, embed)				addLine(string.format(_INFM('InfoQuestHeader'), questCount), "70ee90")				for pos, quest in itemInfo.quests do					addLine(string.format(_INFM('InfoQuestName'), quest.count, quest.name, quest.level), "80ee80")				end				addLine(string.format((_INFM('InfoQuestSource')).." WoWGuru.com"));			end		end		if (itemInfo.vendors) then			local vendorCount = table.getn(itemInfo.vendors)			if (vendorCount > 0) then				addLine("")				addLine(string.format(_INFM('InfoVendorHeader'), vendorCount), "ddff40")				for pos, merchant in itemInfo.vendors do					addLine(string.format(" ".._INFM('InfoVendorName'), merchant), "eeee40")				end			end		end		InformantFrame:Show()	else		clear()		addLine(_INFM('InfoNoItem'), "ff4010")		InformantFrame:Show()	endendfunction onQuit()	if (not InformantConfig.position) then		InformantConfig.position = { }	end	InformantConfig.position.x, InformantConfig.position.y = InformantFrame:GetCenter()endfunction onLoad()	this:RegisterEvent("ADDON_LOADED")	if (not InformantConfig) then		InformantConfig = {}		setFilterDefaults()	end	InformantFrameTitle:SetText(_INFM('FrameTitle'))--	Informant.InitTrades();endlocal function frameLoaded()	Stubby.RegisterEventHook("PLAYER_LEAVING_WORLD", "Informant", onQuit)	Stubby.RegisterFunctionHook("EnhTooltip.AddTooltip", 300, tooltipHandler)	onLoad()	-- Setup the default for stubby to always load (people can override this on a	-- per toon basis)	Stubby.SetConfig("Informant", "LoadType", "always", true)	-- Register our temporary command hook with stubby	Stubby.RegisterBootCode("Informant", "CommandHandler", [[		local function cmdHandler(msg)			local i,j, cmd, param = string.find(string.lower(msg), "^([^ ]+) (.+)$")			if (not cmd) then cmd = string.lower(msg) end			if (not cmd) then cmd = "" end			if (not param) then param = "" end			if (cmd == "load") then				if (param == "") then					Stubby.Print("Manually loading Informant...")					LoadAddOn("Informant")				elseif (param == "always") then					Stubby.Print("Setting Informant to always load for this character")					Stubby.SetConfig("Informant", "LoadType", param)					LoadAddOn("Informant")				elseif (param == "never") then					Stubby.Print("Setting Informant to never load automatically for this character (you may still load manually)")					Stubby.SetConfig("Informant", "LoadType", param)				else					Stubby.Print("Your command was not understood")				end			else				Stubby.Print("Informant is currently not loaded.")				Stubby.Print("  You may load it now by typing |cffffffff/informant load|r")				Stubby.Print("  You may also set your loading preferences for this character by using the following commands:")				Stubby.Print("  |cffffffff/informant load always|r - Informant will always load for this character")				Stubby.Print("  |cffffffff/informant load never|r - Informant will never load automatically for this character (you may still load it manually)")			end		end		SLASH_INFORMANT1 = "/informant"		SLASH_INFORMANT2 = "/inform"		SLASH_INFORMANT3 = "/info"		SLASH_INFORMANT4 = "/inf"		SlashCmdList["INFORMANT"] = cmdHandler	]]);	Stubby.RegisterBootCode("Informant", "Triggers", [[		local loadType = Stubby.GetConfig("Informant", "LoadType")		if (loadType == "always") then			LoadAddOn("Informant")		else			Stubby.Print("]].._INFM('MesgNotLoaded')..[[");		end	]]);endfunction onVariablesLoaded()	setFilterDefaults()	InformantFrameTitle:SetText(_INFM('FrameTitle'))	if (InformantConfig.position) then		InformantFrame:ClearAllPoints()		InformantFrame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", InformantConfig.position.x, InformantConfig.position.y)	end	if (not InformantConfig.welcomed) then		clear()		addLine(_INFM('Welcome'))		InformantConfig.welcomed = true	end	-- Restore key bindings	-- This workaround is required for LoadOnDemand addons since their saved	-- bindings are deleted upon login.	local profile = getKeyBindProfile();	if (InformantConfig and InformantConfig.bindings) then		if (not	InformantConfig.bindings[profile]) then profile = 'global'; end		if (InformantConfig.bindings[profile]) then			for _,key in ipairs(InformantConfig.bindings[profile]) do				SetBinding(key, 'INFORMANT_POPUPDOWN')			end		end	end	this:RegisterEvent("UPDATE_BINDINGS")	-- Monitor changes to bindings	Informant.InitCommands()endfunction onEvent(event)	if (event == "ADDON_LOADED" and string.lower(arg1) == "informant") then		onVariablesLoaded()		this:UnregisterEvent("ADDON_LOADED")	elseif (event == "UPDATE_BINDINGS") then		-- Store key bindings for Informant		local key1, key2 = GetBindingKey('INFORMANT_POPUPDOWN');		local profile = getKeyBindProfile();		if (not InformantConfig.bindings) then InformantConfig.bindings = {}; end		if (not InformantConfig.bindings[profile]) then InformantConfig.bindings[profile] = {}; end		InformantConfig.bindings[profile][1] = key1;		InformantConfig.bindings[profile][2] = key2;	endendfunction frameActive(isActive)	if (isActive) then		scrollUpdate(0)	endendfunction getRowCount()	return table.getn(lines)endfunction scrollUpdate(offset)	local numLines = getRowCount()	if (numLines > 25) then		if (not offset) then			offset = FauxScrollFrame_GetOffset(InformantFrameScrollBar)		else			if (offset > numLines - 25) then offset = numLines - 25 end			FauxScrollFrame_SetOffset(InformantFrameScrollBar, offset)		end	else		offset = 0	end	local line	for i=1, 25 do		line = lines[i+offset]		local f = getglobal("InformantFrameText"..i)		if (line) then			f:SetText(line)			f:Show()		else			f:Hide()		end	end	if (numLines > 25) then		FauxScrollFrame_Update(InformantFrameScrollBar, numLines, 25, numLines)		InformantFrameScrollBar:Show()	else		InformantFrameScrollBar:Hide()	endendfunction testWrap(text)	InformantFrameTextTest:SetText(text)	if (InformantFrameTextTest:GetWidth() < InformantFrame:GetWidth() - 20) then		return text, ""	end	local pos, test, best, rest	best = text	rest = nil	pos = string.find(text, " ")	while (pos) do		test = string.sub(text, 1, pos-1)		InformantFrameTextTest:SetText(test)		if (InformantFrameTextTest:GetWidth() < InformantFrame:GetWidth() - 20) or (not rest) then			best = test			rest = string.sub(test, pos+1)		else			break		end		pos = string.find(text, " ", pos+1)	end	return best, restendfunction addLine(text, color, level)	if (text == nil) then return end	if (not level) then level = 1 end	if (level > 100) then		return	end	if (type(text) == "table") then		for pos, line in text do			addLine(line, color, level)		end		return	end	if (not text) then		table.insert(lines, "nil")	else		local best, rest = testWrap(text)		if (color) then			table.insert(lines, string.format("|cff%s%s|r", color, best))		else			table.insert(lines, best)		end		if (rest) and (rest ~= "") then			addLine(rest, color, level+1)		end	end	scrollUpdate()endfunction clear()	lines = {}	scrollUpdate()endfunction setFilterDefaults()	if (not InformantConfig.filters) then InformantConfig.filters = {}; end	for k,v in pairs(filterDefaults) do		if (InformantConfig.filters[k] == nil) then			InformantConfig.filters[k] = v;		end	endend-- Key binding helper functionsfunction getKeyBindProfile()	if (IsAddOnLoaded("PerCharBinding")) then		return GetRealmName() .. ":" .. UnitName("player")	end	return 'global'end-- GLOBAL OBJECTInformant = {	version = INFORMANT_VERSION,	GetItem = getItem,	GetRowCount = getRowCount,	AddLine = addLine,	Clear = clear,	ShowHideInfo = showHideInfo,	-- These functions are only meant for internal use.	SetSkills = setSkills,	SetRequirements = setRequirements,	SetVendors = setVendors,	SetDatabase = setDatabase,	FrameActive = frameActive,	FrameLoaded = frameLoaded,	ScrollUpdate = scrollUpdate,	GetFilter = getFilter,	GetFilterVal = getFilterVal,	GetLocale = getLocale,	OnEvent = onEvent,	SetFilter = setFilter,	SetFilterDefaults = setFilterDefaults,}

⌨️ 快捷键说明

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